Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16717
Modified Files: Tag: desiredata desire.c s_path.c s_stuff.h Log Message: changed sys_open_absolute and sys_trytoopenone so that they allocate their own dirresult
Index: desire.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v retrieving revision 1.1.2.217.2.165 retrieving revision 1.1.2.217.2.166 diff -C2 -d -r1.1.2.217.2.165 -r1.1.2.217.2.166 *** desire.c 18 Jul 2007 19:07:23 -0000 1.1.2.217.2.165 --- desire.c 18 Jul 2007 23:55:24 -0000 1.1.2.217.2.166 *************** *** 6922,6930 **** open is attempted, otherwise ASCII (this only matters on Microsoft.) If "x" is zero, the file is sought in the directory "." or in the global path.*/ ! int canvas_open(t_canvas *x, const char *name, const char *ext, ! char *dirresult, char **nameresult, unsigned int size, int bin) { 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; start trying in directories named in this and parent environments */ for (t_canvas *y=x; y; y = y->owner) if (y->env) { --- 6922,6929 ---- open is attempted, otherwise ASCII (this only matters on Microsoft.) If "x" is zero, the file is sought in the directory "." or in the global path.*/ ! static int canvas_open_2(t_canvas *x, const char *name, const char *ext, char **dirresult, char **nameresult, int bin) { int fd = -1; /* first check if "name" is absolute (and if so, try to open) */ ! if (sys_open_absolute(name, ext, dirresult, nameresult, bin, &fd)) return fd; /* otherwise "name" is relative; start trying in directories named in this and parent environments */ for (t_canvas *y=x; y; y = y->owner) if (y->env) { *************** *** 6935,6945 **** char *realname; asprintf(&realname, "%s/%s", dir, nl->nl_string); ! if ((fd = sys_trytoopenone(realname, name, ext, dirresult, nameresult, size, bin)) >= 0) return fd; } } ! return open_via_path((x ? canvas_getdir(x)->name : "."), name, ext, dirresult, nameresult, size, bin); } /* end miller 0.40 */
static void canvas_with_reply (t_pd *x, t_symbol *s, int argc, t_atom *argv) { if (!( argc>=2 && IS_A_FLOAT(argv,0) && IS_A_SYMBOL(argv,1) )) return; --- 6934,6954 ---- char *realname; asprintf(&realname, "%s/%s", dir, nl->nl_string); ! if ((fd = sys_trytoopenone(realname, name, ext, dirresult, nameresult, bin)) >= 0) return fd; } } ! *dirresult = (char *)malloc(MAXPDSTRING); ! int r = open_via_path((x ? canvas_getdir(x)->name : "."), name, ext, *dirresult, nameresult, MAXPDSTRING, bin); ! if (r<0) {free(*dirresult); *dirresult = 0;} ! return r; } /* end miller 0.40 */
+ int canvas_open(t_canvas *x, const char *name, const char *ext, char *dirresult, char **nameresult, unsigned int size, int bin) { + char *dirr; + int r = canvas_open_2(x,name,ext,&dirr,nameresult,bin); + if (dirr) {strncpy(dirresult,dirr,size); dirresult[size-1]=0; free(dirr);} + return r; + } + static void canvas_with_reply (t_pd *x, t_symbol *s, int argc, t_atom *argv) { if (!( argc>=2 && IS_A_FLOAT(argv,0) && IS_A_SYMBOL(argv,1) )) return; *************** *** 7517,7521 **** }
- /* this isn't worked out yet. */ static const char *errobject; static const char *errstring; --- 7526,7529 ----
Index: s_path.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_path.c,v retrieving revision 1.3.4.6.2.8.2.8 retrieving revision 1.3.4.6.2.8.2.9 diff -C2 -d -r1.3.4.6.2.8.2.8 -r1.3.4.6.2.8.2.9 *** s_path.c 28 Jun 2007 04:29:16 -0000 1.3.4.6.2.8.2.8 --- s_path.c 18 Jul 2007 23:55:27 -0000 1.3.4.6.2.8.2.9 *************** *** 140,195 **** #endif
! /* try to open a file in the directory "dir", named "name""ext", ! for reading. "Name" may have slashes. The directory is copied to ! "dirresult" which must be at least "size" bytes. "nameresult" is set ! to point to the filename (copied elsewhere into the same buffer). ! The "bin" flag requests opening for binary (which only makes a difference ! on Windows). */ ! ! int sys_trytoopenone(const char *dir, const char *name, const char* ext, ! char *dirresult, char **nameresult, unsigned int size, int bin) ! { ! int fd; ! if (strlen(dir) + strlen(name) + strlen(ext) + 4 > size) return -1; ! strcpy(dirresult, dir); ! 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 ! { ! if (sys_verbose) post("tried %s and succeeded", dirresult); ! sys_unbashfilename(dirresult, dirresult); ! char *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); } ! return -1; }
! /* check if we were given an absolute pathname, if so try to open it ! and return 1 to signal the caller to cancel any path searches */ ! int sys_open_absolute(const char *name, const char* ext, ! char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp) ! { ! if (name[0] == '/' #ifdef MSW || (name[1] == ':' && name[2] == '/') --- 140,180 ---- #endif
! /* try to open a file in the directory "dir", named "name""ext", for reading. "Name" may have slashes. ! The directory is copied to "dirresult" which must be at least "size" bytes. "nameresult" is set ! to point to the filename (copied elsewhere into the same buffer). The "bin" flag requests opening ! for binary (which only makes a difference on Windows). */ ! int sys_trytoopenone(const char *dir, const char *name, const char* ext, char **dirresult, char **nameresult, int bin) { ! bool needslash = (*dir && dir[strlen(dir)-1] != '/'); ! asprintf(dirresult,"%s%s%s%s", dir, needslash ? "/" : "", name, ext); ! sys_bashfilename(*dirresult, *dirresult); ! DEBUG(post("looking for %s",*dirresult)); /* see if we can open the file for reading */ ! int fd = open(*dirresult,O_RDONLY | MSWOPENFLAG(bin)); ! if (fd<0) { ! if (sys_verbose) post("tried %s and failed", *dirresult); ! return -1; } ! #ifdef UNISTD /* in unix, further check that it's not a directory */ ! 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); ! return -1; ! } ! #endif ! if (sys_verbose) post("tried %s and succeeded", *dirresult); ! sys_unbashfilename(*dirresult, *dirresult); ! char *slash = strrchr(*dirresult, '/'); ! if (slash) { ! *slash = 0; ! *nameresult = slash + 1; ! } else *nameresult = *dirresult; ! return fd; }
! /* check if we were given an absolute pathname, if so try to open it and return 1 to signal the caller to cancel any path searches */ ! int sys_open_absolute(const char *name, const char* ext, char **dirresult, char **nameresult, int bin, int *fdp) { ! if (name[0] == '/' #ifdef MSW || (name[1] == ':' && name[2] == '/') *************** *** 197,205 **** ) { int dirlen = strrchr(name, '/') - name; - if (dirlen > MAXPDSTRING-1) dirlen = MAXPDSTRING-1; char *dirbuf = new char[dirlen+1]; ! strncpy(dirbuf, name, dirlen); ! dirbuf[dirlen] = 0; ! *fdp = sys_trytoopenone(dirbuf, name+(dirlen+1), ext, dirresult, nameresult, size, bin); delete[] dirbuf; return 1; --- 182,187 ---- ) { int dirlen = strrchr(name, '/') - name; char *dirbuf = new char[dirlen+1]; ! *fdp = sys_trytoopenone(name, name+dirlen+1, ext, dirresult, nameresult, bin); delete[] dirbuf; return 1; *************** *** 219,240 ****
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; return -1; } --- 201,220 ----
static int do_open_via_path(const char *dir, const char *name, ! const char *ext, char **dirresult, char **nameresult, 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, bin, &fd)) return fd; /* otherwise "name" is relative; try the directory "dir" first. */ ! if ((fd = sys_trytoopenone(dir, name, ext, dirresult, nameresult, 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, bin)) >= 0) return fd; /* next look in "extra" */ ! if (sys_usestdpath && (fd = sys_trytoopenone(pd_extrapath->nl_string, name, ext, dirresult, nameresult, bin)) >= 0) return fd; *dirresult = 0; ! *nameresult = *dirresult; return -1; } *************** *** 243,254 **** extern "C" 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. */ extern "C" 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 */ int fd; --- 223,236 ---- extern "C" int open_via_path(const char *dir, const char *name, const char *ext, char *dirresult, char **nameresult, unsigned int size, int bin) { ! char *dirr; ! int r = do_open_via_path(dir, name, ext, &dirr, nameresult, bin, sys_searchpath); ! if (dirr) {strncpy(dirresult,dirr,size); dirresult[size-1]=0; free(dirr);} ! return r; }
! /* 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. */ extern "C" void open_via_helppath(const char *name, const char *dir) { ! char realname[MAXPDSTRING], *dirbuf, *basename; /* make up a silly "dir" if none is supplied */ int fd; *************** *** 258,268 **** if (strlen(realname) > 3 && !strcmp(realname+strlen(realname)-3, ".pd")) 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" */ snprintf(realname,MAXPDSTRING,"help-%s",name); 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; --- 240,250 ---- if (strlen(realname) > 3 && !strcmp(realname+strlen(realname)-3, ".pd")) realname[strlen(realname)-3] = 0; strcat(realname, "-help.pd"); ! if ((fd = do_open_via_path(dir,realname,"",&dirbuf,&basename,0,sys_helppath))>=0) goto gotone; /* 2. "help-objectname.pd" */ snprintf(realname,MAXPDSTRING,"help-%s",name); realname[MAXPDSTRING-1] = 0; ! if ((fd = do_open_via_path(dir,realname,"",&dirbuf,&basename,0,sys_helppath))>=0) goto gotone; /* 3. "objectname.pd" */ ! if ((fd = do_open_via_path(dir, name,"",&dirbuf,&basename,0,sys_helppath))>=0) goto gotone; post("sorry, couldn't find help patch for "%s"", name); return;
Index: s_stuff.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v retrieving revision 1.5.4.10.2.8.2.15 retrieving revision 1.5.4.10.2.8.2.16 diff -C2 -d -r1.5.4.10.2.8.2.15 -r1.5.4.10.2.8.2.16 *** s_stuff.h 11 Jul 2007 20:57:10 -0000 1.5.4.10.2.8.2.15 --- s_stuff.h 18 Jul 2007 23:55:27 -0000 1.5.4.10.2.8.2.16 *************** *** 38,45 **** #endif
! int sys_open_absolute(const char *name, const char* ext, ! char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp); ! int sys_trytoopenone(const char *dir, const char *name, const char* ext, ! char *dirresult, char **nameresult, unsigned int size, int bin);
/* s_main.c */ --- 38,43 ---- #endif
! int sys_open_absolute( const char *name, const char* ext, char **dirresult, char **nameresult, int bin, int *fdp); ! int sys_trytoopenone(const char *dir, const char *name, const char* ext, char **dirresult, char **nameresult, int bin);
/* s_main.c */