From f9043b5e93c901014a11355c6ea6dbbf0fbf41c8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Dec 2007 07:24:36 +0000 Subject: parses ? placeholders and generates inlets; crashes when you try to do just about anything svn path=/trunk/externals/hcs/; revision=9100 --- sql_query-help.pd | 24 +++++++++------- sql_query.c | 86 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 78 insertions(+), 32 deletions(-) diff --git a/sql_query-help.pd b/sql_query-help.pd index 204a91e..3f9a20f 100644 --- a/sql_query-help.pd +++ b/sql_query-help.pd @@ -1,5 +1,4 @@ -#N canvas 403 84 613 618 10; -#X obj 118 105 sql_query this is a test? more ?; +#N canvas 238 82 613 618 10; #X obj 362 244 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144 -1 -1 0 1; #X floatatom 420 276 5 0 0 0 - - -; @@ -24,11 +23,16 @@ #X msg 172 231 symbol Ang; #X obj 119 322 sql_query insert into table (name \, age) values (? \, ?); -#X connect 4 0 5 0; -#X connect 4 1 6 0; -#X connect 4 1 7 0; -#X connect 9 0 12 0; -#X connect 10 0 12 0; -#X connect 11 0 12 0; -#X connect 12 0 4 0; -#X connect 12 1 4 1; +#X obj 118 105 sql_query this is a test? more ? ? ? ?; +#X msg 39 235 bang; +#X connect 0 0 11 1; +#X connect 1 0 11 1; +#X connect 3 0 4 0; +#X connect 3 1 5 0; +#X connect 3 1 6 0; +#X connect 8 0 11 0; +#X connect 9 0 11 0; +#X connect 10 0 11 0; +#X connect 11 0 3 0; +#X connect 11 1 3 1; +#X connect 13 0 11 0; diff --git a/sql_query.c b/sql_query.c index 754e0b9..85f674e 100644 --- a/sql_query.c +++ b/sql_query.c @@ -44,44 +44,51 @@ */ static t_class *sql_query_class; +static t_class *proxy_inlet_class; + +typedef struct _proxy_inlet +{ + t_pd pd; + void *owner; + unsigned int id; +} t_proxy_inlet; + typedef struct _sql_query { t_object x_obj; t_binbuf* x_query_binbuf; - int inlet_count; + unsigned int placeholder_count; + struct _proxy_inlet*inlets; + t_atom** atoms; t_outlet* x_data_outlet; t_outlet* x_status_outlet; } t_sql_query; +/*------------------------------------------------------------------------------ + * FUNCTION PROTOTYPES + */ +static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom); /*------------------------------------------------------------------------------ * PROXY INLET FUNCTIONS */ -static t_class *proxy_inlet_class = NULL; -typedef struct _proxy_inlet -{ - t_pd pd; - void *owner; - unsigned int id; -} t_proxy_inlet; - -static void proxy_inlet_new(t_proxy_inlet *p, void *owner, unsigned int id) +static void proxy_inlet_new(t_proxy_inlet *p, t_object *owner, unsigned int id) { p->pd = proxy_inlet_class; p->owner = owner; p->id = id; + inlet_new(owner, &p->pd, 0, 0); } -static void proxy_inlet_anything(t_proxy_inlet *x, t_symbol *s, int argc, t_atom *argv) +static void proxy_inlet_anything(t_proxy_inlet *p, t_symbol *s, int argc, t_atom *argv) { - int i; - char buf[MAXPDSTRING]; - post("proxy_inlet_anything: %s", s -> s_name); + post("proxy_inlet_anything: %s %d", s->s_name, argc); + sql_query_set_atom(p->owner, p->id, s, argv); } static void proxy_inlet_setup(void) @@ -101,7 +108,33 @@ static void proxy_inlet_setup(void) * STANDARD CLASS FUNCTIONS */ -static void *sql_query_free(t_sql_query *x) +static void sql_query_set_atom(t_sql_query *x, int atom_num, t_symbol *s, t_atom *atom) +{ + char *buf; + int bufsize; + if( (&s == &s_symbol) || (&s == &s_list) ) + { + atom_string(atom, buf, bufsize); + } + else + { + atom_string(atom, buf, bufsize); + } + post("set atom %s", buf); + x->atoms[atom_num] = atom; +} + +static void sql_query_anything(t_sql_query *x, t_symbol *s, int argc, t_atom *argv) +{ + sql_query_set_atom(x, 0, s, argv); +} + +static void sql_query_bang(t_sql_query *x) +{ + +} + +static void sql_query_free(t_sql_query *x) { binbuf_free(x->x_query_binbuf); } @@ -109,10 +142,10 @@ static void *sql_query_free(t_sql_query *x) static void *sql_query_new(t_symbol *s, int argc, t_atom *argv) { DEBUG(post("sql_query_new");); - char *buf; + unsigned int i; int bufsize; + char *buf; char *current = NULL; - unsigned int total_inlets = 0; t_sql_query *x = (t_sql_query *)pd_new(sql_query_class); x->x_query_binbuf = binbuf_new(); @@ -120,14 +153,23 @@ static void *sql_query_new(t_symbol *s, int argc, t_atom *argv) binbuf_gettext(x->x_query_binbuf, &buf, &bufsize); buf[bufsize] = 0; + x->placeholder_count = 0; current = strchr(buf, PLACEHOLDER); while (current != NULL) { post("found placeholder %c", PLACEHOLDER); - total_inlets++; + x->placeholder_count++; current = strchr(current + 1, PLACEHOLDER); } - post("creating %d inlets", total_inlets); + post("creating %d inlets", x->placeholder_count); + x->inlets = getbytes(x->placeholder_count * sizeof(t_proxy_inlet)); + x->atoms = getbytes(x->placeholder_count * sizeof(t_atom *)); + for(i=1; i< x->placeholder_count; ++i) + { + proxy_inlet_new(&x->inlets[i], (t_object *)x, x->placeholder_count); + post("\tinlet %d", i); + } + x->x_data_outlet = outlet_new(&x->x_obj, 0); x->x_status_outlet = outlet_new(&x->x_obj, 0); @@ -139,14 +181,14 @@ void sql_query_setup(void) DEBUG(post("sql_query_setup");); sql_query_class = class_new(gensym("sql_query"), (t_newmethod)sql_query_new, - (t_newmethod)sql_query_free, + (t_method)sql_query_free, sizeof(t_sql_query), 0, A_GIMME, 0); /* add inlet datatype methods */ -// class_addbang(sql_query_class, (t_method) sql_query_bang); -// class_addanything(sql_query_class, (t_method) sql_query_anything); + class_addbang(sql_query_class, (t_method) sql_query_bang); + class_addanything(sql_query_class, (t_method) sql_query_anything); } -- cgit v1.2.1