diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2011-03-11 05:51:51 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2011-03-11 05:51:51 +0000 |
commit | 592afcf950b33b468ea472228eef9c1b12d73477 (patch) | |
tree | fe270e3f95b810efd3cff32c0191d3ebf3b54864 /logpost.c | |
parent | 4d115fa60ada0e8be73c456efe6d6f56c8a56792 (diff) |
made logpost also use args2symbol()
svn path=/trunk/externals/log/; revision=15027
Diffstat (limited to 'logpost.c')
-rw-r--r-- | logpost.c | 74 |
1 files changed, 31 insertions, 43 deletions
@@ -1,8 +1,6 @@ #include "m_pd.h" -#include <string.h> -/* -------------------------- logpost ------------------------------ */ static t_class *logpost_class; typedef struct _logpost @@ -12,6 +10,22 @@ typedef struct _logpost t_symbol* tag; } t_logpost; +static t_symbol* args2symbol(int argc, t_atom *argv) +{ + t_symbol* s; + char* buf; + int bufsize; + t_binbuf *bb = binbuf_new(); + binbuf_add(bb, argc, argv); + binbuf_gettext(bb, &buf, &bufsize); + buf = resizebytes(buf, bufsize, bufsize+1); + buf[bufsize] = 0; + s = gensym(buf); + freebytes(buf, bufsize+1); + binbuf_free(bb); + return s; +} + static void logpost_bang(t_logpost *x) { logpost(x, (const int)x->level, "%s%sbang", @@ -30,55 +44,30 @@ static void logpost_float(t_logpost *x, t_float f) x->tag->s_name, (*x->tag->s_name ? ": " : ""), f); } -static void logpost_list(t_logpost *x, t_symbol *s, int argc, t_atom *argv) -{ - int i; - if (argc && argv->a_type != A_SYMBOL) startpost("%s:", x->tag->s_name); - else startpost("%s%s%s", x->tag->s_name, - (*x->tag->s_name ? ": " : ""), - (argc > 1 ? s_list.s_name : (argc == 1 ? s_symbol.s_name : - s_bang.s_name))); - postatom(argc, argv); - endpost(); -} - static void logpost_anything(t_logpost *x, t_symbol *s, int argc, t_atom *argv) { - int i; - startpost("%s%s%s", x->tag->s_name, (*x->tag->s_name ? ": " : ""), - s->s_name); - postatom(argc, argv); - endpost(); + t_symbol* output = args2symbol(argc, argv); + logpost(x, (const int)x->level, "%s%s%s %s", + x->tag->s_name, (*x->tag->s_name ? ": " : ""), + s->s_name, output->s_name); } static void *logpost_new(t_symbol *sel, int argc, t_atom *argv) { t_logpost *x = (t_logpost *)pd_new(logpost_class); - if (argc == 0) - x->tag = &s_; - else if (argc == 1) - { - t_symbol *s = atom_getsymbolarg(0, argc, argv); - if (s != &s_) // we have a symbol - x->tag = s; - else // we have a float - { - x->level = atom_getfloatarg(0, argc, argv); - } - } - else + x->tag = &s_; + x->level = 2; + t_symbol *sym = atom_getsymbolarg(0, argc, argv); + if (sym != &s_) // oops, we have a symbol, use default + logpost(x, 3, "[logpost] got '%s' instead of a float for the first argument", + sym->s_name); + else // we have a float + x->level = atom_getfloatarg(0, argc, argv); + if (argc > 1) { - int bufsize; - char *buf; - t_binbuf *bb = binbuf_new(); - binbuf_add(bb, argc, argv); - binbuf_gettext(bb, &buf, &bufsize); - buf = resizebytes(buf, bufsize, bufsize+1); - buf[bufsize] = 0; - x->tag = gensym(buf); - freebytes(buf, bufsize+1); - binbuf_free(bb); + argc--; argv++; // lose the level arg + x->tag = args2symbol(argc, argv); } floatinlet_new(&x->x_obj, &x->level); return (x); @@ -95,6 +84,5 @@ void logpost_setup(void) class_addbang(logpost_class, logpost_bang); class_addfloat(logpost_class, logpost_float); class_addpointer(logpost_class, logpost_pointer); - class_addlist(logpost_class, logpost_list); class_addanything(logpost_class, logpost_anything); } |