From e28af67506e933956426ed99f4b8017f68ae3557 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 27 Aug 2008 22:27:30 +0000 Subject: merged in relevant changes from the v0-40 pd-extended release branch svn path=/trunk/externals/hcs/; revision=10266 --- autoscale-help.pd | 2 +- blocksize_in_ms-help.pd | 2 +- cursor-help.pd | 109 ++++++++++++------------- cursor.c | 34 +++++++- debounce-help.pd | 2 +- embed.pd | 22 ++++++ folder_list.c | 4 +- general/doc/amp~-help.pd | 3 +- general/doc/failsafe-help.pd | 3 +- gui/help/asl-help.pd | 1 + ifeel-help.pd | 2 +- import-help.pd | 21 ----- import.c | 184 ------------------------------------------- keyboard_layout.c | 12 +-- pi-help.pd | 2 +- setenv.c | 135 +++++++++++++++++++++++++++++++ unsetenv.c | 108 +++++++++++++++++++++++++ 17 files changed, 363 insertions(+), 283 deletions(-) create mode 100644 embed.pd delete mode 100644 import-help.pd delete mode 100644 import.c create mode 100644 setenv.c create mode 100644 unsetenv.c diff --git a/autoscale-help.pd b/autoscale-help.pd index 856dbbc..3b79050 100644 --- a/autoscale-help.pd +++ b/autoscale-help.pd @@ -2,7 +2,7 @@ #X floatatom 26 88 5 0 0 0 - - -; #X floatatom 26 152 0 0 0 0 - - -; #X obj 68 270 autoscale; -#X obj 2 2 cnv 15 450 20 empty empty [autoscale] 2 11 1 18 -233017 +#X obj 2 2 cnv 15 450 20 empty empty autoscale 2 11 1 18 -233017 -66577 0; #X msg 418 3 pddp; #X text 18 35 [autoscale] scales a stream of numbers based on an output diff --git a/blocksize_in_ms-help.pd b/blocksize_in_ms-help.pd index ccc47c3..e543341 100644 --- a/blocksize_in_ms-help.pd +++ b/blocksize_in_ms-help.pd @@ -1,5 +1,5 @@ #N canvas 256 153 461 330 10; -#X obj 5 2 cnv 15 450 20 empty empty [blocksize_in_ms] 2 11 1 18 -233017 +#X obj 5 2 cnv 15 450 20 empty empty blocksize_in_ms 2 11 1 18 -233017 -66577 0; #X msg 422 3 pddp; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner diff --git a/cursor-help.pd b/cursor-help.pd index cabfc00..df4555b 100644 --- a/cursor-help.pd +++ b/cursor-help.pd @@ -1,22 +1,17 @@ -#N canvas 121 272 642 509 10; -#X obj 136 401 pddp/print; -#X obj 95 342 tgl 15 0 empty empty empty 0 -6 0 10 -262144 -1 -1 0 -1; +#N canvas 119 64 638 465 10; #X obj 74 370 cursor; -#X msg 70 318 bang; -#X text 111 339 poll the mouse pointer position; -#X text 101 318 get the current mouse position; -#X obj 346 278 pddp/pddplink http://tcl.tk/man/tcl8.4/TkCmd/cursors.htm +#X msg 74 335 bang; +#X text 105 335 get the current mouse position; +#X obj 338 383 pddp/pddplink http://tcl.tk/man/tcl8.4/TkCmd/cursors.htm ; -#X text 231 261 Here's a complete list of the available cursors:; -#X msg 169 229 runmode_disconnect gumby; -#X msg 322 151 boat; -#X msg 282 151 clock; -#X msg 428 151 dot; -#X msg 505 151 gumby; -#X msg 548 151 gobbler; -#X msg 357 151 coffee_mug; -#X msg 458 151 pirate; +#X text 223 366 Here's a complete list of the available cursors:; +#X msg 335 124 boat; +#X msg 295 124 clock; +#X msg 441 124 dot; +#X msg 518 124 gumby; +#X msg 561 124 gobbler; +#X msg 370 124 coffee_mug; +#X msg 471 124 pirate; #X msg 42 44 runmode_nothing; #N canvas 0 22 462 312 make 0; #X obj 95 9 inlet; @@ -24,58 +19,54 @@ #X obj 116 168 pack symbol symbol; #X obj 221 147 symbol; #X obj 94 51 symbol; -#X obj 329 19 inlet; -#X obj 126 111 trigger bang anything; +#X obj 227 16 inlet; #X msg 116 192 set \$1 \$2; #X obj 115 220 trigger bang anything; #X connect 0 0 4 0; -#X connect 2 0 7 0; +#X connect 2 0 6 0; #X connect 3 0 2 1; #X connect 4 0 2 0; -#X connect 5 0 6 0; -#X connect 6 0 2 0; -#X connect 6 1 3 0; -#X connect 7 0 8 0; -#X connect 8 0 1 0; -#X connect 8 1 1 0; +#X connect 5 0 3 0; +#X connect 6 0 7 0; +#X connect 7 0 1 0; +#X connect 7 1 1 0; #X restore 169 205 pd make message; #X msg 59 63 runmode_clickme; #X msg 75 82 runmode_thicken; #X msg 92 101 runmode_addpoint; -#X obj 67 440 pddp/print; +#X obj 74 399 pddp/print; #X msg 110 120 editmode_nothing; -#X msg 126 139 runmode_connect; -#X msg 143 158 runmode_disconnect; -#X text 312 128 now pick a cursor:; -#X obj 169 266 cursor; -#X text 295 229 <-- this is the actual message to send; -#X obj 25 244 metro 100; -#X obj 25 218 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +#X obj 169 286 cursor; +#X text 342 258 <-- this is the actual message to send; +#X obj 56 308 metro 100; +#X obj 56 286 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X text 15 18 set your mouse cursors for this patch:; -#X text 201 81 <-- choose your cursor mode; -#X text 237 293 Here are some pictures of the cursors:; -#X obj 345 309 pddp/pddplink http://www.lehigh.edu/~sol0/ptk/cursors.gif +#X text 229 398 Here are some pictures of the cursors:; +#X obj 337 414 pddp/pddplink http://www.lehigh.edu/~sol0/ptk/cursors.gif ; -#X connect 1 0 2 0; -#X connect 2 0 21 0; -#X connect 2 1 0 0; -#X connect 3 0 2 0; -#X connect 8 0 26 0; -#X connect 9 0 17 1; -#X connect 10 0 17 1; -#X connect 11 0 17 1; -#X connect 12 0 17 1; -#X connect 13 0 17 1; -#X connect 14 0 17 1; -#X connect 15 0 17 1; -#X connect 16 0 17 0; -#X connect 17 0 8 0; -#X connect 18 0 17 0; -#X connect 19 0 17 0; -#X connect 20 0 17 0; -#X connect 22 0 17 0; -#X connect 23 0 17 0; -#X connect 24 0 17 0; -#X connect 28 0 2 0; -#X connect 29 0 28 0; +#X msg 126 139 editmode_connect; +#X msg 143 158 editmode_disconnect; +#X msg 169 259 editmode_disconnect pirate; +#X text 290 55 first pick a cursor:; +#X text 189 80 <-- then choose your cursor mode; +#X connect 0 0 17 0; +#X connect 1 0 0 0; +#X connect 5 0 13 1; +#X connect 6 0 13 1; +#X connect 7 0 13 1; +#X connect 8 0 13 1; +#X connect 9 0 13 1; +#X connect 10 0 13 1; +#X connect 11 0 13 1; +#X connect 12 0 13 0; +#X connect 13 0 28 0; +#X connect 14 0 13 0; +#X connect 15 0 13 0; +#X connect 16 0 13 0; +#X connect 18 0 13 0; +#X connect 21 0 0 0; +#X connect 22 0 21 0; +#X connect 26 0 13 0; +#X connect 27 0 13 0; +#X connect 28 0 19 0; diff --git a/cursor.c b/cursor.c index 52a9409..6cc0bfd 100644 --- a/cursor.c +++ b/cursor.c @@ -8,6 +8,13 @@ static t_symbol *button_symbol; static t_symbol *motion_symbol; static t_symbol *wheel_symbol; +//TODO add reset method for cursor icons, this should probably be done in pd.tk + +// TODO figure out some way to get +//t_int hidio_instance_count; +/* this is used to test for the first instance to execute */ +//double last_execute_time; + static t_class *cursor_class; typedef struct _cursor @@ -16,12 +23,23 @@ typedef struct _cursor t_symbol *receive_symbol; t_canvas *parent_canvas; t_outlet *data_outlet; - t_outlet *status_outlet; +// t_outlet *status_outlet; // not used (yet?) t_int optionc; char *optionv[]; } t_cursor; +/* idea from #tcl for a Tcl unbind +proc unbind {tag event script} { + set bind "" + foreach x [split [bind $tag $event] "\n"] { + if {$x != $script} {lappend bind $x} + } + bind $tag $event {} + foreach x $bind {bind $tag $event $x} + } +*/ + static void cursor_setmethod(t_cursor *x, t_symbol *s, int argc, t_atom *argv) { sys_vgui("set cursor_%s \"%s\"\n", s->s_name, atom_getsymbol(argv)->s_name); @@ -34,6 +52,9 @@ static void cursor_bang(t_cursor *x) x->receive_symbol->s_name); } +/* TODO this needs some kind of working unbind to be useful, otherwise when an + * instance is deleted, you get reams of "error: #123123 no such object" + * messages in the Pd Window. static void cursor_float(t_cursor *x, t_float f) { if(f > 0) @@ -43,9 +64,12 @@ static void cursor_float(t_cursor *x, t_float f) } else { - /* TODO figure out how to turn off this binding */ + // TODO figure out how to turn off this binding + sys_vgui("bind all {+pd [concat %s motion %%x %%y \\;]}\n", + x->receive_symbol->s_name); } } +*/ static void cursor_button_callback(t_cursor *x, t_float button, t_float state) { @@ -90,14 +114,16 @@ static void *cursor_new(void) x->receive_symbol = gensym(buf); pd_bind(&x->x_obj.ob_pd, x->receive_symbol); x->data_outlet = outlet_new(&x->x_obj, 0); - x->status_outlet = outlet_new(&x->x_obj, 0); +// x->status_outlet = outlet_new(&x->x_obj, 0); +/* not working yet sys_vgui("bind . {+pd [concat %s button %%b 1 \\;]}\n", x->receive_symbol->s_name); sys_vgui("bind . {+pd [concat %s button %%b 0 \\;]}\n", x->receive_symbol->s_name); sys_vgui("bind . {+pd [concat %s wheel %%D \\;]}\n", x->receive_symbol->s_name); +*/ return(x); } @@ -109,7 +135,7 @@ void cursor_setup(void) sizeof(t_cursor), 0, 0); class_addbang(cursor_class, (t_method)cursor_bang); - class_addfloat(cursor_class, (t_method)cursor_float); +/* class_addfloat(cursor_class, (t_method)cursor_float); */ button_symbol = gensym("button"); motion_symbol = gensym("motion"); diff --git a/debounce-help.pd b/debounce-help.pd index 529761a..00d65ea 100644 --- a/debounce-help.pd +++ b/debounce-help.pd @@ -1,5 +1,5 @@ #N canvas 429 170 470 540 10; -#X obj 2 2 cnv 15 450 20 empty empty [debounce] 2 11 1 18 -233017 -66577 +#X obj 2 2 cnv 15 450 20 empty empty debounce 2 11 1 18 -233017 -66577 0; #X msg 418 3 pddp; #X text 234 467 released under the GNU GPL; diff --git a/embed.pd b/embed.pd new file mode 100644 index 0000000..265047d --- /dev/null +++ b/embed.pd @@ -0,0 +1,22 @@ +#N canvas 103 147 450 300 10; +#X msg 282 79 menu_toggle_console; +#X obj 69 37 trigger bang bang bang bang bang bang bang bang bang; +#X msg 182 84 wm iconify .; +#X msg 140 13 bang; +#X obj 170 245 hcs/sys_gui; +#X obj 35 75 hcs/window_name; +#X msg 35 98 wm iconify \$1; +#X msg 23 29 bang; +#X obj 70 12 loadbang; +#X msg 256 164 wm title . "My Custom Title"; +#X connect 0 0 4 0; +#X connect 1 0 5 0; +#X connect 1 4 2 0; +#X connect 1 8 0 0; +#X connect 2 0 4 0; +#X connect 3 0 1 0; +#X connect 5 0 6 0; +#X connect 6 0 4 0; +#X connect 7 0 5 0; +#X connect 8 0 1 0; +#X connect 9 0 4 0; diff --git a/folder_list.c b/folder_list.c index 19af453..b6f22f0 100644 --- a/folder_list.c +++ b/folder_list.c @@ -40,8 +40,8 @@ static char *version = "$Revision: 1.12 $"; t_int folder_list_instance_count; -//#define DEBUG(x) -#define DEBUG(x) x +#define DEBUG(x) +//#define DEBUG(x) x /*------------------------------------------------------------------------------ * CLASS DEF diff --git a/general/doc/amp~-help.pd b/general/doc/amp~-help.pd index 19225d6..b4f0058 100644 --- a/general/doc/amp~-help.pd +++ b/general/doc/amp~-help.pd @@ -1,5 +1,6 @@ #N canvas 502 235 465 312 10; -#X obj 5 2 cnv 15 450 20 empty empty [amp~] 2 11 1 18 -233017 -66577 +#X declare -lib hcs; +#X obj 5 2 cnv 15 450 20 empty empty amp~ 2 11 1 18 -233017 -66577 0; #X msg 422 3 pddp; #X text 27 270 (C) Copyright 2004 Hans-Christoph Steiner diff --git a/general/doc/failsafe-help.pd b/general/doc/failsafe-help.pd index 248ef9f..08830c8 100644 --- a/general/doc/failsafe-help.pd +++ b/general/doc/failsafe-help.pd @@ -1,5 +1,6 @@ #N canvas 502 235 469 316 10; -#X obj 5 2 cnv 15 450 20 empty empty [failsafe] 2 11 1 18 -233017 -66577 +#X declare -lib hcs; +#X obj 5 2 cnv 15 450 20 empty empty failsafe 2 11 1 18 -233017 -66577 0; #X msg 422 3 pddp; #X text 244 284 released under the GNU GPL; diff --git a/gui/help/asl-help.pd b/gui/help/asl-help.pd index 6695880..26f5c81 100644 --- a/gui/help/asl-help.pd +++ b/gui/help/asl-help.pd @@ -1,4 +1,5 @@ #N canvas 642 427 458 308 10; +#X declare -lib hcs; #X obj 142 80 asl; #X floatatom 269 196 5 0 0 0 - - -; #X obj 269 56 asl; diff --git a/ifeel-help.pd b/ifeel-help.pd index d520dff..8ab5424 100644 --- a/ifeel-help.pd +++ b/ifeel-help.pd @@ -25,7 +25,7 @@ has a tendency to crash the whole machine. I suspect a bug in the kernel module ifeel.o.; #X text 13 449 by Hans-Christoph Steiner ; -#X obj 324 416 pddp_open all_about_haptics; +#X obj 324 416 pddp/pddplink ../all_about_haptics.pd -text all_about_haptics; #X text 201 417 For more info:; #X msg 251 168 strength 0.56; #X msg 234 124 interval 73; diff --git a/import-help.pd b/import-help.pd deleted file mode 100644 index 8764c7b..0000000 --- a/import-help.pd +++ /dev/null @@ -1,21 +0,0 @@ -#N canvas 476 83 473 364 10; -#X msg 21 102 bang; -#X obj 21 150 import ext13 memento rradical; -#X text 247 315 released under the GNU GPL; -#X msg 33 126 reset; -#X symbolatom 32 176 0 0 0 0 - - -; -#X obj 21 202 print; -#X text 68 101 get next item in list of loaded libs; -#X text 80 125 start at the top of the list again; -#X text 18 22 [import] loads libraries from the patch. On Pd 0.4 or -greater \, it loads the library into the patch's local namespace. On -older versions \, it loads the libraries into the global namespace. -; -#X text 29 239 Sending bangs to [import] makes it output the loaded -libraries one at a time.; -#X text 18 301 (C) Copyright 2004-6 Hans-Christoph Steiner -; -#X connect 0 0 1 0; -#X connect 1 0 4 0; -#X connect 1 0 5 0; -#X connect 3 0 1 0; diff --git a/import.c b/import.c deleted file mode 100644 index 0364685..0000000 --- a/import.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This object loads libraries and libdirs from within a patch. It is the - * first small step towards a patch-specific namespace. Currently, it just - * adds things to the global path. It is a reimplementation of a similar/same - * idea from Guenter Geiger's [using] object. - * - * This object currently depends on the packages/patches/libdir-0.38-4.patch - * for sys_load_lib_dir(). - */ - -#include "m_pd.h" -#include "s_stuff.h" -#include "g_canvas.h" - -#include - -/* WARNING: KLUDGE! */ -/* - * this struct is not publically defined (its in g_canvas.c) so I need to - * include this here. Its from Pd 0.41-test03 2006-11-19. */ -struct _canvasenvironment -{ - t_symbol *ce_dir; /* directory patch lives in */ - int ce_argc; /* number of "$" arguments */ - t_atom *ce_argv; /* array of "$" arguments */ - int ce_dollarzero; /* value of "$0" */ - t_namelist *ce_path; /* search path */ -}; - - -static char *version = "$Revision: 1.2 $"; - -t_int import_instance_count; - -#define DEBUG(x) -//#define DEBUG(x) x - -/*------------------------------------------------------------------------------ - * CLASS DEF - */ -static t_class *import_class; - -typedef struct _import -{ - t_object x_obj; - t_canvas *x_canvas; - t_namelist *x_top; - t_namelist *x_current; - char x_classpath_root[MAXPDSTRING]; - t_outlet *x_data_outlet; - t_outlet *x_status_outlet; -} t_import; - - -static int load_library(t_import *x, char *library_name) -{ - DEBUG(post("load_library");); -#if (PD_MINOR_VERSION >= 40) - if (!sys_load_lib(x->x_canvas, library_name)) return 0; -#else -/* sys_load_lib_dir is only used on Pd-extended < 0.40 */ - if (!sys_load_lib(sys_libdir->s_name, library_name)) - if (!sys_load_lib_dir(sys_libdir->s_name, library_name)) - return 0; -#endif /* (PD_MINOR_VERSION >= 40) */ - return 1; -} - - -static void load_arguments(t_import *x, int argc, t_atom *argv) -{ - t_symbol *library_name; - - while (argc--) { - switch (argv->a_type) { - case A_FLOAT: - post("[import] ERROR: floats not supported: %f", - atom_getfloat(argv)); - break; - case A_SYMBOL: - library_name = atom_getsymbol(argv); - if (!load_library(x,library_name->s_name)) - post("[import]: ERROR: can't load library in %s", - library_name->s_name); - else - post("[import] loaded library: %s",library_name->s_name); - break; - default: - post("[import] ERROR: Unsupported atom type"); - } - argv++; - } -} - - -static void import_output(t_import* x) -{ - DEBUG(post("import_output");); - char buffer[MAXPDSTRING]; - -/* TODO: think about using x->x_current->nl_next so that if [import] is at - * the end of its list, and another element gets added to the local - * namespace, [import] will output the new element on the next bang. */ - if(x->x_current) - { - post("current string: %s", x->x_current->nl_string); - strncpy(buffer, x->x_current->nl_string, MAXPDSTRING); - post("current string buffer: %s", buffer); - outlet_symbol( x->x_data_outlet, gensym(buffer) ); - x->x_current = x->x_current->nl_next; - } - else - outlet_bang(x->x_status_outlet); -} - - -static void import_reset(t_import* x) -{ -/* on >= 0.40, this class uses the patch-local paths, on older versions - * before that existed, this class uses the global classpath */ -#if (PD_MINOR_VERSION >= 40) - x->x_top = canvas_getenv(x->x_canvas)->ce_path; -#else - x->x_top = sys_searchpath; -#endif /* (PD_MINOR_VERSION >= 40) */ - x->x_current = x->x_top; -} - - -static void *import_new(t_symbol *s, int argc, t_atom *argv) -{ - t_import *x = (t_import *)pd_new(import_class); - t_symbol *currentdir; - - if(import_instance_count == 0) - { - post("[import] %s",version); - post("\twritten by Hans-Christoph Steiner "); - post("\tcompiled on "__DATE__" at "__TIME__ " "); - post("\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION, - PD_MINOR_VERSION, PD_BUGFIX_VERSION); - } - import_instance_count++; - - strncpy(x->x_classpath_root, sys_libdir->s_name, MAXPDSTRING - 7); - strcat(x->x_classpath_root, "/extra"); - - x->x_data_outlet = outlet_new(&x->x_obj, &s_symbol); - x->x_status_outlet = outlet_new(&x->x_obj, 0); - - x->x_canvas = canvas_getcurrent(); - load_arguments(x,argc,argv); - import_reset(x); - - return (x); -} - - -static void import_free(t_import *x) -{ - /* TODO: look into freeing the namelist. It probably does not need to - * happen, since this class is just copying the pointer of an existing - * namelist that is handled elsewhere. */ - -/* TODO: perhaps this should remove any libs that this instance had added to - * the namespace */ -} - - -void import_setup(void) -{ - import_class = class_new(gensym("import"), (t_newmethod)import_new, - (t_method)import_free, - sizeof(t_import), - CLASS_DEFAULT, - A_GIMME, - 0); - /* add inlet atom methods */ - class_addbang(import_class,(t_method) import_output); - - /* add inlet selector methods */ - class_addmethod(import_class,(t_method) import_reset, - gensym("reset"), 0); -} diff --git a/keyboard_layout.c b/keyboard_layout.c index 54c6664..b51168c 100644 --- a/keyboard_layout.c +++ b/keyboard_layout.c @@ -22,12 +22,12 @@ typedef struct _keyboard_layout { void keyboard_layout_bang(t_keyboard_layout *x) { //OSStatus err; KeyboardLayoutRef currentLayoutRef; - CFStringRef keyboardName; + const void *keyboardName; char cKeyboardName[100]; KLGetCurrentKeyboardLayout(¤tLayoutRef); KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); - CFStringGetCString(keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); + CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); outlet_symbol(x->x_data_outlet, gensym(cKeyboardName)); } @@ -35,7 +35,7 @@ void keyboard_layout_bang(t_keyboard_layout *x) { void keyboard_layout_menu(t_keyboard_layout *x) { //OSStatus err; KeyboardLayoutRef currentLayoutRef; - CFStringRef keyboardName; + const void *keyboardName; char cKeyboardName[100]; CFIndex countOfLayouts; CFIndex i; @@ -48,7 +48,7 @@ void keyboard_layout_menu(t_keyboard_layout *x) { for(i= 0; is_name, kCFStringEncodingASCII); KLGetKeyboardLayoutWithName(keyboardName, ¤tLayoutRef); KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName); - CFStringGetCString(keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); + CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII); KLSetCurrentKeyboardLayout(currentLayoutRef); //outlet_anything(x->t_out, s, 0, NULL); keyboard_layout_bang(x); diff --git a/pi-help.pd b/pi-help.pd index 0241186..c15c329 100644 --- a/pi-help.pd +++ b/pi-help.pd @@ -1,5 +1,5 @@ #N canvas 65 227 466 251 10; -#X obj 5 2 cnv 15 450 20 empty empty [pi] 2 11 1 18 -233017 -66577 +#X obj 5 2 cnv 15 450 20 empty empty pi 2 11 1 18 -233017 -66577 0; #X msg 422 3 pddp; #X obj 142 149 pi; diff --git a/setenv.c b/setenv.c new file mode 100644 index 0000000..877c062 --- /dev/null +++ b/setenv.c @@ -0,0 +1,135 @@ +/* sets an environment variable */ +/* */ +/* Copyright (c) 2008 Hans-Christoph Steiner */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* --------------------------------------------------------------------------*/ + +#include "m_pd.h" +#include "s_stuff.h" + +#include + +#ifdef _WIN32 +#define _WIN32_WINNT 0x0400 +#include +#include +#else +#include +#endif + +#define DEBUG(x) +//#define DEBUG(x) x + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +static t_class *setenv_class; + +typedef struct _setenv { + t_object x_obj; + t_symbol* x_variable_name; + t_int x_overwrite; + t_outlet* x_data_outlet; +} t_setenv; + +/*------------------------------------------------------------------------------ + * IMPLEMENTATION + */ + +static void setenv_output(t_setenv* x) +{ + DEBUG(post("setenv_output");); + char *envvar_value; + if(x->x_variable_name != &s_) + { + envvar_value = getenv(x->x_variable_name->s_name); + if(envvar_value) + outlet_symbol(x->x_data_outlet, gensym(envvar_value)); + else + pd_error(x, "[setenv]: The environment variable %s is not defined.", x->x_variable_name->s_name); + } + else + pd_error(x, "[setenv]: no environment variable name is set."); +} + + +static void setenv_symbol(t_setenv* x, t_symbol *s) +{ + DEBUG(post("setenv_output");); +#ifdef _WIN32 + SetEnvironmentVariable(x->x_variable_name->s_name, s->s_name); +#else + if(x->x_overwrite == 0) + post("[setenv]: not in overwrite mode."); + setenv(x->x_variable_name->s_name, s->s_name, x->x_overwrite); +#endif + setenv_output(x); +} + +static void setenv_anything(t_setenv* x, t_symbol* s, int argc, t_atom* argv) +{ + t_binbuf *argument_binbuf = binbuf_new(); + char *argument_buffer; + int buffer_length; + if(s != &s_list) + { + t_atom selector; + SETSYMBOL(&selector, s); + binbuf_add(argument_binbuf, 1, &selector); + } + binbuf_add(argument_binbuf, argc, argv); + binbuf_gettext(argument_binbuf, &argument_buffer, &buffer_length); + binbuf_free(argument_binbuf); + argument_buffer[buffer_length] = 0; + setenv_symbol(x, gensym(argument_buffer)); +} + + +static void *setenv_new(t_symbol* s, t_float f) +{ + DEBUG(post("setenv_new");); + t_setenv *x = (t_setenv *)pd_new(setenv_class); + + symbolinlet_new(&x->x_obj, &x->x_variable_name); + x->x_data_outlet = outlet_new(&x->x_obj, &s_symbol); + + x->x_overwrite = (t_int) f; + x->x_variable_name = s; + + return (x); +} + + +void setenv_setup(void) +{ + DEBUG(post("setenv_setup");); + setenv_class = class_new(gensym("setenv"), + (t_newmethod)setenv_new, + 0, + sizeof(t_setenv), + 0, + A_DEFSYMBOL, + A_DEFFLOAT, + 0); + /* add inlet datatype methods */ + class_addbang(setenv_class, (t_method)setenv_output); + class_addsymbol(setenv_class, (t_method)setenv_symbol); + class_addanything(setenv_class, (t_method)setenv_anything); +} + diff --git a/unsetenv.c b/unsetenv.c new file mode 100644 index 0000000..6ba2145 --- /dev/null +++ b/unsetenv.c @@ -0,0 +1,108 @@ +/* unsets an environment variable */ +/* */ +/* Copyright (c) 2008 Hans-Christoph Steiner */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* --------------------------------------------------------------------------*/ + +#include "m_pd.h" +#include "s_stuff.h" + +#include + +#ifdef _WIN32 +#define _WIN32_WINNT 0x0400 +#include +#include +#else +#include +#endif + +#define DEBUG(x) +//#define DEBUG(x) x + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +static t_class *unsetenv_class; + +typedef struct _unsetenv { + t_object x_obj; + t_symbol* x_variable_name; + t_outlet* x_data_outlet; +} t_unsetenv; + +/*------------------------------------------------------------------------------ + * IMPLEMENTATION + */ + +static void unsetenv_bang(t_unsetenv* x) +{ + DEBUG(post("unsetenv_bang");); + +#ifdef _WIN32 + if(x->x_variable_name != &s_) + { + char buf[MAXPDSTRING]; + strncpy(buf, x->x_variable_name->s_name, MAXPDSTRING - 1); + strcat(buf, "="); + putenv(buf); + } +#else + if(x->x_variable_name != &s_) + unsetenv(x->x_variable_name->s_name); +#endif +} + + + +static void unsetenv_symbol(t_unsetenv* x, t_symbol *s) +{ + DEBUG(post("unsetenv_bang");); + x->x_variable_name = s; +} + + +static void *unsetenv_new(t_symbol* s) +{ + DEBUG(post("unsetenv_new");); + t_unsetenv *x = (t_unsetenv *)pd_new(unsetenv_class); + + symbolinlet_new(&x->x_obj, &x->x_variable_name); + + x->x_variable_name = s; + + return (x); +} + + +void unsetenv_setup(void) +{ + DEBUG(post("unsetenv_setup");); + unsetenv_class = class_new(gensym("unsetenv"), + (t_newmethod)unsetenv_new, + 0, + sizeof(t_unsetenv), + 0, + A_DEFSYMBOL, + 0); + /* add inlet datatype methods */ + class_addbang(unsetenv_class, (t_method)unsetenv_bang); + class_addsymbol(unsetenv_class, (t_method)unsetenv_symbol); +} + -- cgit v1.2.1