/[ascend]/trunk/base/generic/general/ospath.c
ViewVC logotype

Diff of /trunk/base/generic/general/ospath.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 584 by johnpye, Sat Apr 29 04:19:17 2006 UTC revision 585 by johnpye, Wed May 10 17:02:21 2006 UTC
# Line 25  Line 25 
25    
26  #ifndef NDEBUG  #ifndef NDEBUG
27  # include <assert.h>  # include <assert.h>
28  # define M(MSG) fprintf(stderr,"%s:%d: (%s) %s\n",__FILE__,__LINE__,__FUNCTION__,MSG)  # define M(MSG) fprintf(stderr,"%s:%d: (%s) %s\n",__FILE__,__LINE__,__FUNCTION__,MSG);fflush(stderr);fflush(stderr)
29  # define X(VAR) fprintf(stderr,"%s:%d: (%s) %s=%s\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR)  # define MC(CLR,MSG) fprintf(stderr,"%c[%sm%s:%d: (%s) %s%c[0m\n",27,CLR,__FILE__,__LINE__,__FUNCTION__,MSG,27);fflush(stderr)
30  # define V(VAR) fprintf(stderr,"%s:%d: (%s) %s=%d\n",__FILE__,__LINE__,__FUNCTION__,#VAR,(VAR))  # define MM(MSG) MC("34",MSG)
31  # define D(VAR) fprintf(stderr,"%s:%d: (%s) %s=",__FILE__,__LINE__,__FUNCTION__,#VAR);ospath_debug(VAR)  # define X(VAR) fprintf(stderr,"%s:%d: (%s) %s=%s\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr)
32    # define C(VAR) fprintf(stderr,"%s:%d: (%s) %s=%c\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr)
33    # define V(VAR) fprintf(stderr,"%s:%d: (%s) %s=%d\n",__FILE__,__LINE__,__FUNCTION__,#VAR,(VAR));fflush(stderr)
34    # define D(VAR) fprintf(stderr,"%s:%d: (%s) %s=",__FILE__,__LINE__,__FUNCTION__,#VAR);ospath_debug(VAR);fflush(stderr)
35    # define DD(VAR) fprintf(stderr,"%c[34;1m%s:%d: (%s)%c[0m %s=",27,__FILE__,__LINE__,__FUNCTION__,27,#VAR);ospath_debug(VAR);fflush(stderr)
36  #else  #else
37  # include <assert.h>  # include <assert.h>
38  # define M(MSG) ((void)0)  # define M(MSG) ((void)0)
39    # define MC(CLR,MSG) ((void)0)
40  # define X(VAR) ((void)0)  # define X(VAR) ((void)0)
41    # define C(VAR) ((void)0)
42  # define V(VAR) ((void)0)  # define V(VAR) ((void)0)
43  # define D(VAR) ((void)0)  # define D(VAR) ((void)0)
44    # define DD(VAR) ((void)0)
45    # define MM(VAR) ((void)0)
46  #endif  #endif
47    
48  #if defined(__WIN32__) && !defined(__MINGW32__)  #if defined(__WIN32__) && !defined(__MINGW32__)
 # include <direct.h>  
 # include <stdlib.h>  
49  # define STRCPY strcpy  # define STRCPY strcpy
50  # define STRNCPY(dest,src,n) strncpy_s(dest,n,src,n)  # define STRNCPY(dest,src,n) strncpy_s(dest,n,src,n)
51  # define STRCAT strcat  # define STRCAT strcat
# Line 77  struct FilePath{ Line 83  struct FilePath{
83    
84  #include <string.h>  #include <string.h>
85    
86  #define MALLOC malloc  #if !defined(MALLOC) && !defined(FREE)
87  #define FREE free  # define MALLOC malloc
88  #define CALLOC calloc  # define FREE free
89    #endif
90    
91  #define E(MSG) fprintf(stderr,"%s:%d: (%s) ERROR: %s\n",__FILE__,__LINE__,__FUNCTION__,MSG)  #define E(MSG) fprintf(stderr,"%s:%d: (%s) ERROR: %s\n",__FILE__,__LINE__,__FUNCTION__,MSG)
92    
# Line 89  void ospath_fixslash(char *path); Line 96  void ospath_fixslash(char *path);
96    
97  struct FilePath *ospath_getcwd();  struct FilePath *ospath_getcwd();
98    
 /**  
     This function cleans up the path string used to construct the FilePath object:  
     1. Get rid of multiple / 's one after the other...  
   
        ie. "///usr/bin///hello/////there// --> "/usr/bin/hello/there/"  
   
     2. Resolve a leading tilde (~) to the current user's HOME path  
   
     3. Remove redundant /./ in middle of path  
   
     4. Remove reduncant dir/.. in path  
   
     5. Environment substitution??  
   
     6. On windows, drive reference if not specified  
   
     7. What about \\server\path and URLs, gnomefs, etc?  
 */  
 void ospath_cleanup(struct FilePath *);  
   
99  void ospath_copy(struct FilePath *dest, struct FilePath *src);  void ospath_copy(struct FilePath *dest, struct FilePath *src);
100    
101    
# Line 141  void ospath_extractdriveletter(struct Fi Line 128  void ospath_extractdriveletter(struct Fi
128  */  */
129  struct FilePath *ospath_new(const char *path){  struct FilePath *ospath_new(const char *path){
130      struct FilePath *fp;      struct FilePath *fp;
131      fp = MALLOC(sizeof(struct FilePath));      fp = ospath_new_noclean(path);
     STRNCPY(fp->path, path, PATH_MAX);  
     //X(fp->path);  
     //X(path);  
     assert(strcmp(fp->path,path)==0);  
 #ifdef WINPATHS  
     //X(fp->drive);  
     ospath_extractdriveletter(fp);  
 #endif  
   
     //X(fp->drive);  
132    
133  #ifdef DO_FIXSLASHES  #ifdef DO_FIXSLASHES
134      ospath_fixslash(fp->path);      ospath_fixslash(fp->path);
# Line 164  struct FilePath *ospath_new(const char * Line 141  struct FilePath *ospath_new(const char *
141      return fp;      return fp;
142  }  }
143    
144  void ospath_free(struct FilePath *fp){  
145      FREE(fp);  
146    /// Create but with no 'cleanup', and no fixing of / vs \.
147    struct FilePath *ospath_new_noclean(const char *path){
148        struct FilePath *fp = (struct FilePath *)MALLOC(sizeof(struct FilePath));
149        STRNCPY(fp->path,path,PATH_MAX);
150        assert(strcmp(fp->path,path)==0);
151    #ifdef WINPATHS
152        //X(fp->path);
153        ospath_extractdriveletter(fp);
154    #endif
155    
156        return fp;
157  }  }
158    
159    struct FilePath *ospath_new_expand_env(const char *path, GetEnvFn *getenvptr){
160        struct FilePath *fp;
161    
162        char *pathnew = env_subst(path,getenvptr);
163        fp = ospath_new(pathnew);
164        FREE(pathnew);
165    
166        return fp;
167    }
168    
169    
170  /**  /**
171      This function will serve to allow #include-style file paths      This function will serve to allow #include-style file paths
172      to be specified with platform-independent forward slashes then      to be specified with platform-independent forward slashes then
# Line 187  void ospath_free(struct FilePath *fp){ Line 186  void ospath_free(struct FilePath *fp){
186      match is OK or not.      match is OK or not.
187  */  */
188  struct FilePath *ospath_new_from_posix(const char *posixpath){  struct FilePath *ospath_new_from_posix(const char *posixpath){
189      struct FilePath *fp = MALLOC(sizeof(struct FilePath));      struct FilePath *fp;
190      STRNCPY(fp->path,posixpath,PATH_MAX);      fp = ospath_new_noclean(posixpath);
 #ifdef WINPATHS  
     X(fp->path);  
     ospath_extractdriveletter(fp);  
 #endif  
191    
192  #ifdef DO_FIXSLASHES  #ifdef DO_FIXSLASHES
193      ospath_fixslash(fp->path);      ospath_fixslash(fp->path);
# Line 204  struct FilePath *ospath_new_from_posix(c Line 199  struct FilePath *ospath_new_from_posix(c
199    
200      return fp;      return fp;
201  }  }
202    
203    void ospath_free(struct FilePath *fp){
204        FREE(fp);
205    }
206    
207    void ospath_free_str(char *str){
208        FREE(str);
209    }
210    
211    
212  #ifdef DO_FIXSLASHES  #ifdef DO_FIXSLASHES
213  void ospath_fixslash(char *path){  void ospath_fixslash(char *path){
# Line 254  void ospath_fixslash(char *path){ Line 258  void ospath_fixslash(char *path){
258    
259      //X(path);      //X(path);
260  }  }
 #endif  
   
   
 /// Create but with no 'cleanup' call  
 struct FilePath *ospath_new_noclean(const char *path){  
     struct FilePath *fp = MALLOC(sizeof(struct FilePath));  
     STRNCPY(fp->path,path,PATH_MAX);  
   
 #ifdef WINPATHS  
     //X(fp->path);  
     ospath_extractdriveletter(fp);  
261  #endif  #endif
262    
     //D(fp);  
   
 /*  
 #ifdef DO_FIXSLASHES  
     ospath_fixslash(fp->path);  
     D(fp);  
 #endif  
 */  
     return fp;  
 }  
   
263  struct FilePath *ospath_getcwd(void){  struct FilePath *ospath_getcwd(void){
264      struct FilePath *fp = MALLOC(sizeof(struct FilePath));      struct FilePath *fp = (struct FilePath *)MALLOC(sizeof(struct FilePath));
265      char *cwd;      char *cwd;
266    
267      // get current working directory      // get current working directory
# Line 377  void ospath_cleanup(struct FilePath *fp) Line 359  void ospath_cleanup(struct FilePath *fp)
359      // reset fp->path as required.      // reset fp->path as required.
360      STRCPY(fp->path, (startslash ? PATH_SEPARATOR_STR : ""));      STRCPY(fp->path, (startslash ? PATH_SEPARATOR_STR : ""));
361    
362        D(fp);
363      X(path);      X(path);
364    
365      // split path into it tokens, using STRTOK which is NOT reentrant      // split path into it tokens, using STRTOK which is NOT reentrant
# Line 390  void ospath_cleanup(struct FilePath *fp) Line 373  void ospath_cleanup(struct FilePath *fp)
373          //M("NEXT TOKEN");          //M("NEXT TOKEN");
374          //X(p);          //X(p);
375          //X(path+strlen(p)+1);          //X(path+strlen(p)+1);
376          if(strcmp(p, "~")==0){          if(*p=='$'){
377                M("PATH COMPONENT WITH ENV VAR");
378    
379            }else if(strcmp(p, "~")==0){
380    
381              if(p == path){ // check that the ~ is the first character in the path              if(p == path){ // check that the ~ is the first character in the path
382                  if(ospath_isvalid(home)){                  if(ospath_isvalid(home)){
# Line 471  int ospath_isvalid(struct FilePath *fp){ Line 457  int ospath_isvalid(struct FilePath *fp){
457  char *ospath_str(struct FilePath *fp){  char *ospath_str(struct FilePath *fp){
458      char *s;      char *s;
459  #ifdef WINPATHS  #ifdef WINPATHS
460      s = CALLOC(strlen(fp->drive)+strlen(fp->path),sizeof(char));      s = (char *)MALLOC(sizeof(char)*(strlen(fp->drive)+strlen(fp->path) ) );
461      STRCPY(s,fp->drive);      STRCPY(s,fp->drive);
462      STRCAT(s,fp->path);      STRCAT(s,fp->path);
463  #else  #else
464      s = CALLOC(strlen(fp->path),sizeof(char));      s = MALLOC(sizeof(char)*strlen(fp->path));
465      STRCPY(s,fp->path);      STRCPY(s,fp->path);
466  #endif  #endif
467      return s;      return s;
# Line 489  void ospath_strcpy(struct FilePath *fp, Line 475  void ospath_strcpy(struct FilePath *fp,
475      STRNCPY(dest,fp->path,destsize);      STRNCPY(dest,fp->path,destsize);
476  #endif  #endif
477  }  }
478    
479    void ospath_strcat(struct FilePath *fp, char *dest, int destsize){
480        int remaining = destsize - strlen(dest);
481    #ifdef WINPATHS
482        STRNCAT(dest,fp->drive,remaining);
483        STRNCAT(dest,fp->path,remaining-strlen(dest));
484    #else
485        STRNCPY(dest,fp->path,remaining);
486    #endif
487    }
488    
489  void ospath_fwrite(struct FilePath *fp, FILE *dest){  void ospath_fwrite(struct FilePath *fp, FILE *dest){
490  #ifdef WINPATHS  #ifdef WINPATHS
491      fprintf(dest,"%s%s",fp->drive,fp->path);      fprintf(dest,"%s%s",fp->drive,fp->path);
# Line 538  struct FilePath *ospath_getparent(struct Line 534  struct FilePath *ospath_getparent(struct
534      }      }
535    
536      len1 = (int)pos - (int)fp->path;      len1 = (int)pos - (int)fp->path;
537        V(len1);
538      //fprintf(stderr,"POS = %d\n",len1);      //fprintf(stderr,"POS = %d\n",len1);
539    
540      if(*pos==PATH_SEPARATOR_CHAR){      if(*pos==PATH_SEPARATOR_CHAR){
# Line 648  char *ospath_getbasefilename(struct File Line 645  char *ospath_getbasefilename(struct File
645      // extract filename given position of find / and return it.      // extract filename given position of find / and return it.
646      if(pos != NULL){      if(pos != NULL){
647          unsigned length1 = length - ((pos - fp->path) + 1);          unsigned length1 = length - ((pos - fp->path) + 1);
648          temp = CALLOC(length1,sizeof(char));          temp = (char *)MALLOC(sizeof(char)*length1);
649    
650          V(length1);          V(length1);
651          STRNCPY(temp, pos + 1, length1);          STRNCPY(temp, pos + 1, length1);
652          return temp;          return temp;
653      }else{      }else{
654          temp = CALLOC(length,sizeof(char));          temp = (char *)MALLOC(sizeof(char)*length);
655          STRNCPY(temp, fp->path, length);          STRNCPY(temp, fp->path, length);
656          return temp;          return temp;
657      }      }
# Line 712  char *ospath_getfileext(struct FilePath Line 709  char *ospath_getfileext(struct FilePath
709    
710      if(pos != NULL && pos!=temp){      if(pos != NULL && pos!=temp){
711          // extract extension.          // extract extension.
712          len1 = temp + strlen(temp) - pos;          len1 = temp + strlen(temp) - pos + 1;
713          temp2 = CALLOC(len1, sizeof(char));          temp2 = (char *)MALLOC(sizeof(char)*len1);
714          STRNCPY(temp2, pos, len1);          STRNCPY(temp2, pos, len1);
715      }else{      }else{
716          // no extension          // no extension
# Line 766  struct FilePath *ospath_root(struct File Line 763  struct FilePath *ospath_root(struct File
763      struct FilePath *r;      struct FilePath *r;
764    
765      if(strlen(fp->drive)){      if(strlen(fp->drive)){
766          temp = CALLOC(strlen(fp->drive)+1, sizeof(char));          temp = (char *)MALLOC(sizeof(char)*strlen(fp->drive)+1);
767          STRCPY(temp,fp->drive);          STRCPY(temp,fp->drive);
768          STRCAT(temp,PATH_SEPARATOR_STR);          STRCAT(temp,PATH_SEPARATOR_STR);
769          X(temp);          X(temp);
# Line 803  int ospath_cmp(struct FilePath *fp1, str Line 800  int ospath_cmp(struct FilePath *fp1, str
800      char temp[2][PATH_MAX];      char temp[2][PATH_MAX];
801  #ifdef WINPATHS  #ifdef WINPATHS
802      char *p;      char *p;
803        struct FilePath *fp;
804  #endif  #endif
805    
806      if(!ospath_isvalid(fp1)){      if(!ospath_isvalid(fp1)){
# Line 818  int ospath_cmp(struct FilePath *fp1, str Line 816  int ospath_cmp(struct FilePath *fp1, str
816      // now, both are valid...      // now, both are valid...
817      //M("BOTH ARE VALID");      //M("BOTH ARE VALID");
818    
819        //Check that paths both have drives, if applic.
820  #ifdef WINPATHS  #ifdef WINPATHS
821      //X(fp1->drive);      if(strcmp(fp1->drive,"")==0){
822      STRCPY(temp[0],fp1->drive);          M("PATH IS MISSING DRIVE LETTER");
823      //X(temp[0]);          D(fp1);
824      //X(fp1->path);          fp = ospath_getcwd();
825            assert(strlen(fp->drive)!=0);
826            X(fp->drive);
827            STRCPY(temp[0],fp->drive);
828            ospath_free(fp);
829        }else{
830            STRCPY(temp[0],fp1->drive);
831        }
832    
833        if(strcmp(fp2->drive,"")==0){
834            M("PATH IS MISSING DRIVE LETTER");
835            D(fp2);
836            fp = ospath_getcwd();
837            assert(strlen(fp->drive)!=0);
838            X(fp->drive);
839            STRCPY(temp[1],fp->drive);
840            ospath_free(fp);
841        }else{
842            STRCPY(temp[1],fp2->drive);
843        }
844    
845      STRCAT(temp[0],fp1->path);      STRCAT(temp[0],fp1->path);
     //X(temp[0]);  
     STRCPY(temp[1],fp2->drive);  
846      STRCAT(temp[1],fp2->path);      STRCAT(temp[1],fp2->path);
847  #else  #else
848      STRCPY(temp[0], fp1->path);      STRCPY(temp[0], fp1->path);
# Line 833  int ospath_cmp(struct FilePath *fp1, str Line 850  int ospath_cmp(struct FilePath *fp1, str
850  #endif  #endif
851    
852  #ifdef WINPATHS  #ifdef WINPATHS
853        X(temp[0]);
854      for(p=temp[0];*p!='\0';++p){      for(p=temp[0];*p!='\0';++p){
855          *p=tolower(*p);          *p=tolower(*p);
856            //C(*p);
857      }      }
858        X(temp[1]);
859      for(p=temp[1];*p!='\0';++p){      for(p=temp[1];*p!='\0';++p){
860          *p=tolower(*p);          *p=tolower(*p);
861            //C(*p);
862      }      }
863      X(temp[0]);      X(temp[0]);
864      X(temp[1]);      X(temp[1]);
# Line 866  struct FilePath *ospath_concat(struct Fi Line 887  struct FilePath *ospath_concat(struct Fi
887      char temp2[PATH_MAX];      char temp2[PATH_MAX];
888      struct FilePath *r;      struct FilePath *r;
889    
890      fp = MALLOC(sizeof(struct FilePath));      fp = (struct FilePath *)MALLOC(sizeof(struct FilePath));
891    
892      D(fp1);      D(fp1);
893      D(fp2);      D(fp2);
# Line 928  struct FilePath *ospath_concat(struct Fi Line 949  struct FilePath *ospath_concat(struct Fi
949      //X(temp2);      //X(temp2);
950      r = ospath_new_noclean(temp2);      r = ospath_new_noclean(temp2);
951      D(r);      D(r);
952    
953      /* ospath_cleanup(r);*/      /* ospath_cleanup(r);*/
954      return r;      return r;
955  }  }
956    
957  void ospath_append(struct FilePath *fp, struct FilePath *fp1){  void ospath_append(struct FilePath *fp, struct FilePath *fp1){
958      char *p;      char *p;
959      char *temp[2];      char temp[2][PATH_MAX];
960      struct FilePath fp2;      struct FilePath fp2;
961    
962      ospath_copy(&fp2,fp1);      ospath_copy(&fp2,fp1);
# Line 957  void ospath_append(struct FilePath *fp, Line 979  void ospath_append(struct FilePath *fp,
979          return;          return;
980      }      }
981    
982      //X(fp->path);      X(fp->path);
983      //X(fp2.path);      X(fp2.path);
984    
985      // both paths are valid...      // both paths are valid...
986      temp[0] = CALLOC(1+strlen(fp->path), sizeof(char));      //temp[0] = CALLOC(1+strlen(fp->path), sizeof(char));
987      STRCPY(temp[0], fp->path);      STRNCPY(temp[0], fp->path, PATH_MAX);
988      temp[1] = CALLOC(strlen(fp2.path), sizeof(char));      //temp[1] = CALLOC(strlen(fp2.path), sizeof(char));
989      STRCPY(temp[1], fp2.path);      STRNCPY(temp[1], fp2.path, PATH_MAX);
990    
991      //X(temp[0]);      X(temp[0]);
992      //X(temp[1]);      X(temp[1]);
993    
994      // make sure temp has a / on the end.      // make sure temp has a / on the end.
995      if(temp[0][strlen(temp[0]) - 1] != PATH_SEPARATOR_CHAR)      if(temp[0][strlen(temp[0]) - 1] != PATH_SEPARATOR_CHAR)
# Line 983  void ospath_append(struct FilePath *fp, Line 1005  void ospath_append(struct FilePath *fp,
1005          *(p-1)='\0';          *(p-1)='\0';
1006      }      }
1007    
1008      //X(temp[0]);      X(temp[0]);
1009      //X(temp[1]);      X(temp[1]);
1010    
1011      // create new path string.      // create new path string.
1012      STRCPY(fp->path,temp[0]);      STRNCPY(fp->path,temp[0], PATH_MAX);
1013      STRCAT(fp->path,temp[1]);      STRNCAT(fp->path,temp[1], PATH_MAX-strlen(fp->path));
1014    
1015        X(fp->path);
1016    
1017      FREE(temp[0]);      //FREE(temp[0]);
1018      FREE(temp[1]);      //M("Freed temp[0]");
1019        //FREE(temp[1]);
1020        //M("Freed temp[1]");
1021    
1022      X(fp);      D(fp);
1023      ospath_cleanup(fp);      ospath_cleanup(fp);
1024  }  }
1025    
# Line 1054  struct FilePath **ospath_searchpath_new( Line 1080  struct FilePath **ospath_searchpath_new(
1080      p=STRTOK(path1,PATH_LISTSEP_STR,nexttok);      p=STRTOK(path1,PATH_LISTSEP_STR,nexttok);
1081      X(p);      X(p);
1082      for(; p!= NULL; p=STRTOK(NULL,PATH_LISTSEP_STR,nexttok)){      for(; p!= NULL; p=STRTOK(NULL,PATH_LISTSEP_STR,nexttok)){
1083          c = CALLOC(strlen(p),sizeof(char));          c = (char *)MALLOC(sizeof(char)*strlen(p));
1084          X(p);          X(p);
1085          STRCPY(c,p);          STRCPY(c,p);
1086          if(n>=LISTMAX){          if(n>=LISTMAX){
# Line 1071  struct FilePath **ospath_searchpath_new( Line 1097  struct FilePath **ospath_searchpath_new(
1097      V(n);      V(n);
1098      */      */
1099    
1100      pp = CALLOC(n+1,sizeof(struct FilePath*));      pp = (struct FilePath **)MALLOC(sizeof(struct FilePath*)*(n+1));
1101      for(i=0; i<n; ++i){      for(i=0; i<n; ++i){
1102          //V(i);          //V(i);
1103          //X(list[i]);          //X(list[i]);
# Line 1130  struct FilePath *ospath_searchpath_itera Line 1156  struct FilePath *ospath_searchpath_itera
1156  FilePathTestFn ospath_searchpath_testexists;  FilePathTestFn ospath_searchpath_testexists;
1157    
1158  /**  /**
1159      Return 1 if the file exists relative inside path      This is a sample searchpath test function. Assumes the 'userfdata' is a
1160        relative FilePath which is appended to path, and then if it matches
1161        the path \GTK\bin\johnpye\extfn, returns true. This is of
1162        course a fairly useless test function, so it's just for testing.
1163  */  */
1164  int ospath_searchpath_testexists(struct FilePath *path,void *file){  int ospath_searchpath_testexists(struct FilePath *path,void *file){
1165      struct FilePath *fp, *fp1, *fp2;      struct FilePath *fp, *fp1, *fp2;
# Line 1139  int ospath_searchpath_testexists(struct Line 1168  int ospath_searchpath_testexists(struct
1168      fp1 = ospath_concat(path,fp);      fp1 = ospath_concat(path,fp);
1169      D(fp1);      D(fp1);
1170    
1171      fp2 = ospath_new("\\GTK\\bin\\johnpye\\extfn");  #ifdef WINPATHS
1172        fp2 = ospath_new("c:\\GTK\\bin\\johnpye\\extfn");
1173    #else
1174        fp2 = ospath_new("/GTK/bin/johnpye/extfn");
1175    #endif
1176    
1177        char *t=ospath_str(fp1);
1178        MC("1",t);
1179        FREE(t);
1180    
1181        t=ospath_str(fp2);
1182        MC("31;1",t);
1183        FREE(t);
1184    
1185      if(ospath_cmp(fp1,fp2)==0){      if(ospath_cmp(fp1,fp2)==0){
1186            MC("32","MATCH");
1187          return 1;          return 1;
1188      }      }
1189        MC("31","NO MATCH");
1190      return 0;      return 0;
1191  }  }
1192    
1193  #include <assert.h>  #include <assert.h>
1194    
1195    // switch to boldface for messages in 'main'
1196    #undef D
1197    #define D DD
1198    #undef M
1199    #define M MM
1200    
1201  int main(void){  int main(void){
1202      struct FilePath *fp1, *fp2, *fp3, *fp4;      struct FilePath *fp1, *fp2, *fp3, *fp4;
1203      char *s1, *s2;      char *s1;
1204      struct FilePath **pp, **p1;// will be returned null-terminated      struct FilePath **pp, **p1;// will be returned null-terminated
1205  #ifdef WINPATHS  #ifdef WINPATHS
1206      char pathtext[]="c:\\Program Files\\GnuWin32\\bin;c:\\GTK\\bin;e:\\ascend\\;..\\..\\pygtk";      char pathtext[]="c:\\Program Files\\GnuWin32\\bin;c:\\GTK\\bin;e:\\ascend\\;..\\..\\pygtk";
# Line 1343  int main(void){ Line 1393  int main(void){
1393  #else  #else
1394      fp1 = ospath_new("\\Program Files\\GnuWin32\\bin");      fp1 = ospath_new("\\Program Files\\GnuWin32\\bin");
1395  #endif  #endif
1396    
1397        assert(pp[0]!=NULL);
1398        assert(fp1!=NULL);
1399    
1400      D(fp1);      D(fp1);
1401      D(pp[0]);      D(pp[0]);
1402    
1403      assert(ospath_cmp(pp[0],fp1)==0);      assert(ospath_cmp(pp[0],fp1)==0);
1404    
1405    
1406      fp2 = ospath_new_noclean("johnpye/extfn");      fp2 = ospath_new_noclean("johnpye/extfn");
1407        D(fp2);
1408    
1409        fflush(stderr);
1410    
1411      fp3 = ospath_searchpath_iterate(pp,&ospath_searchpath_testexists,(void*)fp2);      fp3 = ospath_searchpath_iterate(pp,&ospath_searchpath_testexists,(void*)fp2);
1412    
1413        assert(fp3!=NULL);
1414        D(fp3);
1415        D(pp[1]);
1416    
1417      assert(ospath_cmp(fp3,pp[1])==0);      assert(ospath_cmp(fp3,pp[1])==0);
1418      M("Passed path-search test\n");      M("Passed path-search test\n");
1419    
# Line 1361  int main(void){ Line 1422  int main(void){
1422      ospath_searchpath_free(pp);      ospath_searchpath_free(pp);
1423    
1424      //-------------------------------      //-------------------------------
1425    
1426        M("Path-search test 2...");
1427    
1428      pp = ospath_searchpath_new(pathtext2);      pp = ospath_searchpath_new(pathtext2);
1429    
1430        assert(pp!=NULL);
1431    
1432      for (p1=pp; *p1!=NULL; ++p1){      for (p1=pp; *p1!=NULL; ++p1){
1433          D(*p1);          D(*p1);
1434      }      }
1435    
1436      fp2 = ospath_new_noclean("johnpye/extfn/extfntest");      fp2 = ospath_new_noclean("johnpye/extfn/extfntest");
1437        D(fp2);
1438    
1439      fp3 = ospath_searchpath_iterate(pp,&ospath_searchpath_testexists,(void*)fp2);      fp3 = ospath_searchpath_iterate(pp,&ospath_searchpath_testexists,(void*)fp2);
1440        assert(fp3==NULL);
1441    
     D(fp2);  
     D(fp3);  
   
     assert(fp3==NULL);  
1442      M("Passed path-search test 2\n");      M("Passed path-search test 2\n");
1443    
1444      ospath_free(fp2);      ospath_free(fp2);
# Line 1578  int main(void){ Line 1642  int main(void){
1642    
1643      //---------------------------------      //---------------------------------
1644      M("ALL TESTS PASSED");      M("ALL TESTS PASSED");
1645        return 0;
1646  }  }
1647    
1648    #define DONE_TEST
1649    
1650  #endif  #endif

Legend:
Removed from v.584  
changed lines
  Added in v.585

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22