aboutsummaryrefslogtreecommitdiff
path: root/shared/unstable/standalone.c
diff options
context:
space:
mode:
authorN.N. <krzyszcz@users.sourceforge.net>2004-12-08 15:45:27 +0000
committerN.N. <krzyszcz@users.sourceforge.net>2004-12-08 15:45:27 +0000
commit155fa2c04c7e415803e1546dcde0a47442eef4b3 (patch)
tree94a1714fee23703bddef850e7b5acb60a9c39631 /shared/unstable/standalone.c
parentd5a39ff6469f8762218c00a34f4b0a120a56332b (diff)
*** empty log message ***
svn path=/trunk/externals/miXed/; revision=2361
Diffstat (limited to 'shared/unstable/standalone.c')
-rw-r--r--shared/unstable/standalone.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/shared/unstable/standalone.c b/shared/unstable/standalone.c
new file mode 100644
index 0000000..5b780e9
--- /dev/null
+++ b/shared/unstable/standalone.c
@@ -0,0 +1,80 @@
+/* Copyright (c) 1997-2004 Miller Puckette, krzYszcz, and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* Parts of Pd API are duplicated here, as needed by standalone versions of
+ Pd modules. LATER standalones should be linked to the Pd API library. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "standalone.h"
+
+void *getbytes(size_t nbytes)
+{
+ void *ret;
+ if (nbytes < 1) nbytes = 1;
+ ret = (void *)calloc(nbytes, 1);
+ if (!ret)
+ fprintf(stderr, "ERROR: getbytes() failed -- out of memory");
+ return (ret);
+}
+
+void *resizebytes(void *old, size_t oldsize, size_t newsize)
+{
+ void *ret;
+ if (newsize < 1) newsize = 1;
+ if (oldsize < 1) oldsize = 1;
+ ret = (void *)realloc((char *)old, newsize);
+ if (newsize > oldsize && ret)
+ memset(((char *)ret) + oldsize, 0, newsize - oldsize);
+ if (!ret)
+ fprintf(stderr, "ERROR: resizebytes() failed -- out of memory");
+ return (ret);
+}
+
+void freebytes(void *fatso, size_t nbytes)
+{
+ free(fatso);
+}
+
+#define HASHSIZE 1024
+
+static t_symbol *symhash[HASHSIZE];
+
+static t_symbol *dogensym(char *s, t_symbol *oldsym)
+{
+ t_symbol **sym1, *sym2;
+ unsigned int hash1 = 0, hash2 = 0;
+ int length = 0;
+ char *s2 = s;
+ while (*s2)
+ {
+ hash1 += *s2;
+ hash2 += hash1;
+ length++;
+ s2++;
+ }
+ sym1 = symhash + (hash2 & (HASHSIZE-1));
+ while (sym2 = *sym1)
+ {
+ if (!strcmp(sym2->s_name, s)) return(sym2);
+ sym1 = &sym2->s_next;
+ }
+ if (oldsym) sym2 = oldsym;
+ else
+ {
+ sym2 = (t_symbol *)getbytes(sizeof(*sym2));
+ sym2->s_name = getbytes(length+1);
+ sym2->s_next = 0;
+ sym2->s_thing = 0;
+ strcpy(sym2->s_name, s);
+ }
+ *sym1 = sym2;
+ return (sym2);
+}
+
+t_symbol *gensym(char *s)
+{
+ return(dogensym(s, 0));
+}