Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16722
Modified Files: Tag: desiredata builtins.c Log Message: [unpack] checks types f s p again; also added e meaning any atom. ("e" stands for "element" because "a" is reserved for the real "anything")
Index: builtins.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/builtins.c,v retrieving revision 1.1.2.50 retrieving revision 1.1.2.51 diff -C2 -d -r1.1.2.50 -r1.1.2.51 *** builtins.c 30 Jul 2007 03:02:44 -0000 1.1.2.50 --- builtins.c 30 Jul 2007 04:26:01 -0000 1.1.2.51 *************** *** 1508,1512 **** --- 1508,1524 ---- t_int n; t_outlet **vec; + char *vat; }; + + static t_atomtype atomtype_from_letter(char c) { + switch (c) { + case 'e': return A_ATOM; + case 'f': return A_FLOAT; + case 's': return A_SYMBOL; + case 'p': return A_POINTER; + default: return A_CANT; + } + } + static void *unpack_new(t_symbol *s, int argc, t_atom *argv) { t_unpack *x = (t_unpack *)pd_new(unpack_class); *************** *** 1520,1540 **** x->n = argc; x->vec = (t_outlet **)getbytes(argc * sizeof(*x->vec)); ! t_outlet **u = x->vec; t_atom *ap=argv; ! for (int i=0; i < argc; ap++, i++) u[i] = outlet_new(x,0); return x; } static void unpack_list(t_unpack *x, t_symbol *s, int argc, t_atom *argv) { if (argc > x->n) argc = x->n; ! for (int i=argc-1; i>=0; i--) outlet_atom(x->vec[i],&argv[i]); } static void unpack_anything(t_unpack *x, t_symbol *s, int ac, t_atom *av) { ! t_atom *av2 = (t_atom *)getbytes((ac + 1) * sizeof(t_atom)); ! for (int i = 0; i < ac; i++) av2[i + 1] = av[i]; SETSYMBOL(av2, s); unpack_list(x, 0, ac+1, av2); free(av2); } ! static void unpack_free(t_unpack *x) {free(x->vec);} static void unpack_setup() { unpack_class = class_new2("unpack",unpack_new,unpack_free,sizeof(t_unpack),0,"*"); --- 1532,1567 ---- x->n = argc; x->vec = (t_outlet **)getbytes(argc * sizeof(*x->vec)); ! x->vat = (char *)getbytes(argc); t_atom *ap=argv; ! for (int i=0; i<argc; ap++, i++) { ! x->vec[i] = outlet_new(x,0); ! switch (argv[i].a_type) { ! case A_FLOAT: x->vat[i]='f'; break; ! case A_SYMBOL: { ! const char *s = atom_getstring(&argv[i]); ! if (strlen(s)<1 || (x->vat[i]=atomtype_from_letter(s[0]))==A_CANT) {error("%s: bad type", s); x->vat[i]='f';} ! break; ! } ! default: error("bad type"); ! } ! } return x; } static void unpack_list(t_unpack *x, t_symbol *s, int argc, t_atom *argv) { if (argc > x->n) argc = x->n; ! //for (int i=argc-1; i>=0; i--) outlet_atom(x->vec[i],&argv[i]); ! for (int i=argc-1; i>=0; i--) { ! if (x->vat[i]==A_ATOM || x->vat[i]==argv[i].a_type) outlet_atom(x->vec[i],&argv[i]); ! else error("type mismatch"); ! } } static void unpack_anything(t_unpack *x, t_symbol *s, int ac, t_atom *av) { ! t_atom *av2 = (t_atom *)getbytes((ac+1) * sizeof(t_atom)); ! for (int i=0; i<ac; i++) av2[i+1] = av[i]; SETSYMBOL(av2, s); unpack_list(x, 0, ac+1, av2); free(av2); } ! static void unpack_free(t_unpack *x) {free(x->vec); free(x->vat);} static void unpack_setup() { unpack_class = class_new2("unpack",unpack_new,unpack_free,sizeof(t_unpack),0,"*");