From d1ad56f1da41e7a88eb9a52d6b0daaf145b54ea7 Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Fri, 4 Jul 2008 03:54:32 +0000 Subject: new pd~ and stdout objects in extra svn path=/trunk/; revision=10141 --- pd/extra/stdout/stdout.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pd/extra/stdout/stdout.c (limited to 'pd/extra/stdout/stdout.c') diff --git a/pd/extra/stdout/stdout.c b/pd/extra/stdout/stdout.c new file mode 100644 index 00000000..06c99308 --- /dev/null +++ b/pd/extra/stdout/stdout.c @@ -0,0 +1,51 @@ +/* stdout -- write messages to standard output. + + Copyright 2008 Miller Puckette + BSD license; see README.txt in this distribution for details. +*/ + +#include "m_pd.h" +#include +#include +static t_class *stdout_class; + +typedef struct _stdout +{ + t_object x_obj; +} t_stdout; + +static void *stdout_new(t_float fnonrepeat) +{ + t_stdout *x = (t_stdout *)pd_new(stdout_class); + return (x); +} + +static void stdout_anything(t_stdout *x, t_symbol *s, int argc, t_atom *argv) +{ + char msgbuf[MAXPDSTRING], *sp, *ep = msgbuf+MAXPDSTRING; + msgbuf[0] = 0; + strncpy(msgbuf, s->s_name, MAXPDSTRING); + msgbuf[MAXPDSTRING-1] = 0; + sp = msgbuf + strlen(msgbuf); + while (argc--) + { + if (sp < ep-1) + sp[0] = ' ', sp[1] = 0, sp++; + atom_string(argv++, sp, ep-sp); + sp += strlen(sp); + } + printf("%s;\n", msgbuf); +} + +static void stdout_flush(t_stdout *x) +{ + fflush(stdout); +} + +void stdout_setup(void) +{ + stdout_class = class_new(gensym("stdout"), (t_newmethod)stdout_new, + (t_method)stdout_flush, sizeof(t_stdout), 0, 0); + class_addmethod(stdout_class, (t_method)stdout_flush, gensym("flush"), 0); + class_addanything(stdout_class, stdout_anything); +} -- cgit v1.2.1