ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fropen.c
Revision: 2.6
Committed: Thu Apr 14 04:44:45 1994 UTC (30 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +2 -10 lines
Log Message:
changed extern *libpath to extern *getlibpath()

File Contents

# User Rev Content
1 greg 2.4 /* Copyright (c) 1992 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 greg 2.4 #include "paths.h"
14 greg 1.1
15    
16     FILE *
17     fropen(fname) /* find file and open for reading */
18     register char *fname;
19     {
20 greg 2.6 extern char *strcpy(), *getlibpath();
21 greg 1.1 FILE *fp;
22 greg 2.5 char pname[MAXPATH];
23 greg 1.1 register char *sp, *cp;
24    
25     if (fname == NULL)
26     return(NULL);
27    
28 greg 2.5 if (ISDIRSEP(fname[0]) || fname[0] == '.') /* absolute path */
29 greg 1.1 return(fopen(fname, "r"));
30     /* check search path */
31 greg 2.6 sp = getlibpath();
32 greg 1.1 do {
33     cp = pname;
34 greg 2.3 while (*sp && (*cp = *sp++) != PATHSEP)
35     cp++;
36 greg 2.5 if (cp > pname && !ISDIRSEP(cp[-1]))
37 greg 2.3 *cp++ = DIRSEP;
38 greg 1.1 strcpy(cp, fname);
39     if ((fp = fopen(pname, "r")) != NULL)
40     return(fp); /* got it! */
41     } while (*sp);
42     /* not found */
43     return(NULL);
44     }