[PD-cvs] SF.net SVN: pure-data: [9847] branches/pd-extended/v0-40/externals/hcs
eighthave at users.sourceforge.net
eighthave at users.sourceforge.net
Sun May 18 19:10:02 CEST 2008
Revision: 9847
http://pure-data.svn.sourceforge.net/pure-data/?rev=9847&view=rev
Author: eighthave
Date: 2008-05-18 10:10:01 -0700 (Sun, 18 May 2008)
Log Message:
-----------
dashed out [setenv] and [unsetenv] for messing with Pd's env vars while it is running
Added Paths:
-----------
branches/pd-extended/v0-40/externals/hcs/setenv-help.pd
branches/pd-extended/v0-40/externals/hcs/setenv.c
branches/pd-extended/v0-40/externals/hcs/unsetenv-help.pd
branches/pd-extended/v0-40/externals/hcs/unsetenv.c
Added: branches/pd-extended/v0-40/externals/hcs/setenv-help.pd
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/setenv-help.pd (rev 0)
+++ branches/pd-extended/v0-40/externals/hcs/setenv-help.pd 2008-05-18 17:10:01 UTC (rev 9847)
@@ -0,0 +1,29 @@
+#N canvas 199 179 526 477 10;
+#X obj 196 145 setenv;
+#X msg 196 47 bang;
+#X symbolatom 195 192 0 0 0 0 - - -;
+#X msg 59 51 bang;
+#X symbolatom 58 181 0 0 0 0 - - -;
+#X obj 59 134 setenv HOME;
+#X msg 229 113 symbol SHELL;
+#X msg 316 113 symbol PATH;
+#X msg 396 113 symbol HOME;
+#X symbolatom 55 408 0 0 0 0 - - -;
+#X text 49 240 to enable overwrite mode \, set the second argument
+to 1 (i.e. non-zero);
+#X obj 56 361 setenv HOME 1;
+#X msg 56 278 symbol /home/hans;
+#X msg 66 308 symbol /Users/hans;
+#X text 33 10 by default \, it will not overwrite existing values;
+#X msg 72 89 symbol /blah;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 3 0 5 0;
+#X connect 5 0 4 0;
+#X connect 6 0 0 1;
+#X connect 7 0 0 1;
+#X connect 8 0 0 1;
+#X connect 11 0 9 0;
+#X connect 12 0 11 0;
+#X connect 13 0 11 0;
+#X connect 15 0 5 0;
Added: branches/pd-extended/v0-40/externals/hcs/setenv.c
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/setenv.c (rev 0)
+++ branches/pd-extended/v0-40/externals/hcs/setenv.c 2008-05-18 17:10:01 UTC (rev 9847)
@@ -0,0 +1,123 @@
+/* sets an environment variable */
+/* */
+/* Copyright (c) 2008 Hans-Christoph Steiner <hans at eds.org> */
+/* */
+/* 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 <string.h>
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0400
+#include <windows.h>
+#include <stdio.h>
+#else
+#include <stdlib.h>
+#endif
+
+static char *version = "$Revision: 1.3 $";
+
+t_int setenv_instance_count;
+
+//#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"););
+ if(x->x_overwrite == 0)
+ error("[setenv]: not in overwrite mode, ignoring value.");
+ setenv(x->x_variable_name->s_name, s->s_name, x->x_overwrite); // 1 means overwrite
+ setenv_output(x);
+}
+
+static void setenv_anything(t_setenv* x, t_symbol* s, int argc, t_atom* argv)
+{
+
+}
+
+
+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);
+}
+
Added: branches/pd-extended/v0-40/externals/hcs/unsetenv-help.pd
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/unsetenv-help.pd (rev 0)
+++ branches/pd-extended/v0-40/externals/hcs/unsetenv-help.pd 2008-05-18 17:10:01 UTC (rev 9847)
@@ -0,0 +1,15 @@
+#N canvas 199 179 551 341 10;
+#X obj 196 145 setenv;
+#X msg 196 47 bang;
+#X symbolatom 195 192 0 0 0 0 - - -;
+#X msg 59 51 bang;
+#X msg 229 113 symbol SHELL;
+#X msg 316 113 symbol PATH;
+#X msg 396 113 symbol HOME;
+#X obj 59 134 unsetenv HOME;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 3 0 7 0;
+#X connect 4 0 0 1;
+#X connect 5 0 0 1;
+#X connect 6 0 0 1;
Added: branches/pd-extended/v0-40/externals/hcs/unsetenv.c
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/unsetenv.c (rev 0)
+++ branches/pd-extended/v0-40/externals/hcs/unsetenv.c 2008-05-18 17:10:01 UTC (rev 9847)
@@ -0,0 +1,104 @@
+/* unsets an environment variable */
+/* */
+/* Copyright (c) 2008 Hans-Christoph Steiner <hans at eds.org> */
+/* */
+/* 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 <string.h>
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0400
+#include <windows.h>
+#include <stdio.h>
+#else
+#include <stdlib.h>
+#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"););
+
+ if(x->x_variable_name != &s_)
+ unsetenv(x->x_variable_name->s_name);
+}
+
+
+
+static void unsetenv_symbol(t_unsetenv* x, t_symbol *s)
+{
+ DEBUG(post("unsetenv_bang"););
+ x->x_variable_name = s;
+}
+
+static void unsetenv_anything(t_unsetenv* x, t_symbol* s, int argc, t_atom* argv)
+{
+
+}
+
+
+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);
+ class_addanything(unsetenv_class, (t_method)unsetenv_anything);
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Pd-cvs
mailing list