11 |
|
#include <stdlib.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "rtmath.h" |
14 |
< |
#include "paths.h" |
14 |
> |
#include "rtprocess.h" |
15 |
|
#include "bsdf.h" |
16 |
|
#include "bsdf_m.h" |
17 |
|
#include "random.h" |
142 |
|
return(NULL); |
143 |
|
if (verbose < 0) { /* turn off warnings */ |
144 |
|
strcpy(cp, "-w "); |
145 |
< |
cp += 4; |
145 |
> |
cp += 3; |
146 |
|
} |
147 |
|
while (ac-- > 0) { /* copy each argument */ |
148 |
|
int len = strlen(*av); |
178 |
|
exit(1); |
179 |
|
} |
180 |
|
|
181 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
182 |
+ |
|
183 |
|
/* Open a pipe to/from a command given as an argument list */ |
184 |
|
static FILE * |
185 |
|
popen_arglist(char *av[], char *mode) |
197 |
|
return(popen(cmd, mode)); |
198 |
|
} |
199 |
|
|
200 |
< |
#if defined(_WIN32) || defined(_WIN64) |
200 |
> |
#define pclose_al pclose |
201 |
> |
|
202 |
|
/* Execute system command (Windows version) */ |
203 |
|
static int |
204 |
|
my_exec(char *av[]) |
214 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
215 |
|
return(system(cmd)); |
216 |
|
} |
217 |
< |
#else |
217 |
> |
|
218 |
> |
#else /* UNIX */ |
219 |
> |
|
220 |
> |
static SUBPROC rt_proc = SP_INACTIVE; /* we only support one of these */ |
221 |
> |
|
222 |
> |
/* Open a pipe to a command using an argument list */ |
223 |
> |
static FILE * |
224 |
> |
popen_arglist(char *av[], char *mode) |
225 |
> |
{ |
226 |
> |
int fd; |
227 |
> |
|
228 |
> |
if (rt_proc.pid > 0) { |
229 |
> |
fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname); |
230 |
> |
return(NULL); |
231 |
> |
} |
232 |
> |
if (verbose > 0) { |
233 |
> |
char cmd[4096]; |
234 |
> |
if (!convert_commandline(cmd, sizeof(cmd), av)) |
235 |
> |
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
236 |
> |
fprintf(stderr, "%s: opening pipe %s: %s\n", |
237 |
> |
progname, (*mode=='w') ? "to" : "from", cmd); |
238 |
> |
} |
239 |
> |
if (*mode == 'w') { |
240 |
> |
fd = rt_proc.w = dup(fileno(stdout)); |
241 |
> |
rt_proc.flags |= PF_FILT_OUT; |
242 |
> |
} else if (*mode == 'r') { |
243 |
> |
fd = rt_proc.r = dup(fileno(stdin)); |
244 |
> |
rt_proc.flags |= PF_FILT_INP; |
245 |
> |
} |
246 |
> |
if (fd < 0 || open_process(&rt_proc, av) <= 0) { |
247 |
> |
perror(av[0]); |
248 |
> |
return(NULL); |
249 |
> |
} |
250 |
> |
return(fdopen(fd, mode)); |
251 |
> |
} |
252 |
> |
|
253 |
> |
/* Close command pipe (returns -1 on error to match pclose) */ |
254 |
> |
static int |
255 |
> |
pclose_al(FILE *fp) |
256 |
> |
{ |
257 |
> |
int prob = (fclose(fp) == EOF); |
258 |
> |
|
259 |
> |
if (rt_proc.pid <= 0) |
260 |
> |
return(-1); |
261 |
> |
|
262 |
> |
prob |= (close_process(&rt_proc) != 0); |
263 |
> |
|
264 |
> |
return(-prob); |
265 |
> |
} |
266 |
> |
|
267 |
|
/* Execute system command in our stead (Unix version) */ |
268 |
|
static int |
269 |
|
my_exec(char *av[]) |
284 |
|
perror(compath); |
285 |
|
return(1); |
286 |
|
} |
287 |
+ |
|
288 |
|
#endif |
289 |
|
|
290 |
|
/* Get normalized direction vector from string specification */ |
1427 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1428 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1429 |
|
return(1); |
1430 |
< |
return(pclose(rcfp) < 0); /* all finished! */ |
1430 |
> |
return(pclose_al(rcfp) < 0); /* all finished! */ |
1431 |
|
userr: |
1432 |
|
if (a < argc-2) |
1433 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |