#include "ext13.h" #include "m_pd.h" #include #include #include #include #ifdef NT #pragma warning( disable : 4244 ) #pragma warning( disable : 4305 ) #endif /* -------------------------- sprintf ------------------------------ */ static t_class *sprintf_class; typedef struct _sprintf { t_object x_obj; t_symbol *x_s; t_atom x_vec[10]; t_symbol *x_result; int x_count; } t_sprintf; static void *sprintf_new(t_symbol *s) { char *next; char match[2]; t_sprintf *x = (t_sprintf *)pd_new(sprintf_class); strcpy(match,"sf"); x->x_count=0; if (!s->s_name) s = gensym("%s"); x->x_s=s; next = x->x_s->s_name; while (next){ next = strchr (next,'%'); if (next){ next = strpbrk(next,match); post ("next now:%s",next); if (next){ if (!strncmp(next,"s",1)){ SETSYMBOL(&x->x_vec[x->x_count], gensym("0")); if ( x->x_count ){symbolinlet_new(&x->x_obj, &x->x_vec[x->x_count].a_w.w_symbol);} next++; x->x_count++; post("new symbol"); }else{/*must be d*/ SETFLOAT(&x->x_vec[x->x_count], 0); if ( x->x_count ){floatinlet_new(&x->x_obj, &x->x_vec[x->x_count].a_w.w_float);} next++; x->x_count++; post("new float"); } } } else{post ("no next, x_count:%d",x->x_count);}; } outlet_new(&x->x_obj, &s_symbol); return (x); } static void sprintf_bang(t_sprintf *x) { char result[MAXPDSTRING]; strcpy(result,""); /* post("gotz:%s,%f,fmt:%s,type:%d", x->x_vec[0].a_w.w_symbol->s_name,(float)x->x_vec[1].a_w.w_float,x->x_s->s_name,x->x_vec->a_type,);*/ if (x->x_count==2){ /* sprintf(result,x->x_s->s_name,"a",(float)5);*/ sprintf(result,x->x_s->s_name,x->x_vec[0].a_type == A_FLOAT ? (float)x->x_vec[0].a_w.w_float : *x->x_vec[0].a_w.w_symbol->s_name, x->x_vec[1].a_type == A_FLOAT ? (float)x->x_vec[1].a_w.w_float : *x->x_vec[1].a_w.w_symbol->s_name); post ("result:%s",result); } outlet_symbol(x->x_obj.ob_outlet,gensym(result)); } static void sprintf_symbol(t_sprintf *x, t_symbol *s) { x->x_vec[0].a_w.w_symbol = s; /* post("got:%s, type:%d", x->x_vec->a_w.w_symbol->s_name,x->x_vec->a_type);*/ sprintf_bang(x); } void sprintf_setup(void) { sprintf_class = class_new(gensym("sprintf"), (t_newmethod)sprintf_new, 0, sizeof(t_sprintf), 0, A_DEFSYM, 0); /*sprintf_free fehlt!!!*/ class_addbang(sprintf_class, sprintf_bang); class_addsymbol(sprintf_class, sprintf_symbol); /* class_addfloat(sprintf_class; sprintf_float);*/ }