ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fropen.c
Revision: 2.2
Committed: Tue Jun 16 13:06:58 1992 UTC (31 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +5 -2 lines
Log Message:
added escape character

File Contents

# Content
1 /* Copyright (c) 1992 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 if (*cp == '\\') { /* escape */
49 if (*sp) *cp++ = *sp++;
50 } else
51 cp++;
52 if (cp > pname && cp[-1] != '/')
53 *cp++ = '/';
54 strcpy(cp, fname);
55 if ((fp = fopen(pname, "r")) != NULL)
56 return(fp); /* got it! */
57 } while (*sp);
58 /* not found */
59 return(NULL);
60 }