[PD-cvs] SF.net SVN: pure-data: [9857] branches/pd-extended/v0-40/externals/loaders/ libdir.c

eighthave at users.sourceforge.net eighthave at users.sourceforge.net
Tue May 20 00:56:35 CEST 2008


Revision: 9857
          http://pure-data.svn.sourceforge.net/pure-data/?rev=9857&view=rev
Author:   eighthave
Date:     2008-05-19 15:56:35 -0700 (Mon, 19 May 2008)

Log Message:
-----------
fixed bug where first library loaded had garbage in the path; switched from MAXPDSTRING to FILENAME_MAX, since it is dealing ultimately with filenames

Modified Paths:
--------------
    branches/pd-extended/v0-40/externals/loaders/libdir.c

Modified: branches/pd-extended/v0-40/externals/loaders/libdir.c
===================================================================
--- branches/pd-extended/v0-40/externals/loaders/libdir.c	2008-05-19 19:25:03 UTC (rev 9856)
+++ branches/pd-extended/v0-40/externals/loaders/libdir.c	2008-05-19 22:56:35 UTC (rev 9857)
@@ -40,15 +40,15 @@
 {
     int fd = -1;
     unsigned int i;
-    char helppathname[MAXPDSTRING];
-    char fullclassname[MAXPDSTRING], dirbuf[MAXPDSTRING];
-    char reldirbuf[MAXPDSTRING], curdir[MAXPDSTRING], *nameptr;
+    char helppathname[FILENAME_MAX];
+    char fullclassname[FILENAME_MAX], dirbuf[FILENAME_MAX];
+    char reldirbuf[FILENAME_MAX], curdir[FILENAME_MAX], *nameptr;
     t_canvasenvironment *canvasenvironment;
 
 /* look for meta file (classname)/(classname)-meta.pd */
-    strncpy(fullclassname, classname, MAXPDSTRING - 6);
+    strncpy(fullclassname, classname, FILENAME_MAX - 6);
     strcat(fullclassname, "/");
-    strncat(fullclassname, classname, MAXPDSTRING - strlen(fullclassname) - 6);
+    strncat(fullclassname, classname, FILENAME_MAX - strlen(fullclassname) - 6);
     strcat(fullclassname, "-meta");
     
     /* if this is being called from a canvas, then add the library path to the
@@ -58,45 +58,39 @@
     {
         canvasenvironment = canvas_getenv(canvas);
         if ((fd = canvas_open(0, fullclassname, ".pd",
-                                dirbuf, &nameptr, MAXPDSTRING, 0)) < 0) 
+                              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
+        // 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] == 47) // 47 is "/" in ascii
-                          strncat(reldirbuf, "../", MAXPDSTRING);
+            if(curdir[i] == '/')
+                strncat(reldirbuf, "../", FILENAME_MAX);
         }
-        strncat(reldirbuf, dirbuf, MAXPDSTRING);
-
-
-        // TODO: have this add to the canvas-local path only
+        strncat(reldirbuf, dirbuf, FILENAME_MAX);
         canvasenvironment->ce_path = namelist_append(canvasenvironment->ce_path, 
-                                reldirbuf, 0);
+                                                     reldirbuf, 0);
         post("libdir_loader: added %s to the canvas-local path", classname);
     }
     else
 #endif
     {
         if ((fd = open_via_path(".", fullclassname, ".pd",
-                                dirbuf, &nameptr, MAXPDSTRING, 0)) < 0) 
+                                dirbuf, &nameptr, FILENAME_MAX, 0)) < 0) 
         {
             return (0);
         }
         close(fd);
         sys_searchpath = namelist_append(sys_searchpath, dirbuf, 0);
-        strncpy(helppathname, sys_libdir->s_name, MAXPDSTRING-30);
-        helppathname[MAXPDSTRING-30] = 0;
+        strncpy(helppathname, sys_libdir->s_name, FILENAME_MAX-30);
+        helppathname[FILENAME_MAX-30] = 0;
         strcat(helppathname, "/doc/5.reference/");
         strcat(helppathname, classname);
         sys_helppath = namelist_append(sys_helppath, helppathname, 0);


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