1 |
greg |
1.1 |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
|
|
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
* Find and open a Radiance library file. |
9 |
|
|
*/ |
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 |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
FILE * |
22 |
|
|
fropen(fname) /* find file and open for reading */ |
23 |
|
|
register char *fname; |
24 |
|
|
{ |
25 |
|
|
extern char *strcpy(), *getenv(); |
26 |
|
|
static char *searchpath; |
27 |
|
|
FILE *fp; |
28 |
|
|
char pname[256]; |
29 |
|
|
register char *sp, *cp; |
30 |
|
|
|
31 |
|
|
if (fname == NULL) |
32 |
|
|
return(NULL); |
33 |
|
|
|
34 |
|
|
if (fname[0] == '/' || fname[0] == '.') /* absolute path */ |
35 |
|
|
return(fopen(fname, "r")); |
36 |
|
|
|
37 |
|
|
if (searchpath == NULL) { /* get search path */ |
38 |
|
|
searchpath = getenv(ULIBVAR); |
39 |
|
|
if (searchpath == NULL) |
40 |
|
|
searchpath = DEFPATH; |
41 |
|
|
} |
42 |
|
|
/* check search path */ |
43 |
|
|
sp = searchpath; |
44 |
|
|
do { |
45 |
|
|
cp = pname; |
46 |
|
|
while (*sp && (*cp = *sp++) != ':') |
47 |
|
|
cp++; |
48 |
|
|
if (cp > pname && cp[-1] != '/') |
49 |
|
|
*cp++ = '/'; |
50 |
|
|
strcpy(cp, fname); |
51 |
|
|
if ((fp = fopen(pname, "r")) != NULL) |
52 |
|
|
return(fp); /* got it! */ |
53 |
|
|
} while (*sp); |
54 |
|
|
/* not found */ |
55 |
|
|
return(NULL); |
56 |
|
|
} |