--- ray/src/common/getpath.c 1992/03/25 10:57:29 2.2 +++ ray/src/common/getpath.c 1992/09/08 09:09:24 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -8,35 +8,42 @@ static char SCCSid[] = "$SunId$ LBL"; * getpath.c - function to search for file in a list of directories */ +#include "paths.h" + #define NULL 0 +#ifndef NIX #include - -extern char *strcpy(), *strcat(), *getenv(); extern struct passwd *getpwnam(); +#endif +extern char *strcpy(), *strcat(); + char * getpath(fname, searchpath, mode) /* expand fname, return full path */ register char *fname; register char *searchpath; int mode; { - static char pname[256]; +#ifndef NIX struct passwd *pwent; +#endif + static char pname[256]; register char *cp; if (fname == NULL) return(NULL); switch (*fname) { - case '/': /* relative to root */ + case DIRSEP: /* relative to root */ case '.': /* relative to cwd */ strcpy(pname, fname); return(pname); +#ifndef NIX case '~': /* relative to home directory */ fname++; - if (*fname == '\0' || *fname == '/') { /* ours */ + if (*fname == '\0' || *fname == DIRSEP) { /* ours */ if ((cp = getenv("HOME")) == NULL) return(NULL); strcpy(pname, cp); @@ -46,13 +53,14 @@ int mode; cp = pname; /* user */ do *cp++ = *fname++; - while (*fname && *fname != '/'); + while (*fname && *fname != DIRSEP); *cp = '\0'; if ((pwent = getpwnam(pname)) == NULL) return(NULL); strcpy(pname, pwent->pw_dir); strcat(pname, fname); return(pname); +#endif } if (searchpath == NULL) { /* don't search */ @@ -62,14 +70,10 @@ int mode; /* check search path */ do { cp = pname; - while (*searchpath && (*cp = *searchpath++) != ':') - if (*cp == '\\') { /* escape */ - if (*searchpath) - *cp++ = *searchpath++; - } else - cp++; - if (cp > pname && cp[-1] != '/') - *cp++ = '/'; + while (*searchpath && (*cp = *searchpath++) != PATHSEP) + cp++; + if (cp > pname && cp[-1] != DIRSEP) + *cp++ = DIRSEP; strcpy(cp, fname); if (access(pname, mode) == 0) /* file accessable? */ return(pname);