ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/getpath.c
(Generate patch)

Comparing ray/src/common/getpath.c (file contents):
Revision 2.2 by greg, Wed Mar 25 10:57:29 1992 UTC vs.
Revision 2.4 by greg, Mon Jul 13 16:33:19 1992 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #define  NULL           0
12  
13 + #ifndef  NIX
14   #include  <pwd.h>
15 + #endif
16  
17 + #ifndef DIRSEP
18 + #define DIRSEP          '/'
19 + #endif
20 + #ifndef PATHSEP
21 + #define PATHSEP         ':'
22 + #endif
23 +
24   extern char  *strcpy(), *strcat(), *getenv();
25   extern struct passwd  *getpwnam();
26  
# Line 22 | Line 31 | register char  *fname;
31   register char  *searchpath;
32   int  mode;
33   {
34 <        static char  pname[256];
34 > #ifndef  NIX
35          struct passwd  *pwent;
36 + #endif
37 +        static char  pname[256];
38          register char  *cp;
39  
40          if (fname == NULL)
41                  return(NULL);
42  
43          switch (*fname) {
44 <        case '/':                               /* relative to root */
44 >        case DIRSEP:                            /* relative to root */
45          case '.':                               /* relative to cwd */
46                  strcpy(pname, fname);
47                  return(pname);
48 + #ifndef NIX
49          case '~':                               /* relative to home directory */
50                  fname++;
51 <                if (*fname == '\0' || *fname == '/') {          /* ours */
51 >                if (*fname == '\0' || *fname == DIRSEP) {       /* ours */
52                          if ((cp = getenv("HOME")) == NULL)
53                                  return(NULL);
54                          strcpy(pname, cp);
# Line 46 | Line 58 | int  mode;
58                  cp = pname;                                     /* user */
59                  do
60                          *cp++ = *fname++;
61 <                while (*fname && *fname != '/');
61 >                while (*fname && *fname != DIRSEP);
62                  *cp = '\0';
63                  if ((pwent = getpwnam(pname)) == NULL)
64                          return(NULL);
65                  strcpy(pname, pwent->pw_dir);
66                  strcat(pname, fname);
67                  return(pname);
68 + #endif
69          }
70  
71          if (searchpath == NULL) {                       /* don't search */
# Line 62 | Line 75 | int  mode;
75                                                          /* check search path */
76          do {
77                  cp = pname;
78 <                while (*searchpath && (*cp = *searchpath++) != ':')
79 <                        if (*cp == '\\') {              /* escape */
80 <                                if (*searchpath)
81 <                                        *cp++ = *searchpath++;
69 <                        } else
70 <                                cp++;
71 <                if (cp > pname && cp[-1] != '/')
72 <                        *cp++ = '/';
78 >                while (*searchpath && (*cp = *searchpath++) != PATHSEP)
79 >                        cp++;
80 >                if (cp > pname && cp[-1] != DIRSEP)
81 >                        *cp++ = DIRSEP;
82                  strcpy(cp, fname);
83                  if (access(pname, mode) == 0)           /* file accessable? */
84                          return(pname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines