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.2 by greg, Mon Sep 21 12:02:16 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 54 | Line 56 | char   *mode;
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 < #endif                
69 >                case '\\':
70 >                        *cp++ = *cmd++;
71 >                        break;
72                  case '(':
73                          if (!quote)
74                                  paren++;
# Line 65 | Line 77 | char   *mode;
77                          if (!quote && paren)
78                                  paren--;
79                          break;
80 <                case '\\':
81 <                        if (!quote && cmd[1] == '\n') {
82 <                                *cp++ = ' ';
83 <                                cmd++;
84 <                                continue;
73 <                        }
74 <                        *cp++ = *cmd++;
80 >                case ';':
81 > #endif
82 >                case '|':
83 >                        if (!quote && !paren && cp2 == NULL)
84 >                                cp2 = fname;
85                          break;
86                  case ' ':
87                  case '\t':
# Line 79 | Line 89 | char   *mode;
89                                  while (isspace(cmd[1]))
90                                          cmd++;
91                          break;
82                case '|':
83                case ';':
84                        if (!quote && !paren && cp2 == NULL)
85                                cp2 = fname;
86                        break;
92                  case '\n':
93                  case '\0':
94                          if (cp2 == NULL)
# Line 91 | 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 103 | 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 115 | 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