[PD-cvs] pd/src s_path.c,1.3.4.6.2.8.2.5,1.3.4.6.2.8.2.6

Mathieu Bouchard matju at users.sourceforge.net
Wed Dec 20 05:20:41 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24079

Modified Files:
      Tag: desiredata
	s_path.c 
Log Message:
loader from pd 0.40


Index: s_path.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_path.c,v
retrieving revision 1.3.4.6.2.8.2.5
retrieving revision 1.3.4.6.2.8.2.6
diff -C2 -d -r1.3.4.6.2.8.2.5 -r1.3.4.6.2.8.2.6
*** s_path.c	20 Dec 2006 04:01:33 -0000	1.3.4.6.2.8.2.5
--- s_path.c	20 Dec 2006 04:20:39 -0000	1.3.4.6.2.8.2.6
***************
*** 254,345 ****
  
  /* search for a file in a specified directory, then along the globally
! defined search path, using ext as filename extension.  Exception:
! if the 'name' starts with a slash or a letter, colon, and slash in MSW,
! there is no search and instead we just try to open the file literally.  The
  fd is returned, the directory ends up in the "dirresult" which must be at
  least "size" bytes.  "nameresult" is set to point to the filename, which
! ends up in the same buffer as dirresult. */
  
! int open_via_path(const char *dir, const char *name, const char* ext,
!     char *dirresult, char **nameresult, unsigned int size, int bin)
  {
!     t_namelist *nl, thislist;
      int fd = -1;
-     char listbuf[MAXPDSTRING];
  
!     if (name[0] == '/' 
! #ifdef MSW
!         || (name[1] == ':' && name[2] == '/')
! #endif
!             )
!     {
!         thislist.nl_next = 0;
!         thislist.nl_string = listbuf;
!         listbuf[0] = 0;
!     }
!     else
!     {
!         thislist.nl_string = listbuf;
!         thislist.nl_next = sys_searchpath;
!         strncpy(listbuf, dir, MAXPDSTRING);
!         listbuf[MAXPDSTRING-1] = 0;
!         sys_unbashfilename(listbuf, listbuf);
!     }
  
!         /* search, first, through the search path (to which we prepended the
!         current directory), then, if enabled, look in the "extra" dir */
!     for (nl = &thislist; nl;
!         nl = (nl->nl_next ? nl->nl_next :
!             (nl == pd_extrapath ? 0 : 
!                 (sys_usestdpath ? pd_extrapath : 0))))
!     {
!         if (strlen(nl->nl_string) + strlen(name) + strlen(ext) + 4 >
!             size)
!                 continue;
!         strcpy(dirresult, nl->nl_string);
!         if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
!                strcat(dirresult, "/");
!         strcat(dirresult, name);
!         strcat(dirresult, ext);
!         sys_bashfilename(dirresult, dirresult);
  
-         DEBUG(post("looking for %s",dirresult));
-             /* see if we can open the file for reading */
-         if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
-         {
-                 /* in unix, further check that it's not a directory */
- #ifdef UNISTD
-             struct stat statbuf;
-             int ok =  ((fstat(fd, &statbuf) >= 0) &&
-                 !S_ISDIR(statbuf.st_mode));
-             if (!ok)
-             {
-                 if (sys_verbose) post("tried %s; stat failed or directory",
-                     dirresult);
-                 close (fd);
-                 fd = -1;
-             }
-             else
- #endif
-             {
-                 char *slash;
-                 if (sys_verbose) post("tried %s and succeeded", dirresult);
-                 sys_unbashfilename(dirresult, dirresult);
-                 slash = strrchr(dirresult, '/');
-                 if (slash)
-                 {
-                     *slash = 0;
-                     *nameresult = slash + 1;
-                 }
-                 else *nameresult = dirresult;
-                 
-                 return (fd);  
-             }
-         }
-         else
-         {
-             if (sys_verbose) post("tried %s and failed", dirresult);
-         }
-     }
      *dirresult = 0;
      *nameresult = dirresult;
--- 254,295 ----
  
  /* search for a file in a specified directory, then along the globally
! defined search path, using ext as filename extension.  The
  fd is returned, the directory ends up in the "dirresult" which must be at
  least "size" bytes.  "nameresult" is set to point to the filename, which
! ends up in the same buffer as dirresult.  Exception:
! if the 'name' starts with a slash or a letter, colon, and slash in MSW,
! there is no search and instead we just try to open the file literally.  */
  
! /* see also canvas_openfile() which, in addition, searches down the
! canvas-specific path. */
! 
! static int do_open_via_path(const char *dir, const char *name,
!     const char *ext, char *dirresult, char **nameresult, unsigned int size,
!     int bin, t_namelist *searchpath)
  {
!     t_namelist *nl;
      int fd = -1;
  
!         /* first check if "name" is absolute (and if so, try to open) */
!     if (sys_open_absolute(name, ext, dirresult, nameresult, size, bin, &fd))
!         return (fd);
!     
!         /* otherwise "name" is relative; try the directory "dir" first. */
!     if ((fd = sys_trytoopenone(dir, name, ext,
!         dirresult, nameresult, size, bin)) >= 0)
!             return (fd);
  
!         /* next go through the search path */
!     for (nl = searchpath; nl; nl = nl->nl_next)
!         if ((fd = sys_trytoopenone(nl->nl_string, name, ext,
!             dirresult, nameresult, size, bin)) >= 0)
!                 return (fd);
! 
!         /* next look in "extra" */
!     if (sys_usestdpath &&
!         (fd = sys_trytoopenone(pd_extrapath->nl_string, name, ext,
!             dirresult, nameresult, size, bin)) >= 0)
!                 return (fd);
  
      *dirresult = 0;
      *nameresult = dirresult;
***************
*** 347,419 ****
  }
  
! static int do_open_via_helppath(const char *realname, t_namelist *listp)
  {
!     t_namelist *nl;
!     int fd = -1;
!     char dirresult[MAXPDSTRING], realdir[MAXPDSTRING];
!     for (nl = listp; nl; nl = nl->nl_next)
!     {
!         strcpy(dirresult, nl->nl_string);
!         strcpy(realdir, dirresult);
!         if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
!                strcat(dirresult, "/");
!         strcat(dirresult, realname);
!         sys_bashfilename(dirresult, dirresult);
! 
!         DEBUG(post("looking for %s",dirresult));
!             /* see if we can open the file for reading */
!         if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(0))) >= 0)
!         {
!                 /* in unix, further check that it's not a directory */
! #ifdef UNISTD
!             struct stat statbuf;
!             int ok =  ((fstat(fd, &statbuf) >= 0) &&
!                 !S_ISDIR(statbuf.st_mode));
!             if (!ok)
!             {
!                 if (sys_verbose) post("tried %s; stat failed or directory",
!                     dirresult);
!                 close (fd);
!                 fd = -1;
!             }
!             else
! #endif
!             {
!                 char *slash;
!                 if (sys_verbose) post("tried %s and succeeded", dirresult);
!                 sys_unbashfilename(dirresult, dirresult);
!                 close (fd);
!                 glob_evalfile(0, gensym((char*)realname), gensym(realdir));
!                 return (1);
!             }
!         }
!         else
!         {
!             if (sys_verbose) post("tried %s and failed", dirresult);
!         }
!     }
!     return (0);
  }
  
!     /* LATER make this use open_via_path above.  We expect the ".pd"
      suffix here, even though we have to tear it back off for one of the
      search attempts. */
  void open_via_helppath(const char *name, const char *dir)
  {
!     t_namelist *nl, thislist, *listp;
!     int fd = -1;
!     char dirbuf2[MAXPDSTRING], realname[MAXPDSTRING];
  
-         /* if directory is supplied, put it at head of search list. */
-     if (*dir)
-     {
-         thislist.nl_string = dirbuf2;
-         thislist.nl_next = sys_helppath;
-         strncpy(dirbuf2, dir, MAXPDSTRING);
-         dirbuf2[MAXPDSTRING-1] = 0;
-         sys_unbashfilename(dirbuf2, dirbuf2);
-         listp = &thislist;
-     }
-     else listp = sys_helppath;
          /* 1. "objectname-help.pd" */
      strncpy(realname, name, MAXPDSTRING-10);
--- 297,318 ----
  }
  
! /* open via path, using the global search path. */
! int open_via_path(const char *dir, const char *name, const char *ext,
!     char *dirresult, char **nameresult, unsigned int size, int bin)
  {
!     return (do_open_via_path(dir, name, ext, dirresult, nameresult,
!         size, bin, sys_searchpath));
  }
  
!     /* Open a help file using the help search path.  We expect the ".pd"
      suffix here, even though we have to tear it back off for one of the
      search attempts. */
  void open_via_helppath(const char *name, const char *dir)
  {
!     char realname[MAXPDSTRING], dirbuf[MAXPDSTRING], *basename;
!         /* make up a silly "dir" if none is supplied */
!     const char *usedir = (*dir ? dir : "./");
!     int fd;
  
          /* 1. "objectname-help.pd" */
      strncpy(realname, name, MAXPDSTRING-10);
***************
*** 422,441 ****
          realname[strlen(realname)-3] = 0;
      strcat(realname, "-help.pd");
!     if (do_open_via_helppath(realname, listp))
!         return;
          /* 2. "help-objectname.pd" */
      strcpy(realname, "help-");
      strncat(realname, name, MAXPDSTRING-10);
      realname[MAXPDSTRING-1] = 0;
!     if (do_open_via_helppath(realname, listp))
!         return;
          /* 3. "objectname.pd" */
!     if (do_open_via_helppath(name, listp))
!         return;
      post("sorry, couldn't find help patch for \"%s\"", name);
      return;
  }
  
- 
  /* Startup file reading for linux and MACOSX.  As of 0.38 this will be
  deprecated in favor of the "settings" mechanism */
--- 321,347 ----
          realname[strlen(realname)-3] = 0;
      strcat(realname, "-help.pd");
!     if ((fd = do_open_via_path(dir, realname, "", dirbuf, &basename, 
!         MAXPDSTRING, 0, sys_helppath)) >= 0)
!             goto gotone;
! 
          /* 2. "help-objectname.pd" */
      strcpy(realname, "help-");
      strncat(realname, name, MAXPDSTRING-10);
      realname[MAXPDSTRING-1] = 0;
!     if ((fd = do_open_via_path(dir, realname, "", dirbuf, &basename, 
!         MAXPDSTRING, 0, sys_helppath)) >= 0)
!             goto gotone;
! 
          /* 3. "objectname.pd" */
!     if ((fd = do_open_via_path(dir, name, "", dirbuf, &basename, 
!         MAXPDSTRING, 0, sys_helppath)) >= 0)
!             goto gotone;
      post("sorry, couldn't find help patch for \"%s\"", name);
      return;
+ gotone:
+     close (fd);
+     glob_evalfile(0, gensym((char*)basename), gensym(dirbuf));
  }
  
  /* Startup file reading for linux and MACOSX.  As of 0.38 this will be
  deprecated in favor of the "settings" mechanism */





More information about the Pd-cvs mailing list