ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fropen.c
Revision: 2.3
Committed: Tue Jun 16 13:07:45 1992 UTC (31 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +12 -9 lines
Log Message:
added macros for directory and path separation characters

File Contents

# User Rev Content
1 greg 2.3 /* Copyright (c) 1990 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     #ifndef DEFPATH
14     #define DEFPATH ":/usr/local/lib/ray"
15     #endif
16     #ifndef ULIBVAR
17     #define ULIBVAR "RAYPATH"
18     #endif
19 greg 2.3 #ifndef DIRSEP
20     #define DIRSEP '/'
21     #endif
22     #ifndef PATHSEP
23     #define PATHSEP ':'
24     #endif
25 greg 1.1
26 greg 1.2 char *libpath = NULL; /* library search path */
27 greg 1.1
28 greg 1.2
29 greg 1.1 FILE *
30     fropen(fname) /* find file and open for reading */
31     register char *fname;
32     {
33     extern char *strcpy(), *getenv();
34     FILE *fp;
35     char pname[256];
36     register char *sp, *cp;
37    
38     if (fname == NULL)
39     return(NULL);
40    
41 greg 2.3 if (fname[0] == DIRSEP || fname[0] == '.') /* absolute path */
42 greg 1.1 return(fopen(fname, "r"));
43    
44 greg 1.2 if (libpath == NULL) { /* get search path */
45     libpath = getenv(ULIBVAR);
46     if (libpath == NULL)
47     libpath = DEFPATH;
48 greg 1.1 }
49     /* check search path */
50 greg 1.2 sp = libpath;
51 greg 1.1 do {
52     cp = pname;
53 greg 2.3 while (*sp && (*cp = *sp++) != PATHSEP)
54     cp++;
55     if (cp > pname && cp[-1] != DIRSEP)
56     *cp++ = DIRSEP;
57 greg 1.1 strcpy(cp, fname);
58     if ((fp = fopen(pname, "r")) != NULL)
59     return(fp); /* got it! */
60     } while (*sp);
61     /* not found */
62     return(NULL);
63     }