aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcarmen rocco <ix9@users.sourceforge.net>2005-03-08 21:20:35 +0000
committercarmen rocco <ix9@users.sourceforge.net>2005-03-08 21:20:35 +0000
commit77c7a463710ee0a5f95630c07da304fd0d296d3f (patch)
tree6b7ebd8c6926ab65d099cfe62239a189cb07edaf
svn path=/trunk/externals/control/popen/; revision=2606
-rwxr-xr-xMakefile27
-rwxr-xr-xMakefilewin27
-rwxr-xr-xpopen-help.pd41
-rw-r--r--popen.PNGbin0 -> 17406 bytes
-rwxr-xr-xpopen.c90
5 files changed, 185 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100755
index 0000000..28d3699
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,27 @@
+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
diff --git a/Makefilewin b/Makefilewin
new file mode 100755
index 0000000..07a7c2b
--- /dev/null
+++ b/Makefilewin
@@ -0,0 +1,27 @@
+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
diff --git a/popen-help.pd b/popen-help.pd
new file mode 100755
index 0000000..973e22f
--- /dev/null
+++ b/popen-help.pd
@@ -0,0 +1,41 @@
+#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;
diff --git a/popen.PNG b/popen.PNG
new file mode 100644
index 0000000..c725935
--- /dev/null
+++ b/popen.PNG
Binary files differ
diff --git a/popen.c b/popen.c
new file mode 100755
index 0000000..547fac4
--- /dev/null
+++ b/popen.c
@@ -0,0 +1,90 @@
+/* :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);
+}