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