| 1 |
#ifndef lint |
| 2 |
static const char RCSid[] = "$Id: fropen.c,v 2.14 2003/08/26 04:24:26 greg Exp $"; |
| 3 |
#endif |
| 4 |
/* |
| 5 |
* Find and open a Radiance library file. |
| 6 |
* |
| 7 |
* External symbols declared in rtio.h |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "copyright.h" |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
|
| 14 |
#include "rtio.h" |
| 15 |
#include "paths.h" |
| 16 |
|
| 17 |
|
| 18 |
FILE * |
| 19 |
frlibopen(fname) /* find file and open for reading */ |
| 20 |
register char *fname; |
| 21 |
{ |
| 22 |
FILE *fp; |
| 23 |
char pname[PATH_MAX]; |
| 24 |
register char *sp, *cp; |
| 25 |
|
| 26 |
if (fname == NULL) |
| 27 |
return(NULL); |
| 28 |
|
| 29 |
if (ISABS(fname) || fname[0] == '.') /* absolute path */ |
| 30 |
return(fopen(fname, "r")); |
| 31 |
/* check search path */ |
| 32 |
sp = getrlibpath(); |
| 33 |
do { |
| 34 |
cp = pname; |
| 35 |
while (*sp && (*cp = *sp++) != PATHSEP) |
| 36 |
cp++; |
| 37 |
if (cp > pname && !ISDIRSEP(cp[-1])) |
| 38 |
*cp++ = DIRSEP; |
| 39 |
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 |
} |