40 |
|
|
41 |
/* to test this code, 'gcc -DTEST ospath.c && ./a' */ |
/* to test this code, 'gcc -DTEST ospath.c && ./a' */ |
42 |
|
|
43 |
#ifndef __FUNCTION__ |
#ifndef __GNUC__ |
44 |
# define __FUNCTION__ "<ospath>" |
# ifndef __FUNCTION__ |
45 |
|
# define __FUNCTION__ "<ospath>" |
46 |
|
# endif |
47 |
#endif |
#endif |
48 |
|
|
49 |
|
|
73 |
# define X(VAR) fprintf(stderr,"%s:%d: (%s) %s=%s\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr) |
# define X(VAR) fprintf(stderr,"%s:%d: (%s) %s=%s\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr) |
74 |
# define C(VAR) fprintf(stderr,"%s:%d: (%s) %s=%c\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr) |
# define C(VAR) fprintf(stderr,"%s:%d: (%s) %s=%c\n",__FILE__,__LINE__,__FUNCTION__,#VAR,VAR);fflush(stderr) |
75 |
# define V(VAR) fprintf(stderr,"%s:%d: (%s) %s=%d\n",__FILE__,__LINE__,__FUNCTION__,#VAR,(VAR));fflush(stderr) |
# define V(VAR) fprintf(stderr,"%s:%d: (%s) %s=%d\n",__FILE__,__LINE__,__FUNCTION__,#VAR,(VAR));fflush(stderr) |
76 |
|
# define P(VAR) fprintf(stderr,"%s:%d: (%s) %s=%p\n",__FILE__,__LINE__,__FUNCTION__,#VAR,(VAR));fflush(stderr) |
77 |
# define D(VAR) fprintf(stderr,"%s:%d: (%s) %s=",__FILE__,__LINE__,__FUNCTION__,#VAR);ospath_debug(VAR);fflush(stderr) |
# define D(VAR) fprintf(stderr,"%s:%d: (%s) %s=",__FILE__,__LINE__,__FUNCTION__,#VAR);ospath_debug(VAR);fflush(stderr) |
78 |
# 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) |
# 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) |
79 |
#else |
#else |
84 |
# define C(VAR) ((void)0) |
# define C(VAR) ((void)0) |
85 |
# define V(VAR) ((void)0) |
# define V(VAR) ((void)0) |
86 |
# define D(VAR) ((void)0) |
# define D(VAR) ((void)0) |
87 |
|
# define P(VAR) ((void)0) |
88 |
# define DD(VAR) ((void)0) |
# define DD(VAR) ((void)0) |
89 |
# define MM(VAR) ((void)0) |
# define MM(VAR) ((void)0) |
90 |
#endif |
#endif |
192 |
/** Create but with no 'cleanup', and no fixing of / vs \. */ |
/** Create but with no 'cleanup', and no fixing of / vs \. */ |
193 |
struct FilePath *ospath_new_noclean(const char *path){ |
struct FilePath *ospath_new_noclean(const char *path){ |
194 |
struct FilePath *fp = (struct FilePath *)MALLOC(sizeof(struct FilePath)); |
struct FilePath *fp = (struct FilePath *)MALLOC(sizeof(struct FilePath)); |
195 |
|
P(fp); |
196 |
|
X(path); |
197 |
STRNCPY(fp->path,path,PATH_MAX); |
STRNCPY(fp->path,path,PATH_MAX); |
198 |
assert(strcmp(fp->path,path)==0); |
assert(strcmp(fp->path,path)==0); |
199 |
#ifdef WINPATHS |
#ifdef WINPATHS |
259 |
|
|
260 |
void ospath_free(struct FilePath *fp){ |
void ospath_free(struct FilePath *fp){ |
261 |
if(fp!=NULL){ |
if(fp!=NULL){ |
262 |
|
P(fp); |
263 |
FREE(fp); |
FREE(fp); |
264 |
} |
} |
265 |
fp=NULL; |
fp=NULL; |
334 |
#endif |
#endif |
335 |
|
|
336 |
struct FilePath *ospath_getcwd(void){ |
struct FilePath *ospath_getcwd(void){ |
337 |
struct FilePath *fp = (struct FilePath *)MALLOC(sizeof(struct FilePath)); |
struct FilePath *fp; |
338 |
char *cwd; |
char *cwd; |
339 |
|
|
340 |
/* get current working directory */ |
/* get current working directory */ |
487 |
|
|
488 |
D(fp); |
D(fp); |
489 |
X(p); |
X(p); |
|
#if 0 |
|
490 |
X(path+strlen(p)+1); |
X(path+strlen(p)+1); |
491 |
|
|
492 |
ospath_free(working); |
ospath_free(working); |
|
#endif |
|
493 |
continue; |
continue; |
494 |
}else{/* later in the path: just skip it */ |
}else{/* later in the path: just skip it */ |
495 |
M("SKIPPING '.' IN PATH"); |
M("SKIPPING '.' IN PATH"); |
502 |
if(ospath_isvalid(parent)){ |
if(ospath_isvalid(parent)){ |
503 |
ospath_copy(fp,parent); |
ospath_copy(fp,parent); |
504 |
} |
} |
|
#if 0 |
|
505 |
ospath_free(parent); |
ospath_free(parent); |
|
#endif |
|
506 |
continue; |
continue; |
507 |
} |
} |
508 |
|
|
646 |
return ospath_new_noclean(fp->path); |
return ospath_new_noclean(fp->path); |
647 |
} |
} |
648 |
|
|
649 |
|
M("Creating 'sub'"); |
650 |
fp1 = ospath_new_noclean(sub); |
fp1 = ospath_new_noclean(sub); |
651 |
|
M("... 'sub'"); |
652 |
D(fp1); |
D(fp1); |
653 |
return fp1; |
return fp1; |
654 |
} |
} |
1260 |
#if 0 |
#if 0 |
1261 |
D(pp[i]); |
D(pp[i]); |
1262 |
#endif |
#endif |
1263 |
|
FREE(list[i]); |
1264 |
} |
} |
1265 |
pp[n] = NULL; |
pp[n] = NULL; |
1266 |
|
|