| 16 |
|
#ifndef ULIBVAR |
| 17 |
|
#define ULIBVAR "RAYPATH" |
| 18 |
|
#endif |
| 19 |
+ |
#ifndef DIRSEP |
| 20 |
+ |
#define DIRSEP '/' |
| 21 |
+ |
#endif |
| 22 |
+ |
#ifndef PATHSEP |
| 23 |
+ |
#define PATHSEP ':' |
| 24 |
+ |
#endif |
| 25 |
|
|
| 26 |
+ |
char *libpath = NULL; /* library search path */ |
| 27 |
|
|
| 28 |
+ |
|
| 29 |
|
FILE * |
| 30 |
|
fropen(fname) /* find file and open for reading */ |
| 31 |
|
register char *fname; |
| 32 |
|
{ |
| 33 |
|
extern char *strcpy(), *getenv(); |
| 26 |
– |
static char *searchpath; |
| 34 |
|
FILE *fp; |
| 35 |
|
char pname[256]; |
| 36 |
|
register char *sp, *cp; |
| 38 |
|
if (fname == NULL) |
| 39 |
|
return(NULL); |
| 40 |
|
|
| 41 |
< |
if (fname[0] == '/' || fname[0] == '.') /* absolute path */ |
| 41 |
> |
if (fname[0] == DIRSEP || fname[0] == '.') /* absolute path */ |
| 42 |
|
return(fopen(fname, "r")); |
| 43 |
|
|
| 44 |
< |
if (searchpath == NULL) { /* get search path */ |
| 45 |
< |
searchpath = getenv(ULIBVAR); |
| 46 |
< |
if (searchpath == NULL) |
| 47 |
< |
searchpath = DEFPATH; |
| 44 |
> |
if (libpath == NULL) { /* get search path */ |
| 45 |
> |
libpath = getenv(ULIBVAR); |
| 46 |
> |
if (libpath == NULL) |
| 47 |
> |
libpath = DEFPATH; |
| 48 |
|
} |
| 49 |
|
/* check search path */ |
| 50 |
< |
sp = searchpath; |
| 50 |
> |
sp = libpath; |
| 51 |
|
do { |
| 52 |
|
cp = pname; |
| 53 |
< |
while (*sp && (*cp = *sp++) != ':') |
| 53 |
> |
while (*sp && (*cp = *sp++) != PATHSEP) |
| 54 |
|
cp++; |
| 55 |
< |
if (cp > pname && cp[-1] != '/') |
| 56 |
< |
*cp++ = '/'; |
| 55 |
> |
if (cp > pname && cp[-1] != DIRSEP) |
| 56 |
> |
*cp++ = DIRSEP; |
| 57 |
|
strcpy(cp, fname); |
| 58 |
|
if ((fp = fopen(pname, "r")) != NULL) |
| 59 |
|
return(fp); /* got it! */ |