1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.12 |
static const char RCSid[] = "$Id: fropen.c,v 2.11 2003/06/30 14:59:11 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Find and open a Radiance library file. |
6 |
greg |
2.8 |
* |
7 |
|
|
* External symbols declared in standard.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.9 |
#include "copyright.h" |
11 |
greg |
1.1 |
|
12 |
|
|
#include <stdio.h> |
13 |
|
|
|
14 |
greg |
2.4 |
#include "paths.h" |
15 |
greg |
1.1 |
|
16 |
|
|
|
17 |
|
|
FILE * |
18 |
greg |
2.7 |
frlibopen(fname) /* find file and open for reading */ |
19 |
greg |
1.1 |
register char *fname; |
20 |
|
|
{ |
21 |
greg |
2.12 |
extern char *getrlibpath(); |
22 |
greg |
1.1 |
FILE *fp; |
23 |
schorsch |
2.11 |
char pname[PATH_MAX]; |
24 |
greg |
1.1 |
register char *sp, *cp; |
25 |
|
|
|
26 |
|
|
if (fname == NULL) |
27 |
|
|
return(NULL); |
28 |
|
|
|
29 |
greg |
2.5 |
if (ISDIRSEP(fname[0]) || fname[0] == '.') /* absolute path */ |
30 |
greg |
1.1 |
return(fopen(fname, "r")); |
31 |
|
|
/* check search path */ |
32 |
greg |
2.10 |
sp = getrlibpath(); |
33 |
greg |
1.1 |
do { |
34 |
|
|
cp = pname; |
35 |
greg |
2.3 |
while (*sp && (*cp = *sp++) != PATHSEP) |
36 |
|
|
cp++; |
37 |
greg |
2.5 |
if (cp > pname && !ISDIRSEP(cp[-1])) |
38 |
greg |
2.3 |
*cp++ = DIRSEP; |
39 |
greg |
1.1 |
strcpy(cp, fname); |
40 |
|
|
if ((fp = fopen(pname, "r")) != NULL) |
41 |
|
|
return(fp); /* got it! */ |
42 |
|
|
} while (*sp); |
43 |
|
|
/* not found */ |
44 |
|
|
return(NULL); |
45 |
|
|
} |