1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
19
(l) 1210:forum::f�r::uml�ute:1999
21
"makesymbol" is something between "symbol" and "makefilename",
22
thus storing and creating (formatted) symbols...
26
the use of only "%s" is really not very satisfying
28
split the entire format string into subformats with only
29
one format-placeholder ("%[^%]*[diufFgGxXoscpn]") .
30
split the entire format string into subformats with only one format-placeholder,
32
when a list comes in, evaluate each subformat (with prior type-conversion)
41
#define MAXSTRINGARGS 10
42
#define MAXSTRINGLENG MAXPDSTRING
44
/* ----------------------- makesymbol --------------------- */
46
static t_class *makesymbol_class;
48
typedef struct _makesymbol
57
static void reset_mask(t_makesymbol *x, t_symbol *s)
63
x->mask = "%s%s%s%s%s%s%s%s%s%s";
64
x->x_sym = gensym("");
68
typedef char cstring[MAXSTRINGLENG];
70
static t_symbol* list2symbol(char *masque, int argc, t_atom *argv)
72
cstring*buf=(cstring*)getbytes(MAXSTRINGARGS*sizeof(cstring));
76
for(i=0; i<MAXSTRINGARGS; i++)*buf[i]=0;
78
for (i=0; i<argc; i++) {
79
atom_string(argv+i, buf[i], MAXSTRINGLENG);
84
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]);
86
freebytes(buf, MAXSTRINGARGS*sizeof(cstring));
87
return (gensym(buffer));
90
static void makesymbol_list(t_makesymbol *x, t_symbol *s, int argc, t_atom *argv)
93
x->x_sym = list2symbol(x->mask, argc, argv);
94
outlet_symbol(x->x_obj.ob_outlet, x->x_sym);
97
static void makesymbol_bang(t_makesymbol *x)
99
outlet_symbol(x->x_obj.ob_outlet, x->x_sym);
103
static void *makesymbol_new(t_symbol *s, int argc, t_atom *argv)
105
t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class);
108
x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char));
113
atom_string(argv, x->buf, MAXSTRINGLENG);
114
x->x_sym = gensym(x->buf);
116
x->mask = "%s%s%s%s%s%s%s%s%s%s";
117
x->x_sym = gensym("");
120
outlet_new(&x->x_obj, &s_symbol);
121
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1"));
126
static void makesymbol_free(t_makesymbol *x)
128
freebytes(x->buf, MAXSTRINGLENG*sizeof(char));
132
static void makesymbol_helper(t_makesymbol *x)
135
post("\n%c makesymbol :: create a formatted symbol", HEARTSYMBOL);
136
post("<list of anything>\t: glue up to 10 list-elements to 1 formatted symbol\n"
137
"'bang'\t\t\t: re-output\n"
138
"'help'\t\t\t: view this"
139
"\ninlet2 : <format-string>: new format-string (symbol !)"
140
"\noutlet : <symbol>\t: formatted concatenation");
141
post("\ncreation:\"makesymbol [<format-string>]\": C-style format-string (%s only)", "%s");
144
void makesymbol_setup(void)
146
makesymbol_class = class_new(gensym("makesymbol"),
147
(t_newmethod)makesymbol_new, (t_method)makesymbol_free,
148
sizeof(t_makesymbol), 0, A_GIMME, 0);
150
class_addlist(makesymbol_class, makesymbol_list);
151
class_addbang(makesymbol_class, makesymbol_bang);
153
class_addmethod(makesymbol_class, (t_method)reset_mask, gensym("sym1"), A_SYMBOL, 0);
155
class_addmethod(makesymbol_class, (t_method)makesymbol_helper, gensym("help"), 0);
156
zexy_register("makesymbol");