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

Comparing ray/src/common/popen.c (file contents):
Revision 2.1 by greg, Tue Sep 8 09:08:02 1992 UTC vs.
Revision 2.4 by greg, Wed Nov 4 12:59:17 1992 UTC

# Line 27 | Line 27 | popen(cmd, mode)               /* open command for reading or writi
27   register char   *cmd;
28   char    *mode;
29   {
30 <        extern FILE     *fopen();
31 <        extern char     *malloc(), *mktemp(), *strcpy();
32 <        static int      fnum = 0;
30 >        extern char     *malloc(), *strcpy();
31          FILE    *fp;
32          char    *newcmd, *fname;
33          register char   *cp, *cp2 = NULL;
34          int     quote = '\0', paren = 0;
35          
36 +        while (isspace(*cmd))
37 +                cmd++;
38 +        if (!*cmd)
39 +                return(NULL);
40          fname = malloc(TEMPLEN+1);
41          newcmd = malloc(TEMPLEN+6+strlen(cmd));
42          if (fname == NULL | newcmd == NULL)
# Line 43 | Line 45 | char   *mode;
45                                  /* build our command */
46          for (cp = newcmd; ; cmd++) {
47                  switch (*cmd) {
46                case '"':
48                  case '\'':
49 +                case '"':
50                          if (!quote)
51                                  quote = *cmd;
52                          else if (quote == *cmd)
53                                  quote = '\0';
54 + #ifdef MSDOS
55 +                        else
56 +                                break;
57 +                        *cp++ = '"';            /* double quotes only */
58 +                        continue;
59 +                case '\\':
60 +                        if (!quote && cmd[1] == '\n') {
61 +                                *cp++ = ' ';
62 +                                cmd++;
63 +                                continue;
64 +                        }
65 +                        cmd++;
66                          break;
67 + #else
68 +                        break;
69 +                case '\\':
70 +                        *cp++ = *cmd++;
71 +                        break;
72                  case '(':
73                          if (!quote)
74                                  paren++;
# Line 58 | Line 77 | char   *mode;
77                          if (!quote && paren)
78                                  paren--;
79                          break;
61                case '\\':
62                        if (!quote && cmd[1] == '\n') {
63                                *cp++ = ' ';
64                                cmd++;
65                                continue;
66                        }
67                        *cp++ = *cmd++;
68                        break;
69                case '|':
80                  case ';':
81 + #endif
82 +                case '|':
83                          if (!quote && !paren && cp2 == NULL)
84                                  cp2 = fname;
85                          break;
86 +                case ' ':
87 +                case '\t':
88 +                        if (!quote)
89 +                                while (isspace(cmd[1]))
90 +                                        cmd++;
91 +                        break;
92                  case '\n':
93                  case '\0':
94                          if (cp2 == NULL)
# Line 78 | Line 96 | char   *mode;
96                          break;
97                  }
98                  if (cp2 == fname && *mode == 'w') {     /* add input file */
99 <                        *cp++ = ' '; *cp++ = '<'; *cp++ = ' ';
99 >                        *cp++ = ' '; *cp++ = '<';
100                          while (*cp2)
101                                  *cp++ = *cp2++;
102                          *cp++ = ' ';
# Line 90 | Line 108 | char   *mode;
108          if (*mode == 'r') {                     /* add output file */
109                  while (isspace(cp[-1]) || cp[-1] == ';')
110                          cp--;
111 <                *cp++ = ' '; *cp++ = '>'; *cp++ = ' ';
111 >                *cp++ = ' '; *cp++ = '>';
112                  while (*cp2)
113                          *cp++ = *cp2++;
114                  *cp = '\0';
# Line 102 | Line 120 | char   *mode;
120                  return(NULL);
121          }
122          if (fileno(fp) >= NFILE) {
123 <                fputs("popen: too many open files\n", stderr);
124 <                exit(1);
123 >                eputs("popen: too many open files\n");
124 >                quit(1);
125          }
126          pips[fileno(fp)].f = fname;
127          if (*mode == 'r') {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines