aboutsummaryrefslogtreecommitdiff
path: root/src/list2symbol.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
commit2b60d55c919e7588f5aff15936e83c300b3660bb (patch)
tree14d860de7f28083d3756ad91b627de70f26788f6 /src/list2symbol.c
parentc500bc542cb7cc78d6dac3f7da3bff626056b1aa (diff)
zexy-2.0:
- use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641
Diffstat (limited to 'src/list2symbol.c')
-rw-r--r--src/list2symbol.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/list2symbol.c b/src/list2symbol.c
new file mode 100644
index 0000000..cc40aa7
--- /dev/null
+++ b/src/list2symbol.c
@@ -0,0 +1,141 @@
+/******************************************************
+ *
+ * zexy - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 1999:forum::für::umläute:2004
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+#include "zexy.h"
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * list2symbol: convert a list into a single symbol
+*/
+
+/* ------------------------- list2symbol ------------------------------- */
+
+static t_class *list2symbol_class;
+
+typedef struct _list2symbol
+{
+ t_object x_obj;
+ int ac;
+ t_atom *ap;
+ t_symbol *s,*connector;
+} t_list2symbol;
+
+static void list2symbol_connector(t_list2symbol *x, t_symbol *s){
+ x->connector = s;
+}
+
+static void list2symbol_bang(t_list2symbol *x)
+{
+ t_atom *argv=x->ap;
+ int argc=x->ac;
+ char *result = 0;
+ int length = 0, len=0;
+ int i= argc;
+ char *connector=0;
+ char connlen=0;
+ if(x->connector)connector=x->connector->s_name;
+ if(connector)connlen=strlen(connector);
+
+ /* 1st get the length of the symbol */
+ if(x->s)length+=strlen(x->s->s_name);
+ else length-=connlen;
+
+ length+=i*connlen;
+
+ while(i--){
+ char buffer[MAXPDSTRING];
+ atom_string(argv++, buffer, MAXPDSTRING);
+ length+=strlen(buffer);
+ }
+
+ if (length<0){
+ outlet_symbol(x->x_obj.ob_outlet, gensym(""));
+ return;
+ }
+
+ result = (char*)getbytes((length+1)*sizeof(char));
+
+ /* 2nd create the symbol */
+ if (x->s){
+ char *buf = x->s->s_name;
+ strcpy(result+len, buf);
+ len+=strlen(buf);
+ if(i && connector){
+ strcpy(result+len, connector);
+ len += connlen;
+ }
+ }
+ i=argc;
+ argv=x->ap;
+ while(i--){
+ char buffer[MAXPDSTRING];
+ atom_string(argv++, buffer, MAXPDSTRING);
+ strcpy(result+len, buffer);
+ len += strlen(buffer);
+ if(i && connector){
+ strcpy(result+len, connector);
+ len += connlen;
+ }
+ }
+ result[length]=0;
+ outlet_symbol(x->x_obj.ob_outlet, gensym(result));
+ freebytes(result, (length+1)*sizeof(char));
+}
+
+static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv)
+{
+ x->s =s;
+ x->ac=argc;
+ x->ap=argv;
+
+ list2symbol_bang(x);
+}
+
+static void list2symbol_list(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv)
+{
+ list2symbol_anything(x, 0, argc, argv);
+}
+static void *list2symbol_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_list2symbol *x = (t_list2symbol *)pd_new(list2symbol_class);
+
+ outlet_new(&x->x_obj, 0);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym(""));
+ x->connector = gensym(" ");
+ list2symbol_anything(x, 0, argc, argv);
+
+ return (x);
+}
+
+static void list2symbol_free(t_list2symbol *x)
+{}
+
+
+void list2symbol_setup(void)
+{
+ list2symbol_class = class_new(gensym("list2symbol"), (t_newmethod)list2symbol_new,
+ (t_method)list2symbol_free, sizeof(t_list2symbol), 0, A_GIMME, 0);
+
+ class_addcreator((t_newmethod)list2symbol_new, gensym("l2s"), A_GIMME, 0);
+ class_addbang (list2symbol_class, list2symbol_bang);
+ class_addlist (list2symbol_class, list2symbol_list);
+ class_addanything(list2symbol_class, list2symbol_anything);
+ class_addmethod (list2symbol_class, (t_method)list2symbol_connector, gensym(""), A_SYMBOL, 0);
+
+ class_sethelpsymbol(list2symbol_class, gensym("zexy/list2symbol"));
+ zexy_register("list2symbol");
+}