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.4 by greg, Fri Mar 12 13:37:03 1993 UTC vs.
Revision 2.76 by schorsch, Fri Mar 26 21:36:19 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 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 <time.h>
12  
13 + #include "platform.h"
14 + #include "rtprocess.h"
15 + #include "view.h"
16 + #include "paths.h"
17 + #include "vars.h"
18  
19 < typedef struct {
20 <        char    *name;          /* variable name */
21 <        short   nick;           /* # characters required for nickname */
22 <        short   nass;           /* # assignments made */
23 <        char    *value;         /* assigned value(s) */
24 <        int     (*fixval)();    /* assignment checking function */
25 < } VARIABLE;
19 > #ifdef _WIN32
20 >  #define DELCMD "del"
21 >  #define RENAMECMD "rename"
22 > #else
23 >  #define DELCMD "rm -f"
24 >  #define RENAMECMD "mv"
25 >  #include <sys/types.h>
26 >  #include <sys/wait.h>
27 > #endif
28  
29 < int     onevalue(), catvalues();
30 <
31 <                                /* variables */
32 < #define OBJECT          0               /* object files */
33 < #define SCENE           1               /* scene files */
34 < #define MATERIAL        2               /* material files */
35 < #define RENDER          3               /* rendering options */
36 < #define OCONV           4               /* oconv options */
37 < #define PFILT           5               /* pfilt options */
38 < #define VIEW            6               /* view(s) for picture(s) */
39 < #define ZONE            7               /* simulation zone */
40 < #define QUALITY         8               /* desired rendering quality */
41 < #define OCTREE          9               /* octree file name */
42 < #define PICTURE         10              /* picture file name */
43 < #define AMBFILE         11              /* ambient file name */
44 < #define OPTFILE         12              /* rendering options file */
45 < #define EXPOSURE        13              /* picture exposure setting */
46 < #define RESOLUTION      14              /* maximum picture resolution */
47 < #define UP              15              /* view up (X, Y or Z) */
48 < #define INDIRECT        16              /* indirection in lighting */
49 < #define DETAIL          17              /* level of scene detail */
50 < #define PENUMBRAS       18              /* shadow penumbras are desired */
51 < #define VARIABILITY     19              /* level of light variability */
52 < #define REPORT          20              /* report frequency and errfile */
29 >                                /* variables (alphabetical by name) */
30 > #define AMBFILE         0               /* ambient file name */
31 > #define DETAIL          1               /* level of scene detail */
32 > #define EXPOSURE        2               /* picture exposure setting */
33 > #define EYESEP          3               /* interocular distance */
34 > #define ILLUM           4               /* mkillum input files */
35 > #define INDIRECT        5               /* indirection in lighting */
36 > #define MATERIAL        6               /* material files */
37 > #define MKILLUM         7               /* mkillum options */
38 > #define OBJECT          8               /* object files */
39 > #define OCONV           9               /* oconv options */
40 > #define OCTREE          10              /* octree file name */
41 > #define OPTFILE         11              /* rendering options file */
42 > #define PENUMBRAS       12              /* shadow penumbras are desired */
43 > #define PFILT           13              /* pfilt options */
44 > #define PICTURE         14              /* picture file root name */
45 > #define QUALITY         15              /* desired rendering quality */
46 > #define RAWFILE         16              /* raw picture file root name */
47 > #define RENDER          17              /* rendering options */
48 > #define REPORT          18              /* report frequency and errfile */
49 > #define RESOLUTION      19              /* maximum picture resolution */
50 > #define SCENE           20              /* scene files */
51 > #define UP              21              /* view up (X, Y or Z) */
52 > #define VARIABILITY     22              /* level of light variability */
53 > #define VIEWS           23              /* view(s) for picture(s) */
54 > #define ZFILE           24              /* distance file root name */
55 > #define ZONE            25              /* simulation zone */
56                                  /* total number of variables */
57 < #define NVARS           21
57 > int NVARS = 26;
58  
59 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
60 <        {"objects",     3,      0,      NULL,   catvalues},
61 <        {"scene",       3,      0,      NULL,   catvalues},
59 > VARIABLE        vv[] = {                /* variable-value pairs */
60 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
61 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
62 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
63 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
64 >        {"illum",       3,      0,      NULL,   catvalues},
65 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
66          {"materials",   3,      0,      NULL,   catvalues},
67 <        {"render",      3,      0,      NULL,   catvalues},
67 >        {"mkillum",     3,      0,      NULL,   catvalues},
68 >        {"objects",     3,      0,      NULL,   catvalues},
69          {"oconv",       3,      0,      NULL,   catvalues},
57        {"pfilt",       2,      0,      NULL,   catvalues},
58        {"view",        2,      0,      NULL,   NULL},
59        {"ZONE",        2,      0,      NULL,   onevalue},
60        {"QUALITY",     3,      0,      NULL,   onevalue},
70          {"OCTREE",      3,      0,      NULL,   onevalue},
62        {"PICTURE",     3,      0,      NULL,   onevalue},
63        {"AMBFILE",     3,      0,      NULL,   onevalue},
71          {"OPTFILE",     3,      0,      NULL,   onevalue},
72 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
72 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
73 >        {"pfilt",       2,      0,      NULL,   catvalues},
74 >        {"PICTURE",     3,      0,      NULL,   onevalue},
75 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
76 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
77 >        {"render",      3,      0,      NULL,   catvalues},
78 >        {"REPORT",      3,      0,      NULL,   onevalue},
79          {"RESOLUTION",  3,      0,      NULL,   onevalue},
80 +        {"scene",       3,      0,      NULL,   catvalues},
81          {"UP",          2,      0,      NULL,   onevalue},
82 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
83 <        {"DETAIL",      3,      0,      NULL,   onevalue},
84 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
85 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
72 <        {"REPORT",      3,      0,      NULL,   onevalue},
82 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
83 >        {"view",        2,      0,      NULL,   NULL},
84 >        {"ZFILE",       2,      0,      NULL,   onevalue},
85 >        {"ZONE",        2,      0,      NULL,   onevalue},
86   };
87  
88 < VARIABLE        *matchvar();
89 < char    *nvalue();
90 < int     vscale();
88 >                                /* overture calculation file */
89 > #ifdef NULL_DEVICE
90 > char    overfile[] = NULL_DEVICE;
91 > #else
92 > char    overfile[] = "overture.unf";
93 > #endif
94  
79 #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
95  
96 < #define vnam(vc)        (vv[vc].name)
97 < #define vdef(vc)        (vv[vc].nass)
98 < #define vval(vc)        (vv[vc].value)
99 < #define vint(vc)        atoi(vval(vc))
85 < #define vlet(vc)        UPPER(vval(vc)[0])
86 < #define vbool(vc)       (vlet(vc)=='T')
96 > time_t  scenedate;              /* date of latest scene or object file */
97 > time_t  octreedate;             /* date of octree */
98 > time_t  matdate;                /* date of latest material file */
99 > time_t  illumdate;              /* date of last illum file */
100  
101 < #define HIGH            2
102 < #define MEDIUM          1
103 < #define LOW             0
101 > char    *oct0name;              /* name of pre-mkillum octree */
102 > time_t  oct0date;               /* date of pre-mkillum octree */
103 > char    *oct1name;              /* name of post-mkillum octree */
104 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
105  
106 < int     lowqopts(), medqopts(), hiqopts();
93 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94 <
95 < #define renderopts      (*setqopts[vscale(QUALITY)])
96 <
97 < extern long     fdate(), time();
98 <
99 < long    scenedate;              /* date of latest scene or object file */
100 < long    octreedate;             /* date of octree */
101 <
106 > int     nowarn = 0;             /* no warnings */
107   int     explicate = 0;          /* explicate variables */
108   int     silent = 0;             /* do work silently */
109 < int     noaction = 0;           /* don't do anything */
110 < char    *rvdevice = NULL;       /* rview output device */
109 > int     touchonly = 0;          /* touch files only */
110 > int     nprocs = 1;             /* maximum executing processes */
111 > int     sayview = 0;            /* print view out */
112 > char    *rvdevice = NULL;       /* rvu output device */
113   char    *viewselect = NULL;     /* specific view only */
114  
115   int     overture = 0;           /* overture calculation needed */
116  
117 + int     children_running = 0;   /* set negative in children */
118 +
119   char    *progname;              /* global argv[0] */
120 + char    *rifname;               /* global rad input file name */
121  
122 < char    radname[MAXPATH];       /* root Radiance file name */
122 > char    radname[PATH_MAX];      /* root Radiance file name */
123  
124 + #define inchild()       (children_running < 0)
125  
126 < main(argc, argv)
127 < int     argc;
128 < char    *argv[];
126 > static void rootname(char       *rn, char       *fn);
127 > static time_t checklast(char    *fnames);
128 > static char * newfname(char     *orig, int      pred);
129 > static void checkfiles(void);
130 > static void getoctcube(double   org[3], double  *sizp);
131 > static void setdefaults(void);
132 > static void oconv(void);
133 > static char * addarg(char       *op, char       *arg);
134 > static void oconvopts(char      *oo);
135 > static void mkillumopts(char    *mo);
136 > static void checkambfile(void);
137 > static double ambval(void);
138 > static void renderopts(char     *op, char       *po);
139 > static void lowqopts(char       *op, char       *po);
140 > static void medqopts(char       *op, char       *po);
141 > static void hiqopts(char        *op, char       *po);
142 > static void xferopts(char       *ro);
143 > static void pfiltopts(char      *po);
144 > static int matchword(char       *s1, char       *s2);
145 > static char * specview(char     *vs);
146 > static char * getview(int       n, char *vn);
147 > static int myprintview(char     *vopts, FILE    *fp);
148 > static void rvu(char    *opts, char     *po);
149 > static void rpict(char  *opts, char     *po);
150 > static int touch(char   *fn);
151 > static int runcom(char  *cs);
152 > static int rmfile(char  *fn);
153 > static int mvfile(char  *fold, char     *fnew);
154 > static int next_process(void);
155 > static void wait_process(int    all);
156 > static void finish_process(void);
157 > static void badvalue(int        vc);
158 > static void syserr(char *s);
159 >
160 >
161 > int
162 > main(
163 >        int     argc,
164 >        char    *argv[]
165 > )
166   {
167          char    ropts[512];
168 +        char    popts[64];
169          int     i;
170  
171          progname = argv[0];
# Line 127 | Line 176 | char   *argv[];
176                          silent++;
177                          break;
178                  case 'n':
179 <                        noaction++;
179 >                        nprocs = 0;
180                          break;
181 +                case 'N':
182 +                        nprocs = atoi(argv[++i]);
183 +                        if (nprocs < 0)
184 +                                nprocs = 0;
185 +                        break;
186 +                case 't':
187 +                        touchonly++;
188 +                        break;
189                  case 'e':
190                          explicate++;
191                          break;
192                  case 'o':
193                          rvdevice = argv[++i];
194                          break;
195 +                case 'V':
196 +                        sayview++;
197 +                        break;
198                  case 'v':
199                          viewselect = argv[++i];
200                          break;
201 +                case 'w':
202 +                        nowarn++;
203 +                        break;
204                  default:
205                          goto userr;
206                  }
207          if (i >= argc)
208                  goto userr;
209 +        rifname = argv[i];
210 +                                /* check command-line options */
211 +        if ((nprocs > 1) & (viewselect != NULL))
212 +                nprocs = 1;
213                                  /* assign Radiance root file name */
214 <        rootname(radname, argv[i]);
214 >        rootname(radname, rifname);
215                                  /* load variable values */
216 <        load(argv[i]);
216 >        loadvars(rifname);
217                                  /* get any additional assignments */
218          for (i++; i < argc; i++)
219 <                setvariable(argv[i]);
219 >                if (setvariable(argv[i], matchvar) < 0) {
220 >                        fprintf(stderr, "%s: unknown variable: %s\n",
221 >                                        progname, argv[i]);
222 >                        quit(1);
223 >                }
224                                  /* check assignments */
225          checkvalues();
226                                  /* check files and dates */
# Line 158 | Line 229 | char   *argv[];
229          setdefaults();
230                                  /* print all values if requested */
231          if (explicate)
232 <                printvals();
233 <                                /* run simulation */
232 >                printvars(stdout);
233 >                                /* build octree (and run mkillum) */
234          oconv();
235 <        renderopts(ropts);
235 >                                /* check date on ambient file */
236 >        checkambfile();
237 >                                /* run simulation */
238 >        renderopts(ropts, popts);
239          xferopts(ropts);
240          if (rvdevice != NULL)
241 <                rview(ropts);
241 >                rvu(ropts, popts);
242          else
243 <                rpict(ropts);
244 <        exit(0);
243 >                rpict(ropts, popts);
244 >        quit(0);
245   userr:
246          fprintf(stderr,
247 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
247 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
248                          progname);
249 <        exit(1);
249 >        quit(1);
250 >        return 1; /* pro forma return */
251   }
252  
253  
254 < rootname(rn, fn)                /* remove tail from end of fn */
255 < register char   *rn, *fn;
254 > static void
255 > rootname(               /* remove tail from end of fn */
256 >        register char   *rn,
257 >        register char   *fn
258 > )
259   {
260          char    *tp, *dp;
261  
262 <        for (tp = NULL, dp = rn; *rn = *fn++; rn++)
262 >        for (tp = NULL, dp = rn; (*rn = *fn++); rn++)
263                  if (ISDIRSEP(*rn))
264                          dp = rn;
265                  else if (*rn == '.')
# Line 191 | Line 269 | register char  *rn, *fn;
269   }
270  
271  
272 < load(rfname)                    /* load Radiance simulation file */
273 < char    *rfname;
272 > static time_t
273 > checklast(                      /* check files and find most recent */
274 >        register char   *fnames
275 > )
276   {
277 <        FILE    *fp;
278 <        char    buf[512];
199 <        register char   *cp;
277 >        char    thisfile[PATH_MAX];
278 >        time_t  thisdate, lastdate = 0;
279  
280 <        if (rfname == NULL)
281 <                fp = stdin;
282 <        else if ((fp = fopen(rfname, "r")) == NULL)
283 <                syserr(rfname);
284 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
285 <                for (cp = buf; *cp; cp++) {
286 <                        switch (*cp) {
287 <                        case '\\':
288 <                        case '\n':
289 <                                *cp = ' ';
211 <                                continue;
212 <                        case '#':
213 <                                *cp = '\0';
214 <                                break;
215 <                        default:
216 <                                continue;
217 <                        }
218 <                        break;
219 <                }
220 <                setvariable(buf);
280 >        if (fnames == NULL)
281 >                return(0);
282 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
283 >                if (thisfile[0] == '!' ||
284 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
285 >                        continue;
286 >                if (!(thisdate = fdate(thisfile)))
287 >                        syserr(thisfile);
288 >                if (thisdate > lastdate)
289 >                        lastdate = thisdate;
290          }
291 <        fclose(fp);
291 >        return(lastdate);
292   }
293  
294  
295 < setvariable(ass)                /* assign variable according to string */
296 < register char   *ass;
295 > static char *
296 > newfname(               /* create modified file name */
297 >        char    *orig,
298 >        int     pred
299 > )
300   {
229        char    varname[32];
301          register char   *cp;
302 <        register VARIABLE       *vp;
303 <        register int    i;
233 <        int     n;
302 >        register int    n;
303 >        int     suffix;
304  
305 <        while (isspace(*ass))           /* skip leading space */
306 <                ass++;
307 <        cp = varname;                   /* extract name */
308 <        while (cp < varname+sizeof(varname)-1
309 <                        && *ass && !isspace(*ass) && *ass != '=')
240 <                *cp++ = *ass++;
241 <        *cp = '\0';
242 <        if (!varname[0])
243 <                return;         /* no variable name! */
244 <                                        /* trim value */
245 <        while (isspace(*ass) || *ass == '=')
246 <                ass++;
247 <        cp = ass + strlen(ass);
248 <        do
249 <                *cp-- = '\0';
250 <        while (cp >= ass && isspace(*cp));
251 <        n = cp - ass + 1;
252 <        if (!n) {
253 <                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
254 <                                progname, varname);
255 <                return;
305 >        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
306 >        while (*cp) {
307 >                if (*cp == '.') suffix = n;
308 >                else if (ISDIRSEP(*cp)) suffix = -1;
309 >                cp++; n++;
310          }
311 <                                        /* match variable from list */
312 <        vp = matchvar(varname);
259 <        if (vp == NULL) {
260 <                fprintf(stderr, "%s: unknown variable '%s'\n",
261 <                                progname, varname);
262 <                exit(1);
263 <        }
264 <                                        /* assign new value */
265 <        if (i = vp->nass) {
266 <                cp = vp->value;
267 <                while (i--)
268 <                        while (*cp++)
269 <                                ;
270 <                i = cp - vp->value;
271 <                vp->value = realloc(vp->value, i+n+1);
272 <        } else
273 <                vp->value = malloc(n+1);
274 <        if (vp->value == NULL)
311 >        if (suffix == -1) suffix = n;
312 >        if ((cp = bmalloc(n+2)) == NULL)
313                  syserr(progname);
314 <        strcpy(vp->value+i, ass);
315 <        vp->nass++;
316 < }
279 <
280 <
281 < VARIABLE *
282 < matchvar(nam)                   /* match a variable by its name */
283 < char    *nam;
284 < {
285 <        int     n = strlen(nam);
286 <        register int    i;
287 <
288 <        for (i = 0; i < NVARS; i++)
289 <                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
290 <                        return(vv+i);
291 <        return(NULL);
292 < }
293 <
294 <
295 < char *
296 < nvalue(vp, n)                   /* return nth variable value */
297 < VARIABLE        *vp;
298 < register int    n;
299 < {
300 <        register char   *cp;
301 <
302 <        if (vp == NULL || n < 0 || n >= vp->nass)
303 <                return(NULL);
304 <        cp = vp->value;
305 <        while (n--)
306 <                while (*cp++)
307 <                        ;
314 >        strncpy(cp, orig, suffix);
315 >        cp[suffix] = pred;                      /* root name + pred + suffix */
316 >        strcpy(cp+suffix+1, orig+suffix);
317          return(cp);
318   }
319  
320  
321 < int
322 < vscale(vc)                      /* return scale for variable vc */
314 < int     vc;
321 > static void
322 > checkfiles(void)                        /* check for existence and modified times */
323   {
324 <        switch(vlet(vc)) {
317 <        case 'H':
318 <                return(HIGH);
319 <        case 'M':
320 <                return(MEDIUM);
321 <        case 'L':
322 <                return(LOW);
323 <        }
324 <        badvalue(vc);
325 < }
324 >        time_t  objdate;
325  
327
328 checkvalues()                   /* check assignments */
329 {
330        register int    i;
331
332        for (i = 0; i < NVARS; i++)
333                if (vv[i].fixval != NULL)
334                        (*vv[i].fixval)(vv+i);
335 }
336
337
338 onevalue(vp)                    /* only one assignment for this variable */
339 register VARIABLE       *vp;
340 {
341        if (vp->nass < 2)
342                return;
343        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
344                        progname, vp->name);
345        do
346                vp->value += strlen(vp->value)+1;
347        while (--vp->nass > 1);
348 }
349
350
351 catvalues(vp)                   /* concatenate variable values */
352 register VARIABLE       *vp;
353 {
354        register char   *cp;
355
356        if (vp->nass < 2)
357                return;
358        for (cp = vp->value; vp->nass > 1; vp->nass--) {
359                while (*cp)
360                        cp++;
361                *cp++ = ' ';
362        }
363 }
364
365
366 long
367 checklast(fnames)                       /* check files and find most recent */
368 register char   *fnames;
369 {
370        char    thisfile[MAXPATH];
371        long    thisdate, lastdate = -1;
372        register char   *cp;
373
374        while (*fnames) {
375                while (isspace(*fnames)) fnames++;
376                cp = thisfile;
377                while (*fnames && !isspace(*fnames))
378                        *cp++ = *fnames++;
379                *cp = '\0';
380                if ((thisdate = fdate(thisfile)) < 0)
381                        syserr(thisfile);
382                if (thisdate > lastdate)
383                        lastdate = thisdate;
384        }
385        return(lastdate);
386 }
387
388
389 checkfiles()                    /* check for existence and modified times */
390 {
391        char    *cp;
392        long    objdate;
393
326          if (!vdef(OCTREE)) {
327 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
327 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
328                          syserr(progname);
329 <                sprintf(cp, "%s.oct", radname);
398 <                vval(OCTREE) = cp;
329 >                sprintf(vval(OCTREE), "%s.oct", radname);
330                  vdef(OCTREE)++;
331 +        } else if (vval(OCTREE)[0] == '!') {
332 +                fprintf(stderr, "%s: illegal '%s' specification\n",
333 +                                progname, vnam(OCTREE));
334 +                quit(1);
335          }
336          octreedate = fdate(vval(OCTREE));
337 <        scenedate = -1;
338 <        if (vdef(SCENE)) {
339 <                scenedate = checklast(vval(SCENE));
340 <                if (vdef(OBJECT)) {
341 <                        objdate = checklast(vval(OBJECT));
342 <                        if (objdate > scenedate)
343 <                                scenedate = objdate;
344 <                }
337 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
338 >                oct0name = newfname(vval(OCTREE), '0');
339 >                oct1name = newfname(vval(OCTREE), '1');
340 >                oct0date = fdate(oct0name);
341 >                oct1date = fdate(oct1name);
342 >        } else
343 >                oct0name = oct1name = vval(OCTREE);
344 >        if ((scenedate = checklast(vval(SCENE))) &&
345 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
346 >                scenedate = objdate;
347 >        illumdate = checklast(vval(ILLUM));
348 >        if (!octreedate & !scenedate & !illumdate) {
349 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
350 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
351 >                quit(1);
352          }
353 <        if (octreedate < 0 & scenedate < 0) {
412 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
413 <                                vnam(OCTREE), vnam(SCENE));
414 <                exit(1);
415 <        }
353 >        matdate = checklast(vval(MATERIAL));
354   }      
355  
356  
357 < getoctcube(org, sizp)           /* get octree bounding cube */
358 < double  org[3], *sizp;
357 > static void
358 > getoctcube(             /* get octree bounding cube */
359 >        double  org[3],
360 >        double  *sizp
361 > )
362   {
422        extern FILE     *popen();
363          static double   oorg[3], osiz = 0.;
364 <        char    buf[MAXPATH+16];
364 >        double  min[3], max[3];
365 >        char    buf[1024];
366          FILE    *fp;
367 +        register int    i;
368  
369          if (osiz <= FTINY) {
370 <                oconv();                /* does nothing if done already */
371 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
372 <                if ((fp = popen(buf, "r")) == NULL)
373 <                        syserr("getinfo");
374 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
375 <                                &oorg[2], &osiz) != 4) {
376 <                        fprintf(stderr,
370 >                if (!nprocs && fdate(oct1name) <
371 >                                (scenedate>illumdate?scenedate:illumdate)) {
372 >                                                        /* run getbbox */
373 >                        sprintf(buf, "getbbox -w -h %s",
374 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
375 >                        if ((fp = popen(buf, "r")) == NULL)
376 >                                syserr("getbbox");
377 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
378 >                                        &min[0], &max[0], &min[1], &max[1],
379 >                                        &min[2], &max[2]) != 6) {
380 >                                fprintf(stderr,
381 >                        "%s: error reading bounding box from getbbox\n",
382 >                                                progname);
383 >                                quit(1);
384 >                        }
385 >                        for (i = 0; i < 3; i++)
386 >                                if (max[i] - min[i] > osiz)
387 >                                        osiz = max[i] - min[i];
388 >                        for (i = 0; i < 3; i++)
389 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
390 >                        pclose(fp);
391 >                } else {                                /* from octree */
392 >                        oconv();        /* does nothing if done already */
393 >                        sprintf(buf, "getinfo -d < %s", oct1name);
394 >                        if ((fp = popen(buf, "r")) == NULL)
395 >                                syserr("getinfo");
396 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
397 >                                        &oorg[2], &osiz) != 4) {
398 >                                fprintf(stderr,
399                          "%s: error reading bounding cube from getinfo\n",
400 <                                        progname);
401 <                        exit(1);
400 >                                                progname);
401 >                                quit(1);
402 >                        }
403 >                        pclose(fp);
404                  }
439                pclose(fp);
405          }
406          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
407   }
408  
409  
410 < setdefaults()                   /* set default values for unassigned var's */
410 > static void
411 > setdefaults(void)                       /* set default values for unassigned var's */
412   {
413 <        double  org[3], size;
413 >        double  org[3], lim[3], size;
414          char    buf[128];
415  
416          if (!vdef(ZONE)) {
# Line 454 | Line 420 | setdefaults()                  /* set default values for unassigned v
420                  vval(ZONE) = savqstr(buf);
421                  vdef(ZONE)++;
422          }
423 +        if (!vdef(EYESEP)) {
424 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
425 +                                &org[0], &lim[0], &org[1], &lim[1],
426 +                                &org[2], &lim[2]) != 6)
427 +                        badvalue(ZONE);
428 +                sprintf(buf, "%f",
429 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
430 +                vval(EYESEP) = savqstr(buf);
431 +                vdef(EYESEP)++;
432 +        }
433          if (!vdef(INDIRECT)) {
434                  vval(INDIRECT) = "0";
435                  vdef(INDIRECT)++;
# Line 470 | Line 446 | setdefaults()                  /* set default values for unassigned v
446                  vval(PICTURE) = radname;
447                  vdef(PICTURE)++;
448          }
449 <        if (!vdef(VIEW)) {
450 <                vval(VIEW) = "X";
451 <                vdef(VIEW)++;
449 >        if (!vdef(VIEWS)) {
450 >                vval(VIEWS) = "X";
451 >                vdef(VIEWS)++;
452          }
453          if (!vdef(DETAIL)) {
454                  vval(DETAIL) = "M";
# Line 489 | Line 465 | setdefaults()                  /* set default values for unassigned v
465   }
466  
467  
468 < printvals()                     /* print variable values */
468 > static void
469 > oconv(void)                             /* run oconv and mkillum if necessary */
470   {
471 <        register int    i, j;
471 >        static char     illumtmp[] = "ilXXXXXX";
472 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
473  
474 <        for (i = 0; i < NVARS; i++)
475 <                for (j = 0; j < vdef(i); j++)
476 <                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
477 <        fflush(stdout);
478 < }
479 <
480 <
481 < oconv()                         /* run oconv if necessary */
482 < {
483 <        char    combuf[512], ocopts[64];
484 <
485 <        if (octreedate >= scenedate)    /* check dates */
474 >        oconvopts(ocopts);              /* get options */
475 >        if (octreedate < scenedate) {   /* check date on original octree */
476 >                if (touchonly && octreedate)
477 >                        touch(vval(OCTREE));
478 >                else {                          /* build command */
479 >                        if (vdef(MATERIAL))
480 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
481 >                                                vval(MATERIAL), vval(SCENE),
482 >                                                vval(OCTREE));
483 >                        else
484 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
485 >                                                vval(SCENE), vval(OCTREE));
486 >                        
487 >                        if (runcom(combuf)) {           /* run it */
488 >                                fprintf(stderr,
489 >                                "%s: error generating octree\n\t%s removed\n",
490 >                                                progname, vval(OCTREE));
491 >                                unlink(vval(OCTREE));
492 >                                quit(1);
493 >                        }
494 >                }
495 >                octreedate = time((time_t *)NULL);
496 >                if (octreedate < scenedate)     /* in case clock is off */
497 >                        octreedate = scenedate;
498 >        }
499 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
500 >                oct1date = octreedate > matdate ? octreedate : matdate;
501 >        if ((oct1date >= octreedate) & (oct1date >= matdate)
502 >                        & (oct1date >= illumdate))      /* all done */
503                  return;
504 <                                        /* build command */
505 <        oconvopts(ocopts);
506 <        if (vdef(MATERIAL))
507 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
508 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
509 <        else
510 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
511 <                                vval(SCENE), vval(OCTREE));
512 <        
513 <        if (runcom(combuf)) {           /* run it */
514 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
515 <                                progname, vval(OCTREE));
516 <                unlink(vval(OCTREE));
517 <                exit(1);
504 >                                                /* make octree0 */
505 >        if ((oct0date < scenedate) | (oct0date < illumdate)) {
506 >                if (touchonly && oct0date)
507 >                        touch(oct0name);
508 >                else {                          /* build command */
509 >                        if (octreedate)
510 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
511 >                                        vval(OCTREE), vval(ILLUM), oct0name);
512 >                        else if (vdef(MATERIAL))
513 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
514 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
515 >                        else
516 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
517 >                                        vval(ILLUM), oct0name);
518 >                        if (runcom(combuf)) {           /* run it */
519 >                                fprintf(stderr,
520 >                                "%s: error generating octree\n\t%s removed\n",
521 >                                                progname, oct0name);
522 >                                unlink(oct0name);
523 >                                quit(1);
524 >                        }
525 >                }
526 >                oct0date = time((time_t *)NULL);
527 >                if (oct0date < octreedate)      /* in case clock is off */
528 >                        oct0date = octreedate;
529 >                if (oct0date < illumdate)       /* ditto */
530 >                        oct0date = illumdate;
531 >                }
532 >        if (touchonly && oct1date)
533 >                touch(oct1name);
534 >        else {
535 >                mkillumopts(mkopts);            /* build mkillum command */
536 >                mktemp(illumtmp);
537 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
538 >                                oct0name, vval(ILLUM), illumtmp);
539 >                if (runcom(combuf)) {                   /* run it */
540 >                        fprintf(stderr, "%s: error running mkillum\n",
541 >                                        progname);
542 >                        unlink(illumtmp);
543 >                        quit(1);
544 >                }
545 >                                                /* make octree1 (frozen) */
546 >                if (octreedate)
547 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
548 >                                vval(OCTREE), illumtmp, oct1name);
549 >                else if (vdef(MATERIAL))
550 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
551 >                                vval(MATERIAL), illumtmp, oct1name);
552 >                else
553 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
554 >                                illumtmp, oct1name);
555 >                if (runcom(combuf)) {           /* run it */
556 >                        fprintf(stderr,
557 >                                "%s: error generating octree\n\t%s removed\n",
558 >                                        progname, oct1name);
559 >                        unlink(oct1name);
560 >                        unlink(illumtmp);
561 >                        quit(1);
562 >                }
563 >                rmfile(illumtmp);
564          }
565 <        octreedate = time(0);
565 >        oct1date = time((time_t *)NULL);
566 >        if (oct1date < oct0date)        /* in case clock is off */
567 >                oct1date = oct0date;
568   }
569  
570  
571 < char *
572 < addarg(op, arg)                         /* add argument and advance pointer */
573 < register char   *op, *arg;
571 > static char *
572 > addarg(                         /* add argument and advance pointer */
573 > register char   *op,
574 > register char   *arg
575 > )
576   {
577          *op = ' ';
578 <        while (*++op = *arg++)
578 >        while ( (*++op = *arg++) )
579                  ;
580          return(op);
581   }
582  
583  
584 < oconvopts(oo)                           /* get oconv options */
585 < register char   *oo;
584 > static void
585 > oconvopts(                              /* get oconv options */
586 >        register char   *oo
587 > )
588   {
589          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
590  
# Line 547 | Line 594 | register char  *oo;
594   }
595  
596  
597 < double
598 < ambval()                                /* compute ambient value */
597 > static void
598 > mkillumopts(                            /* get mkillum options */
599 >        register char   *mo
600 > )
601   {
602 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
603 +
604 +        *mo = '\0';
605 +        if (vdef(MKILLUM))
606 +                addarg(mo, vval(MKILLUM));
607 + }
608 +
609 +
610 + static void
611 + checkambfile(void)                      /* check date on ambient file */
612 + {
613 +        time_t  afdate;
614 +
615 +        if (!vdef(AMBFILE))
616 +                return;
617 +        if (!(afdate = fdate(vval(AMBFILE))))
618 +                return;
619 +        if (oct1date > afdate) {
620 +                if (touchonly)
621 +                        touch(vval(AMBFILE));
622 +                else
623 +                        rmfile(vval(AMBFILE));
624 +        }
625 + }
626 +
627 +
628 + static double
629 + ambval(void)                            /* compute ambient value */
630 + {
631          if (vdef(EXPOSURE)) {
632                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
633 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
634 <                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
557 <                        return(.5/atof(vval(EXPOSURE)));
558 <                badvalue(EXPOSURE);
633 >                        return(.5/pow(2.,vflt(EXPOSURE)));
634 >                return(.5/vflt(EXPOSURE));
635          }
636          if (vlet(ZONE) == 'E')
637                  return(10.);
638          if (vlet(ZONE) == 'I')
639                  return(.01);
640          badvalue(ZONE);
641 +        return 0; /* pro forma return */
642   }
643  
644  
645 < lowqopts(op)                            /* low quality rendering options */
646 < register char   *op;
645 > static void
646 > renderopts(                     /* set rendering options */
647 >        char    *op,
648 >        char    *po
649 > )
650   {
651 +        switch(vscale(QUALITY)) {
652 +        case LOW:
653 +                lowqopts(op, po);
654 +                break;
655 +        case MEDIUM:
656 +                medqopts(op, po);
657 +                break;
658 +        case HIGH:
659 +                hiqopts(op, po);
660 +                break;
661 +        }
662 + }
663 +
664 +
665 + static void
666 + lowqopts(                       /* low quality rendering options */
667 +        register char   *op,
668 +        char    *po
669 + )
670 + {
671          double  d, org[3], siz[3];
672  
673          *op = '\0';
674 +        *po = '\0';
675          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
676                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
677                  badvalue(ZONE);
678          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
679 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
680 +                badvalue(ZONE);
681          getoctcube(org, &d);
682          d *= 3./(siz[0]+siz[1]+siz[2]);
683          switch (vscale(DETAIL)) {
684          case LOW:
685 <                op = addarg(op, "-ps 16 -dp 16");
686 <                sprintf(op, " -ar %d", (int)(4*d));
685 >                po = addarg(po, "-ps 16");
686 >                op = addarg(op, "-dp 64");
687 >                sprintf(op, " -ar %d", (int)(8*d));
688                  op += strlen(op);
689                  break;
690          case MEDIUM:
691 <                op = addarg(op, "-ps 8 -dp 32");
692 <                sprintf(op, " -ar %d", (int)(8*d));
691 >                po = addarg(po, "-ps 8");
692 >                op = addarg(op, "-dp 128");
693 >                sprintf(op, " -ar %d", (int)(16*d));
694                  op += strlen(op);
695                  break;
696          case HIGH:
697 <                op = addarg(op, "-ps 4 -dp 64");
698 <                sprintf(op, " -ar %d", (int)(16*d));
697 >                po = addarg(po, "-ps 4");
698 >                op = addarg(op, "-dp 256");
699 >                sprintf(op, " -ar %d", (int)(32*d));
700                  op += strlen(op);
701                  break;
702          }
703 <        op = addarg(op, "-pt .16");
703 >        po = addarg(po, "-pt .16");
704          if (vbool(PENUMBRAS))
705                  op = addarg(op, "-ds .4");
706          else
707                  op = addarg(op, "-ds 0");
708 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
708 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
709          if (vdef(AMBFILE)) {
710                  sprintf(op, " -af %s", vval(AMBFILE));
711                  op += strlen(op);
# Line 607 | Line 713 | register char  *op;
713                  overture = 0;
714          switch (vscale(VARIABILITY)) {
715          case LOW:
716 <                op = addarg(op, "-aa .4 -ad 32");
716 >                op = addarg(op, "-aa .3 -ad 256");
717                  break;
718          case MEDIUM:
719 <                op = addarg(op, "-aa .3 -ad 64");
719 >                op = addarg(op, "-aa .25 -ad 512");
720                  break;
721          case HIGH:
722 <                op = addarg(op, "-aa .25 -ad 128");
722 >                op = addarg(op, "-aa .2 -ad 1024");
723                  break;
724          }
725          op = addarg(op, "-as 0");
726          d = ambval();
727          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
728          op += strlen(op);
729 <        op = addarg(op, "-lr 3 -lw .02");
729 >        op = addarg(op, "-lr 6 -lw .01");
730          if (vdef(RENDER))
731                  op = addarg(op, vval(RENDER));
732   }
733  
734  
735 < medqopts(op)                            /* medium quality rendering options */
736 < register char   *op;
735 > static void
736 > medqopts(                       /* medium quality rendering options */
737 >        register char   *op,
738 >        char    *po
739 > )
740   {
741 <        double  d, org[3], siz[3];
741 >        double  d, org[3], siz[3], asz;
742  
743          *op = '\0';
744 +        *po = '\0';
745          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
746                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
747                  badvalue(ZONE);
748          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
749 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
750 +                badvalue(ZONE);
751          getoctcube(org, &d);
752 <        d *= 3./(siz[0]+siz[1]+siz[2]);
752 >        asz = (siz[0]+siz[1]+siz[2])/3.;
753 >        d /= asz;
754          switch (vscale(DETAIL)) {
755          case LOW:
756 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
757 <                op = addarg(op, "-dp 64");
758 <                sprintf(op, " -ar %d", (int)(8*d));
756 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
757 >                op = addarg(op, "-dp 256");
758 >                sprintf(op, " -ar %d", (int)(16*d));
759                  op += strlen(op);
760 +                sprintf(op, " -ms %.2g", asz/20.);
761 +                op += strlen(op);
762                  break;
763          case MEDIUM:
764 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
765 <                op = addarg(op, "-dp 128");
766 <                sprintf(op, " -ar %d", (int)(16*d));
764 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
765 >                op = addarg(op, "-dp 512");
766 >                sprintf(op, " -ar %d", (int)(32*d));
767                  op += strlen(op);
768 +                sprintf(op, " -ms %.2g", asz/40.);
769 +                op += strlen(op);
770                  break;
771          case HIGH:
772 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
773 <                op = addarg(op, "-dp 256");
774 <                sprintf(op, " -ar %d", (int)(32*d));
772 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
773 >                op = addarg(op, "-dp 1024");
774 >                sprintf(op, " -ar %d", (int)(64*d));
775                  op += strlen(op);
776 +                sprintf(op, " -ms %.2g", asz/80.);
777 +                op += strlen(op);
778                  break;
779          }
780 <        op = addarg(op, "-pt .08");
780 >        po = addarg(po, "-pt .08");
781          if (vbool(PENUMBRAS))
782 <                op = addarg(op, "-ds .2 -dj .35");
782 >                op = addarg(op, "-ds .2 -dj .5");
783          else
784                  op = addarg(op, "-ds .3");
785 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
786 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
787 <        op += strlen(op);
785 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
786 >        if ( (overture = vint(INDIRECT)) ) {
787 >                sprintf(op, " -ab %d", overture);
788 >                op += strlen(op);
789 >        }
790          if (vdef(AMBFILE)) {
791                  sprintf(op, " -af %s", vval(AMBFILE));
792                  op += strlen(op);
# Line 673 | Line 794 | register char  *op;
794                  overture = 0;
795          switch (vscale(VARIABILITY)) {
796          case LOW:
797 <                op = addarg(op, "-aa .25 -ad 128 -as 0");
797 >                op = addarg(op, "-aa .2 -ad 329 -as 42");
798                  break;
799          case MEDIUM:
800 <                op = addarg(op, "-aa .2 -ad 300 -as 64");
800 >                op = addarg(op, "-aa .15 -ad 800 -as 128");
801                  break;
802          case HIGH:
803 <                op = addarg(op, "-aa .15 -ad 500 -as 128");
803 >                op = addarg(op, "-aa .1 -ad 1536 -as 392");
804                  break;
805          }
806          d = ambval();
807          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
808          op += strlen(op);
809 <        op = addarg(op, "-lr 6 -lw .002");
809 >        op = addarg(op, "-lr 8 -lw .002");
810          if (vdef(RENDER))
811                  op = addarg(op, vval(RENDER));
812   }
813  
814  
815 < hiqopts(op)                             /* high quality rendering options */
816 < register char   *op;
815 > static void
816 > hiqopts(                                /* high quality rendering options */
817 >        register char   *op,
818 >        char    *po
819 > )
820   {
821 <        double  d, org[3], siz[3];
821 >        double  d, org[3], siz[3], asz;
822  
823          *op = '\0';
824 +        *po = '\0';
825          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
826                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
827                  badvalue(ZONE);
828          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
829 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
830 +                badvalue(ZONE);
831          getoctcube(org, &d);
832 <        d *= 3./(siz[0]+siz[1]+siz[2]);
832 >        asz = (siz[0]+siz[1]+siz[2])/3.;
833 >        d /= asz;
834          switch (vscale(DETAIL)) {
835          case LOW:
836 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
837 <                op = addarg(op, "-dp 256");
838 <                sprintf(op, " -ar %d", (int)(16*d));
836 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
837 >                op = addarg(op, "-dp 1024");
838 >                sprintf(op, " -ar %d", (int)(32*d));
839                  op += strlen(op);
840 +                sprintf(op, " -ms %.2g", asz/40.);
841 +                op += strlen(op);
842                  break;
843          case MEDIUM:
844 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
845 <                op = addarg(op, "-dp 512");
846 <                sprintf(op, " -ar %d", (int)(32*d));
844 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
845 >                op = addarg(op, "-dp 2048");
846 >                sprintf(op, " -ar %d", (int)(64*d));
847                  op += strlen(op);
848 +                sprintf(op, " -ms %.2g", asz/80.);
849 +                op += strlen(op);
850                  break;
851          case HIGH:
852 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
853 <                op = addarg(op, "-dp 1024");
854 <                sprintf(op, " -ar %d", (int)(64*d));
852 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
853 >                op = addarg(op, "-dp 4096");
854 >                sprintf(op, " -ar %d", (int)(128*d));
855                  op += strlen(op);
856 +                sprintf(op, " -ms %.2g", asz/160.);
857 +                op += strlen(op);
858                  break;
859          }
860 <        op = addarg(op, "-pt .04");
860 >        po = addarg(po, "-pt .04");
861          if (vbool(PENUMBRAS))
862 <                op = addarg(op, "-ds .1 -dj .7");
862 >                op = addarg(op, "-ds .1 -dj .65");
863          else
864                  op = addarg(op, "-ds .2");
865 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
865 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
866          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
867          op += strlen(op);
868          if (vdef(AMBFILE)) {
# Line 738 | Line 872 | register char  *op;
872                  overture = 0;
873          switch (vscale(VARIABILITY)) {
874          case LOW:
875 <                op = addarg(op, "-aa .15 -ad 200 -as 0");
875 >                op = addarg(op, "-aa .125 -ad 512 -as 64");
876                  break;
877          case MEDIUM:
878 <                op = addarg(op, "-aa .125 -ad 512 -as 128");
878 >                op = addarg(op, "-aa .1 -ad 1536 -as 768");
879                  break;
880          case HIGH:
881 <                op = addarg(op, "-aa .08 -ad 850 -as 256");
881 >                op = addarg(op, "-aa .075 -ad 4096 -as 2048");
882                  break;
883          }
884          d = ambval();
# Line 756 | Line 890 | register char  *op;
890   }
891  
892  
893 < xferopts(ro)                            /* transfer options if indicated */
894 < char    *ro;
893 > static void
894 > xferopts(                               /* transfer options if indicated */
895 >        char    *ro
896 > )
897   {
898          int     fd, n;
899 +        register char   *cp;
900          
901          n = strlen(ro);
902          if (n < 2)
903                  return;
904          if (vdef(OPTFILE)) {
905 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
905 >                for (cp = ro; cp[1]; cp++)
906 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
907 >                                        (cp[2] == '-' && isalpha(cp[3]))))
908 >                                *cp = '\n';
909 >                        else
910 >                                *cp = cp[1];
911 >                *cp = '\n';
912 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
913 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
914                          syserr(vval(OPTFILE));
915 <                if (write(fd, ro+1, n-1) != n-1)
771 <                        syserr(vval(OPTFILE));
772 <                write(fd, "\n", 1);
773 <                close(fd);
774 <                sprintf(ro, " \"^%s\"", vval(OPTFILE));
915 >                sprintf(ro, " @%s", vval(OPTFILE));
916          }
917 < #ifdef MSDOS
917 > #ifdef _WIN32
918          else if (n > 50) {
919 <                register char   *evp = bmalloc(n+6);
779 <                if (evp == NULL)
780 <                        syserr(progname);
781 <                strcpy(evp, "ROPT=");
782 <                strcat(evp, ro);
783 <                if (putenv(evp) != 0) {
784 <                        fprintf(stderr, "%s: out of environment space\n",
785 <                                        progname);
786 <                        exit(1);
787 <                }
919 >                setenv("ROPT", ro+1);
920                  strcpy(ro, " $ROPT");
921          }
922   #endif
923   }
924  
925  
926 < pfiltopts(po)                           /* get pfilt options */
927 < register char   *po;
926 > static void
927 > pfiltopts(                              /* get pfilt options */
928 >        register char   *po
929 > )
930   {
931          *po = '\0';
932          if (vdef(EXPOSURE)) {
933                  po = addarg(po, "-1 -e");
934                  po = addarg(po, vval(EXPOSURE));
935          }
936 <        if (vscale(QUALITY) == HIGH)
937 <                po = addarg(po, "-r .65");
936 >        switch (vscale(QUALITY)) {
937 >        case MEDIUM:
938 >                po = addarg(po, "-r .6");
939 >                break;
940 >        case HIGH:
941 >                po = addarg(po, "-m .25");
942 >                break;
943 >        }
944          if (vdef(PFILT))
945                  po = addarg(po, vval(PFILT));
946   }
947  
948  
949 < matchword(s1, s2)                       /* match white-delimited words */
950 < register char   *s1, *s2;
949 > static int
950 > matchword(                      /* match white-delimited words */
951 >        register char   *s1,
952 >        register char   *s2
953 > )
954   {
955          while (isspace(*s1)) s1++;
956          while (isspace(*s2)) s2++;
# Line 818 | Line 961 | register char  *s1, *s2;
961   }
962  
963  
964 < char *
965 < specview(vs)                            /* get proper view spec from vs */
966 < register char   *vs;
964 > static char *
965 > specview(                               /* get proper view spec from vs */
966 >        register char   *vs
967 > )
968   {
969          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
970                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
# Line 838 | Line 982 | register char  *vs;
982                          upax = 1-'X'+UPPER(vval(UP)[1]);
983                  else
984                          upax = 1-'X'+vlet(UP);
985 <                if (upax < 1 | upax > 3)
985 >                if ((upax < 1) | (upax > 3))
986                          badvalue(UP);
987                  if (vval(UP)[0] == '-')
988                          upax = -upax;
# Line 861 | Line 1005 | register char  *vs;
1005                  zpos = -1; vs++;
1006          }
1007          viewtype = 'v';
1008 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1008 >        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1009                  viewtype = *vs++;
1010          cp = viewopts;
1011          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 872 | Line 1016 | register char  *vs;
1016                          badvalue(ZONE);
1017                  for (i = 0; i < 3; i++) {
1018                          dim[i] -= cent[i];
1019 +                        if (dim[i] <= FTINY)
1020 +                                badvalue(ZONE);
1021                          cent[i] += .5*dim[i];
1022                  }
1023                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
# Line 914 | Line 1060 | register char  *vs;
1060                  case 'h':
1061                          cp = addarg(cp, "-vh 180 -vv 180");
1062                          break;
1063 +                case 'c':
1064 +                        cp = addarg(cp, "-vh 180 -vv 90");
1065 +                        break;
1066                  }
1067          } else {
1068                  while (!isspace(*vs))           /* else skip id */
# Line 924 | Line 1073 | register char  *vs;
1073                          cp += strlen(cp);
1074                  }
1075          }
1076 <                                        /* append any additional options */
1076 >        if (cp == viewopts)             /* append any additional options */
1077 >                vs++;           /* skip prefixed space if unneeded */
1078          strcpy(cp, vs);
1079 + #ifdef _WIN32
1080 +        if (strlen(viewopts) > 40) {
1081 +                setenv("VIEW", viewopts);
1082 +                return("$VIEW");
1083 +        }
1084 + #endif
1085          return(viewopts);
1086   }
1087  
1088  
1089 < char *
1090 < getview(n, vn)                          /* get view n, or NULL if none */
1091 < int     n;
1092 < char    *vn;
1089 > static char *
1090 > getview(                                /* get view n, or NULL if none */
1091 >        int     n,
1092 >        char    *vn             /* returned view name */
1093 > )
1094   {
1095          register char   *mv;
1096  
1097 <        if (viewselect != NULL) {
1097 >        if (viewselect != NULL) {               /* command-line selected */
1098                  if (n)                          /* only do one */
1099                          return(NULL);
1100                  if (viewselect[0] == '-') {     /* already specified */
# Line 950 | Line 1107 | char   *vn;
1107                                  ;
1108                          *vn = '\0';
1109                  }
1110 +                                                /* view number? */
1111 +                if (isint(viewselect))
1112 +                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1113                                                  /* check list */
1114 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1114 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1115                          if (matchword(viewselect, mv))
1116                                  return(specview(mv));
1117                  return(specview(viewselect));   /* standard view? */
1118          }
1119 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1120 <                if (*mv != '-')
1121 <                        while (*mv && !isspace(*mv))
1122 <                                *vn++ = *mv++;
1119 >        mv = nvalue(VIEWS, n);          /* use view n */
1120 >        if ((vn != NULL) & (mv != NULL)) {
1121 >                register char   *mv2 = mv;
1122 >                if (*mv2 != '-')
1123 >                        while (*mv2 && !isspace(*mv2))
1124 >                                *vn++ = *mv2++;
1125                  *vn = '\0';
1126          }
1127 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1127 >        return(specview(mv));
1128   }
1129  
1130  
1131 < rview(opts)                             /* run rview with first view */
1132 < char    *opts;
1131 > static int
1132 > myprintview(                    /* print out selected view */
1133 >        register char   *vopts,
1134 >        FILE    *fp
1135 > )
1136   {
1137 <        char    combuf[512];
1137 >        VIEW    vwr;
1138 >        char    buf[128];
1139 >        register char   *cp;
1140 >        if (vopts == NULL)
1141 >                return(-1);
1142 > #ifdef _WIN32
1143 >        if (vopts[0] == '$') {
1144 >                vopts = getenv(vopts+1);
1145 >                goto again;
1146 >        }
1147 > #endif
1148 >        vwr = stdview;
1149 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1150 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1151 >                        *atos(buf, sizeof(buf), cp += 4)) {
1152 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1153 >                sscanview(&vwr, cp);            /* reset tail */
1154 >        }
1155 >        fputs(VIEWSTR, fp);
1156 >        fprintview(&vwr, fp);                   /* print full spec. */
1157 >        fputc('\n', fp);
1158 >        return(0);
1159 > }
1160 >
1161 >
1162 > static void
1163 > rvu(                            /* run rvu with first view */
1164 >        char    *opts,
1165 >        char    *po
1166 > )
1167 > {
1168 >        char    *vw;
1169 >        char    combuf[PATH_MAX];
1170                                          /* build command */
1171 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1171 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1172 >                return;
1173 >        if (sayview)
1174 >                myprintview(vw, stdout);
1175 >        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1176          if (rvdevice != NULL)
1177                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1178 <        strcat(combuf, vval(OCTREE));
1178 >        if (vdef(EXPOSURE))
1179 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1180 >        strcat(combuf, oct1name);
1181          if (runcom(combuf)) {           /* run it */
1182 <                fprintf(stderr, "%s: error running rview\n", progname);
1183 <                exit(1);
1182 >                fprintf(stderr, "%s: error running rvu\n", progname);
1183 >                quit(1);
1184          }
1185   }
1186  
1187  
1188 < rpict(opts)                             /* run rpict and pfilt for each view */
1189 < char    *opts;
1188 > static void
1189 > rpict(                          /* run rpict and pfilt for each view */
1190 >        char    *opts,
1191 >        char    *po
1192 > )
1193   {
1194 <        char    combuf[1024];
1195 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1194 >        char    combuf[PATH_MAX];
1195 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1196 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1197 >        char    rppopt[128], *pfile = NULL;
1198          char    pfopts[128];
1199          char    vs[32], *vw;
1200          int     vn, mult;
1201 +        FILE    *fp;
1202 +        time_t  rfdt, pfdt;
1203                                          /* get pfilt options */
1204          pfiltopts(pfopts);
1205                                          /* get resolution, reporting */
1206 <        mult = vscale(QUALITY)+1;
1206 >        switch (vscale(QUALITY)) {
1207 >        case LOW:
1208 >                mult = 1;
1209 >                break;
1210 >        case MEDIUM:
1211 >                mult = 2;
1212 >                break;
1213 >        case HIGH:
1214 >                mult = 3;
1215 >                break;
1216 >        }
1217          {
1218                  int     xres, yres;
1219                  double  aspect;
# Line 1020 | Line 1240 | char   *opts;
1240                  else
1241                          badvalue(REPORT);
1242          }
1243 <                                        /* check date on ambient file */
1244 <        if (vdef(AMBFILE)) {
1245 <                long    afdate = fdate(vval(AMBFILE));
1246 <                if (afdate >= 0 & octreedate > afdate)
1247 <                        rmfile(vval(AMBFILE));
1243 >                                        /* set up parallel rendering */
1244 >        if ((nprocs > 1) & (!vdef(ZFILE))) {
1245 >                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1246 >                pfile = rppopt+9;
1247 >                if (mktemp(pfile) == NULL)
1248 >                        pfile = NULL;
1249          }
1250 <                                        /* do each view */
1030 <        vn = 0;
1250 >        vn = 0;                                 /* do each view */
1251          while ((vw = getview(vn++, vs)) != NULL) {
1252 +                if (sayview)
1253 +                        myprintview(vw, stdout);
1254                  if (!vs[0])
1255                          sprintf(vs, "%d", vn);
1256                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1257 +                if (vdef(ZFILE))
1258 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1259 +                else
1260 +                        zopt[0] = '\0';
1261                                                  /* check date on picture */
1262 <                if (fdate(picfile) > octreedate)
1262 >                pfdt = fdate(picfile);
1263 >                if (pfdt >= oct1date)
1264                          continue;
1265 +                                                /* get raw file name */
1266 +                sprintf(rawfile, "%s_%s.unf",
1267 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1268 +                rfdt = fdate(rawfile);
1269 +                if (touchonly) {                /* update times only */
1270 +                        if (rfdt) {
1271 +                                if (rfdt < oct1date)
1272 +                                        touch(rawfile);
1273 +                        } else if (pfdt && pfdt < oct1date)
1274 +                                touch(picfile);
1275 +                        continue;
1276 +                }
1277 +                if (next_process()) {           /* parallel running? */
1278 +                        if (pfile != NULL)
1279 +                                sleep(20);
1280 +                        continue;
1281 +                }
1282 +                /* XXX Remember to call finish_process() */
1283                                                  /* build rpict command */
1284 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1285 <                if (fdate(rawfile) > octreedate)        /* recover */
1286 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1287 <                                        rep, opts, rawfile, vval(OCTREE));
1288 <                else {
1284 >                if (rfdt >= oct1date) {         /* recover */
1285 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1286 >                                rep, po, opts, zopt, rawfile, oct1name);
1287 >                        if (runcom(combuf))     /* run rpict */
1288 >                                goto rperror;
1289 >                } else {
1290                          if (overture) {         /* run overture calculation */
1291                                  sprintf(combuf,
1292                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1293                                                  rep, vw, opts,
1294 <                                                vval(OCTREE), rawfile);
1294 >                                                oct1name, overfile);
1295                                  if (runcom(combuf)) {
1296                                          fprintf(stderr,
1297 <                        "%s: error in overture for view %s\n\t%s removed\n",
1298 <                                                progname, vs, rawfile);
1299 <                                        unlink(rawfile);
1054 <                                        exit(1);
1297 >                                        "%s: error in overture for view %s\n",
1298 >                                                progname, vs);
1299 >                                        quit(1);
1300                                  }
1301 + #ifndef NULL_DEVICE
1302 +                                rmfile(overfile);
1303 + #endif
1304                          }
1305 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1306 <                                        rep, vw, res, opts,
1307 <                                        vval(OCTREE), rawfile);
1305 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1306 >                                        rep, vw, res, po, opts,
1307 >                                        zopt, oct1name, rawfile);
1308 >                        if (pfile != NULL && inchild()) {
1309 >                                                /* rpict persistent mode */
1310 >                                if (!silent)
1311 >                                        printf("\t%s\n", combuf);
1312 >                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1313 >                                                rep, rppopt, res, po, opts,
1314 >                                                oct1name, rawfile);
1315 >                                fflush(stdout);
1316 >                                fp = popen(combuf, "w");
1317 >                                if (fp == NULL)
1318 >                                        goto rperror;
1319 >                                myprintview(vw, fp);
1320 >                                if (pclose(fp))
1321 >                                        goto rperror;
1322 >                        } else {                /* rpict normal mode */
1323 >                                if (runcom(combuf))
1324 >                                        goto rperror;
1325 >                        }
1326                  }
1327 <                if (runcom(combuf)) {           /* run rpict */
1062 <                        fprintf(stderr, "%s: error rendering view %s\n",
1063 <                                        progname, vs);
1064 <                        exit(1);
1065 <                }
1327 >                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1328                                                  /* build pfilt command */
1329 <                if (mult > 1)
1330 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1329 >                        if (mult > 1)
1330 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1331                                          pfopts, mult, mult, rawfile, picfile);
1332 <                else
1333 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1334 <                                        rawfile, picfile);
1335 <                if (runcom(combuf)) {           /* run pfilt */
1336 <                        fprintf(stderr,
1337 <                        "%s: error filtering view %s\n\t%s removed\n",
1338 <                                        progname, vs, picfile);
1339 <                        unlink(picfile);
1340 <                        exit(1);
1332 >                        else
1333 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1334 >                                                rawfile, picfile);
1335 >                        if (runcom(combuf)) {   /* run pfilt */
1336 >                                fprintf(stderr,
1337 >                                "%s: error filtering view %s\n\t%s removed\n",
1338 >                                                progname, vs, picfile);
1339 >                                unlink(picfile);
1340 >                                quit(1);
1341 >                        }
1342                  }
1343 <                                                /* remove raw file */
1344 <                rmfile(rawfile);
1343 >                                                /* remove/rename raw file */
1344 >                if (vdef(RAWFILE)) {
1345 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1346 >                        mvfile(rawfile, combuf);
1347 >                } else
1348 >                        rmfile(rawfile);
1349 >                finish_process();               /* exit if child */
1350          }
1351 +        wait_process(1);                /* wait for children to finish */
1352 +        if (pfile != NULL) {            /* clean up rpict persistent mode */
1353 +                int     pid;
1354 +                fp = fopen(pfile, "r");
1355 +                if (fp != NULL) {
1356 +                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1357 +                                        kill(pid, 1) < 0)
1358 +                                unlink(pfile);
1359 +                        fclose(fp);
1360 +                }
1361 +        }
1362 +        return;
1363 + rperror:
1364 +        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1365 +        quit(1);
1366   }
1367  
1368  
1369 < runcom(cs)                      /* run command */
1370 < char    *cs;
1369 > static int
1370 > touch(                  /* update a file */
1371 >        char    *fn
1372 > )
1373   {
1374 +        if (!silent)
1375 +                printf("\ttouch %s\n", fn);
1376 +        if (!nprocs)
1377 +                return(0);
1378 + #ifdef notused
1379 +        if (access(fn, F_OK) == -1)             /* create it */
1380 +                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1381 +                        return(-1);
1382 + #endif
1383 +        return(setfdate(fn, time((time_t *)NULL)));
1384 + }
1385 +
1386 +
1387 + static int
1388 + runcom(                 /* run command */
1389 +        char    *cs
1390 + )
1391 + {
1392          if (!silent)            /* echo it */
1393                  printf("\t%s\n", cs);
1394 <        if (noaction)
1394 >        if (!nprocs)
1395                  return(0);
1396          fflush(stdout);         /* flush output and pass to shell */
1397          return(system(cs));
1398   }
1399  
1400  
1401 < rmfile(fn)                      /* remove a file */
1402 < char    *fn;
1401 > static int
1402 > rmfile(                 /* remove a file */
1403 >        char    *fn
1404 > )
1405   {
1406          if (!silent)
1407 < #ifdef MSDOS
1408 <                printf("\tdel %s\n", fn);
1104 < #else
1105 <                printf("\trm -f %s\n", fn);
1106 < #endif
1107 <        if (noaction)
1407 >                printf("\t%s %s\n", DELCMD, fn);
1408 >        if (!nprocs)
1409                  return(0);
1410          return(unlink(fn));
1411   }
1412  
1413  
1414 < badvalue(vc)                    /* report bad variable value and exit */
1415 < int     vc;
1414 > static int
1415 > mvfile(         /* move a file */
1416 >        char    *fold,
1417 >        char    *fnew
1418 > )
1419   {
1420 +        if (!silent)
1421 +                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1422 +        if (!nprocs)
1423 +                return(0);
1424 +        return(rename(fold, fnew));
1425 + }
1426 +
1427 +
1428 + #ifdef RHAS_FORK_EXEC
1429 + static int
1430 + next_process(void)                      /* fork the next process (max. nprocs) */
1431 + {
1432 +        int     child_pid;
1433 +
1434 +        if (nprocs <= 1)
1435 +                return(0);              /* it's us or no one */
1436 +        if (inchild()) {
1437 +                fprintf(stderr, "%s: internal error 1 in next_process()\n",
1438 +                                progname);
1439 +                quit(1);
1440 +        }
1441 +        if (children_running >= nprocs)
1442 +                wait_process(0);        /* wait for someone to finish */
1443 +        fflush(stdout);
1444 +        child_pid = fork();             /* split process */
1445 +        if (child_pid == 0) {           /* we're the child */
1446 +                children_running = -1;
1447 +                return(0);
1448 +        }
1449 +        if (child_pid > 0) {            /* we're the parent */
1450 +                ++children_running;
1451 +                return(1);
1452 +        }
1453 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1454 +        return(0);
1455 + }
1456 +
1457 + static void
1458 + wait_process(                   /* wait for process(es) to finish */
1459 +        int     all
1460 + )
1461 + {
1462 +        int     ourstatus = 0;
1463 +        int     pid, status;
1464 +
1465 +        if (all)
1466 +                all = children_running;
1467 +        else if (children_running > 0)
1468 +                all = 1;
1469 +        while (all-- > 0) {
1470 +                pid = wait(&status);
1471 +                if (pid < 0)
1472 +                        syserr(progname);
1473 +                status = status>>8 & 0xff;
1474 +                --children_running;
1475 +                if (status != 0) {      /* child's problem is our problem */
1476 +                        if ((ourstatus == 0) & (children_running > 0))
1477 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1478 +                                                progname);
1479 +                        ourstatus = status;
1480 +                        all = children_running;
1481 +                }
1482 +        }
1483 +        if (ourstatus != 0)
1484 +                quit(ourstatus);        /* bad status from child */
1485 + }
1486 + #else   /* ! RHAS_FORK_EXEC */
1487 + static int
1488 + next_process(void)
1489 + {
1490 +        return(0);                      /* cannot start new process */
1491 + }
1492 + static void
1493 + wait_process(all)
1494 + int     all;
1495 + {
1496 +        (void)all;                      /* no one to wait for */
1497 + }
1498 + int
1499 + kill(pid, sig) /* win|unix_process.c should also wait and kill */
1500 + int pid, sig;
1501 + {
1502 +        return 0;
1503 + }
1504 + #endif  /* ! RHAS_FORK_EXEC */
1505 +
1506 + static void
1507 + finish_process(void)                    /* exit a child process */
1508 + {
1509 +        if (!inchild())
1510 +                return;                 /* in parent -- noop */
1511 +        exit(0);
1512 + }
1513 +
1514 + #ifdef _WIN32
1515 + setenv(vname, value)            /* set an environment variable */
1516 + char    *vname, *value;
1517 + {
1518 +        register char   *evp;
1519 +
1520 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1521 +        if (evp == NULL)
1522 +                syserr(progname);
1523 +        sprintf(evp, "%s=%s", vname, value);
1524 +        if (putenv(evp) != 0) {
1525 +                fprintf(stderr, "%s: out of environment space\n", progname);
1526 +                quit(1);
1527 +        }
1528 +        if (!silent)
1529 +                printf("set %s\n", evp);
1530 + }
1531 + #endif
1532 +
1533 +
1534 + static void
1535 + badvalue(                       /* report bad variable value and exit */
1536 +        int     vc
1537 + )
1538 + {
1539          fprintf(stderr, "%s: bad value for variable '%s'\n",
1540                          progname, vnam(vc));
1541 <        exit(1);
1541 >        quit(1);
1542   }
1543  
1544  
1545 < syserr(s)                       /* report a system error and exit */
1546 < char    *s;
1545 > static void
1546 > syserr(                 /* report a system error and exit */
1547 >        char    *s
1548 > )
1549   {
1550          perror(s);
1551 <        exit(1);
1551 >        quit(1);
1552 > }
1553 >
1554 >
1555 > void
1556 > quit(ec)                        /* exit program */
1557 > int     ec;
1558 > {
1559 >        exit(ec);
1560   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines