1 |
– |
/* Copyright (c) 1994 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 |
|
* Executive program for oconv, rpict and pfilt |
6 |
|
*/ |
7 |
|
|
8 |
|
#include "standard.h" |
9 |
< |
#include "paths.h" |
9 |
> |
|
10 |
|
#include <ctype.h> |
14 |
– |
#include <sys/types.h> |
11 |
|
|
12 |
+ |
#include "platform.h" |
13 |
+ |
#include "view.h" |
14 |
+ |
#include "paths.h" |
15 |
+ |
#include "vars.h" |
16 |
|
|
17 |
< |
typedef struct { |
18 |
< |
char *name; /* variable name */ |
19 |
< |
short nick; /* # characters required for nickname */ |
20 |
< |
short nass; /* # assignments made */ |
21 |
< |
char *value; /* assigned value(s) */ |
22 |
< |
int (*fixval)(); /* assignment checking function */ |
23 |
< |
} VARIABLE; |
24 |
< |
|
25 |
< |
int onevalue(), catvalues(), boolvalue(), |
26 |
< |
qualvalue(), fltvalue(), intvalue(); |
27 |
< |
|
28 |
< |
/* variables */ |
29 |
< |
#define OBJECT 0 /* object files */ |
30 |
< |
#define SCENE 1 /* scene files */ |
31 |
< |
#define MATERIAL 2 /* material files */ |
32 |
< |
#define ILLUM 3 /* mkillum input files */ |
33 |
< |
#define MKILLUM 4 /* mkillum options */ |
34 |
< |
#define RENDER 5 /* rendering options */ |
35 |
< |
#define OCONV 6 /* oconv options */ |
36 |
< |
#define PFILT 7 /* pfilt options */ |
37 |
< |
#define VIEW 8 /* view(s) for picture(s) */ |
38 |
< |
#define ZONE 9 /* simulation zone */ |
39 |
< |
#define QUALITY 10 /* desired rendering quality */ |
40 |
< |
#define OCTREE 11 /* octree file name */ |
41 |
< |
#define PICTURE 12 /* picture file root name */ |
42 |
< |
#define AMBFILE 13 /* ambient file name */ |
43 |
< |
#define OPTFILE 14 /* rendering options file */ |
44 |
< |
#define EXPOSURE 15 /* picture exposure setting */ |
45 |
< |
#define RESOLUTION 16 /* maximum picture resolution */ |
46 |
< |
#define UP 17 /* view up (X, Y or Z) */ |
47 |
< |
#define INDIRECT 18 /* indirection in lighting */ |
48 |
< |
#define DETAIL 19 /* level of scene detail */ |
49 |
< |
#define PENUMBRAS 20 /* shadow penumbras are desired */ |
50 |
< |
#define VARIABILITY 21 /* level of light variability */ |
51 |
< |
#define REPORT 22 /* report frequency and errfile */ |
52 |
< |
#define RAWFILE 23 /* raw picture file root name */ |
17 |
> |
/* variables (alphabetical by name) */ |
18 |
> |
#define AMBFILE 0 /* ambient file name */ |
19 |
> |
#define DETAIL 1 /* level of scene detail */ |
20 |
> |
#define EXPOSURE 2 /* picture exposure setting */ |
21 |
> |
#define EYESEP 3 /* interocular distance */ |
22 |
> |
#define ILLUM 4 /* mkillum input files */ |
23 |
> |
#define INDIRECT 5 /* indirection in lighting */ |
24 |
> |
#define MATERIAL 6 /* material files */ |
25 |
> |
#define MKILLUM 7 /* mkillum options */ |
26 |
> |
#define OBJECT 8 /* object files */ |
27 |
> |
#define OCONV 9 /* oconv options */ |
28 |
> |
#define OCTREE 10 /* octree file name */ |
29 |
> |
#define OPTFILE 11 /* rendering options file */ |
30 |
> |
#define PENUMBRAS 12 /* shadow penumbras are desired */ |
31 |
> |
#define PFILT 13 /* pfilt options */ |
32 |
> |
#define PICTURE 14 /* picture file root name */ |
33 |
> |
#define QUALITY 15 /* desired rendering quality */ |
34 |
> |
#define RAWFILE 16 /* raw picture file root name */ |
35 |
> |
#define RENDER 17 /* rendering options */ |
36 |
> |
#define REPORT 18 /* report frequency and errfile */ |
37 |
> |
#define RESOLUTION 19 /* maximum picture resolution */ |
38 |
> |
#define SCENE 20 /* scene files */ |
39 |
> |
#define UP 21 /* view up (X, Y or Z) */ |
40 |
> |
#define VARIABILITY 22 /* level of light variability */ |
41 |
> |
#define VIEWS 23 /* view(s) for picture(s) */ |
42 |
|
#define ZFILE 24 /* distance file root name */ |
43 |
+ |
#define ZONE 25 /* simulation zone */ |
44 |
|
/* total number of variables */ |
45 |
< |
#define NVARS 25 |
45 |
> |
int NVARS = 26; |
46 |
|
|
47 |
< |
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
48 |
< |
{"objects", 3, 0, NULL, catvalues}, |
49 |
< |
{"scene", 3, 0, NULL, catvalues}, |
50 |
< |
{"materials", 3, 0, NULL, catvalues}, |
47 |
> |
VARIABLE vv[] = { /* variable-value pairs */ |
48 |
> |
{"AMBFILE", 3, 0, NULL, onevalue}, |
49 |
> |
{"DETAIL", 3, 0, NULL, qualvalue}, |
50 |
> |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
51 |
> |
{"EYESEP", 3, 0, NULL, fltvalue}, |
52 |
|
{"illum", 3, 0, NULL, catvalues}, |
53 |
+ |
{"INDIRECT", 3, 0, NULL, intvalue}, |
54 |
+ |
{"materials", 3, 0, NULL, catvalues}, |
55 |
|
{"mkillum", 3, 0, NULL, catvalues}, |
56 |
< |
{"render", 3, 0, NULL, catvalues}, |
56 |
> |
{"objects", 3, 0, NULL, catvalues}, |
57 |
|
{"oconv", 3, 0, NULL, catvalues}, |
65 |
– |
{"pfilt", 2, 0, NULL, catvalues}, |
66 |
– |
{"view", 2, 0, NULL, NULL}, |
67 |
– |
{"ZONE", 2, 0, NULL, onevalue}, |
68 |
– |
{"QUALITY", 3, 0, NULL, qualvalue}, |
58 |
|
{"OCTREE", 3, 0, NULL, onevalue}, |
70 |
– |
{"PICTURE", 3, 0, NULL, onevalue}, |
71 |
– |
{"AMBFILE", 3, 0, NULL, onevalue}, |
59 |
|
{"OPTFILE", 3, 0, NULL, onevalue}, |
60 |
< |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
60 |
> |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
61 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
62 |
> |
{"PICTURE", 3, 0, NULL, onevalue}, |
63 |
> |
{"QUALITY", 3, 0, NULL, qualvalue}, |
64 |
> |
{"RAWFILE", 3, 0, NULL, onevalue}, |
65 |
> |
{"render", 3, 0, NULL, catvalues}, |
66 |
> |
{"REPORT", 3, 0, NULL, onevalue}, |
67 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
68 |
+ |
{"scene", 3, 0, NULL, catvalues}, |
69 |
|
{"UP", 2, 0, NULL, onevalue}, |
76 |
– |
{"INDIRECT", 3, 0, NULL, intvalue}, |
77 |
– |
{"DETAIL", 3, 0, NULL, qualvalue}, |
78 |
– |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
70 |
|
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
71 |
< |
{"REPORT", 3, 0, NULL, onevalue}, |
81 |
< |
{"RAWFILE", 3, 0, NULL, onevalue}, |
71 |
> |
{"view", 2, 0, NULL, NULL}, |
72 |
|
{"ZFILE", 2, 0, NULL, onevalue}, |
73 |
+ |
{"ZONE", 2, 0, NULL, onevalue}, |
74 |
|
}; |
75 |
|
|
85 |
– |
VARIABLE *matchvar(); |
86 |
– |
char *nvalue(); |
87 |
– |
|
88 |
– |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
89 |
– |
|
90 |
– |
#define vnam(vc) (vv[vc].name) |
91 |
– |
#define vdef(vc) (vv[vc].nass) |
92 |
– |
#define vval(vc) (vv[vc].value) |
93 |
– |
#define vint(vc) atoi(vval(vc)) |
94 |
– |
#define vlet(vc) UPPER(vval(vc)[0]) |
95 |
– |
#define vscale vlet |
96 |
– |
#define vbool(vc) (vlet(vc)=='T') |
97 |
– |
|
98 |
– |
#define HIGH 'H' |
99 |
– |
#define MEDIUM 'M' |
100 |
– |
#define LOW 'L' |
101 |
– |
|
76 |
|
/* overture calculation file */ |
77 |
< |
#ifdef NIX |
78 |
< |
char overfile[] = "overture.unf"; |
77 |
> |
#ifdef NULL_DEVICE |
78 |
> |
char overfile[] = NULL_DEVICE; |
79 |
|
#else |
80 |
< |
char overfile[] = "/dev/null"; |
80 |
> |
char overfile[] = "overture.unf"; |
81 |
|
#endif |
82 |
|
|
83 |
< |
extern time_t fdate(), time(); |
83 |
> |
extern time_t time(); |
84 |
|
|
85 |
|
time_t scenedate; /* date of latest scene or object file */ |
86 |
|
time_t octreedate; /* date of octree */ |
96 |
|
int explicate = 0; /* explicate variables */ |
97 |
|
int silent = 0; /* do work silently */ |
98 |
|
int touchonly = 0; /* touch files only */ |
99 |
< |
int noaction = 0; /* don't do anything */ |
99 |
> |
int nprocs = 1; /* maximum executing processes */ |
100 |
|
int sayview = 0; /* print view out */ |
101 |
|
char *rvdevice = NULL; /* rview output device */ |
102 |
|
char *viewselect = NULL; /* specific view only */ |
103 |
|
|
104 |
|
int overture = 0; /* overture calculation needed */ |
105 |
|
|
106 |
+ |
int children_running = 0; /* set negative in children */ |
107 |
+ |
|
108 |
|
char *progname; /* global argv[0] */ |
109 |
|
char *rifname; /* global rad input file name */ |
110 |
|
|
111 |
< |
char radname[MAXPATH]; /* root Radiance file name */ |
111 |
> |
char radname[PATH_MAX]; /* root Radiance file name */ |
112 |
|
|
113 |
|
|
114 |
|
main(argc, argv) |
127 |
|
silent++; |
128 |
|
break; |
129 |
|
case 'n': |
130 |
< |
noaction++; |
130 |
> |
nprocs = 0; |
131 |
|
break; |
132 |
+ |
case 'N': |
133 |
+ |
nprocs = atoi(argv[++i]); |
134 |
+ |
if (nprocs < 0) |
135 |
+ |
nprocs = 0; |
136 |
+ |
break; |
137 |
|
case 't': |
138 |
|
touchonly++; |
139 |
|
break; |
161 |
|
/* assign Radiance root file name */ |
162 |
|
rootname(radname, rifname); |
163 |
|
/* load variable values */ |
164 |
< |
load(rifname); |
164 |
> |
loadvars(rifname); |
165 |
|
/* get any additional assignments */ |
166 |
|
for (i++; i < argc; i++) |
167 |
< |
setvariable(argv[i]); |
167 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
168 |
> |
fprintf(stderr, "%s: unknown variable: %s\n", |
169 |
> |
progname, argv[i]); |
170 |
> |
quit(1); |
171 |
> |
} |
172 |
|
/* check assignments */ |
173 |
|
checkvalues(); |
174 |
|
/* check files and dates */ |
177 |
|
setdefaults(); |
178 |
|
/* print all values if requested */ |
179 |
|
if (explicate) |
180 |
< |
printvals(); |
180 |
> |
printvars(stdout); |
181 |
|
/* build octree (and run mkillum) */ |
182 |
|
oconv(); |
183 |
|
/* check date on ambient file */ |
189 |
|
rview(ropts, popts); |
190 |
|
else |
191 |
|
rpict(ropts, popts); |
192 |
< |
exit(0); |
192 |
> |
quit(0); |
193 |
|
userr: |
194 |
|
fprintf(stderr, |
195 |
< |
"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
195 |
> |
"Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
196 |
|
progname); |
197 |
< |
exit(1); |
197 |
> |
quit(1); |
198 |
|
} |
199 |
|
|
200 |
|
|
213 |
|
} |
214 |
|
|
215 |
|
|
231 |
– |
#define NOCHAR 127 /* constant for character to delete */ |
232 |
– |
|
233 |
– |
|
234 |
– |
load(rfname) /* load Radiance simulation file */ |
235 |
– |
char *rfname; |
236 |
– |
{ |
237 |
– |
FILE *fp; |
238 |
– |
char buf[512]; |
239 |
– |
register char *cp; |
240 |
– |
|
241 |
– |
if (rfname == NULL) |
242 |
– |
fp = stdin; |
243 |
– |
else if ((fp = fopen(rfname, "r")) == NULL) |
244 |
– |
syserr(rfname); |
245 |
– |
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
246 |
– |
for (cp = buf; *cp; cp++) { |
247 |
– |
switch (*cp) { |
248 |
– |
case '\\': |
249 |
– |
*cp++ = NOCHAR; |
250 |
– |
continue; |
251 |
– |
case '#': |
252 |
– |
*cp = '\0'; |
253 |
– |
break; |
254 |
– |
default: |
255 |
– |
continue; |
256 |
– |
} |
257 |
– |
break; |
258 |
– |
} |
259 |
– |
setvariable(buf); |
260 |
– |
} |
261 |
– |
fclose(fp); |
262 |
– |
} |
263 |
– |
|
264 |
– |
|
265 |
– |
setvariable(ass) /* assign variable according to string */ |
266 |
– |
register char *ass; |
267 |
– |
{ |
268 |
– |
char varname[32]; |
269 |
– |
int n; |
270 |
– |
register char *cp; |
271 |
– |
register VARIABLE *vp; |
272 |
– |
register int i; |
273 |
– |
|
274 |
– |
while (isspace(*ass)) /* skip leading space */ |
275 |
– |
ass++; |
276 |
– |
cp = varname; /* extract name */ |
277 |
– |
while (cp < varname+sizeof(varname)-1 |
278 |
– |
&& *ass && !isspace(*ass) && *ass != '=') |
279 |
– |
*cp++ = *ass++; |
280 |
– |
*cp = '\0'; |
281 |
– |
if (!varname[0]) |
282 |
– |
return; /* no variable name! */ |
283 |
– |
/* trim value */ |
284 |
– |
while (isspace(*ass) || *ass == '=') |
285 |
– |
ass++; |
286 |
– |
for (n = strlen(ass); n > 0; n--) |
287 |
– |
if (!isspace(ass[n-1])) |
288 |
– |
break; |
289 |
– |
if (!n && !nowarn) { |
290 |
– |
fprintf(stderr, "%s: warning - missing value for variable '%s'\n", |
291 |
– |
progname, varname); |
292 |
– |
return; |
293 |
– |
} |
294 |
– |
/* match variable from list */ |
295 |
– |
vp = matchvar(varname); |
296 |
– |
if (vp == NULL) { |
297 |
– |
fprintf(stderr, "%s: unknown variable '%s'\n", |
298 |
– |
progname, varname); |
299 |
– |
exit(1); |
300 |
– |
} |
301 |
– |
/* assign new value */ |
302 |
– |
if (i = vp->nass) { |
303 |
– |
cp = vp->value; |
304 |
– |
while (i--) |
305 |
– |
while (*cp++) |
306 |
– |
; |
307 |
– |
i = cp - vp->value; |
308 |
– |
vp->value = realloc(vp->value, i+n+1); |
309 |
– |
} else |
310 |
– |
vp->value = malloc(n+1); |
311 |
– |
if (vp->value == NULL) |
312 |
– |
syserr(progname); |
313 |
– |
cp = vp->value+i; /* copy value, squeezing spaces */ |
314 |
– |
*cp = *ass; |
315 |
– |
for (i = 1; i <= n; i++) { |
316 |
– |
if (ass[i] == NOCHAR) |
317 |
– |
continue; |
318 |
– |
if (isspace(*cp)) |
319 |
– |
while (isspace(ass[i])) |
320 |
– |
i++; |
321 |
– |
*++cp = ass[i]; |
322 |
– |
} |
323 |
– |
if (isspace(*cp)) /* remove trailing space */ |
324 |
– |
*cp = '\0'; |
325 |
– |
vp->nass++; |
326 |
– |
} |
327 |
– |
|
328 |
– |
|
329 |
– |
VARIABLE * |
330 |
– |
matchvar(nam) /* match a variable by its name */ |
331 |
– |
char *nam; |
332 |
– |
{ |
333 |
– |
int n = strlen(nam); |
334 |
– |
register int i; |
335 |
– |
|
336 |
– |
for (i = 0; i < NVARS; i++) |
337 |
– |
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
338 |
– |
return(vv+i); |
339 |
– |
return(NULL); |
340 |
– |
} |
341 |
– |
|
342 |
– |
|
343 |
– |
char * |
344 |
– |
nvalue(vp, n) /* return nth variable value */ |
345 |
– |
VARIABLE *vp; |
346 |
– |
register int n; |
347 |
– |
{ |
348 |
– |
register char *cp; |
349 |
– |
|
350 |
– |
if (vp == NULL | n < 0 | n >= vp->nass) |
351 |
– |
return(NULL); |
352 |
– |
cp = vp->value; |
353 |
– |
while (n--) |
354 |
– |
while (*cp++) |
355 |
– |
; |
356 |
– |
return(cp); |
357 |
– |
} |
358 |
– |
|
359 |
– |
|
360 |
– |
checkvalues() /* check assignments */ |
361 |
– |
{ |
362 |
– |
register int i; |
363 |
– |
|
364 |
– |
for (i = 0; i < NVARS; i++) |
365 |
– |
if (vv[i].fixval != NULL) |
366 |
– |
(*vv[i].fixval)(vv+i); |
367 |
– |
} |
368 |
– |
|
369 |
– |
|
370 |
– |
onevalue(vp) /* only one assignment for this variable */ |
371 |
– |
register VARIABLE *vp; |
372 |
– |
{ |
373 |
– |
if (vp->nass < 2) |
374 |
– |
return; |
375 |
– |
if (!nowarn) |
376 |
– |
fprintf(stderr, |
377 |
– |
"%s: warning - multiple assignment of variable '%s'\n", |
378 |
– |
progname, vp->name); |
379 |
– |
do |
380 |
– |
vp->value += strlen(vp->value)+1; |
381 |
– |
while (--vp->nass > 1); |
382 |
– |
} |
383 |
– |
|
384 |
– |
|
385 |
– |
catvalues(vp) /* concatenate variable values */ |
386 |
– |
register VARIABLE *vp; |
387 |
– |
{ |
388 |
– |
register char *cp; |
389 |
– |
|
390 |
– |
if (vp->nass < 2) |
391 |
– |
return; |
392 |
– |
for (cp = vp->value; vp->nass > 1; vp->nass--) { |
393 |
– |
while (*cp) |
394 |
– |
cp++; |
395 |
– |
*cp++ = ' '; |
396 |
– |
} |
397 |
– |
} |
398 |
– |
|
399 |
– |
|
400 |
– |
int |
401 |
– |
badmatch(tv, cv) /* case insensitive truncated comparison */ |
402 |
– |
register char *tv, *cv; |
403 |
– |
{ |
404 |
– |
if (!*tv) return(1); /* null string cannot match */ |
405 |
– |
do |
406 |
– |
if (UPPER(*tv) != *cv++) |
407 |
– |
return(1); |
408 |
– |
while (*++tv); |
409 |
– |
return(0); /* OK */ |
410 |
– |
} |
411 |
– |
|
412 |
– |
|
413 |
– |
boolvalue(vp) /* check boolean for legal values */ |
414 |
– |
register VARIABLE *vp; |
415 |
– |
{ |
416 |
– |
if (!vp->nass) return; |
417 |
– |
onevalue(vp); |
418 |
– |
switch (UPPER(vp->value[0])) { |
419 |
– |
case 'T': |
420 |
– |
if (badmatch(vp->value, "TRUE")) break; |
421 |
– |
return; |
422 |
– |
case 'F': |
423 |
– |
if (badmatch(vp->value, "FALSE")) break; |
424 |
– |
return; |
425 |
– |
} |
426 |
– |
fprintf(stderr, "%s: illegal value for boolean variable '%s'\n", |
427 |
– |
progname, vp->name); |
428 |
– |
exit(1); |
429 |
– |
} |
430 |
– |
|
431 |
– |
|
432 |
– |
qualvalue(vp) /* check qualitative var. for legal values */ |
433 |
– |
register VARIABLE *vp; |
434 |
– |
{ |
435 |
– |
if (!vp->nass) return; |
436 |
– |
onevalue(vp); |
437 |
– |
switch (UPPER(vp->value[0])) { |
438 |
– |
case 'L': |
439 |
– |
if (badmatch(vp->value, "LOW")) break; |
440 |
– |
return; |
441 |
– |
case 'M': |
442 |
– |
if (badmatch(vp->value, "MEDIUM")) break; |
443 |
– |
return; |
444 |
– |
case 'H': |
445 |
– |
if (badmatch(vp->value, "HIGH")) break; |
446 |
– |
return; |
447 |
– |
} |
448 |
– |
fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n", |
449 |
– |
progname, vp->name); |
450 |
– |
exit(1); |
451 |
– |
} |
452 |
– |
|
453 |
– |
|
454 |
– |
intvalue(vp) /* check integer variable for legal values */ |
455 |
– |
register VARIABLE *vp; |
456 |
– |
{ |
457 |
– |
if (!vp->nass) return; |
458 |
– |
onevalue(vp); |
459 |
– |
if (isint(vp->value)) return; |
460 |
– |
fprintf(stderr, "%s: illegal value for integer variable '%s'\n", |
461 |
– |
progname, vp->name); |
462 |
– |
exit(1); |
463 |
– |
} |
464 |
– |
|
465 |
– |
|
466 |
– |
fltvalue(vp) /* check float variable for legal values */ |
467 |
– |
register VARIABLE *vp; |
468 |
– |
{ |
469 |
– |
if (!vp->nass) return; |
470 |
– |
onevalue(vp); |
471 |
– |
if (isflt(vp->value)) return; |
472 |
– |
fprintf(stderr, "%s: illegal value for real variable '%s'\n", |
473 |
– |
progname, vp->name); |
474 |
– |
exit(1); |
475 |
– |
} |
476 |
– |
|
477 |
– |
|
216 |
|
time_t |
217 |
|
checklast(fnames) /* check files and find most recent */ |
218 |
|
register char *fnames; |
219 |
|
{ |
220 |
< |
char thisfile[MAXPATH]; |
220 |
> |
char thisfile[PATH_MAX]; |
221 |
|
time_t thisdate, lastdate = 0; |
484 |
– |
register char *cp; |
222 |
|
|
223 |
|
if (fnames == NULL) |
224 |
|
return(0); |
225 |
< |
while (*fnames) { |
226 |
< |
while (isspace(*fnames)) fnames++; |
227 |
< |
cp = thisfile; |
228 |
< |
while (*fnames && !isspace(*fnames)) |
492 |
< |
*cp++ = *fnames++; |
493 |
< |
*cp = '\0'; |
225 |
> |
while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { |
226 |
> |
if (thisfile[0] == '!' || |
227 |
> |
(thisfile[0] == '\\' && thisfile[1] == '!')) |
228 |
> |
continue; |
229 |
|
if (!(thisdate = fdate(thisfile))) |
230 |
|
syserr(thisfile); |
231 |
|
if (thisdate > lastdate) |
240 |
|
char *orig; |
241 |
|
int pred; |
242 |
|
{ |
508 |
– |
extern char *rindex(); |
243 |
|
register char *cp; |
244 |
|
register int n; |
245 |
|
int suffix; |
269 |
|
syserr(progname); |
270 |
|
sprintf(vval(OCTREE), "%s.oct", radname); |
271 |
|
vdef(OCTREE)++; |
272 |
+ |
} else if (vval(OCTREE)[0] == '!') { |
273 |
+ |
fprintf(stderr, "%s: illegal '%s' specification\n", |
274 |
+ |
progname, vnam(OCTREE)); |
275 |
+ |
quit(1); |
276 |
|
} |
277 |
|
octreedate = fdate(vval(OCTREE)); |
278 |
|
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
289 |
|
if (!octreedate & !scenedate & !illumdate) { |
290 |
|
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
291 |
|
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
292 |
< |
exit(1); |
292 |
> |
quit(1); |
293 |
|
} |
294 |
|
matdate = checklast(vval(MATERIAL)); |
295 |
|
} |
301 |
|
extern FILE *popen(); |
302 |
|
static double oorg[3], osiz = 0.; |
303 |
|
double min[3], max[3]; |
304 |
< |
char buf[512]; |
304 |
> |
char buf[1024]; |
305 |
|
FILE *fp; |
306 |
|
register int i; |
307 |
|
|
308 |
|
if (osiz <= FTINY) |
309 |
< |
if (noaction && fdate(oct1name) < |
309 |
> |
if (!nprocs && fdate(oct1name) < |
310 |
|
(scenedate>illumdate?scenedate:illumdate)) { |
311 |
|
/* run getbbox */ |
312 |
|
sprintf(buf, "getbbox -w -h %s", |
319 |
|
fprintf(stderr, |
320 |
|
"%s: error reading bounding box from getbbox\n", |
321 |
|
progname); |
322 |
< |
exit(1); |
322 |
> |
quit(1); |
323 |
|
} |
324 |
|
for (i = 0; i < 3; i++) |
325 |
|
if (max[i] - min[i] > osiz) |
337 |
|
fprintf(stderr, |
338 |
|
"%s: error reading bounding cube from getinfo\n", |
339 |
|
progname); |
340 |
< |
exit(1); |
340 |
> |
quit(1); |
341 |
|
} |
342 |
|
pclose(fp); |
343 |
|
} |
347 |
|
|
348 |
|
setdefaults() /* set default values for unassigned var's */ |
349 |
|
{ |
350 |
< |
double org[3], size; |
350 |
> |
double org[3], lim[3], size; |
351 |
|
char buf[128]; |
352 |
|
|
353 |
|
if (!vdef(ZONE)) { |
357 |
|
vval(ZONE) = savqstr(buf); |
358 |
|
vdef(ZONE)++; |
359 |
|
} |
360 |
+ |
if (!vdef(EYESEP)) { |
361 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
362 |
+ |
&org[0], &lim[0], &org[1], &lim[1], |
363 |
+ |
&org[2], &lim[2]) != 6) |
364 |
+ |
badvalue(ZONE); |
365 |
+ |
sprintf(buf, "%f", |
366 |
+ |
0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); |
367 |
+ |
vval(EYESEP) = savqstr(buf); |
368 |
+ |
vdef(EYESEP)++; |
369 |
+ |
} |
370 |
|
if (!vdef(INDIRECT)) { |
371 |
|
vval(INDIRECT) = "0"; |
372 |
|
vdef(INDIRECT)++; |
383 |
|
vval(PICTURE) = radname; |
384 |
|
vdef(PICTURE)++; |
385 |
|
} |
386 |
< |
if (!vdef(VIEW)) { |
387 |
< |
vval(VIEW) = "X"; |
388 |
< |
vdef(VIEW)++; |
386 |
> |
if (!vdef(VIEWS)) { |
387 |
> |
vval(VIEWS) = "X"; |
388 |
> |
vdef(VIEWS)++; |
389 |
|
} |
390 |
|
if (!vdef(DETAIL)) { |
391 |
|
vval(DETAIL) = "M"; |
402 |
|
} |
403 |
|
|
404 |
|
|
657 |
– |
printvals() /* print variable values */ |
658 |
– |
{ |
659 |
– |
int i, j, clipline; |
660 |
– |
register char *cp; |
661 |
– |
register int k; |
662 |
– |
|
663 |
– |
for (i = 0; i < NVARS; i++) /* print each variable */ |
664 |
– |
for (j = 0; j < vdef(i); j++) { /* print each assignment */ |
665 |
– |
fputs(vnam(i), stdout); |
666 |
– |
fputs("= ", stdout); |
667 |
– |
k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 ) |
668 |
– |
- strlen(vnam(i)) ; |
669 |
– |
cp = nvalue(vv+i, j); |
670 |
– |
while (*cp) { |
671 |
– |
putchar(*cp++); |
672 |
– |
if (--k <= 0) { /* line too long */ |
673 |
– |
while (*cp && !isspace(*cp)) |
674 |
– |
putchar(*cp++); /* finish this word */ |
675 |
– |
if (*cp) { /* start new line */ |
676 |
– |
putchar('\n'); |
677 |
– |
fputs(vnam(i), stdout); |
678 |
– |
putchar('='); |
679 |
– |
k = clipline; |
680 |
– |
} |
681 |
– |
} |
682 |
– |
} |
683 |
– |
putchar('\n'); |
684 |
– |
} |
685 |
– |
fflush(stdout); |
686 |
– |
} |
687 |
– |
|
688 |
– |
|
405 |
|
oconv() /* run oconv and mkillum if necessary */ |
406 |
|
{ |
407 |
|
static char illumtmp[] = "ilXXXXXX"; |
408 |
< |
char combuf[512], ocopts[64], mkopts[64]; |
408 |
> |
char combuf[PATH_MAX], ocopts[64], mkopts[64]; |
409 |
|
|
410 |
|
oconvopts(ocopts); /* get options */ |
411 |
|
if (octreedate < scenedate) { /* check date on original octree */ |
425 |
|
"%s: error generating octree\n\t%s removed\n", |
426 |
|
progname, vval(OCTREE)); |
427 |
|
unlink(vval(OCTREE)); |
428 |
< |
exit(1); |
428 |
> |
quit(1); |
429 |
|
} |
430 |
|
} |
431 |
|
octreedate = time((time_t *)NULL); |
456 |
|
"%s: error generating octree\n\t%s removed\n", |
457 |
|
progname, oct0name); |
458 |
|
unlink(oct0name); |
459 |
< |
exit(1); |
459 |
> |
quit(1); |
460 |
|
} |
461 |
|
} |
462 |
|
oct0date = time((time_t *)NULL); |
476 |
|
fprintf(stderr, "%s: error running mkillum\n", |
477 |
|
progname); |
478 |
|
unlink(illumtmp); |
479 |
< |
exit(1); |
479 |
> |
quit(1); |
480 |
|
} |
481 |
|
/* make octree1 (frozen) */ |
482 |
|
if (octreedate) |
493 |
|
"%s: error generating octree\n\t%s removed\n", |
494 |
|
progname, oct1name); |
495 |
|
unlink(oct1name); |
496 |
< |
exit(1); |
496 |
> |
unlink(illumtmp); |
497 |
> |
quit(1); |
498 |
|
} |
499 |
|
rmfile(illumtmp); |
500 |
|
} |
558 |
|
{ |
559 |
|
if (vdef(EXPOSURE)) { |
560 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
561 |
< |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
562 |
< |
return(.5/atof(vval(EXPOSURE))); |
561 |
> |
return(.5/pow(2.,vflt(EXPOSURE))); |
562 |
> |
return(.5/vflt(EXPOSURE)); |
563 |
|
} |
564 |
|
if (vlet(ZONE) == 'E') |
565 |
|
return(10.); |
658 |
|
register char *op; |
659 |
|
char *po; |
660 |
|
{ |
661 |
< |
double d, org[3], siz[3]; |
661 |
> |
double d, org[3], siz[3], asz; |
662 |
|
|
663 |
|
*op = '\0'; |
664 |
|
*po = '\0'; |
669 |
|
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
670 |
|
badvalue(ZONE); |
671 |
|
getoctcube(org, &d); |
672 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
672 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
673 |
> |
d /= asz; |
674 |
|
switch (vscale(DETAIL)) { |
675 |
|
case LOW: |
676 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
677 |
|
op = addarg(op, "-dp 256"); |
678 |
|
sprintf(op, " -ar %d", (int)(8*d)); |
679 |
|
op += strlen(op); |
680 |
+ |
sprintf(op, " -ms %.2g", asz/20.); |
681 |
+ |
op += strlen(op); |
682 |
|
break; |
683 |
|
case MEDIUM: |
684 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
685 |
|
op = addarg(op, "-dp 512"); |
686 |
|
sprintf(op, " -ar %d", (int)(16*d)); |
687 |
|
op += strlen(op); |
688 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
689 |
+ |
op += strlen(op); |
690 |
|
break; |
691 |
|
case HIGH: |
692 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
693 |
|
op = addarg(op, "-dp 1024"); |
694 |
|
sprintf(op, " -ar %d", (int)(32*d)); |
695 |
|
op += strlen(op); |
696 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
697 |
+ |
op += strlen(op); |
698 |
|
break; |
699 |
|
} |
700 |
|
po = addarg(po, "-pt .08"); |
736 |
|
register char *op; |
737 |
|
char *po; |
738 |
|
{ |
739 |
< |
double d, org[3], siz[3]; |
739 |
> |
double d, org[3], siz[3], asz; |
740 |
|
|
741 |
|
*op = '\0'; |
742 |
|
*po = '\0'; |
747 |
|
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
748 |
|
badvalue(ZONE); |
749 |
|
getoctcube(org, &d); |
750 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
750 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
751 |
> |
d /= asz; |
752 |
|
switch (vscale(DETAIL)) { |
753 |
|
case LOW: |
754 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
755 |
|
op = addarg(op, "-dp 1024"); |
756 |
|
sprintf(op, " -ar %d", (int)(16*d)); |
757 |
|
op += strlen(op); |
758 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
759 |
+ |
op += strlen(op); |
760 |
|
break; |
761 |
|
case MEDIUM: |
762 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
763 |
|
op = addarg(op, "-dp 2048"); |
764 |
|
sprintf(op, " -ar %d", (int)(32*d)); |
765 |
|
op += strlen(op); |
766 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
767 |
+ |
op += strlen(op); |
768 |
|
break; |
769 |
|
case HIGH: |
770 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
771 |
|
op = addarg(op, "-dp 4096"); |
772 |
|
sprintf(op, " -ar %d", (int)(64*d)); |
773 |
|
op += strlen(op); |
774 |
+ |
sprintf(op, " -ms %.2g", asz/160.); |
775 |
+ |
op += strlen(op); |
776 |
|
break; |
777 |
|
} |
778 |
|
po = addarg(po, "-pt .04"); |
819 |
|
return; |
820 |
|
if (vdef(OPTFILE)) { |
821 |
|
for (cp = ro; cp[1]; cp++) |
822 |
< |
if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) |
822 |
> |
if (isspace(cp[1]) && (cp[2] == '@' || |
823 |
> |
(cp[2] == '-' && isalpha(cp[3])))) |
824 |
|
*cp = '\n'; |
825 |
|
else |
826 |
|
*cp = cp[1]; |
830 |
|
syserr(vval(OPTFILE)); |
831 |
|
sprintf(ro, " @%s", vval(OPTFILE)); |
832 |
|
} |
833 |
< |
#ifdef MSDOS |
833 |
> |
#ifdef _WIN32 |
834 |
|
else if (n > 50) { |
835 |
|
setenv("ROPT", ro+1); |
836 |
|
strcpy(ro, " $ROPT"); |
849 |
|
} |
850 |
|
switch (vscale(QUALITY)) { |
851 |
|
case MEDIUM: |
852 |
< |
po = addarg(po, "-r 1"); |
852 |
> |
po = addarg(po, "-r .6"); |
853 |
|
break; |
854 |
|
case HIGH: |
855 |
|
po = addarg(po, "-m .25"); |
986 |
|
if (cp == viewopts) /* append any additional options */ |
987 |
|
vs++; /* skip prefixed space if unneeded */ |
988 |
|
strcpy(cp, vs); |
989 |
< |
#ifdef MSDOS |
989 |
> |
#ifdef _WIN32 |
990 |
|
if (strlen(viewopts) > 40) { |
991 |
|
setenv("VIEW", viewopts); |
992 |
|
return("$VIEW"); |
1018 |
|
} |
1019 |
|
/* view number? */ |
1020 |
|
if (isint(viewselect)) |
1021 |
< |
return(specview(nvalue(vv+VIEW, atoi(viewselect)-1))); |
1021 |
> |
return(specview(nvalue(VIEWS, atoi(viewselect)-1))); |
1022 |
|
/* check list */ |
1023 |
< |
while ((mv = nvalue(vv+VIEW, n++)) != NULL) |
1023 |
> |
while ((mv = nvalue(VIEWS, n++)) != NULL) |
1024 |
|
if (matchword(viewselect, mv)) |
1025 |
|
return(specview(mv)); |
1026 |
|
return(specview(viewselect)); /* standard view? */ |
1027 |
|
} |
1028 |
< |
mv = nvalue(vv+VIEW, n); /* use view n */ |
1028 |
> |
mv = nvalue(VIEWS, n); /* use view n */ |
1029 |
|
if (vn != NULL & mv != NULL) { |
1030 |
|
register char *mv2 = mv; |
1031 |
|
if (*mv2 != '-') |
1040 |
|
printview(vopts) /* print out selected view */ |
1041 |
|
register char *vopts; |
1042 |
|
{ |
1043 |
< |
extern char *atos(), *getenv(); |
1044 |
< |
char buf[256]; |
1313 |
< |
FILE *fp; |
1043 |
> |
VIEW vwr; |
1044 |
> |
char buf[128]; |
1045 |
|
register char *cp; |
1046 |
< |
|
1046 |
> |
again: |
1047 |
|
if (vopts == NULL) |
1048 |
|
return(-1); |
1049 |
< |
fputs("VIEW=", stdout); |
1050 |
< |
do { |
1051 |
< |
if (matchword(vopts, "-vf")) { /* expand view file */ |
1052 |
< |
vopts = sskip(vopts); |
1053 |
< |
if (!*atos(buf, sizeof(buf), vopts)) |
1323 |
< |
return(-1); |
1324 |
< |
if ((fp = fopen(buf, "r")) == NULL) |
1325 |
< |
return(-1); |
1326 |
< |
for (buf[sizeof(buf)-2] = '\n'; |
1327 |
< |
fgets(buf, sizeof(buf), fp) != NULL && |
1328 |
< |
buf[0] != '\n'; |
1329 |
< |
buf[sizeof(buf)-2] = '\n') { |
1330 |
< |
if (buf[sizeof(buf)-2] != '\n') { |
1331 |
< |
ungetc(buf[sizeof(buf)-2], fp); |
1332 |
< |
buf[sizeof(buf)-2] = '\0'; |
1333 |
< |
} |
1334 |
< |
if (matchword(buf, "VIEW=") || |
1335 |
< |
matchword(buf, "rview")) { |
1336 |
< |
for (cp = sskip(buf); *cp && *cp != '\n'; cp++) |
1337 |
< |
putchar(*cp); |
1338 |
< |
} |
1339 |
< |
} |
1340 |
< |
fclose(fp); |
1341 |
< |
vopts = sskip(vopts); |
1342 |
< |
} else { |
1343 |
< |
while (isspace(*vopts)) |
1344 |
< |
vopts++; |
1345 |
< |
putchar(' '); |
1346 |
< |
#ifdef MSDOS |
1347 |
< |
if (*vopts == '$') { /* expand env. var. */ |
1348 |
< |
if (!*atos(buf, sizeof(buf), vopts+1)) |
1349 |
< |
return(-1); |
1350 |
< |
if ((cp = getenv(buf)) == NULL) |
1351 |
< |
return(-1); |
1352 |
< |
fputs(cp, stdout); |
1353 |
< |
vopts = sskip(vopts); |
1354 |
< |
} else |
1049 |
> |
#ifdef _WIN32 |
1050 |
> |
if (vopts[0] == '$') { |
1051 |
> |
vopts = getenv(vopts+1); |
1052 |
> |
goto again; |
1053 |
> |
} |
1054 |
|
#endif |
1055 |
< |
while (*vopts && !isspace(*vopts)) |
1056 |
< |
putchar(*vopts++); |
1057 |
< |
} |
1058 |
< |
} while (*vopts++); |
1059 |
< |
putchar('\n'); |
1055 |
> |
copystruct(&vwr, &stdview); |
1056 |
> |
sscanview(&vwr, cp=vopts); /* set initial options */ |
1057 |
> |
while ((cp = strstr(cp, "-vf ")) != NULL && |
1058 |
> |
*atos(buf, sizeof(buf), cp += 4)) { |
1059 |
> |
viewfile(buf, &vwr, NULL); /* load -vf file */ |
1060 |
> |
sscanview(&vwr, cp); /* reset tail */ |
1061 |
> |
} |
1062 |
> |
fputs(VIEWSTR, stdout); |
1063 |
> |
fprintview(&vwr, stdout); /* print full spec. */ |
1064 |
> |
fputc('\n', stdout); |
1065 |
|
return(0); |
1066 |
|
} |
1067 |
|
|
1070 |
|
char *opts, *po; |
1071 |
|
{ |
1072 |
|
char *vw; |
1073 |
< |
char combuf[512]; |
1073 |
> |
char combuf[PATH_MAX]; |
1074 |
|
/* build command */ |
1075 |
|
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1076 |
|
return; |
1084 |
|
strcat(combuf, oct1name); |
1085 |
|
if (runcom(combuf)) { /* run it */ |
1086 |
|
fprintf(stderr, "%s: error running rview\n", progname); |
1087 |
< |
exit(1); |
1087 |
> |
quit(1); |
1088 |
|
} |
1089 |
|
} |
1090 |
|
|
1092 |
|
rpict(opts, po) /* run rpict and pfilt for each view */ |
1093 |
|
char *opts, *po; |
1094 |
|
{ |
1095 |
< |
char combuf[1024]; |
1096 |
< |
char rawfile[MAXPATH], picfile[MAXPATH]; |
1097 |
< |
char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; |
1095 |
> |
char combuf[PATH_MAX]; |
1096 |
> |
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1097 |
> |
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1098 |
|
char pfopts[128]; |
1099 |
|
char vs[32], *vw; |
1100 |
|
int vn, mult; |
1139 |
|
else |
1140 |
|
badvalue(REPORT); |
1141 |
|
} |
1142 |
< |
/* do each view */ |
1439 |
< |
vn = 0; |
1142 |
> |
vn = 0; /* do each view */ |
1143 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1144 |
|
if (sayview) |
1145 |
|
printview(vw); |
1166 |
|
touch(picfile); |
1167 |
|
continue; |
1168 |
|
} |
1169 |
+ |
if (next_process()) /* parallel running? */ |
1170 |
+ |
continue; |
1171 |
+ |
/* XXX Remember to call finish_process() */ |
1172 |
|
/* build rpict command */ |
1173 |
|
if (rfdt >= oct1date) /* recover */ |
1174 |
|
sprintf(combuf, "rpict%s%s%s%s -ro %s %s", |
1183 |
|
fprintf(stderr, |
1184 |
|
"%s: error in overture for view %s\n", |
1185 |
|
progname, vs); |
1186 |
< |
exit(1); |
1186 |
> |
quit(1); |
1187 |
|
} |
1188 |
< |
#ifdef NIX |
1188 |
> |
#ifndef NULL_DEVICE |
1189 |
|
rmfile(overfile); |
1190 |
|
#endif |
1191 |
|
} |
1196 |
|
if (runcom(combuf)) { /* run rpict */ |
1197 |
|
fprintf(stderr, "%s: error rendering view %s\n", |
1198 |
|
progname, vs); |
1199 |
< |
exit(1); |
1199 |
> |
quit(1); |
1200 |
|
} |
1201 |
|
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1202 |
|
/* build pfilt command */ |
1211 |
|
"%s: error filtering view %s\n\t%s removed\n", |
1212 |
|
progname, vs, picfile); |
1213 |
|
unlink(picfile); |
1214 |
< |
exit(1); |
1214 |
> |
quit(1); |
1215 |
|
} |
1216 |
|
} |
1217 |
|
/* remove/rename raw file */ |
1220 |
|
mvfile(rawfile, combuf); |
1221 |
|
} else |
1222 |
|
rmfile(rawfile); |
1223 |
+ |
finish_process(); /* leave if child */ |
1224 |
|
} |
1225 |
+ |
wait_process(1); /* wait for children to finish */ |
1226 |
|
} |
1227 |
|
|
1228 |
|
|
1231 |
|
{ |
1232 |
|
if (!silent) |
1233 |
|
printf("\ttouch %s\n", fn); |
1234 |
< |
if (noaction) |
1234 |
> |
if (!nprocs) |
1235 |
|
return(0); |
1236 |
|
#ifdef notused |
1237 |
|
if (access(fn, F_OK) == -1) /* create it */ |
1247 |
|
{ |
1248 |
|
if (!silent) /* echo it */ |
1249 |
|
printf("\t%s\n", cs); |
1250 |
< |
if (noaction) |
1250 |
> |
if (!nprocs) |
1251 |
|
return(0); |
1252 |
|
fflush(stdout); /* flush output and pass to shell */ |
1253 |
|
return(system(cs)); |
1258 |
|
char *fn; |
1259 |
|
{ |
1260 |
|
if (!silent) |
1261 |
< |
#ifdef MSDOS |
1261 |
> |
#ifdef _WIN32 |
1262 |
|
printf("\tdel %s\n", fn); |
1263 |
|
#else |
1264 |
|
printf("\trm -f %s\n", fn); |
1265 |
|
#endif |
1266 |
< |
if (noaction) |
1266 |
> |
if (!nprocs) |
1267 |
|
return(0); |
1268 |
|
return(unlink(fn)); |
1269 |
|
} |
1273 |
|
char *fold, *fnew; |
1274 |
|
{ |
1275 |
|
if (!silent) |
1276 |
< |
#ifdef MSDOS |
1276 |
> |
#ifdef _WIN32 |
1277 |
|
printf("\trename %s %s\n", fold, fnew); |
1278 |
|
#else |
1279 |
|
printf("\tmv %s %s\n", fold, fnew); |
1280 |
|
#endif |
1281 |
< |
if (noaction) |
1281 |
> |
if (!nprocs) |
1282 |
|
return(0); |
1283 |
|
return(rename(fold, fnew)); |
1284 |
|
} |
1285 |
|
|
1286 |
|
|
1287 |
< |
#ifdef MSDOS |
1287 |
> |
#ifdef RHAS_FORK_EXEC |
1288 |
> |
int |
1289 |
> |
next_process() /* fork the next process (max. nprocs) */ |
1290 |
> |
{ |
1291 |
> |
int child_pid; |
1292 |
> |
|
1293 |
> |
if (nprocs <= 1) |
1294 |
> |
return(0); /* it's us or no one */ |
1295 |
> |
if (children_running < 0) { |
1296 |
> |
fprintf(stderr, "%s: internal error 1 in spawn_process()\n", |
1297 |
> |
progname); |
1298 |
> |
quit(1); |
1299 |
> |
} |
1300 |
> |
if (children_running >= nprocs) |
1301 |
> |
wait_process(0); /* wait for someone to finish */ |
1302 |
> |
fflush(stdout); |
1303 |
> |
child_pid = fork(); /* split process */ |
1304 |
> |
if (child_pid == 0) { /* we're the child */ |
1305 |
> |
children_running = -1; |
1306 |
> |
return(0); |
1307 |
> |
} |
1308 |
> |
if (child_pid > 0) { /* we're the parent */ |
1309 |
> |
++children_running; |
1310 |
> |
return(1); |
1311 |
> |
} |
1312 |
> |
fprintf(stderr, "%s: warning -- fork() failed\n", progname); |
1313 |
> |
return(0); |
1314 |
> |
} |
1315 |
> |
|
1316 |
> |
wait_process(all) /* wait for process(es) to finish */ |
1317 |
> |
int all; |
1318 |
> |
{ |
1319 |
> |
int ourstatus = 0; |
1320 |
> |
int pid, status; |
1321 |
> |
|
1322 |
> |
if (all) |
1323 |
> |
all = children_running; |
1324 |
> |
else if (children_running > 0) |
1325 |
> |
all = 1; |
1326 |
> |
while (all-- > 0) { |
1327 |
> |
pid = wait(&status); |
1328 |
> |
if (pid < 0) |
1329 |
> |
syserr(progname); |
1330 |
> |
status = status>>8 & 0xff; |
1331 |
> |
--children_running; |
1332 |
> |
if (status != 0) { /* child's problem is our problem */ |
1333 |
> |
if (ourstatus == 0 & children_running > 0) |
1334 |
> |
fprintf(stderr, "%s: waiting for remaining processes\n", |
1335 |
> |
progname); |
1336 |
> |
ourstatus = status; |
1337 |
> |
all = children_running; |
1338 |
> |
} |
1339 |
> |
} |
1340 |
> |
if (ourstatus != 0) |
1341 |
> |
quit(ourstatus); /* bad status from child */ |
1342 |
> |
} |
1343 |
> |
#else /* ! RHAS_FORK_EXEC */ |
1344 |
> |
int |
1345 |
> |
next_process() |
1346 |
> |
{ |
1347 |
> |
return(0); /* cannot start new process */ |
1348 |
> |
} |
1349 |
> |
wait_process(all) |
1350 |
> |
int all; |
1351 |
> |
{ |
1352 |
> |
(void)all; /* no one to wait for */ |
1353 |
> |
} |
1354 |
> |
#endif /* ! RHAS_FORK_EXEC */ |
1355 |
> |
|
1356 |
> |
finish_process() /* exit a child process */ |
1357 |
> |
{ |
1358 |
> |
if (children_running >= 0) |
1359 |
> |
return; /* in parent -- noop */ |
1360 |
> |
exit(0); |
1361 |
> |
} |
1362 |
> |
|
1363 |
> |
#ifdef _WIN32 |
1364 |
|
setenv(vname, value) /* set an environment variable */ |
1365 |
|
char *vname, *value; |
1366 |
|
{ |
1372 |
|
sprintf(evp, "%s=%s", vname, value); |
1373 |
|
if (putenv(evp) != 0) { |
1374 |
|
fprintf(stderr, "%s: out of environment space\n", progname); |
1375 |
< |
exit(1); |
1375 |
> |
quit(1); |
1376 |
|
} |
1377 |
|
if (!silent) |
1378 |
|
printf("set %s\n", evp); |
1385 |
|
{ |
1386 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1387 |
|
progname, vnam(vc)); |
1388 |
< |
exit(1); |
1388 |
> |
quit(1); |
1389 |
|
} |
1390 |
|
|
1391 |
|
|
1393 |
|
char *s; |
1394 |
|
{ |
1395 |
|
perror(s); |
1396 |
< |
exit(1); |
1396 |
> |
quit(1); |
1397 |
> |
} |
1398 |
> |
|
1399 |
> |
|
1400 |
> |
void |
1401 |
> |
quit(ec) /* exit program */ |
1402 |
> |
int ec; |
1403 |
> |
{ |
1404 |
> |
exit(ec); |
1405 |
|
} |