From cedae1ddf578e27670f7727e1cc794c5fb955000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 7 Sep 2006 16:48:27 +0000 Subject: an object to write to the syslog (linux only) svn path=/trunk/externals/iem/syslog/; revision=5900 --- syslog.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 syslog.c (limited to 'syslog.c') diff --git a/syslog.c b/syslog.c new file mode 100644 index 0000000..908ef18 --- /dev/null +++ b/syslog.c @@ -0,0 +1,138 @@ +/****************************************************** + * + * syslog - implementation file + * + * copyleft (c) IOhannes m zmölnig + * + * 1999:forum::für::umläute:2004 + * + * institute of electronic music and acoustics (iem) + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + +/* + syslog : syslog-code for message-objects +*/ + + +#include +#include + +#include "m_pd.h" + +/* ------------------------- syslog ------------------------------- */ + +/* +MESSAGE SYSLOG: simple and easy +*/ + +static t_class *syslog_class; + +typedef struct _syslog +{ + t_object x_obj; + t_float x_level; +} t_syslog; + + +static void syslog_anything(t_syslog *x, t_symbol*s, t_int argc, t_atom*argv) +{ + int level=x->x_level; + char *result = 0; + int pos=0, i=0; + t_atom*ap; + int length=0; + + /* 1st get the length of the symbol */ + if(s)length+=strlen(s->s_name); + else length-=1; + length+=argc; + + i=argc; + ap=argv; + while(i--){ + char buffer[MAXPDSTRING]; + int len=0; + if(A_SYMBOL==ap->a_type){ + len=strlen(ap->a_w.w_symbol->s_name); + } else { + atom_string(ap, buffer, MAXPDSTRING); + len=strlen(buffer); + } + length+=len; + ap++; + } + + if(length<=0)return; + + result = (char*)getbytes((length+1)*sizeof(char)); + + if (s) { + char *buf = s->s_name; + strcpy(result+pos, buf); + pos+=strlen(buf); + if(i){ + strcpy(result+pos, " "); + pos += 1; + } + } + + ap=argv; + i=argc; + while(i--){ + if(A_SYMBOL==ap->a_type){ + strcpy(result+pos, ap->a_w.w_symbol->s_name); + pos+= strlen(ap->a_w.w_symbol->s_name); + } else { + char buffer[MAXPDSTRING]; + atom_string(ap, buffer, MAXPDSTRING); + strcpy(result+pos, buffer); + pos += strlen(buffer); + } + ap++; + if(i){ + strcpy(result+pos, " "); + pos++; + } + } + + result[length]=0; + if(result){ + syslog(level, "%s", result); + freebytes(result, length+1); + } + +} +static void syslog_free(t_syslog *x) +{ + closelog(); +} + +static void *syslog_new(t_symbol*s) +{ + t_syslog *x = (t_syslog *)pd_new(syslog_class); + x->x_level=LOG_NOTICE; + if(s&&s!=&s_){ + openlog(s->s_name, 0, LOG_USER); + } else { + openlog("puredata", 0, LOG_USER); + } + + floatinlet_new(&x->x_obj, &x->x_level); + return (x); +} + + +void syslog_setup(void) +{ + syslog_class = class_new(gensym("syslog"), (t_newmethod)syslog_new, + (t_method)syslog_free, sizeof(t_syslog), + 0, + A_DEFSYM, A_NULL); + + class_addanything(syslog_class, syslog_anything); +} -- cgit v1.2.1