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

Diff of /trunk/ascend/general/ospath.c

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

revision 2334 by jpye, Fri Dec 24 05:11:35 2010 UTC revision 2335 by jpye, Sun Dec 26 03:24:37 2010 UTC
# Line 39  Line 39 
39    
40  #include "ospath.h"  #include "ospath.h"
41    
42  /* to test this code, 'gcc -DTEST ospath.c && ./a' */  //#define OSPATH_DEBUG
43    
44  #ifndef __GNUC__  #ifndef __GNUC__
45  # ifndef __FUNCTION__  # ifndef __FUNCTION__
# Line 50  Line 50 
50    
51  /* #define VERBOSE */  /* #define VERBOSE */
52    
53  #if !defined(TEST) && !defined(VERBOSE)  #if !defined(VERBOSE)
54  #ifndef NDEBUG  #ifndef NDEBUG
55  # define NDEBUG  # define NDEBUG
56  #endif  #endif
# Line 610  struct FilePath *ospath_getparent(struct Line 610  struct FilePath *ospath_getparent(struct
610      char sub[PATH_MAX];      char sub[PATH_MAX];
611      struct FilePath *fp1, *fp2;      struct FilePath *fp1, *fp2;
612    
613    #ifdef OSPATH_DEBUG
614        fprintf(stderr,"finding parent of %s\n",fp->path);
615    #endif
616      D(fp);      D(fp);
617    
618      if(strlen(fp->path) == 0){      if(strlen(fp->path) == 0){
# Line 618  struct FilePath *ospath_getparent(struct Line 621  struct FilePath *ospath_getparent(struct
621          ospath_free(fp1);          ospath_free(fp1);
622          return fp2;          return fp2;
623      }else if(ospath_isroot(fp)){      }else if(ospath_isroot(fp)){
624    #ifdef OSPATH_DEBUG
625            fprintf(stderr,"path is root\n");
626    #endif
627          /* stay at root */          /* stay at root */
628          return ospath_new("/");          return ospath_new("/");
629      }      }
# Line 631  struct FilePath *ospath_getparent(struct Line 637  struct FilePath *ospath_getparent(struct
637          ) ? length - 1 : length; /* then remove last char */          ) ? length - 1 : length; /* then remove last char */
638    
639      for(pos = fp->path + offset - 1; *pos!=PATH_SEPARATOR_CHAR && pos>=fp->path; --pos){      for(pos = fp->path + offset - 1; *pos!=PATH_SEPARATOR_CHAR && pos>=fp->path; --pos){
640  #if 0  #ifdef OSPATH_DEBUG
641          fprintf(stderr,"CURRENT CHAR: %c\n",*pos);          CONSOLE_DEBUG("CURRENT CHAR: %c\n",*pos);
642  #endif  #endif
643      }      }
644    
# Line 847  char *ospath_getfileext(struct FilePath Line 853  char *ospath_getfileext(struct FilePath
853    
854  int ospath_isroot(struct FilePath *fp)  int ospath_isroot(struct FilePath *fp)
855  {  {
856      if(!ospath_isvalid(fp))      if(!ospath_isvalid(fp)){
857      {  #ifdef OSPATH_DEBUG
858            fprintf(stderr,"path is invalid\n");
859    #endif
860          return 0;          return 0;
861      }      }
862    
863      return strcmp(fp->path, PATH_SEPARATOR_STR) ? 1 : 0;      return strcmp(fp->path, PATH_SEPARATOR_STR) ? 0 : 1;
864  }  }
865    
866  unsigned ospath_depth(struct FilePath *fp){  unsigned ospath_depth(struct FilePath *fp){

Legend:
Removed from v.2334  
changed lines
  Added in v.2335

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