[PD-cvs] SF.net SVN: pure-data: [9862] branches/pd-extended/v0-40
eighthave at users.sourceforge.net
eighthave at users.sourceforge.net
Wed May 21 19:12:37 CEST 2008
Revision: 9862
http://pure-data.svn.sourceforge.net/pure-data/?rev=9862&view=rev
Author: eighthave
Date: 2008-05-21 10:12:36 -0700 (Wed, 21 May 2008)
Log Message:
-----------
A big commit to get the namespace stuff with [import] ironed out, and to get
[declare] working as advertized in the help patch.
- [import] adds #X declare -lib statements to the file upon save, like
[declare]. This is done by hacking g_canvas.c directly, but in the future,
this should be done via a public API for externals. Also because of this,
import.c is statically linked into the Pd binary.
- fixed absolute pathnames in [declare], #X declare, and in canvas_open() so
that they work properly. Also, absolute path names are used by libdir so
that the libdir's path entry in the canvas-local ce_path can be opened
relative to Pd rather than relative to the parent patch
Modified Paths:
--------------
branches/pd-extended/v0-40/externals/Makefile
branches/pd-extended/v0-40/externals/loaders/libdir.c
branches/pd-extended/v0-40/pd/src/g_canvas.c
branches/pd-extended/v0-40/pd/src/m_conf.c
branches/pd-extended/v0-40/pd/src/m_pd.h
branches/pd-extended/v0-40/pd/src/makefile.in
branches/pd-extended/v0-40/pd/src/s_main.c
branches/pd-extended/v0-40/pd/src/s_path.c
Added Paths:
-----------
branches/pd-extended/v0-40/pd/doc/5.reference/import-help.pd
branches/pd-extended/v0-40/pd/src/import.c
Removed Paths:
-------------
branches/pd-extended/v0-40/externals/hcs/import-help.pd
branches/pd-extended/v0-40/externals/hcs/import.c
Modified: branches/pd-extended/v0-40/externals/Makefile
===================================================================
--- branches/pd-extended/v0-40/externals/Makefile 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/externals/Makefile 2008-05-21 17:12:36 UTC (rev 9862)
@@ -1044,10 +1044,6 @@
--license "GNU GPL" \
--version ""
install -p $(HCS_OBJECTS:.c=.$(EXTENSION)) $(objectsdir)/$(HCS_NAME)
-# temp kludge: install [classpath] and [import] into global namespace since
-# they are used for loading libraries
- install -p $(externals_src)/hcs/classpath.$(EXTENSION) \
- $(externals_src)/hcs/import.$(EXTENSION) $(objectsdir)
install -p $(shell ls -1 $(externals_src)/hcs/*.pd | \
grep -v '\-help.pd') $(objectsdir)/$(HCS_NAME)
# hmm, these don't have a home yet...
Deleted: branches/pd-extended/v0-40/externals/hcs/import-help.pd
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/import-help.pd 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/externals/hcs/import-help.pd 2008-05-21 17:12:36 UTC (rev 9862)
@@ -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 <hans at at.or.at>
-;
-#X connect 0 0 1 0;
-#X connect 1 0 4 0;
-#X connect 1 0 5 0;
-#X connect 3 0 1 0;
Deleted: branches/pd-extended/v0-40/externals/hcs/import.c
===================================================================
--- branches/pd-extended/v0-40/externals/hcs/import.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/externals/hcs/import.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -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. <hans at at.or.at>
- *
- * 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 <string.h>
-
-/* 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 <hans at at.or.at>");
- 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);
-}
Modified: branches/pd-extended/v0-40/externals/loaders/libdir.c
===================================================================
--- branches/pd-extended/v0-40/externals/loaders/libdir.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/externals/loaders/libdir.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -41,8 +41,8 @@
int fd = -1;
unsigned int i;
char helppathname[FILENAME_MAX];
- char fullclassname[FILENAME_MAX], dirbuf[FILENAME_MAX];
- char reldirbuf[FILENAME_MAX], curdir[FILENAME_MAX], *nameptr;
+ char fullclassname[FILENAME_MAX], dirbuf[FILENAME_MAX], pathbuf[FILENAME_MAX];
+ char *nameptr;
t_canvasenvironment *canvasenvironment;
/* look for meta file (classname)/(classname)-meta.pd */
@@ -57,26 +57,21 @@
if(canvas)
{
canvasenvironment = canvas_getenv(canvas);
- if ((fd = canvas_open(0, fullclassname, ".pd",
+ if ((fd = canvas_open(NULL, fullclassname, ".pd",
dirbuf, &nameptr, FILENAME_MAX, 0)) < 0)
{
return (0);
}
close(fd);
- // G.Holzmann: canvas will look to a relative path to it, so we cannot add
- // the absulote dirbuf path, we have to make it relative to the current canvas
- // (see from line 1561 in g_canvas.c)
- sys_unbashfilename(canvas_getdir(canvas)->s_name, curdir);
- reldirbuf[0] = '\0';
- // count depth of the current dir
- for(i=0; i<strlen(curdir); i++)
- {
- if(curdir[i] == '/')
- strncat(reldirbuf, "../", FILENAME_MAX);
- }
- strncat(reldirbuf, dirbuf, FILENAME_MAX);
+ /* add Pd's base path to the path to make it an absolute path. This
+ * needs to be an absolute path because relative paths in the ce_path
+ * are interpreted as relative to the parent path's current
+ * directory. hans at eds.org */
+ sys_unbashfilename(sys_libdir->s_name, pathbuf);
+ strcat(pathbuf, "/extra/");
+ strncat(pathbuf, classname, FILENAME_MAX - strlen(pathbuf));
canvasenvironment->ce_path = namelist_append(canvasenvironment->ce_path,
- reldirbuf, 0);
+ pathbuf, 0);
post("libdir_loader: added %s to the canvas-local path", classname);
}
else
Copied: branches/pd-extended/v0-40/pd/doc/5.reference/import-help.pd (from rev 9856, branches/pd-extended/v0-40/externals/hcs/import-help.pd)
===================================================================
--- branches/pd-extended/v0-40/pd/doc/5.reference/import-help.pd (rev 0)
+++ branches/pd-extended/v0-40/pd/doc/5.reference/import-help.pd 2008-05-21 17:12:36 UTC (rev 9862)
@@ -0,0 +1,21 @@
+#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 <hans at at.or.at>
+;
+#X connect 0 0 1 0;
+#X connect 1 0 4 0;
+#X connect 1 0 5 0;
+#X connect 3 0 1 0;
Modified: branches/pd-extended/v0-40/pd/src/g_canvas.c
===================================================================
--- branches/pd-extended/v0-40/pd/src/g_canvas.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/g_canvas.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -1473,6 +1473,7 @@
before any objects are created in it. */
static t_class *declare_class;
+extern t_class *import_class;
typedef struct _declare
{
@@ -1498,6 +1499,9 @@
void canvas_savedeclarationsto(t_canvas *x, t_binbuf *b)
{
+ int i, argc;
+ t_atom *argv;
+ char savename[FILENAME_MAX];
t_gobj *y;
for (y = x->gl_list; y; y = y->g_next)
@@ -1508,6 +1512,19 @@
binbuf_addbinbuf(b, ((t_declare *)y)->x_obj.te_binbuf);
binbuf_addv(b, ";");
}
+ else if (pd_class(&y->g_pd) == import_class)
+ {
+ binbuf_addv(b, "s", gensym("#X"));
+ binbuf_addv(b, "s", gensym("declare"));
+ argc = binbuf_getnatom(((t_object *)y)->te_binbuf) - 1;
+ argv = binbuf_getvec(((t_object *)y)->te_binbuf) + 1;
+ for(i = 0; i < argc; ++i)
+ {
+ binbuf_addv(b, "s", gensym("-lib"));
+ binbuf_add(b, 1, argv + i);
+ }
+ binbuf_addv(b, ";");
+ }
else if (pd_class(&y->g_pd) == canvas_class)
canvas_savedeclarationsto((t_canvas *)y, b);
}
@@ -1515,20 +1532,16 @@
static void canvas_completepath(char *from, char *to)
{
- if(! (from[0] == '/' || from[0] == '~'
-#ifdef MSW
- || from[0] == '%' || (from[1] == ':' && from[2] == '/')
-#endif
- ))
+ if (sys_isabsolutepath(from))
{
+ to[0] = '\0';
+ }
+ else
+ { // if not absolute path, append Pd lib dir
strncpy(to, sys_libdir->s_name, FILENAME_MAX-4);
to[FILENAME_MAX-3] = '\0';
strcat(to, "/");
}
- else
- {
- to[0] = '\0';
- }
strncat(to, from, FILENAME_MAX-strlen(to));
to[FILENAME_MAX-1] = '\0';
}
@@ -1611,9 +1624,16 @@
for (nl = y->gl_env->ce_path; nl; nl = nl->nl_next)
{
char realname[FILENAME_MAX];
- strncpy(realname, dir, FILENAME_MAX);
- realname[FILENAME_MAX-3] = 0;
- strcat(realname, "/");
+ if (sys_isabsolutepath(nl->nl_string))
+ {
+ realname[0] = '\0';
+ }
+ else
+ { // if not absolute path, append Pd lib dir
+ strncpy(realname, dir, FILENAME_MAX);
+ realname[FILENAME_MAX-3] = 0;
+ strcat(realname, "/");
+ }
strncat(realname, nl->nl_string, FILENAME_MAX-strlen(realname));
realname[FILENAME_MAX-1] = 0;
if ((fd = sys_trytoopenone(realname, name, ext,
Copied: branches/pd-extended/v0-40/pd/src/import.c (from rev 9856, branches/pd-extended/v0-40/externals/hcs/import.c)
===================================================================
--- branches/pd-extended/v0-40/pd/src/import.c (rev 0)
+++ branches/pd-extended/v0-40/pd/src/import.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -0,0 +1,172 @@
+/*
+ * 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. <hans at at.or.at>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* 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
+ */
+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[FILENAME_MAX];
+ 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 (!sys_load_lib(x->x_canvas, library_name))
+ return 0;
+ else
+ 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:
+ pd_error(x, "[import] ERROR: floats not supported: %f",
+ atom_getfloat(argv));
+ break;
+ case A_SYMBOL:
+ library_name = atom_getsymbol(argv);
+ post("loading %s", library_name->s_name);
+ if (!load_library(x,library_name->s_name))
+ pd_error(x, "[import]: ERROR: can't load library in %s",
+ library_name->s_name);
+ else
+ post("[import] loaded library: %s",library_name->s_name);
+ break;
+ default:
+ pd_error(x, "[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));
+// outlet_symbol( x->x_data_outlet, gensym(strrchr(buffer, '/') + 1) );
+ x->x_current = x->x_current->nl_next;
+ }
+ else
+ outlet_bang(x->x_status_outlet);
+}
+
+
+static void import_reset(t_import* x)
+{
+ x->x_top = canvas_getenv(x->x_canvas)->ce_path;
+ 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;
+
+ 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);
+
+ if(import_instance_count == 0)
+ {
+ post("[import] %s",version);
+ post("\tWARNING! this is alpha, the interface could change!");
+ post("\tcompiled against Pd version %d.%d.%d", PD_MAJOR_VERSION,
+ PD_MINOR_VERSION, PD_BUGFIX_VERSION);
+ }
+ import_instance_count++;
+
+ 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);
+}
Modified: branches/pd-extended/v0-40/pd/src/m_conf.c
===================================================================
--- branches/pd-extended/v0-40/pd/src/m_conf.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/m_conf.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -51,6 +51,8 @@
void d_osc_setup(void);
void d_soundfile_setup(void);
void d_ugen_setup(void);
+/* kludge until there is a declare API for externals, hans at eds.org */
+void import_setup(void);
void conf_init(void)
{
@@ -98,5 +100,7 @@
d_osc_setup();
d_soundfile_setup();
d_ugen_setup();
+/* kludge until there is a declare API for externals, hans at eds.org */
+ import_setup();
}
Modified: branches/pd-extended/v0-40/pd/src/m_pd.h
===================================================================
--- branches/pd-extended/v0-40/pd/src/m_pd.h 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/m_pd.h 2008-05-21 17:12:36 UTC (rev 9862)
@@ -475,6 +475,7 @@
/* ------------ system interface routines ------------------- */
EXTERN int sys_isreadablefile(const char *name);
+EXTERN int sys_isabsolutepath(const char *dir);
EXTERN void sys_bashfilename(const char *from, char *to);
EXTERN void sys_unbashfilename(const char *from, char *to);
EXTERN int open_via_path(const char *name, const char *ext, const char *dir,
Modified: branches/pd-extended/v0-40/pd/src/makefile.in
===================================================================
--- branches/pd-extended/v0-40/pd/src/makefile.in 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/makefile.in 2008-05-21 17:12:36 UTC (rev 9862)
@@ -62,6 +62,7 @@
d_delay.c d_resample.c \
x_arithmetic.c x_connective.c x_interface.c x_midi.c x_misc.c \
x_time.c x_acoustics.c x_net.c x_qlist.c x_gui.c x_list.c d_soundfile.c \
+ import.c \
$(SYSSRC)
OBJ = $(SRC:.c=.o)
Modified: branches/pd-extended/v0-40/pd/src/s_main.c
===================================================================
--- branches/pd-extended/v0-40/pd/src/s_main.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/s_main.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -440,7 +440,7 @@
INSTALL_PREFIX. In MSW, we don't try to use INSTALL_PREFIX. */
void sys_findprogdir(char *progname)
{
- char sbuf[MAXPDSTRING], sbuf2[MAXPDSTRING], *sp;
+ char sbuf[FILENAME_MAX], sbuf2[FILENAME_MAX], *sp;
char *lastslash;
#ifdef HAVE_UNISTD_H
struct stat statbuf;
@@ -449,12 +449,12 @@
/* find out by what string Pd was invoked; put answer in "sbuf". */
#ifdef MSW
GetModuleFileName(NULL, sbuf2, sizeof(sbuf2));
- sbuf2[MAXPDSTRING-1] = 0;
+ sbuf2[FILENAME_MAX-1] = 0;
sys_unbashfilename(sbuf2, sbuf);
#endif /* MSW */
#ifdef HAVE_UNISTD_H
- strncpy(sbuf, progname, MAXPDSTRING);
- sbuf[MAXPDSTRING-1] = 0;
+ strncpy(sbuf, progname, FILENAME_MAX);
+ sbuf[FILENAME_MAX-1] = 0;
#endif
lastslash = strrchr(sbuf, '/');
if (lastslash)
@@ -501,28 +501,29 @@
sys_libdir = gensym(sbuf2);
sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
#else
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/lib/pd");
- if (stat(sbuf, &statbuf) >= 0)
+ realpath(sbuf2, sbuf);
+ strncpy(sbuf2, sbuf, FILENAME_MAX-30);
+ sbuf[FILENAME_MAX-30] = 0;
+ strcat(sbuf2, "/lib/pd");
+ if (stat(sbuf2, &statbuf) >= 0)
{
/* complicated layout: lib dir is the one we just stat-ed above */
- sys_libdir = gensym(sbuf);
+ sys_libdir = gensym(sbuf2);
/* gui lives in .../lib/pd/bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/lib/pd/bin");
- sys_guidir = gensym(sbuf);
+ strncpy(sbuf2, sbuf, FILENAME_MAX-30);
+ sbuf[FILENAME_MAX-30] = 0;
+ strcat(sbuf2, "/lib/pd/bin");
+ sys_guidir = gensym(sbuf2);
}
else
{
/* simple layout: lib dir is the parent */
- sys_libdir = gensym(sbuf2);
+ sys_libdir = gensym(sbuf);
/* gui lives in .../bin */
- strncpy(sbuf, sbuf2, MAXPDSTRING-30);
- sbuf[MAXPDSTRING-30] = 0;
- strcat(sbuf, "/bin");
- sys_guidir = gensym(sbuf);
+ strncpy(sbuf2, sbuf, FILENAME_MAX-30);
+ sbuf[FILENAME_MAX-30] = 0;
+ strcat(sbuf2, "/bin");
+ sys_guidir = gensym(sbuf2);
}
#endif
}
Modified: branches/pd-extended/v0-40/pd/src/s_path.c
===================================================================
--- branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-20 19:54:07 UTC (rev 9861)
+++ branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-21 17:12:36 UTC (rev 9862)
@@ -98,6 +98,24 @@
strncpy(to, buf, FILENAME_MAX - 1);
#endif
}
+
+/* test if path is absolute or relative, based on leading /, env vars, ~, etc */
+int sys_isabsolutepath(const char *dir)
+{
+ if (dir[0] == '/' || dir[0] == '~'
+#ifdef MSW
+ || dir[0] == '%' || (dir[1] == ':' && dir[2] == '/')
+#endif
+ )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
/******************* Utility functions used below ******************/
/*!
@@ -281,11 +299,7 @@
int sys_open_absolute(const char *name, const char* ext,
char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp)
{
- if (name[0] == '/' || name[0] == '~'
-#ifdef MSW
- || name[0] == '%' || (name[1] == ':' && name[2] == '/')
-#endif
- )
+ if (sys_isabsolutepath(name))
{
char dirbuf[FILENAME_MAX];
int dirlen = (strrchr(name, '/') - name);
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