11 |
|
#include <stdlib.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "rtmath.h" |
14 |
< |
#include "rtprocess.h" |
14 |
> |
#include "paths.h" |
15 |
|
#include "bsdf.h" |
16 |
|
#include "bsdf_m.h" |
17 |
|
#include "random.h" |
23 |
|
#define getc getc_unlocked |
24 |
|
#endif |
25 |
|
|
26 |
– |
#ifdef _WIN32 |
27 |
– |
#define SPECIALS " \t\"$*?" |
28 |
– |
#define QUOTCHAR '"' |
29 |
– |
#else |
30 |
– |
#define SPECIALS " \t\n'\"()${}*?[];|&" |
31 |
– |
#define QUOTCHAR '\'' |
32 |
– |
#define ALTQUOT '"' |
33 |
– |
#endif |
34 |
– |
|
26 |
|
#define MAXRCARG 512 |
27 |
|
|
28 |
|
char *progname; /* global argv[0] */ |
133 |
|
return(ST_NONE); |
134 |
|
} |
135 |
|
|
145 |
– |
/* Check if any of the characters in str2 are found in str1 */ |
146 |
– |
static int |
147 |
– |
matchany(const char *str1, const char *str2) |
148 |
– |
{ |
149 |
– |
while (*str1) { |
150 |
– |
const char *cp = str2; |
151 |
– |
while (*cp) |
152 |
– |
if (*cp++ == *str1) |
153 |
– |
return(*str1); |
154 |
– |
++str1; |
155 |
– |
} |
156 |
– |
return(0); |
157 |
– |
} |
158 |
– |
|
136 |
|
/* Add arguments to oconv command */ |
137 |
|
static char * |
138 |
|
oconv_command(int ac, char *av[]) |
169 |
|
exit(1); |
170 |
|
} |
171 |
|
|
195 |
– |
/* Convert a set of arguments into a command line for pipe() or system() */ |
196 |
– |
static char * |
197 |
– |
convert_commandline(char *cmd, const int len, char *av[]) |
198 |
– |
{ |
199 |
– |
int match; |
200 |
– |
char *cp; |
201 |
– |
|
202 |
– |
for (cp = cmd; *av != NULL; av++) { |
203 |
– |
const int n = strlen(*av); |
204 |
– |
if (cp+n >= cmd+(len-3)) { |
205 |
– |
fputs(progname, stderr); |
206 |
– |
return(NULL); |
207 |
– |
} |
208 |
– |
if (matchany(*av, SPECIALS)) { |
209 |
– |
const int quote = |
210 |
– |
#ifdef ALTQUOT |
211 |
– |
strchr(*av, QUOTCHAR) ? ALTQUOT : |
212 |
– |
#endif |
213 |
– |
QUOTCHAR; |
214 |
– |
*cp++ = quote; |
215 |
– |
strcpy(cp, *av); |
216 |
– |
cp += n; |
217 |
– |
*cp++ = quote; |
218 |
– |
} else { |
219 |
– |
strcpy(cp, *av); |
220 |
– |
cp += n; |
221 |
– |
} |
222 |
– |
*cp++ = ' '; |
223 |
– |
} |
224 |
– |
if (cp <= cmd) |
225 |
– |
return(NULL); |
226 |
– |
*--cp = '\0'; |
227 |
– |
return(cmd); |
228 |
– |
} |
229 |
– |
|
172 |
|
/* Open a pipe to/from a command given as an argument list */ |
173 |
|
static FILE * |
174 |
|
popen_arglist(char *av[], char *mode) |
271 |
|
{ |
272 |
|
char *cp = pargs; |
273 |
|
int nparams = 0; |
274 |
+ |
int quot; |
275 |
|
int i; |
276 |
|
|
277 |
|
for ( ; ; ) { |
308 |
|
case 'o': |
309 |
|
if (*cp++ != '=') |
310 |
|
break; |
311 |
+ |
quot = 0; |
312 |
+ |
if ((*cp == '"') | (*cp == '\'')) |
313 |
+ |
quot = *cp++; |
314 |
|
i = 0; |
315 |
< |
while (*cp && !isspace(*cp++)) |
316 |
< |
i++; |
315 |
> |
while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { |
316 |
> |
i++; cp++; |
317 |
> |
} |
318 |
|
if (!i) |
319 |
|
break; |
320 |
< |
*--cp = '\0'; |
320 |
> |
if (!*cp) { |
321 |
> |
if (quot) |
322 |
> |
break; |
323 |
> |
cp[1] = '\0'; |
324 |
> |
} |
325 |
> |
*cp = '\0'; |
326 |
|
p->outfn = savqstr(cp-i); |
327 |
< |
*cp++ = ' '; |
327 |
> |
*cp++ = quot ? quot : ' '; |
328 |
|
++nparams; |
329 |
|
continue; |
330 |
|
case ' ': |