1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
|
13 |
< |
#ifndef DEFPATH |
14 |
< |
#define DEFPATH ":/usr/local/lib/ray" |
15 |
< |
#endif |
16 |
< |
#ifndef ULIBVAR |
17 |
< |
#define ULIBVAR "RAYPATH" |
18 |
< |
#endif |
13 |
> |
#include "paths.h" |
14 |
|
|
20 |
– |
char *libpath = NULL; /* library search path */ |
15 |
|
|
22 |
– |
|
16 |
|
FILE * |
17 |
|
fropen(fname) /* find file and open for reading */ |
18 |
|
register char *fname; |
19 |
|
{ |
20 |
< |
extern char *strcpy(), *getenv(); |
20 |
> |
extern char *strcpy(), *getlibpath(); |
21 |
|
FILE *fp; |
22 |
< |
char pname[256]; |
22 |
> |
char pname[MAXPATH]; |
23 |
|
register char *sp, *cp; |
24 |
|
|
25 |
|
if (fname == NULL) |
26 |
|
return(NULL); |
27 |
|
|
28 |
< |
if (fname[0] == '/' || fname[0] == '.') /* absolute path */ |
28 |
> |
if (ISDIRSEP(fname[0]) || fname[0] == '.') /* absolute path */ |
29 |
|
return(fopen(fname, "r")); |
37 |
– |
|
38 |
– |
if (libpath == NULL) { /* get search path */ |
39 |
– |
libpath = getenv(ULIBVAR); |
40 |
– |
if (libpath == NULL) |
41 |
– |
libpath = DEFPATH; |
42 |
– |
} |
30 |
|
/* check search path */ |
31 |
< |
sp = libpath; |
31 |
> |
sp = getlibpath(); |
32 |
|
do { |
33 |
|
cp = pname; |
34 |
< |
while (*sp && (*cp = *sp++) != ':') |
34 |
> |
while (*sp && (*cp = *sp++) != PATHSEP) |
35 |
|
cp++; |
36 |
< |
if (cp > pname && cp[-1] != '/') |
37 |
< |
*cp++ = '/'; |
36 |
> |
if (cp > pname && !ISDIRSEP(cp[-1])) |
37 |
> |
*cp++ = DIRSEP; |
38 |
|
strcpy(cp, fname); |
39 |
|
if ((fp = fopen(pname, "r")) != NULL) |
40 |
|
return(fp); /* got it! */ |