ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fropen.c
Revision: 1.2
Committed: Sun Dec 9 09:21:05 1990 UTC (33 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +7 -6 lines
Log Message:
made libpath global so it could be set before call

File Contents

# Content
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 char *libpath = NULL; /* library search path */
21
22
23 FILE *
24 fropen(fname) /* find file and open for reading */
25 register char *fname;
26 {
27 extern char *strcpy(), *getenv();
28 FILE *fp;
29 char pname[256];
30 register char *sp, *cp;
31
32 if (fname == NULL)
33 return(NULL);
34
35 if (fname[0] == '/' || fname[0] == '.') /* absolute path */
36 return(fopen(fname, "r"));
37
38 if (libpath == NULL) { /* get search path */
39 libpath = getenv(ULIBVAR);
40 if (libpath == NULL)
41 libpath = DEFPATH;
42 }
43 /* check search path */
44 sp = libpath;
45 do {
46 cp = pname;
47 while (*sp && (*cp = *sp++) != ':')
48 cp++;
49 if (cp > pname && cp[-1] != '/')
50 *cp++ = '/';
51 strcpy(cp, fname);
52 if ((fp = fopen(pname, "r")) != NULL)
53 return(fp); /* got it! */
54 } while (*sp);
55 /* not found */
56 return(NULL);
57 }