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.3 by greg, Tue Sep 29 09:25:54 1992 UTC vs.
Revision 2.6 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * popen() and pclose() calls for systems without pipe facilities
6   */
7  
8 + #include "copyright.h"
9 +
10   #include <stdio.h>
11 + #include <stdlib.h>
12 + #include <string.h>
13   #include <ctype.h>
14   #include "paths.h"
15  
# Line 27 | Line 28 | popen(cmd, mode)               /* open command for reading or writi
28   register char   *cmd;
29   char    *mode;
30   {
30        extern FILE     *fopen();
31        extern char     *malloc(), *mktemp(), *strcpy();
32        static int      fnum = 0;
31          FILE    *fp;
32          char    *newcmd, *fname;
33          register char   *cp, *cp2 = NULL;
34          int     quote = '\0', paren = 0;
35          
36 <        fname = malloc(TEMPLEN+1);
37 <        newcmd = malloc(TEMPLEN+6+strlen(cmd));
36 >        while (isspace(*cmd))
37 >                cmd++;
38 >        if (!*cmd)
39 >                return(NULL);
40 >        fname = (char *)malloc(TEMPLEN+1);
41 >        newcmd = (char *)malloc(TEMPLEN+6+strlen(cmd));
42          if (fname == NULL | newcmd == NULL)
43                  return(NULL);
44          mktemp(strcpy(fname,TEMPLATE));
# 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                
70 < #ifndef MSDOS
69 >                case '\\':
70 >                        *cp++ = *cmd++;
71 >                        break;
72                  case '(':
73                          if (!quote)
74                                  paren++;
# Line 66 | Line 77 | char   *mode;
77                          if (!quote && paren)
78                                  paren--;
79                          break;
80 <                case '\\':
70 <                        if (!quote && cmd[1] == '\n') {
71 <                                *cp++ = ' ';
72 <                                cmd++;
73 <                                continue;
74 <                        }
75 <                        *cp++ = *cmd++;
76 <                        break;
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;
84                case '|':
85                case ';':
86                        if (!quote && !paren && cp2 == NULL)
87                                cp2 = fname;
88                        break;
92                  case '\n':
93                  case '\0':
94                          if (cp2 == NULL)
# Line 93 | 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 105 | 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';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines