aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-03-07 12:13:31 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-03-07 12:13:31 +0000
commit2243aed73c65c75981b37a7ff133f41732ceaff3 (patch)
treed05fd5783d9d0e2bb1d92fc37714f50c6391a6ca
parenta1be5724ee0497921c22eb576ced078fa197b2c3 (diff)
list2symbol now has a separator that can be defined by the users
svn path=/trunk/externals/zexy/; revision=456
-rw-r--r--examples/list2symbol.pd22
-rw-r--r--src/z_datetime.c2
-rw-r--r--src/z_strings.c86
3 files changed, 91 insertions, 19 deletions
diff --git a/examples/list2symbol.pd b/examples/list2symbol.pd
index 801803f..12c0592 100644
--- a/examples/list2symbol.pd
+++ b/examples/list2symbol.pd
@@ -1,16 +1,22 @@
-#N canvas 190 131 809 343 10;
+#N canvas 198 171 809 343 10;
#X obj 135 48 list2symbol;
#X text 219 48 convert a list into a symbol;
#X obj 457 50 l2s;
-#X symbolatom 75 230 50 0 0;
-#X obj 75 202 list2symbol;
-#X msg 75 156 list this was a list and is now a symbol;
-#X msg 159 177 anythings work fine too;
-#X obj 507 212 l2s my bonnie is over the ocean;
-#X obj 507 232 print;
-#X msg 507 191 bang;
+#X symbolatom 75 286 50 0 0;
+#X obj 75 258 list2symbol;
+#X msg 75 97 list this was a list and is now a symbol;
+#X msg 159 118 anythings work fine too;
+#X obj 507 268 l2s my bonnie is over the ocean;
+#X obj 507 288 print;
+#X msg 507 247 bang;
+#X symbolatom 147 223 10 0 0;
+#X msg 147 188 symbol --;
+#X text 230 187 by default \, list-elements are separated by spaces.
+You can set the separator to any symbol;
#X connect 4 0 3 0;
#X connect 5 0 4 0;
#X connect 6 0 4 0;
#X connect 7 0 8 0;
#X connect 9 0 7 0;
+#X connect 10 0 4 1;
+#X connect 11 0 10 0;
diff --git a/src/z_datetime.c b/src/z_datetime.c
index efe9d8c..d6b59a3 100644
--- a/src/z_datetime.c
+++ b/src/z_datetime.c
@@ -18,8 +18,8 @@
#include "zexy.h"
-#include <sys/timeb.h>
#include <time.h>
+#include <sys/timeb.h>
/* ----------------------- time --------------------- */
diff --git a/src/z_strings.c b/src/z_strings.c
index 4992d18..08314e8 100644
--- a/src/z_strings.c
+++ b/src/z_strings.c
@@ -166,19 +166,26 @@ static void strcmp_setup(void)
/* ------------------------- list2symbol ------------------------------- */
-/* compare 2 lists ( == for lists) */
-
static t_class *list2symbol_class;
typedef struct _list2symbol
{
t_object x_obj;
-
+#ifdef OLD
t_binbuf *bbuf;
+#endif
+ 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)
{
+#ifdef OLD
char *str=0, *s2;
int n=0;
@@ -190,40 +197,98 @@ static void list2symbol_bang(t_list2symbol *x)
outlet_symbol(x->x_obj.ob_outlet, gensym(s2));
freebytes(str, n);
freebytes(s2,n+1);
+#else
+ t_atom *argv=x->ap;
+ int argc=x->ac;
+ char *result = 0;
+ char string[MAXPDSTRING];
+ int length = 0;
+ int i= argc;
+
+ if (x->s){
+ char *buf = x->s->s_name;
+ int newlen = length + strlen(buf);
+ strcpy(string+length, buf);
+ length = newlen;
+ if(i && x->connector){
+ char *buf = x->connector->s_name;
+ newlen = length + strlen(buf);
+ strcpy(string+length, buf);
+ length = newlen;
+ }
+ }
+ while(i--){
+ char buffer[MAXPDSTRING];
+ int newlen;
+ atom_string(argv++, buffer, MAXPDSTRING);
+ newlen = length + strlen(buffer);
+ strcpy(string+length, buffer);
+ length = newlen;
+ if(i && x->connector){
+ char *buf = x->connector->s_name;
+ newlen = length + strlen(buf);
+ strcpy(string+length, buf);
+ length = newlen;
+ }
+ }
+ length = strlen(string);
+ result = (char*)getbytes((length+1)*sizeof(char));
+ strcpy(result, string);
+ result[length]=0;
+ outlet_symbol(x->x_obj.ob_outlet, gensym(result));
+ freebytes(result, (length+1)*sizeof(char));
+#endif
}
-static void list2symbol_list(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv)
-{
- binbuf_clear(x->bbuf);
- binbuf_add(x->bbuf, argc, argv);
-
- list2symbol_bang(x);
-}
static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv)
{
+#ifdef OLD
t_atom ap;
binbuf_clear(x->bbuf);
SETSYMBOL(&ap, s);
binbuf_add(x->bbuf, 1, &ap);
binbuf_add(x->bbuf, argc, argv);
+#else
+ x->s =s;
+ x->ac=argc;
+ x->ap=argv;
+#endif
list2symbol_bang(x);
}
+static void list2symbol_list(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv)
+{
+#ifdef OLD
+ binbuf_clear(x->bbuf);
+ binbuf_add(x->bbuf, argc, argv);
+#else
+ list2symbol_anything(x, 0, argc, argv);
+#endif
+ list2symbol_bang(x);
+}
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);
+#ifdef OLD
x->bbuf = binbuf_new();
binbuf_add(x->bbuf, argc, argv);
+#else
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym(""));
+ x->connector = gensym(" ");
+#endif
+ list2symbol_anything(x, 0, argc, argv);
return (x);
}
static void list2symbol_free(t_list2symbol *x)
{
+#ifdef OLD
binbuf_free(x->bbuf);
+#endif
}
@@ -236,6 +301,7 @@ static void list2symbol_setup(void)
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"));
}