1 |
greg |
2.4 |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
greg |
1.1 |
|
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 |
greg |
2.4 |
#include "paths.h" |
14 |
greg |
1.1 |
|
15 |
|
|
|
16 |
|
|
FILE * |
17 |
greg |
2.7 |
frlibopen(fname) /* find file and open for reading */ |
18 |
greg |
1.1 |
register char *fname; |
19 |
|
|
{ |
20 |
greg |
2.6 |
extern char *strcpy(), *getlibpath(); |
21 |
greg |
1.1 |
FILE *fp; |
22 |
greg |
2.5 |
char pname[MAXPATH]; |
23 |
greg |
1.1 |
register char *sp, *cp; |
24 |
|
|
|
25 |
|
|
if (fname == NULL) |
26 |
|
|
return(NULL); |
27 |
|
|
|
28 |
greg |
2.5 |
if (ISDIRSEP(fname[0]) || fname[0] == '.') /* absolute path */ |
29 |
greg |
1.1 |
return(fopen(fname, "r")); |
30 |
|
|
/* check search path */ |
31 |
greg |
2.6 |
sp = getlibpath(); |
32 |
greg |
1.1 |
do { |
33 |
|
|
cp = pname; |
34 |
greg |
2.3 |
while (*sp && (*cp = *sp++) != PATHSEP) |
35 |
|
|
cp++; |
36 |
greg |
2.5 |
if (cp > pname && !ISDIRSEP(cp[-1])) |
37 |
greg |
2.3 |
*cp++ = DIRSEP; |
38 |
greg |
1.1 |
strcpy(cp, fname); |
39 |
|
|
if ((fp = fopen(pname, "r")) != NULL) |
40 |
|
|
return(fp); /* got it! */ |
41 |
|
|
} while (*sp); |
42 |
|
|
/* not found */ |
43 |
|
|
return(NULL); |
44 |
|
|
} |