ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.41 by greg, Mon Oct 24 13:49:16 1994 UTC vs.
Revision 2.69 by schorsch, Mon Jul 14 20:02:30 2003 UTC

# Line 1 | Line 1
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>
11 < #include <sys/types.h>
11 > #include <time.h>
12  
13 + #include "platform.h"
14 + #include "view.h"
15 + #include "paths.h"
16 + #include "vars.h"
17  
18 < typedef struct {
19 <        char    *name;          /* variable name */
20 <        short   nick;           /* # characters required for nickname */
21 <        short   nass;           /* # assignments made */
22 <        char    *value;         /* assigned value(s) */
23 <        int     (*fixval)();    /* assignment checking function */
24 < } VARIABLE;
18 > #ifdef _WIN32
19 >  #define DELCMD "del"
20 >  #define RENAMECMD "rename"
21 > #else
22 >  #define DELCMD "rm -f"
23 >  #define RENAMECMD "mv"
24 > #endif
25  
26 < int     onevalue(), catvalues(), boolvalue(),
27 <        qualvalue(), fltvalue(), intvalue();
28 <
29 <                                /* variables */
30 < #define OBJECT          0               /* object files */
31 < #define SCENE           1               /* scene files */
32 < #define MATERIAL        2               /* material files */
33 < #define ILLUM           3               /* mkillum input files */
34 < #define MKILLUM         4               /* mkillum options */
35 < #define RENDER          5               /* rendering options */
36 < #define OCONV           6               /* oconv options */
37 < #define PFILT           7               /* pfilt options */
38 < #define VIEW            8               /* view(s) for picture(s) */
39 < #define ZONE            9               /* simulation zone */
40 < #define QUALITY         10              /* desired rendering quality */
41 < #define OCTREE          11              /* octree file name */
42 < #define PICTURE         12              /* picture file name */
43 < #define AMBFILE         13              /* ambient file name */
44 < #define OPTFILE         14              /* rendering options file */
45 < #define EXPOSURE        15              /* picture exposure setting */
46 < #define RESOLUTION      16              /* maximum picture resolution */
47 < #define UP              17              /* view up (X, Y or Z) */
48 < #define INDIRECT        18              /* indirection in lighting */
49 < #define DETAIL          19              /* level of scene detail */
50 < #define PENUMBRAS       20              /* shadow penumbras are desired */
51 < #define VARIABILITY     21              /* level of light variability */
52 < #define REPORT          22              /* report frequency and errfile */
26 >                                /* variables (alphabetical by name) */
27 > #define AMBFILE         0               /* ambient file name */
28 > #define DETAIL          1               /* level of scene detail */
29 > #define EXPOSURE        2               /* picture exposure setting */
30 > #define EYESEP          3               /* interocular distance */
31 > #define ILLUM           4               /* mkillum input files */
32 > #define INDIRECT        5               /* indirection in lighting */
33 > #define MATERIAL        6               /* material files */
34 > #define MKILLUM         7               /* mkillum options */
35 > #define OBJECT          8               /* object files */
36 > #define OCONV           9               /* oconv options */
37 > #define OCTREE          10              /* octree file name */
38 > #define OPTFILE         11              /* rendering options file */
39 > #define PENUMBRAS       12              /* shadow penumbras are desired */
40 > #define PFILT           13              /* pfilt options */
41 > #define PICTURE         14              /* picture file root name */
42 > #define QUALITY         15              /* desired rendering quality */
43 > #define RAWFILE         16              /* raw picture file root name */
44 > #define RENDER          17              /* rendering options */
45 > #define REPORT          18              /* report frequency and errfile */
46 > #define RESOLUTION      19              /* maximum picture resolution */
47 > #define SCENE           20              /* scene files */
48 > #define UP              21              /* view up (X, Y or Z) */
49 > #define VARIABILITY     22              /* level of light variability */
50 > #define VIEWS           23              /* view(s) for picture(s) */
51 > #define ZFILE           24              /* distance file root name */
52 > #define ZONE            25              /* simulation zone */
53                                  /* total number of variables */
54 < #define NVARS           23
54 > int NVARS = 26;
55  
56 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
57 <        {"objects",     3,      0,      NULL,   catvalues},
58 <        {"scene",       3,      0,      NULL,   catvalues},
59 <        {"materials",   3,      0,      NULL,   catvalues},
56 > VARIABLE        vv[] = {                /* variable-value pairs */
57 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
58 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
59 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
60 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
61          {"illum",       3,      0,      NULL,   catvalues},
62 +        {"INDIRECT",    3,      0,      NULL,   intvalue},
63 +        {"materials",   3,      0,      NULL,   catvalues},
64          {"mkillum",     3,      0,      NULL,   catvalues},
65 <        {"render",      3,      0,      NULL,   catvalues},
65 >        {"objects",     3,      0,      NULL,   catvalues},
66          {"oconv",       3,      0,      NULL,   catvalues},
63        {"pfilt",       2,      0,      NULL,   catvalues},
64        {"view",        2,      0,      NULL,   NULL},
65        {"ZONE",        2,      0,      NULL,   onevalue},
66        {"QUALITY",     3,      0,      NULL,   qualvalue},
67          {"OCTREE",      3,      0,      NULL,   onevalue},
68        {"PICTURE",     3,      0,      NULL,   onevalue},
69        {"AMBFILE",     3,      0,      NULL,   onevalue},
68          {"OPTFILE",     3,      0,      NULL,   onevalue},
69 <        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
69 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
70 >        {"pfilt",       2,      0,      NULL,   catvalues},
71 >        {"PICTURE",     3,      0,      NULL,   onevalue},
72 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
73 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
74 >        {"render",      3,      0,      NULL,   catvalues},
75 >        {"REPORT",      3,      0,      NULL,   onevalue},
76          {"RESOLUTION",  3,      0,      NULL,   onevalue},
77 +        {"scene",       3,      0,      NULL,   catvalues},
78          {"UP",          2,      0,      NULL,   onevalue},
74        {"INDIRECT",    3,      0,      NULL,   intvalue},
75        {"DETAIL",      3,      0,      NULL,   qualvalue},
76        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
79          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
80 <        {"REPORT",      3,      0,      NULL,   onevalue},
80 >        {"view",        2,      0,      NULL,   NULL},
81 >        {"ZFILE",       2,      0,      NULL,   onevalue},
82 >        {"ZONE",        2,      0,      NULL,   onevalue},
83   };
84  
81 VARIABLE        *matchvar();
82 char    *nvalue();
83
84 #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
85
86 #define vnam(vc)        (vv[vc].name)
87 #define vdef(vc)        (vv[vc].nass)
88 #define vval(vc)        (vv[vc].value)
89 #define vint(vc)        atoi(vval(vc))
90 #define vlet(vc)        UPPER(vval(vc)[0])
91 #define vscale          vlet
92 #define vbool(vc)       (vlet(vc)=='T')
93
94 #define HIGH            'H'
95 #define MEDIUM          'M'
96 #define LOW             'L'
97
85                                  /* overture calculation file */
86 < #ifdef NIX
87 < char    overfile[] = "overture.raw";
86 > #ifdef NULL_DEVICE
87 > char    overfile[] = NULL_DEVICE;
88   #else
89 < char    overfile[] = "/dev/null";
89 > char    overfile[] = "overture.unf";
90   #endif
91  
105 extern time_t   fdate(), time();
92  
93   time_t  scenedate;              /* date of latest scene or object file */
94   time_t  octreedate;             /* date of octree */
# Line 118 | Line 104 | int    nowarn = 0;             /* no warnings */
104   int     explicate = 0;          /* explicate variables */
105   int     silent = 0;             /* do work silently */
106   int     touchonly = 0;          /* touch files only */
107 < int     noaction = 0;           /* don't do anything */
107 > int     nprocs = 1;             /* maximum executing processes */
108   int     sayview = 0;            /* print view out */
109   char    *rvdevice = NULL;       /* rview output device */
110   char    *viewselect = NULL;     /* specific view only */
111  
112   int     overture = 0;           /* overture calculation needed */
113  
114 + int     children_running = 0;   /* set negative in children */
115 +
116   char    *progname;              /* global argv[0] */
117   char    *rifname;               /* global rad input file name */
118  
119 < char    radname[MAXPATH];       /* root Radiance file name */
119 > char    radname[PATH_MAX];      /* root Radiance file name */
120  
121 + #define inchild()       (children_running < 0)
122  
123 +
124   main(argc, argv)
125   int     argc;
126   char    *argv[];
# Line 147 | Line 137 | char   *argv[];
137                          silent++;
138                          break;
139                  case 'n':
140 <                        noaction++;
140 >                        nprocs = 0;
141                          break;
142 +                case 'N':
143 +                        nprocs = atoi(argv[++i]);
144 +                        if (nprocs < 0)
145 +                                nprocs = 0;
146 +                        break;
147                  case 't':
148                          touchonly++;
149                          break;
# Line 173 | Line 168 | char   *argv[];
168          if (i >= argc)
169                  goto userr;
170          rifname = argv[i];
171 +                                /* check command-line options */
172 +        if (nprocs > 1 & viewselect != NULL)
173 +                nprocs = 1;
174                                  /* assign Radiance root file name */
175          rootname(radname, rifname);
176                                  /* load variable values */
177 <        load(rifname);
177 >        loadvars(rifname);
178                                  /* get any additional assignments */
179          for (i++; i < argc; i++)
180 <                setvariable(argv[i]);
180 >                if (setvariable(argv[i], matchvar) < 0) {
181 >                        fprintf(stderr, "%s: unknown variable: %s\n",
182 >                                        progname, argv[i]);
183 >                        quit(1);
184 >                }
185                                  /* check assignments */
186          checkvalues();
187                                  /* check files and dates */
# Line 188 | Line 190 | char   *argv[];
190          setdefaults();
191                                  /* print all values if requested */
192          if (explicate)
193 <                printvals();
193 >                printvars(stdout);
194                                  /* build octree (and run mkillum) */
195          oconv();
196                                  /* check date on ambient file */
# Line 200 | Line 202 | char   *argv[];
202                  rview(ropts, popts);
203          else
204                  rpict(ropts, popts);
205 <        exit(0);
205 >        quit(0);
206   userr:
207          fprintf(stderr,
208 < "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
208 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
209                          progname);
210 <        exit(1);
210 >        quit(1);
211   }
212  
213  
# Line 224 | Line 226 | register char  *rn, *fn;
226   }
227  
228  
227 #define NOCHAR  127             /* constant for character to delete */
228
229
230 load(rfname)                    /* load Radiance simulation file */
231 char    *rfname;
232 {
233        FILE    *fp;
234        char    buf[512];
235        register char   *cp;
236
237        if (rfname == NULL)
238                fp = stdin;
239        else if ((fp = fopen(rfname, "r")) == NULL)
240                syserr(rfname);
241        while (fgetline(buf, sizeof(buf), fp) != NULL) {
242                for (cp = buf; *cp; cp++) {
243                        switch (*cp) {
244                        case '\\':
245                                *cp++ = NOCHAR;
246                                continue;
247                        case '#':
248                                *cp = '\0';
249                                break;
250                        default:
251                                continue;
252                        }
253                        break;
254                }
255                setvariable(buf);
256        }
257        fclose(fp);
258 }
259
260
261 setvariable(ass)                /* assign variable according to string */
262 register char   *ass;
263 {
264        char    varname[32];
265        int     n;
266        register char   *cp;
267        register VARIABLE       *vp;
268        register int    i;
269
270        while (isspace(*ass))           /* skip leading space */
271                ass++;
272        cp = varname;                   /* extract name */
273        while (cp < varname+sizeof(varname)-1
274                        && *ass && !isspace(*ass) && *ass != '=')
275                *cp++ = *ass++;
276        *cp = '\0';
277        if (!varname[0])
278                return;         /* no variable name! */
279                                        /* trim value */
280        while (isspace(*ass) || *ass == '=')
281                ass++;
282        for (n = strlen(ass); n > 0; n--)
283                if (!isspace(ass[n-1]))
284                        break;
285        if (!n && !nowarn) {
286                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
287                                progname, varname);
288                return;
289        }
290                                        /* match variable from list */
291        vp = matchvar(varname);
292        if (vp == NULL) {
293                fprintf(stderr, "%s: unknown variable '%s'\n",
294                                progname, varname);
295                exit(1);
296        }
297                                        /* assign new value */
298        if (i = vp->nass) {
299                cp = vp->value;
300                while (i--)
301                        while (*cp++)
302                                ;
303                i = cp - vp->value;
304                vp->value = realloc(vp->value, i+n+1);
305        } else
306                vp->value = malloc(n+1);
307        if (vp->value == NULL)
308                syserr(progname);
309        cp = vp->value+i;               /* copy value, squeezing spaces */
310        *cp = *ass;
311        for (i = 1; i <= n; i++) {
312                if (ass[i] == NOCHAR)
313                        continue;
314                if (isspace(*cp))
315                        while (isspace(ass[i]))
316                                i++;
317                *++cp = ass[i];
318        }
319        if (isspace(*cp))               /* remove trailing space */
320                *cp = '\0';
321        vp->nass++;
322 }
323
324
325 VARIABLE *
326 matchvar(nam)                   /* match a variable by its name */
327 char    *nam;
328 {
329        int     n = strlen(nam);
330        register int    i;
331
332        for (i = 0; i < NVARS; i++)
333                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
334                        return(vv+i);
335        return(NULL);
336 }
337
338
339 char *
340 nvalue(vp, n)                   /* return nth variable value */
341 VARIABLE        *vp;
342 register int    n;
343 {
344        register char   *cp;
345
346        if (vp == NULL | n < 0 | n >= vp->nass)
347                return(NULL);
348        cp = vp->value;
349        while (n--)
350                while (*cp++)
351                        ;
352        return(cp);
353 }
354
355
356 checkvalues()                   /* check assignments */
357 {
358        register int    i;
359
360        for (i = 0; i < NVARS; i++)
361                if (vv[i].fixval != NULL)
362                        (*vv[i].fixval)(vv+i);
363 }
364
365
366 onevalue(vp)                    /* only one assignment for this variable */
367 register VARIABLE       *vp;
368 {
369        if (vp->nass < 2)
370                return;
371        if (!nowarn)
372                fprintf(stderr,
373                "%s: warning - multiple assignment of variable '%s'\n",
374                        progname, vp->name);
375        do
376                vp->value += strlen(vp->value)+1;
377        while (--vp->nass > 1);
378 }
379
380
381 catvalues(vp)                   /* concatenate variable values */
382 register VARIABLE       *vp;
383 {
384        register char   *cp;
385
386        if (vp->nass < 2)
387                return;
388        for (cp = vp->value; vp->nass > 1; vp->nass--) {
389                while (*cp)
390                        cp++;
391                *cp++ = ' ';
392        }
393 }
394
395
396 int
397 badmatch(tv, cv)                /* case insensitive truncated comparison */
398 register char   *tv, *cv;
399 {
400        if (!*tv) return(1);            /* null string cannot match */
401        do
402                if (UPPER(*tv) != *cv++)
403                        return(1);
404        while (*++tv);
405        return(0);              /* OK */
406 }
407
408
409 boolvalue(vp)                   /* check boolean for legal values */
410 register VARIABLE       *vp;
411 {
412        if (!vp->nass) return;
413        onevalue(vp);
414        switch (UPPER(vp->value[0])) {
415        case 'T':
416                if (badmatch(vp->value, "TRUE")) break;
417                return;
418        case 'F':
419                if (badmatch(vp->value, "FALSE")) break;
420                return;
421        }
422        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
423                        progname, vp->name);
424        exit(1);
425 }
426
427
428 qualvalue(vp)                   /* check qualitative var. for legal values */
429 register VARIABLE       *vp;
430 {
431        if (!vp->nass) return;
432        onevalue(vp);
433        switch (UPPER(vp->value[0])) {
434        case 'L':
435                if (badmatch(vp->value, "LOW")) break;
436                return;
437        case 'M':
438                if (badmatch(vp->value, "MEDIUM")) break;
439                return;
440        case 'H':
441                if (badmatch(vp->value, "HIGH")) break;
442                return;
443        }
444        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
445                        progname, vp->name);
446        exit(1);
447 }
448
449
450 intvalue(vp)                    /* check integer variable for legal values */
451 register VARIABLE       *vp;
452 {
453        if (!vp->nass) return;
454        onevalue(vp);
455        if (isint(vp->value)) return;
456        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
457                        progname, vp->name);
458        exit(1);
459 }
460
461
462 fltvalue(vp)                    /* check float variable for legal values */
463 register VARIABLE       *vp;
464 {
465        if (!vp->nass) return;
466        onevalue(vp);
467        if (isflt(vp->value)) return;
468        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
469                        progname, vp->name);
470        exit(1);
471 }
472
473
229   time_t
230   checklast(fnames)                       /* check files and find most recent */
231   register char   *fnames;
232   {
233 <        char    thisfile[MAXPATH];
233 >        char    thisfile[PATH_MAX];
234          time_t  thisdate, lastdate = 0;
480        register char   *cp;
235  
236          if (fnames == NULL)
237                  return(0);
238 <        while (*fnames) {
239 <                while (isspace(*fnames)) fnames++;
240 <                cp = thisfile;
241 <                while (*fnames && !isspace(*fnames))
488 <                        *cp++ = *fnames++;
489 <                *cp = '\0';
238 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
239 >                if (thisfile[0] == '!' ||
240 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
241 >                        continue;
242                  if (!(thisdate = fdate(thisfile)))
243                          syserr(thisfile);
244                  if (thisdate > lastdate)
# Line 501 | Line 253 | newfname(orig, pred)           /* create modified file name */
253   char    *orig;
254   int     pred;
255   {
504        extern char     *rindex();
256          register char   *cp;
257          register int    n;
258          int     suffix;
# Line 531 | Line 282 | checkfiles()                   /* check for existence and modified tim
282                          syserr(progname);
283                  sprintf(vval(OCTREE), "%s.oct", radname);
284                  vdef(OCTREE)++;
285 +        } else if (vval(OCTREE)[0] == '!') {
286 +                fprintf(stderr, "%s: illegal '%s' specification\n",
287 +                                progname, vnam(OCTREE));
288 +                quit(1);
289          }
290          octreedate = fdate(vval(OCTREE));
291          if (vdef(ILLUM)) {              /* illum requires secondary octrees */
# Line 547 | Line 302 | checkfiles()                   /* check for existence and modified tim
302          if (!octreedate & !scenedate & !illumdate) {
303                  fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
304                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
305 <                exit(1);
305 >                quit(1);
306          }
307          matdate = checklast(vval(MATERIAL));
308   }      
# Line 559 | Line 314 | double org[3], *sizp;
314          extern FILE     *popen();
315          static double   oorg[3], osiz = 0.;
316          double  min[3], max[3];
317 <        char    buf[512];
317 >        char    buf[1024];
318          FILE    *fp;
319          register int    i;
320  
321          if (osiz <= FTINY)
322 <                if (noaction && fdate(oct1name) <
322 >                if (!nprocs && fdate(oct1name) <
323                                  (scenedate>illumdate?scenedate:illumdate)) {
324                                                          /* run getbbox */
325                          sprintf(buf, "getbbox -w -h %s",
# Line 577 | Line 332 | double org[3], *sizp;
332                                  fprintf(stderr,
333                          "%s: error reading bounding box from getbbox\n",
334                                                  progname);
335 <                                exit(1);
335 >                                quit(1);
336                          }
337                          for (i = 0; i < 3; i++)
338                                  if (max[i] - min[i] > osiz)
# Line 595 | Line 350 | double org[3], *sizp;
350                                  fprintf(stderr,
351                          "%s: error reading bounding cube from getinfo\n",
352                                                  progname);
353 <                                exit(1);
353 >                                quit(1);
354                          }
355                          pclose(fp);
356                  }
# Line 605 | Line 360 | double org[3], *sizp;
360  
361   setdefaults()                   /* set default values for unassigned var's */
362   {
363 <        double  org[3], size;
363 >        double  org[3], lim[3], size;
364          char    buf[128];
365  
366          if (!vdef(ZONE)) {
# Line 615 | Line 370 | setdefaults()                  /* set default values for unassigned v
370                  vval(ZONE) = savqstr(buf);
371                  vdef(ZONE)++;
372          }
373 +        if (!vdef(EYESEP)) {
374 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
375 +                                &org[0], &lim[0], &org[1], &lim[1],
376 +                                &org[2], &lim[2]) != 6)
377 +                        badvalue(ZONE);
378 +                sprintf(buf, "%f",
379 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
380 +                vval(EYESEP) = savqstr(buf);
381 +                vdef(EYESEP)++;
382 +        }
383          if (!vdef(INDIRECT)) {
384                  vval(INDIRECT) = "0";
385                  vdef(INDIRECT)++;
# Line 631 | Line 396 | setdefaults()                  /* set default values for unassigned v
396                  vval(PICTURE) = radname;
397                  vdef(PICTURE)++;
398          }
399 <        if (!vdef(VIEW)) {
400 <                vval(VIEW) = "X";
401 <                vdef(VIEW)++;
399 >        if (!vdef(VIEWS)) {
400 >                vval(VIEWS) = "X";
401 >                vdef(VIEWS)++;
402          }
403          if (!vdef(DETAIL)) {
404                  vval(DETAIL) = "M";
# Line 650 | Line 415 | setdefaults()                  /* set default values for unassigned v
415   }
416  
417  
653 printvals()                     /* print variable values */
654 {
655        int     i, j, clipline;
656        register char   *cp;
657        register int    k;
658
659        for (i = 0; i < NVARS; i++)             /* print each variable */
660            for (j = 0; j < vdef(i); j++) {     /* print each assignment */
661                fputs(vnam(i), stdout);
662                fputs("= ", stdout);
663                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
664                                - strlen(vnam(i)) ;
665                cp = nvalue(vv+i, j);
666                while (*cp) {
667                    putchar(*cp++);
668                    if (--k <= 0) {             /* line too long */
669                        while (*cp && !isspace(*cp))
670                            putchar(*cp++);     /* finish this word */
671                        if (*cp) {              /* start new line */
672                            putchar('\n');
673                            fputs(vnam(i), stdout);
674                            putchar('=');
675                            k = clipline;
676                        }
677                    }
678                }
679                putchar('\n');
680            }
681        fflush(stdout);
682 }
683
684
418   oconv()                         /* run oconv and mkillum if necessary */
419   {
420          static char     illumtmp[] = "ilXXXXXX";
421 <        char    combuf[512], ocopts[64], mkopts[64];
421 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
422  
423          oconvopts(ocopts);              /* get options */
424          if (octreedate < scenedate) {   /* check date on original octree */
# Line 705 | Line 438 | oconv()                                /* run oconv and mkillum if necessary */
438                                  "%s: error generating octree\n\t%s removed\n",
439                                                  progname, vval(OCTREE));
440                                  unlink(vval(OCTREE));
441 <                                exit(1);
441 >                                quit(1);
442                          }
443                  }
444                  octreedate = time((time_t *)NULL);
# Line 736 | Line 469 | oconv()                                /* run oconv and mkillum if necessary */
469                                  "%s: error generating octree\n\t%s removed\n",
470                                                  progname, oct0name);
471                                  unlink(oct0name);
472 <                                exit(1);
472 >                                quit(1);
473                          }
474                  }
475                  oct0date = time((time_t *)NULL);
# Line 756 | Line 489 | oconv()                                /* run oconv and mkillum if necessary */
489                          fprintf(stderr, "%s: error running mkillum\n",
490                                          progname);
491                          unlink(illumtmp);
492 <                        exit(1);
492 >                        quit(1);
493                  }
494                                                  /* make octree1 (frozen) */
495                  if (octreedate)
# Line 773 | Line 506 | oconv()                                /* run oconv and mkillum if necessary */
506                                  "%s: error generating octree\n\t%s removed\n",
507                                          progname, oct1name);
508                          unlink(oct1name);
509 <                        exit(1);
509 >                        unlink(illumtmp);
510 >                        quit(1);
511                  }
512                  rmfile(illumtmp);
513          }
# Line 837 | Line 571 | ambval()                               /* compute ambient value */
571   {
572          if (vdef(EXPOSURE)) {
573                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
574 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
575 <                return(.5/atof(vval(EXPOSURE)));
574 >                        return(.5/pow(2.,vflt(EXPOSURE)));
575 >                return(.5/vflt(EXPOSURE));
576          }
577          if (vlet(ZONE) == 'E')
578                  return(10.);
# Line 937 | Line 671 | medqopts(op, po)                       /* medium quality rendering options
671   register char   *op;
672   char    *po;
673   {
674 <        double  d, org[3], siz[3];
674 >        double  d, org[3], siz[3], asz;
675  
676          *op = '\0';
677          *po = '\0';
# Line 948 | Line 682 | char   *po;
682          if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
683                  badvalue(ZONE);
684          getoctcube(org, &d);
685 <        d *= 3./(siz[0]+siz[1]+siz[2]);
685 >        asz = (siz[0]+siz[1]+siz[2])/3.;
686 >        d /= asz;
687          switch (vscale(DETAIL)) {
688          case LOW:
689                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
690                  op = addarg(op, "-dp 256");
691                  sprintf(op, " -ar %d", (int)(8*d));
692                  op += strlen(op);
693 +                sprintf(op, " -ms %.2g", asz/20.);
694 +                op += strlen(op);
695                  break;
696          case MEDIUM:
697                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
698                  op = addarg(op, "-dp 512");
699                  sprintf(op, " -ar %d", (int)(16*d));
700                  op += strlen(op);
701 +                sprintf(op, " -ms %.2g", asz/40.);
702 +                op += strlen(op);
703                  break;
704          case HIGH:
705                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
706                  op = addarg(op, "-dp 1024");
707                  sprintf(op, " -ar %d", (int)(32*d));
708                  op += strlen(op);
709 +                sprintf(op, " -ms %.2g", asz/80.);
710 +                op += strlen(op);
711                  break;
712          }
713          po = addarg(po, "-pt .08");
# Line 1008 | Line 749 | hiqopts(op, po)                                /* high quality rendering options *
749   register char   *op;
750   char    *po;
751   {
752 <        double  d, org[3], siz[3];
752 >        double  d, org[3], siz[3], asz;
753  
754          *op = '\0';
755          *po = '\0';
# Line 1019 | Line 760 | char   *po;
760          if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
761                  badvalue(ZONE);
762          getoctcube(org, &d);
763 <        d *= 3./(siz[0]+siz[1]+siz[2]);
763 >        asz = (siz[0]+siz[1]+siz[2])/3.;
764 >        d /= asz;
765          switch (vscale(DETAIL)) {
766          case LOW:
767                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
768                  op = addarg(op, "-dp 1024");
769                  sprintf(op, " -ar %d", (int)(16*d));
770                  op += strlen(op);
771 +                sprintf(op, " -ms %.2g", asz/40.);
772 +                op += strlen(op);
773                  break;
774          case MEDIUM:
775                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
776                  op = addarg(op, "-dp 2048");
777                  sprintf(op, " -ar %d", (int)(32*d));
778                  op += strlen(op);
779 +                sprintf(op, " -ms %.2g", asz/80.);
780 +                op += strlen(op);
781                  break;
782          case HIGH:
783                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
784                  op = addarg(op, "-dp 4096");
785                  sprintf(op, " -ar %d", (int)(64*d));
786                  op += strlen(op);
787 +                sprintf(op, " -ms %.2g", asz/160.);
788 +                op += strlen(op);
789                  break;
790          }
791          po = addarg(po, "-pt .04");
792          if (vbool(PENUMBRAS))
793 <                op = addarg(op, "-ds .1 -dj .7");
793 >                op = addarg(op, "-ds .1 -dj .65");
794          else
795                  op = addarg(op, "-ds .2");
796          op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
# Line 1084 | Line 832 | char   *ro;
832                  return;
833          if (vdef(OPTFILE)) {
834                  for (cp = ro; cp[1]; cp++)
835 <                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
835 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
836 >                                        (cp[2] == '-' && isalpha(cp[3]))))
837                                  *cp = '\n';
838                          else
839                                  *cp = cp[1];
# Line 1094 | Line 843 | char   *ro;
843                          syserr(vval(OPTFILE));
844                  sprintf(ro, " @%s", vval(OPTFILE));
845          }
846 < #ifdef MSDOS
846 > #ifdef _WIN32
847          else if (n > 50) {
848                  setenv("ROPT", ro+1);
849                  strcpy(ro, " $ROPT");
# Line 1113 | Line 862 | register char  *po;
862          }
863          switch (vscale(QUALITY)) {
864          case MEDIUM:
865 <                po = addarg(po, "-r 1");
865 >                po = addarg(po, "-r .6");
866                  break;
867          case HIGH:
868                  po = addarg(po, "-m .25");
# Line 1179 | Line 928 | register char  *vs;
928                  zpos = -1; vs++;
929          }
930          viewtype = 'v';
931 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
931 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
932                  viewtype = *vs++;
933          cp = viewopts;
934          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 1234 | Line 983 | register char  *vs;
983                  case 'h':
984                          cp = addarg(cp, "-vh 180 -vv 180");
985                          break;
986 +                case 'c':
987 +                        cp = addarg(cp, "-vh 180 -vv 90");
988 +                        break;
989                  }
990          } else {
991                  while (!isspace(*vs))           /* else skip id */
# Line 1247 | Line 999 | register char  *vs;
999          if (cp == viewopts)             /* append any additional options */
1000                  vs++;           /* skip prefixed space if unneeded */
1001          strcpy(cp, vs);
1002 < #ifdef MSDOS
1002 > #ifdef _WIN32
1003          if (strlen(viewopts) > 40) {
1004                  setenv("VIEW", viewopts);
1005                  return("$VIEW");
# Line 1279 | Line 1031 | char   *vn;            /* returned view name */
1031                  }
1032                                                  /* view number? */
1033                  if (isint(viewselect))
1034 <                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1034 >                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1035                                                  /* check list */
1036 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1036 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1037                          if (matchword(viewselect, mv))
1038                                  return(specview(mv));
1039                  return(specview(viewselect));   /* standard view? */
1040          }
1041 <        mv = nvalue(vv+VIEW, n);                /* use view n */
1041 >        mv = nvalue(VIEWS, n);          /* use view n */
1042          if (vn != NULL & mv != NULL) {
1043                  register char   *mv2 = mv;
1044                  if (*mv2 != '-')
# Line 1298 | Line 1050 | char   *vn;            /* returned view name */
1050   }
1051  
1052  
1053 < printview(vopts)                        /* print out selected view */
1053 > int
1054 > myprintview(vopts, fp)                  /* print out selected view */
1055   register char   *vopts;
1056 + FILE    *fp;
1057   {
1058 <        extern char     *atos(), *getenv();
1059 <        char    buf[256];
1306 <        FILE    *fp;
1058 >        VIEW    vwr;
1059 >        char    buf[128];
1060          register char   *cp;
1061 <
1061 > again:
1062          if (vopts == NULL)
1063                  return(-1);
1064 <        fputs("VIEW=", stdout);
1065 <        do {
1066 <                if (matchword(vopts, "-vf")) {          /* expand view file */
1067 <                        vopts = sskip(vopts);
1068 <                        if (!*atos(buf, sizeof(buf), vopts))
1316 <                                return(-1);
1317 <                        if ((fp = fopen(buf, "r")) == NULL)
1318 <                                return(-1);
1319 <                        for (buf[sizeof(buf)-2] = '\n';
1320 <                                        fgets(buf, sizeof(buf), fp) != NULL &&
1321 <                                                buf[0] != '\n';
1322 <                                        buf[sizeof(buf)-2] = '\n') {
1323 <                                if (buf[sizeof(buf)-2] != '\n') {
1324 <                                        ungetc(buf[sizeof(buf)-2], fp);
1325 <                                        buf[sizeof(buf)-2] = '\0';
1326 <                                }
1327 <                                if (matchword(buf, "VIEW=") ||
1328 <                                                matchword(buf, "rview")) {
1329 <                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1330 <                                                putchar(*cp);
1331 <                                }
1332 <                        }
1333 <                        fclose(fp);
1334 <                        vopts = sskip(vopts);
1335 <                } else {
1336 <                        while (isspace(*vopts))
1337 <                                vopts++;
1338 <                        putchar(' ');
1339 < #ifdef MSDOS
1340 <                        if (*vopts == '$') {            /* expand env. var. */
1341 <                                if (!*atos(buf, sizeof(buf), vopts+1))
1342 <                                        return(-1);
1343 <                                if ((cp = getenv(buf)) == NULL)
1344 <                                        return(-1);
1345 <                                fputs(cp, stdout);
1346 <                                vopts = sskip(vopts);
1347 <                        } else
1064 > #ifdef _WIN32
1065 >        if (vopts[0] == '$') {
1066 >                vopts = getenv(vopts+1);
1067 >                goto again;
1068 >        }
1069   #endif
1070 <                                while (*vopts && !isspace(*vopts))
1071 <                                        putchar(*vopts++);
1072 <                }
1073 <        } while (*vopts++);
1074 <        putchar('\n');
1070 >        copystruct(&vwr, &stdview);
1071 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1072 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1073 >                        *atos(buf, sizeof(buf), cp += 4)) {
1074 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1075 >                sscanview(&vwr, cp);            /* reset tail */
1076 >        }
1077 >        fputs(VIEWSTR, fp);
1078 >        fprintview(&vwr, fp);                   /* print full spec. */
1079 >        fputc('\n', fp);
1080          return(0);
1081   }
1082  
# Line 1359 | Line 1085 | rview(opts, po)                                /* run rview with first view */
1085   char    *opts, *po;
1086   {
1087          char    *vw;
1088 <        char    combuf[512];
1088 >        char    combuf[PATH_MAX];
1089                                          /* build command */
1090          if (touchonly || (vw = getview(0, NULL)) == NULL)
1091                  return;
1092          if (sayview)
1093 <                printview(vw);
1093 >                myprintview(vw, stdout);
1094          sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1095          if (rvdevice != NULL)
1096                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
# Line 1373 | Line 1099 | char   *opts, *po;
1099          strcat(combuf, oct1name);
1100          if (runcom(combuf)) {           /* run it */
1101                  fprintf(stderr, "%s: error running rview\n", progname);
1102 <                exit(1);
1102 >                quit(1);
1103          }
1104   }
1105  
# Line 1381 | Line 1107 | char   *opts, *po;
1107   rpict(opts, po)                         /* run rpict and pfilt for each view */
1108   char    *opts, *po;
1109   {
1110 <        char    combuf[1024];
1111 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1110 >        char    combuf[PATH_MAX];
1111 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1112 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1113 >        char    rppopt[128], *pfile = NULL;
1114          char    pfopts[128];
1115          char    vs[32], *vw;
1116          int     vn, mult;
1117 +        FILE    *fp;
1118          time_t  rfdt, pfdt;
1119                                          /* get pfilt options */
1120          pfiltopts(pfopts);
# Line 1427 | Line 1156 | char   *opts, *po;
1156                  else
1157                          badvalue(REPORT);
1158          }
1159 <                                        /* do each view */
1160 <        vn = 0;
1159 >                                        /* set up parallel rendering */
1160 >        if (nprocs > 1 & !vdef(ZFILE)) {
1161 >                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1162 >                pfile = rppopt+9;
1163 >                if (mktemp(pfile) == NULL)
1164 >                        pfile = NULL;
1165 >        }
1166 >        vn = 0;                                 /* do each view */
1167          while ((vw = getview(vn++, vs)) != NULL) {
1168                  if (sayview)
1169 <                        printview(vw);
1169 >                        myprintview(vw, stdout);
1170                  if (!vs[0])
1171                          sprintf(vs, "%d", vn);
1172                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1173 +                if (vdef(ZFILE))
1174 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1175 +                else
1176 +                        zopt[0] = '\0';
1177                                                  /* check date on picture */
1178                  pfdt = fdate(picfile);
1179                  if (pfdt >= oct1date)
1180                          continue;
1181                                                  /* get raw file name */
1182 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1182 >                sprintf(rawfile, "%s_%s.unf",
1183 >                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1184                  rfdt = fdate(rawfile);
1185                  if (touchonly) {                /* update times only */
1186                          if (rfdt) {
# Line 1450 | Line 1190 | char   *opts, *po;
1190                                  touch(picfile);
1191                          continue;
1192                  }
1193 +                if (next_process()) {           /* parallel running? */
1194 +                        if (pfile != NULL)
1195 +                                sleep(20);
1196 +                        continue;
1197 +                }
1198 +                /* XXX Remember to call finish_process() */
1199                                                  /* build rpict command */
1200 <                if (rfdt >= oct1date)           /* recover */
1201 <                        sprintf(combuf, "rpict%s%s%s -ro %s %s",
1202 <                                        rep, po, opts, rawfile, oct1name);
1203 <                else {
1200 >                if (rfdt >= oct1date) {         /* recover */
1201 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1202 >                                rep, po, opts, zopt, rawfile, oct1name);
1203 >                        if (runcom(combuf))     /* run rpict */
1204 >                                goto rperror;
1205 >                } else {
1206                          if (overture) {         /* run overture calculation */
1207                                  sprintf(combuf,
1208                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
# Line 1464 | Line 1212 | char   *opts, *po;
1212                                          fprintf(stderr,
1213                                          "%s: error in overture for view %s\n",
1214                                                  progname, vs);
1215 <                                        exit(1);
1215 >                                        quit(1);
1216                                  }
1217 < #ifdef NIX
1217 > #ifndef NULL_DEVICE
1218                                  rmfile(overfile);
1219   #endif
1220                          }
1221 <                        sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1221 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1222                                          rep, vw, res, po, opts,
1223 <                                oct1name, rawfile);
1223 >                                        zopt, oct1name, rawfile);
1224 >                        if (pfile != NULL && inchild()) {
1225 >                                                /* rpict persistent mode */
1226 >                                if (!silent)
1227 >                                        printf("\t%s\n", combuf);
1228 >                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1229 >                                                rep, rppopt, res, po, opts,
1230 >                                                oct1name, rawfile);
1231 >                                fflush(stdout);
1232 >                                fp = popen(combuf, "w");
1233 >                                if (fp == NULL)
1234 >                                        goto rperror;
1235 >                                myprintview(vw, fp);
1236 >                                if (pclose(fp))
1237 >                                        goto rperror;
1238 >                        } else {                /* rpict normal mode */
1239 >                                if (runcom(combuf))
1240 >                                        goto rperror;
1241 >                        }
1242                  }
1243 <                if (runcom(combuf)) {           /* run rpict */
1478 <                        fprintf(stderr, "%s: error rendering view %s\n",
1479 <                                        progname, vs);
1480 <                        exit(1);
1481 <                }
1243 >                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1244                                                  /* build pfilt command */
1245 <                if (mult > 1)
1246 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1245 >                        if (mult > 1)
1246 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1247                                          pfopts, mult, mult, rawfile, picfile);
1248 <                else
1249 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1250 <                                        rawfile, picfile);
1251 <                if (runcom(combuf)) {           /* run pfilt */
1252 <                        fprintf(stderr,
1253 <                        "%s: error filtering view %s\n\t%s removed\n",
1254 <                                        progname, vs, picfile);
1255 <                        unlink(picfile);
1256 <                        exit(1);
1248 >                        else
1249 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1250 >                                                rawfile, picfile);
1251 >                        if (runcom(combuf)) {   /* run pfilt */
1252 >                                fprintf(stderr,
1253 >                                "%s: error filtering view %s\n\t%s removed\n",
1254 >                                                progname, vs, picfile);
1255 >                                unlink(picfile);
1256 >                                quit(1);
1257 >                        }
1258                  }
1259 <                                                /* remove raw file */
1260 <                rmfile(rawfile);
1259 >                                                /* remove/rename raw file */
1260 >                if (vdef(RAWFILE)) {
1261 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1262 >                        mvfile(rawfile, combuf);
1263 >                } else
1264 >                        rmfile(rawfile);
1265 >                finish_process();               /* leave if child */
1266          }
1267 +        wait_process(1);                /* wait for children to finish */
1268 +        if (pfile != NULL) {            /* clean up rpict persistent mode */
1269 +                int     pid;
1270 +                fp = fopen(pfile, "r");
1271 +                if (fp != NULL) {
1272 +                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1273 +                                        kill(pid, 1) == -1)
1274 +                                unlink(pfile);
1275 +                        fclose(fp);
1276 +                }
1277 +        }
1278 +        return;
1279 + rperror:
1280 +        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1281 +        quit(1);
1282   }
1283  
1284  
# Line 1504 | Line 1287 | char   *fn;
1287   {
1288          if (!silent)
1289                  printf("\ttouch %s\n", fn);
1290 <        if (noaction)
1290 >        if (!nprocs)
1291                  return(0);
1292   #ifdef notused
1293          if (access(fn, F_OK) == -1)             /* create it */
# Line 1520 | Line 1303 | char   *cs;
1303   {
1304          if (!silent)            /* echo it */
1305                  printf("\t%s\n", cs);
1306 <        if (noaction)
1306 >        if (!nprocs)
1307                  return(0);
1308          fflush(stdout);         /* flush output and pass to shell */
1309          return(system(cs));
# Line 1531 | Line 1314 | rmfile(fn)                     /* remove a file */
1314   char    *fn;
1315   {
1316          if (!silent)
1317 < #ifdef MSDOS
1318 <                printf("\tdel %s\n", fn);
1536 < #else
1537 <                printf("\trm -f %s\n", fn);
1538 < #endif
1539 <        if (noaction)
1317 >                printf("\t%s %s\n", DELCMD, fn);
1318 >        if (!nprocs)
1319                  return(0);
1320          return(unlink(fn));
1321   }
1322  
1323  
1324 < #ifdef MSDOS
1324 > mvfile(fold, fnew)              /* move a file */
1325 > char    *fold, *fnew;
1326 > {
1327 >        if (!silent)
1328 >                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1329 >        if (!nprocs)
1330 >                return(0);
1331 >        return(rename(fold, fnew));
1332 > }
1333 >
1334 >
1335 > #ifdef RHAS_FORK_EXEC
1336 > int
1337 > next_process()                  /* fork the next process (max. nprocs) */
1338 > {
1339 >        int     child_pid;
1340 >
1341 >        if (nprocs <= 1)
1342 >                return(0);              /* it's us or no one */
1343 >        if (inchild()) {
1344 >                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1345 >                                progname);
1346 >                quit(1);
1347 >        }
1348 >        if (children_running >= nprocs)
1349 >                wait_process(0);        /* wait for someone to finish */
1350 >        fflush(stdout);
1351 >        child_pid = fork();             /* split process */
1352 >        if (child_pid == 0) {           /* we're the child */
1353 >                children_running = -1;
1354 >                return(0);
1355 >        }
1356 >        if (child_pid > 0) {            /* we're the parent */
1357 >                ++children_running;
1358 >                return(1);
1359 >        }
1360 >        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1361 >        return(0);
1362 > }
1363 >
1364 > wait_process(all)                       /* wait for process(es) to finish */
1365 > int     all;
1366 > {
1367 >        int     ourstatus = 0;
1368 >        int     pid, status;
1369 >
1370 >        if (all)
1371 >                all = children_running;
1372 >        else if (children_running > 0)
1373 >                all = 1;
1374 >        while (all-- > 0) {
1375 >                pid = wait(&status);
1376 >                if (pid < 0)
1377 >                        syserr(progname);
1378 >                status = status>>8 & 0xff;
1379 >                --children_running;
1380 >                if (status != 0) {      /* child's problem is our problem */
1381 >                        if (ourstatus == 0 & children_running > 0)
1382 >                                fprintf(stderr, "%s: waiting for remaining processes\n",
1383 >                                                progname);
1384 >                        ourstatus = status;
1385 >                        all = children_running;
1386 >                }
1387 >        }
1388 >        if (ourstatus != 0)
1389 >                quit(ourstatus);        /* bad status from child */
1390 > }
1391 > #else   /* ! RHAS_FORK_EXEC */
1392 > int
1393 > next_process()
1394 > {
1395 >        return(0);                      /* cannot start new process */
1396 > }
1397 > wait_process(all)
1398 > int     all;
1399 > {
1400 >        (void)all;                      /* no one to wait for */
1401 > }
1402 > int
1403 > kill(pid, sig) /* win|unix_process.c should also wait and kill */
1404 > int pid, sig;
1405 > {
1406 >        return 0;
1407 > }
1408 > #endif  /* ! RHAS_FORK_EXEC */
1409 >
1410 > finish_process()                        /* exit a child process */
1411 > {
1412 >        if (!inchild())
1413 >                return;                 /* in parent -- noop */
1414 >        exit(0);
1415 > }
1416 >
1417 > #ifdef _WIN32
1418   setenv(vname, value)            /* set an environment variable */
1419   char    *vname, *value;
1420   {
# Line 1554 | Line 1426 | char   *vname, *value;
1426          sprintf(evp, "%s=%s", vname, value);
1427          if (putenv(evp) != 0) {
1428                  fprintf(stderr, "%s: out of environment space\n", progname);
1429 <                exit(1);
1429 >                quit(1);
1430          }
1431          if (!silent)
1432                  printf("set %s\n", evp);
# Line 1567 | Line 1439 | int    vc;
1439   {
1440          fprintf(stderr, "%s: bad value for variable '%s'\n",
1441                          progname, vnam(vc));
1442 <        exit(1);
1442 >        quit(1);
1443   }
1444  
1445  
# Line 1575 | Line 1447 | syserr(s)                      /* report a system error and exit */
1447   char    *s;
1448   {
1449          perror(s);
1450 <        exit(1);
1450 >        quit(1);
1451 > }
1452 >
1453 >
1454 > void
1455 > quit(ec)                        /* exit program */
1456 > int     ec;
1457 > {
1458 >        exit(ec);
1459   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines