Update of /cvsroot/pure-data/externals/control/popen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1381
Added Files: Makefile Makefilewin popen-help.pd popen.PNG popen.c Log Message: popen()
--- NEW FILE: popen-help.pd --- #N canvas 458 385 649 268 10; #X msg 121 28 echo lol; #X obj 121 48 popen; #X symbolatom 111 85 10 0 0 0 - - -; #X obj 168 75 bng 15 163840 50 0 empty empty empty 0 0 0 8 -62784 -237312 -237312; #X obj 168 93 tgl 15 0 empty empty empty 0 0 0 8 -62784 -237312 -237312 0 1; #X msg 170 29 echo roffl | sed s/fl/lmao/; #X obj 111 114 select roflmao; #X obj 189 88 tgl 42 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X text 16 10 popen(); #X text 41 159 so simple it should work on most any platform; #X text 39 176 always outputs a symbol; #X text 42 199 non-threaded to maintain right to left execution order ; #X text 41 218 always executes in a real shell (sh on linux , cmd on win (add a bash -c if you want it to run in a minGW/cygwin bash)) so stuff like || and < can be used..; #X obj 258 97 popen; #X msg 258 117 add2 $1; #X msg 303 103 Linux a 2.6.11-gentoo-r1 #4 Sun Mar 6 16:43:59 GMT 2005 x86_64 AMD Athlon(tm) 64 Processor 3000+ AuthenticAMD GNU/Linux ; #X msg 303 65 cat /proc/cpuinfo; #X msg 303 82 set; #X msg 253 65 uname -a; #X connect 0 0 1 0; #X connect 1 0 2 0; #X connect 1 1 3 0; #X connect 2 0 6 0; #X connect 3 0 4 0; #X connect 5 0 1 0; #X connect 6 0 7 0; #X connect 13 0 14 0; #X connect 14 0 15 0; #X connect 16 0 17 0; #X connect 16 0 13 0; #X connect 17 0 15 0; #X connect 18 0 17 0; #X connect 18 0 13 0;
--- NEW FILE: Makefile --- prefix=/usr/lib/pd
EXTERNALS = popen.c
all: $(EXTERNALS:.c=.pd_linux)
.SUFFIXES: .pd_linux
CFLAGS = -g -DUNIX -Wall -W -Wshadow -Wstrict-prototypes \ -Wno-unused -Wno-parentheses -Wno-switch -fPIC
INCLUDE = -I. -I.. -I$(prefix)/src
%.pd_linux: %.c $(CC) $(CFLAGS) $(INCLUDE) -o "$*.o" -c "$*.c" gcc -shared -o "$*.pd_linux" "$*.o"
clean: -rm *.pd_linux *.o
install-doc: @test -d $(prefix)/doc/5.reference || mkdir -p $(prefix)/doc/5.reference install *.pd $(prefix)/doc/5.reference
install: install-doc @test -d $(prefix)/extra || mkdir -p $(prefix)/extra install *.pd_linux $(prefix)/extra
--- NEW FILE: popen.PNG --- (This appears to be a binary file; contents omitted.)
--- NEW FILE: popen.c --- /* :popen: for PD - windows + linux + (probably mac) - carmen rocco */
#include <m_pd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #define INBUFSIZE 1024
static t_class *popen_class;
typedef struct _popen { t_object x_obj; char buffer[128]; t_symbol *x_s; t_outlet* x_done; } t_popen;
static void popen_out(t_popen* x) { int i; int size = 0; size = strlen(x->buffer); for (i=0;i<size;i++) if (x->buffer[i] == '\n' || x->buffer[i] == '\r') x->buffer[i] = '\0'; fprintf(stderr, "%s",x->buffer); x->x_s = gensym(x->buffer); outlet_symbol(x->x_obj.ob_outlet, x->x_s); }
static void popen_anything(t_popen *x, t_symbol *s, int argc, t_atom *argv) { int i; char arg[MAXPDSTRING]; char cmd[20] = ""; FILE *pPipe; int size = 0; for (i=0;i<argc;i++) { atom_string(argv,arg+size,MAXPDSTRING - size); argv++; size=strlen(arg); arg[size++] = ' '; } arg[size-1] = '\0';
strcat(cmd, s->s_name); strcat(cmd, " "); strcat(cmd, arg); post("sending %s",cmd);
#ifdef NT if( (pPipe = _popen( cmd, "rt" )) == NULL ) #else if( (pPipe = popen( cmd, "r" )) == NULL ) #endif return;
while( !feof( pPipe ) ) { if( fgets( x->buffer, 128, pPipe ) != NULL ) popen_out(x); } #ifdef NT _pclose( pPipe ); #else pclose( pPipe ); #endif
outlet_bang(x->x_done); }
void popen_free(t_popen* x) { }
static void *popen_new(void) { t_popen *x = (t_popen *)pd_new(popen_class); outlet_new(&x->x_obj, &s_symbol); x->x_done = outlet_new(&x->x_obj, &s_bang); return (x); }
void popen_setup(void) { popen_class = class_new(gensym("popen"), (t_newmethod)popen_new, (t_method)popen_free,sizeof(t_popen), 0,0); class_addbang(popen_class,popen_out); class_addanything(popen_class, popen_anything); }
--- NEW FILE: Makefilewin --- prefix=../..
EXTERNALS = popen.c
all: $(EXTERNALS:.c=.dll)
.SUFFIXES: .dll
CFLAGS = -g -DPD -DNT -Wall -W -Wshadow -Wstrict-prototypes \ -Wno-unused -Wno-parentheses -Wno-switch
INCLUDE = -I. -I.. -I$(prefix)/src
%.dll: %.c $(CC) $(CFLAGS) $(INCLUDE) -o "$*.o" -c "$*.c" gcc -shared -o "$*.dll" "$*.o" $(prefix)/bin/pd.dll \ `test -f $*.libs && cat $*.libs` clean: -rm *.dll *.o
install-doc: @test -d $(prefix)/doc/5.reference || mkdir -p $(prefix)/doc/5.reference install *.pd $(prefix)/doc/5.reference
install: install-doc @test -d $(prefix)/extra || mkdir -p $(prefix)/extra install *.dll $(prefix)/extra