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.37 by greg, Sat Jan 1 09:16:50 1994 UTC vs.
Revision 2.133 by greg, Mon Dec 23 01:39:27 2024 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 > #include <signal.h>
13  
14 + #include "platform.h"
15 + #include "rtprocess.h"
16 + #include "view.h"
17 + #include "paths.h"
18 + #include "vars.h"
19  
20 < typedef struct {
21 <        char    *name;          /* variable name */
22 <        short   nick;           /* # characters required for nickname */
23 <        short   nass;           /* # assignments made */
24 <        char    *value;         /* assigned value(s) */
25 <        int     (*fixval)();    /* assignment checking function */
26 < } VARIABLE;
20 > #if defined(_WIN32) || defined(_WIN64)
21 >  #define DELCMD "del"
22 >  #define RENAMECMD "rename"
23 > #else
24 >  #define DELCMD "rm -f"
25 >  #define RENAMECMD "mv"
26 >  #include <sys/types.h>
27 >  #include <sys/wait.h>
28 >  #include <signal.h>
29 > #endif
30  
31 < int     onevalue(), catvalues(), boolvalue(),
32 <        qualvalue(), fltvalue(), intvalue();
33 <
34 <                                /* variables */
35 < #define OBJECT          0               /* object files */
36 < #define SCENE           1               /* scene files */
37 < #define MATERIAL        2               /* material files */
38 < #define ILLUM           3               /* mkillum input files */
39 < #define MKILLUM         4               /* mkillum options */
40 < #define RENDER          5               /* rendering options */
41 < #define OCONV           6               /* oconv options */
42 < #define PFILT           7               /* pfilt options */
37 < #define VIEW            8               /* view(s) for picture(s) */
38 < #define ZONE            9               /* simulation zone */
39 < #define QUALITY         10              /* desired rendering quality */
31 >                                /* variables (alphabetical by name) */
32 > #define AMBFILE         0               /* ambient file name */
33 > #define DETAIL          1               /* level of scene detail */
34 > #define EXPOSURE        2               /* picture exposure setting */
35 > #define EYESEP          3               /* interocular distance */
36 > #define ILLUM           4               /* mkillum input files */
37 > #define INDIRECT        5               /* indirection in lighting */
38 > #define MATERIAL        6               /* material files */
39 > #define MKILLUM         7               /* mkillum options */
40 > #define MKPMAP          8               /* mkpmap options */
41 > #define OBJECT          9               /* object files */
42 > #define OCONV           10              /* oconv options */
43   #define OCTREE          11              /* octree file name */
44 < #define PICTURE         12              /* picture file name */
45 < #define AMBFILE         13              /* ambient file name */
46 < #define OPTFILE         14              /* rendering options file */
47 < #define EXPOSURE        15              /* picture exposure setting */
48 < #define RESOLUTION      16              /* maximum picture resolution */
49 < #define UP              17              /* view up (X, Y or Z) */
50 < #define INDIRECT        18              /* indirection in lighting */
51 < #define DETAIL          19              /* level of scene detail */
52 < #define PENUMBRAS       20              /* shadow penumbras are desired */
53 < #define VARIABILITY     21              /* level of light variability */
54 < #define REPORT          22              /* report frequency and errfile */
44 > #define OPTFILE         12              /* rendering options file */
45 > #define PCMAP           13              /* caustic photon map */
46 > #define PENUMBRAS       14              /* shadow penumbras are desired */
47 > #define PFILT           15              /* pfilt options */
48 > #define PGMAP           16              /* global photon map */
49 > #define PICTURE         17              /* picture file root name */
50 > #define QUALITY         18              /* desired rendering quality */
51 > #define RAWFILE         19              /* raw picture file root name */
52 > #define RENDER          20              /* rendering options */
53 > #define REPORT          21              /* report frequency and errfile */
54 > #define RESOLUTION      22              /* maximum picture resolution */
55 > #define RPICT           23              /* rpict parameters */
56 > #define RVU             24              /* rvu parameters */
57 > #define SCENE           25              /* scene files */
58 > #define UP              26              /* view up (X, Y or Z) */
59 > #define VARIABILITY     27              /* level of light variability */
60 > #define VIEWS           28              /* view(s) for picture(s) */
61 > #define ZFILE           29              /* distance file root name */
62 > #define ZONE            30              /* simulation zone */
63                                  /* total number of variables */
64 < #define NVARS           23
64 > int NVARS = 31;
65  
66 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
67 <        {"objects",     3,      0,      NULL,   catvalues},
68 <        {"scene",       3,      0,      NULL,   catvalues},
69 <        {"materials",   3,      0,      NULL,   catvalues},
66 > VARIABLE        vv[] = {                /* variable-value pairs */
67 >        {"AMBFILE",     3,      0,      NULL,   strvalue},
68 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
69 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
70 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
71          {"illum",       3,      0,      NULL,   catvalues},
72 +        {"INDIRECT",    3,      0,      NULL,   intvalue},
73 +        {"materials",   3,      0,      NULL,   catvalues},
74          {"mkillum",     3,      0,      NULL,   catvalues},
75 <        {"render",      3,      0,      NULL,   catvalues},
75 >        {"mkpmap",      3,      0,      NULL,   catvalues},
76 >        {"objects",     3,      0,      NULL,   catvalues},
77          {"oconv",       3,      0,      NULL,   catvalues},
78 +        {"OCTREE",      3,      0,      NULL,   strvalue},
79 +        {"OPTFILE",     3,      0,      NULL,   strvalue},
80 +        {"PCMAP",       2,      0,      NULL,   strvalue},
81 +        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
82          {"pfilt",       2,      0,      NULL,   catvalues},
83 <        {"view",        2,      0,      NULL,   NULL},
84 <        {"ZONE",        2,      0,      NULL,   onevalue},
83 >        {"PGMAP",       2,      0,      NULL,   strvalue},
84 >        {"PICTURE",     3,      0,      NULL,   strvalue},
85          {"QUALITY",     3,      0,      NULL,   qualvalue},
86 <        {"OCTREE",      3,      0,      NULL,   onevalue},
87 <        {"PICTURE",     3,      0,      NULL,   onevalue},
88 <        {"AMBFILE",     3,      0,      NULL,   onevalue},
70 <        {"OPTFILE",     3,      0,      NULL,   onevalue},
71 <        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
86 >        {"RAWFILE",     3,      0,      NULL,   strvalue},
87 >        {"render",      3,      0,      NULL,   catvalues},
88 >        {"REPORT",      3,      0,      NULL,   onevalue},
89          {"RESOLUTION",  3,      0,      NULL,   onevalue},
90 +        {"rpict",       3,      0,      NULL,   catvalues},
91 +        {"rvu",         3,      0,      NULL,   catvalues},
92 +        {"scene",       3,      0,      NULL,   catvalues},
93          {"UP",          2,      0,      NULL,   onevalue},
74        {"INDIRECT",    3,      0,      NULL,   intvalue},
75        {"DETAIL",      3,      0,      NULL,   qualvalue},
76        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
94          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
95 <        {"REPORT",      3,      0,      NULL,   onevalue},
95 >        {"view",        2,      0,      NULL,   NULL},
96 >        {"ZFILE",       2,      0,      NULL,   strvalue},
97 >        {"ZONE",        2,      0,      NULL,   onevalue},
98   };
99  
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
100                                  /* overture calculation file */
101 < #ifdef NIX
102 < char    overfile[] = "overture.raw";
101 > #ifdef NULL_DEVICE
102 > char    overfile[] = NULL_DEVICE;
103   #else
104 < char    overfile[] = "/dev/null";
104 > char    overfile[] = "overture.unf";
105   #endif
106  
105 extern time_t   fdate(), time();
107  
108   time_t  scenedate;              /* date of latest scene or object file */
109   time_t  octreedate;             /* date of octree */
# Line 114 | Line 115 | time_t oct0date;               /* date of pre-mkillum octree */
115   char    *oct1name;              /* name of post-mkillum octree */
116   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
117  
118 + char    *pgmapname;             /* name of global photon map */
119 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
120 + char    *pcmapname;             /* name of caustic photon map */
121 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
122 +
123   int     nowarn = 0;             /* no warnings */
124   int     explicate = 0;          /* explicate variables */
125   int     silent = 0;             /* do work silently */
126 < int     noaction = 0;           /* don't do anything */
126 > int     touchonly = 0;          /* touch files only */
127 > int     nprocs = 1;             /* maximum executing processes */
128   int     sayview = 0;            /* print view out */
129 < char    *rvdevice = NULL;       /* rview output device */
129 > char    *rvdevice = NULL;       /* rvu output device */
130   char    *viewselect = NULL;     /* specific view only */
131  
132 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
133 +
134 + #define R_CMDMAX        (5*PATH_MAX+512)
135 +                                /* command paths */
136 + char    c_oconv[256] = "oconv";
137 + char    c_mkillum[256] = "mkillum";
138 + char    c_mkpmap[256] = "mkpmap";
139 + char    c_rvu[256] = "rvu";
140 + char    c_rpict[256] = DEF_RPICT_PATH;
141 + char    c_rpiece[] = "rpiece";
142 + char    c_pfilt[256] = "pfilt";
143 +
144   int     overture = 0;           /* overture calculation needed */
145  
146 + int     children_running = 0;   /* set negative in children */
147 +
148   char    *progname;              /* global argv[0] */
149   char    *rifname;               /* global rad input file name */
150  
151 < char    radname[MAXPATH];       /* root Radiance file name */
151 > char    radname[PATH_MAX];      /* root Radiance file name */
152  
153 + #define inchild()       (children_running < 0)
154  
155 < main(argc, argv)
156 < int     argc;
157 < char    *argv[];
155 > static void rootname(char       *rn, char       *fn);
156 > static time_t checklast(char    *fnames);
157 > static char * newfname(char     *orig, int      pred);
158 > static void checkfiles(void);
159 > static void getoctcube(double   org[3], double  *sizp);
160 > static void setdefaults(void);
161 > static void oconv(void);
162 > static void mkpmap(void);
163 > static char * addarg(char       *op, char       *arg);
164 > static void oconvopts(char      *oo);
165 > static void mkillumopts(char    *mo);
166 > static void mkpmapopts(char     *mo);
167 > static void checkambfile(void);
168 > static double ambval(void);
169 > static void renderopts(char     *op, char       *po);
170 > static void lowqopts(char       *op, char       *po);
171 > static void medqopts(char       *op, char       *po);
172 > static void hiqopts(char        *op, char       *po);
173 > static void xferopts(char       *ro);
174 > static void pfiltopts(char      *po);
175 > static int matchword(char       *s1, char       *s2);
176 > static char * specview(char     *vs);
177 > static char * getview(int       n, char *vn);
178 > static int myprintview(char     *vopts, FILE    *fp);
179 > static void rvu(char    *opts, char     *po);
180 > static void rpict(char  *opts, char     *po);
181 > static int touch(char   *fn);
182 > static int runcom(char  *cs);
183 > static int rmfile(char  *fn);
184 > static int mvfile(char  *fold, char     *fnew);
185 > static int next_process(int     reserve);
186 > static void wait_process(int    all);
187 > static void finish_process(void);
188 > static void badvalue(int        vc);
189 > static void syserr(char *s);
190 >
191 >
192 > int
193 > main(
194 >        int     argc,
195 >        char    *argv[]
196 > )
197   {
198          char    ropts[512];
199 +        char    popts[64];
200          int     i;
201  
202          progname = argv[0];
# Line 145 | Line 207 | char   *argv[];
207                          silent++;
208                          break;
209                  case 'n':
210 <                        noaction++;
210 >                        nprocs = 0;
211                          break;
212 +                case 'N':
213 +                        nprocs = atoi(argv[++i]);
214 +                        if (nprocs < 0)
215 +                                nprocs = 0;
216 +                        break;
217 +                case 't':
218 +                        touchonly++;
219 +                        break;
220                  case 'e':
221                          explicate++;
222                          break;
# Line 171 | Line 241 | char   *argv[];
241                                  /* assign Radiance root file name */
242          rootname(radname, rifname);
243                                  /* load variable values */
244 <        load(rifname);
244 >        loadvars(rifname);
245                                  /* get any additional assignments */
246 <        for (i++; i < argc; i++)
247 <                setvariable(argv[i]);
246 >        for (i++; i < argc; i++) {
247 >                int     rv = setvariable(argv[i], matchvar);
248 >                if (rv < 0) {
249 >                        fprintf(stderr, "%s: unknown setting: %s\n",
250 >                                        progname, argv[i]);
251 >                        quit(1);
252 >                }
253 >                if (!rv)
254 >                        fprintf(stderr,
255 >                        "%s: bad variable assignment: %s (ignored)\n",
256 >                                        progname, argv[i]);
257 >        }
258                                  /* check assignments */
259          checkvalues();
260                                  /* check files and dates */
# Line 183 | Line 263 | char   *argv[];
263          setdefaults();
264                                  /* print all values if requested */
265          if (explicate)
266 <                printvals();
266 >                printvars(stdout);
267                                  /* build octree (and run mkillum) */
268          oconv();
269 +                                /* run mkpmap if indicated */
270 +        mkpmap();
271                                  /* check date on ambient file */
272          checkambfile();
273                                  /* run simulation */
274 <        renderopts(ropts);
274 >        renderopts(ropts, popts);
275          xferopts(ropts);
276          if (rvdevice != NULL)
277 <                rview(ropts);
277 >                rvu(ropts, popts);
278          else
279 <                rpict(ropts);
280 <        exit(0);
279 >                rpict(ropts, popts);
280 >        quit(0);
281   userr:
282          fprintf(stderr,
283 <        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
283 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
284                          progname);
285 <        exit(1);
285 >        quit(1);
286 >        return 1; /* pro forma return */
287   }
288  
289  
290 < rootname(rn, fn)                /* remove tail from end of fn */
291 < register char   *rn, *fn;
290 > static void
291 > rootname(               /* remove tail from end of fn */
292 >        char    *rn,
293 >        char    *fn
294 > )
295   {
296          char    *tp, *dp;
297  
298 <        for (tp = NULL, dp = rn; *rn = *fn++; rn++)
298 >        for (tp = NULL, dp = rn; (*rn = *fn++); rn++)
299                  if (ISDIRSEP(*rn))
300                          dp = rn;
301                  else if (*rn == '.')
# Line 219 | Line 305 | register char  *rn, *fn;
305   }
306  
307  
308 < #define NOCHAR  127             /* constant for character to delete */
309 <
310 <
311 < load(rfname)                    /* load Radiance simulation file */
226 < char    *rfname;
308 > static time_t
309 > checklast(                      /* check files and find most recent */
310 >        char    *fnames
311 > )
312   {
313 <        FILE    *fp;
229 <        char    buf[512];
230 <        register char   *cp;
231 <
232 <        if (rfname == NULL)
233 <                fp = stdin;
234 <        else if ((fp = fopen(rfname, "r")) == NULL)
235 <                syserr(rfname);
236 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
237 <                for (cp = buf; *cp; cp++) {
238 <                        switch (*cp) {
239 <                        case '\\':
240 <                                *cp++ = NOCHAR;
241 <                                continue;
242 <                        case '#':
243 <                                *cp = '\0';
244 <                                break;
245 <                        default:
246 <                                continue;
247 <                        }
248 <                        break;
249 <                }
250 <                setvariable(buf);
251 <        }
252 <        fclose(fp);
253 < }
254 <
255 <
256 < setvariable(ass)                /* assign variable according to string */
257 < register char   *ass;
258 < {
259 <        char    varname[32];
260 <        int     n;
261 <        register char   *cp;
262 <        register VARIABLE       *vp;
263 <        register int    i;
264 <
265 <        while (isspace(*ass))           /* skip leading space */
266 <                ass++;
267 <        cp = varname;                   /* extract name */
268 <        while (cp < varname+sizeof(varname)-1
269 <                        && *ass && !isspace(*ass) && *ass != '=')
270 <                *cp++ = *ass++;
271 <        *cp = '\0';
272 <        if (!varname[0])
273 <                return;         /* no variable name! */
274 <                                        /* trim value */
275 <        while (isspace(*ass) || *ass == '=')
276 <                ass++;
277 <        for (n = strlen(ass); n > 0; n--)
278 <                if (!isspace(ass[n-1]))
279 <                        break;
280 <        if (!n && !nowarn) {
281 <                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
282 <                                progname, varname);
283 <                return;
284 <        }
285 <                                        /* match variable from list */
286 <        vp = matchvar(varname);
287 <        if (vp == NULL) {
288 <                fprintf(stderr, "%s: unknown variable '%s'\n",
289 <                                progname, varname);
290 <                exit(1);
291 <        }
292 <                                        /* assign new value */
293 <        if (i = vp->nass) {
294 <                cp = vp->value;
295 <                while (i--)
296 <                        while (*cp++)
297 <                                ;
298 <                i = cp - vp->value;
299 <                vp->value = realloc(vp->value, i+n+1);
300 <        } else
301 <                vp->value = malloc(n+1);
302 <        if (vp->value == NULL)
303 <                syserr(progname);
304 <        cp = vp->value+i;               /* copy value, squeezing spaces */
305 <        *cp = *ass;
306 <        for (i = 1; i <= n; i++) {
307 <                if (ass[i] == NOCHAR)
308 <                        continue;
309 <                if (isspace(*cp))
310 <                        while (isspace(ass[i]))
311 <                                i++;
312 <                *++cp = ass[i];
313 <        }
314 <        if (isspace(*cp))               /* remove trailing space */
315 <                *cp = '\0';
316 <        vp->nass++;
317 < }
318 <
319 <
320 < VARIABLE *
321 < matchvar(nam)                   /* match a variable by its name */
322 < char    *nam;
323 < {
324 <        int     n = strlen(nam);
325 <        register int    i;
326 <
327 <        for (i = 0; i < NVARS; i++)
328 <                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
329 <                        return(vv+i);
330 <        return(NULL);
331 < }
332 <
333 <
334 < char *
335 < nvalue(vp, n)                   /* return nth variable value */
336 < VARIABLE        *vp;
337 < register int    n;
338 < {
339 <        register char   *cp;
340 <
341 <        if (vp == NULL | n < 0 | n >= vp->nass)
342 <                return(NULL);
343 <        cp = vp->value;
344 <        while (n--)
345 <                while (*cp++)
346 <                        ;
347 <        return(cp);
348 < }
349 <
350 <
351 < checkvalues()                   /* check assignments */
352 < {
353 <        register int    i;
354 <
355 <        for (i = 0; i < NVARS; i++)
356 <                if (vv[i].fixval != NULL)
357 <                        (*vv[i].fixval)(vv+i);
358 < }
359 <
360 <
361 < onevalue(vp)                    /* only one assignment for this variable */
362 < register VARIABLE       *vp;
363 < {
364 <        if (vp->nass < 2)
365 <                return;
366 <        if (!nowarn)
367 <                fprintf(stderr,
368 <                "%s: warning - multiple assignment of variable '%s'\n",
369 <                        progname, vp->name);
370 <        do
371 <                vp->value += strlen(vp->value)+1;
372 <        while (--vp->nass > 1);
373 < }
374 <
375 <
376 < catvalues(vp)                   /* concatenate variable values */
377 < register VARIABLE       *vp;
378 < {
379 <        register char   *cp;
380 <
381 <        if (vp->nass < 2)
382 <                return;
383 <        for (cp = vp->value; vp->nass > 1; vp->nass--) {
384 <                while (*cp)
385 <                        cp++;
386 <                *cp++ = ' ';
387 <        }
388 < }
389 <
390 <
391 < int
392 < badmatch(tv, cv)                /* case insensitive truncated comparison */
393 < register char   *tv, *cv;
394 < {
395 <        if (!*tv) return(1);            /* null string cannot match */
396 <        do
397 <                if (UPPER(*tv) != *cv++)
398 <                        return(1);
399 <        while (*++tv);
400 <        return(0);              /* OK */
401 < }
402 <
403 <
404 < boolvalue(vp)                   /* check boolean for legal values */
405 < register VARIABLE       *vp;
406 < {
407 <        if (!vp->nass) return;
408 <        onevalue(vp);
409 <        switch (UPPER(vp->value[0])) {
410 <        case 'T':
411 <                if (badmatch(vp->value, "TRUE")) break;
412 <                return;
413 <        case 'F':
414 <                if (badmatch(vp->value, "FALSE")) break;
415 <                return;
416 <        }
417 <        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
418 <                        progname, vp->name);
419 <        exit(1);
420 < }
421 <
422 <
423 < qualvalue(vp)                   /* check qualitative var. for legal values */
424 < register VARIABLE       *vp;
425 < {
426 <        if (!vp->nass) return;
427 <        onevalue(vp);
428 <        switch (UPPER(vp->value[0])) {
429 <        case 'L':
430 <                if (badmatch(vp->value, "LOW")) break;
431 <                return;
432 <        case 'M':
433 <                if (badmatch(vp->value, "MEDIUM")) break;
434 <                return;
435 <        case 'H':
436 <                if (badmatch(vp->value, "HIGH")) break;
437 <                return;
438 <        }
439 <        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
440 <                        progname, vp->name);
441 <        exit(1);
442 < }
443 <
444 <
445 < intvalue(vp)                    /* check integer variable for legal values */
446 < register VARIABLE       *vp;
447 < {
448 <        if (!vp->nass) return;
449 <        onevalue(vp);
450 <        if (isint(vp->value)) return;
451 <        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
452 <                        progname, vp->name);
453 <        exit(1);
454 < }
455 <
456 <
457 < fltvalue(vp)                    /* check float variable for legal values */
458 < register VARIABLE       *vp;
459 < {
460 <        if (!vp->nass) return;
461 <        onevalue(vp);
462 <        if (isflt(vp->value)) return;
463 <        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
464 <                        progname, vp->name);
465 <        exit(1);
466 < }
467 <
468 <
469 < time_t
470 < checklast(fnames)                       /* check files and find most recent */
471 < register char   *fnames;
472 < {
473 <        char    thisfile[MAXPATH];
313 >        char    thisfile[PATH_MAX];
314          time_t  thisdate, lastdate = 0;
475        register char   *cp;
315  
316          if (fnames == NULL)
317                  return(0);
318 <        while (*fnames) {
319 <                while (isspace(*fnames)) fnames++;
320 <                cp = thisfile;
321 <                while (*fnames && !isspace(*fnames))
322 <                        *cp++ = *fnames++;
323 <                *cp = '\0';
318 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
319 >                if (thisfile[0] == '!' ||
320 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
321 >                        if (!lastdate)
322 >                                lastdate = 1;
323 >                        continue;
324 >                }
325                  if (!(thisdate = fdate(thisfile)))
326                          syserr(thisfile);
327                  if (thisdate > lastdate)
# Line 491 | Line 331 | register char  *fnames;
331   }
332  
333  
334 < char *
335 < newfname(orig, pred)            /* create modified file name */
336 < char    *orig;
337 < int     pred;
334 > static char *
335 > newfname(               /* create modified file name */
336 >        char    *orig,
337 >        int     pred
338 > )
339   {
340 <        extern char     *rindex();
341 <        register char   *cp;
501 <        register int    n;
340 >        char    *cp;
341 >        int     n;
342          int     suffix;
343  
344          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 517 | Line 357 | int    pred;
357   }
358  
359  
360 < checkfiles()                    /* check for existence and modified times */
360 > static void
361 > checkfiles(void)                        /* check for existence and modified times */
362   {
363 +        char    fntemp[256];
364          time_t  objdate;
365  
366          if (!vdef(OCTREE)) {
# Line 526 | Line 368 | checkfiles()                   /* check for existence and modified tim
368                          syserr(progname);
369                  sprintf(vval(OCTREE), "%s.oct", radname);
370                  vdef(OCTREE)++;
371 +        } else if (vval(OCTREE)[0] == '!') {
372 +                fprintf(stderr, "%s: illegal '%s' specification\n",
373 +                                progname, vnam(OCTREE));
374 +                quit(1);
375          }
376          octreedate = fdate(vval(OCTREE));
377          if (vdef(ILLUM)) {              /* illum requires secondary octrees */
# Line 542 | Line 388 | checkfiles()                   /* check for existence and modified tim
388          if (!octreedate & !scenedate & !illumdate) {
389                  fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
390                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
391 <                exit(1);
391 >                quit(1);
392          }
393 +        if (vdef(PGMAP)) {
394 +                if (!*sskip2(vval(PGMAP),1)) {
395 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
396 +                                        progname, vnam(PGMAP));
397 +                        quit(1);
398 +                }
399 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
400 +                pgmapname = savqstr(fntemp);
401 +                pgmapdate = fdate(pgmapname);
402 +        }
403 +        if (vdef(PCMAP)) {
404 +                if (!*sskip2(vval(PCMAP),1)) {
405 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
406 +                                        progname, vnam(PCMAP));
407 +                        quit(1);
408 +                }
409 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
410 +                pcmapname = savqstr(fntemp);
411 +                pcmapdate = fdate(pcmapname);
412 +        }
413          matdate = checklast(vval(MATERIAL));
414   }      
415  
416  
417 < getoctcube(org, sizp)           /* get octree bounding cube */
418 < double  org[3], *sizp;
417 > static void
418 > getoctcube(             /* get octree bounding cube */
419 >        double  org[3],
420 >        double  *sizp
421 > )
422   {
554        extern FILE     *popen();
423          static double   oorg[3], osiz = 0.;
424          double  min[3], max[3];
425 <        char    buf[512];
425 >        char    buf[1024];
426          FILE    *fp;
427 <        register int    i;
427 >        int     i;
428  
429 <        if (osiz <= FTINY)
430 <                if (noaction && fdate(oct1name) <
429 >        if (osiz <= FTINY) {
430 >                if (!nprocs && fdate(oct1name) <
431                                  (scenedate>illumdate?scenedate:illumdate)) {
432                                                          /* run getbbox */
433                          sprintf(buf, "getbbox -w -h %s",
# Line 572 | Line 440 | double org[3], *sizp;
440                                  fprintf(stderr,
441                          "%s: error reading bounding box from getbbox\n",
442                                                  progname);
443 <                                exit(1);
443 >                                quit(1);
444                          }
445                          for (i = 0; i < 3; i++)
446                                  if (max[i] - min[i] > osiz)
# Line 590 | Line 458 | double org[3], *sizp;
458                                  fprintf(stderr,
459                          "%s: error reading bounding cube from getinfo\n",
460                                                  progname);
461 <                                exit(1);
461 >                                quit(1);
462                          }
463                          pclose(fp);
464                  }
465 +        }
466          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
467   }
468  
469  
470 < setdefaults()                   /* set default values for unassigned var's */
470 > static void
471 > setdefaults(void)                       /* set default values for unassigned var's */
472   {
473 <        double  org[3], size;
473 >        double  org[3], lim[3], size;
474          char    buf[128];
475  
476          if (!vdef(ZONE)) {
# Line 610 | Line 480 | setdefaults()                  /* set default values for unassigned v
480                  vval(ZONE) = savqstr(buf);
481                  vdef(ZONE)++;
482          }
483 +        if (!vdef(EYESEP)) {
484 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
485 +                                &org[0], &lim[0], &org[1], &lim[1],
486 +                                &org[2], &lim[2]) != 6)
487 +                        badvalue(ZONE);
488 +                sprintf(buf, "%f",
489 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
490 +                vval(EYESEP) = savqstr(buf);
491 +                vdef(EYESEP)++;
492 +        }
493          if (!vdef(INDIRECT)) {
494                  vval(INDIRECT) = "0";
495                  vdef(INDIRECT)++;
# Line 626 | Line 506 | setdefaults()                  /* set default values for unassigned v
506                  vval(PICTURE) = radname;
507                  vdef(PICTURE)++;
508          }
509 <        if (!vdef(VIEW)) {
510 <                vval(VIEW) = "X";
511 <                vdef(VIEW)++;
509 >        if (!vdef(VIEWS)) {
510 >                vval(VIEWS) = "X";
511 >                vdef(VIEWS)++;
512          }
513          if (!vdef(DETAIL)) {
514                  vval(DETAIL) = "M";
# Line 645 | Line 525 | setdefaults()                  /* set default values for unassigned v
525   }
526  
527  
528 < printvals()                     /* print variable values */
528 > static void
529 > oconv(void)                             /* run oconv and mkillum if necessary */
530   {
650        int     i, j, clipline;
651        register char   *cp;
652        register int    k;
653
654        for (i = 0; i < NVARS; i++)             /* print each variable */
655            for (j = 0; j < vdef(i); j++) {     /* print each assignment */
656                fputs(vnam(i), stdout);
657                fputs("= ", stdout);
658                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
659                                - strlen(vnam(i)) ;
660                cp = nvalue(vv+i, j);
661                while (*cp) {
662                    putchar(*cp++);
663                    if (--k <= 0) {             /* line too long */
664                        while (*cp && !isspace(*cp))
665                            putchar(*cp++);     /* finish this word */
666                        if (*cp) {              /* start new line */
667                            putchar('\n');
668                            fputs(vnam(i), stdout);
669                            putchar('=');
670                            k = clipline;
671                        }
672                    }
673                }
674                putchar('\n');
675            }
676        fflush(stdout);
677 }
678
679
680 oconv()                         /* run oconv and mkillum if necessary */
681 {
531          static char     illumtmp[] = "ilXXXXXX";
532 <        char    combuf[512], ocopts[64], mkopts[64];
532 >        char    combuf[R_CMDMAX], ocopts[64], mkopts[1024];
533  
534          oconvopts(ocopts);              /* get options */
535          if (octreedate < scenedate) {   /* check date on original octree */
536 <                                                /* build command */
537 <                if (vdef(MATERIAL))
538 <                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
539 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
540 <                else
541 <                        sprintf(combuf, "oconv%s %s > %s", ocopts,
542 <                                        vval(SCENE), vval(OCTREE));
543 <                
544 <                if (runcom(combuf)) {           /* run it */
545 <                        fprintf(stderr,
536 >                if (touchonly && octreedate)
537 >                        touch(vval(OCTREE));
538 >                else {                          /* build command */
539 >                        if (vdef(MATERIAL))
540 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
541 >                                                ocopts, vval(MATERIAL),
542 >                                                vval(SCENE), vval(OCTREE));
543 >                        else
544 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
545 >                                                vval(SCENE), vval(OCTREE));
546 >                        
547 >                        if (runcom(combuf)) {           /* run it */
548 >                                fprintf(stderr,
549                                  "%s: error generating octree\n\t%s removed\n",
550 <                                        progname, vval(OCTREE));
551 <                        unlink(vval(OCTREE));
552 <                        exit(1);
550 >                                                progname, vval(OCTREE));
551 >                                unlink(vval(OCTREE));
552 >                                quit(1);
553 >                        }
554                  }
555                  octreedate = time((time_t *)NULL);
556 +                if (octreedate < scenedate)     /* in case clock is off */
557 +                        octreedate = scenedate;
558          }
559          if (oct1name == vval(OCTREE))           /* no mkillum? */
560                  oct1date = octreedate > matdate ? octreedate : matdate;
561 <        if (oct1date >= octreedate & oct1date >= matdate
562 <                        & oct1date >= illumdate)        /* all done */
561 >        if ((oct1date >= octreedate) & (oct1date >= matdate)
562 >                        & (oct1date >= illumdate))      /* all done */
563                  return;
564                                                  /* make octree0 */
565 <        if (oct0date < scenedate | oct0date < illumdate) {
566 <                                                /* build command */
565 >        if ((oct0date < scenedate) | (oct0date < illumdate)) {
566 >                if (touchonly && (oct0date || oct1date)) {
567 >                        if (oct0date)
568 >                                touch(oct0name);
569 >                } else {                        /* build command */
570 >                        if (octreedate)
571 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
572 >                                        ocopts, vval(OCTREE),
573 >                                        vval(ILLUM), oct0name);
574 >                        else if (vdef(MATERIAL))
575 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
576 >                                        ocopts, vval(MATERIAL),
577 >                                        vval(ILLUM), oct0name);
578 >                        else
579 >                                sprintf(combuf, "%s%s %s > %s", c_oconv,
580 >                                        ocopts, vval(ILLUM), oct0name);
581 >                        if (runcom(combuf)) {           /* run it */
582 >                                fprintf(stderr,
583 >                                "%s: error generating octree\n\t%s removed\n",
584 >                                                progname, oct0name);
585 >                                unlink(oct0name);
586 >                                quit(1);
587 >                        }
588 >                }
589 >                oct0date = time((time_t *)NULL);
590 >                if (oct0date < octreedate)      /* in case clock is off */
591 >                        oct0date = octreedate;
592 >                if (oct0date < illumdate)       /* ditto */
593 >                        oct0date = illumdate;
594 >        }
595 >        if (touchonly && oct1date)
596 >                touch(oct1name);
597 >        else {
598 >                mkillumopts(mkopts);            /* build mkillum command */
599 >                mktemp(illumtmp);
600 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
601 >                                oct0name, vval(ILLUM), illumtmp);
602 >                if (runcom(combuf)) {                   /* run it */
603 >                        fprintf(stderr, "%s: error running %s\n",
604 >                                        progname, c_mkillum);
605 >                        unlink(illumtmp);
606 >                        quit(1);
607 >                }
608 >                rmfile(oct0name);
609 >                                                /* make octree1 (frozen) */
610                  if (octreedate)
611 <                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
612 <                                vval(OCTREE), vval(ILLUM), oct0name);
611 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
612 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
613                  else if (vdef(MATERIAL))
614 <                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
615 <                                vval(MATERIAL), vval(ILLUM), oct0name);
614 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
615 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
616                  else
617 <                        sprintf(combuf, "oconv%s %s > %s", ocopts,
618 <                                vval(ILLUM), oct0name);
617 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
618 >                                illumtmp, oct1name);
619                  if (runcom(combuf)) {           /* run it */
620                          fprintf(stderr,
621                                  "%s: error generating octree\n\t%s removed\n",
622 <                                        progname, oct0name);
623 <                        unlink(oct0name);
624 <                        exit(1);
622 >                                        progname, oct1name);
623 >                        unlink(oct1name);
624 >                        unlink(illumtmp);
625 >                        quit(1);
626                  }
627 <                oct0date = time((time_t *)NULL);
627 >                rmfile(illumtmp);
628          }
730        mkillumopts(mkopts);                    /* build mkillum command */
731        mktemp(illumtmp);
732        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
733                        oct0name, vval(ILLUM), illumtmp);
734        if (runcom(combuf)) {                   /* run it */
735                fprintf(stderr, "%s: error running mkillum\n", progname);
736                unlink(illumtmp);
737                exit(1);
738        }
739                                                /* make octree1 (frozen) */
740        if (octreedate)
741                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
742                        vval(OCTREE), illumtmp, oct1name);
743        else if (vdef(MATERIAL))
744                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
745                        vval(MATERIAL), illumtmp, oct1name);
746        else
747                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
748                        illumtmp, oct1name);
749        if (runcom(combuf)) {           /* run it */
750                fprintf(stderr,
751                        "%s: error generating octree\n\t%s removed\n",
752                                progname, oct1name);
753                unlink(oct1name);
754                exit(1);
755        }
629          oct1date = time((time_t *)NULL);
630 <        rmfile(illumtmp);
630 >        if (oct1date < oct0date)        /* in case clock is off */
631 >                oct1date = oct0date;
632   }
633  
634  
635 < char *
636 < addarg(op, arg)                         /* add argument and advance pointer */
763 < register char   *op, *arg;
635 > static void
636 > mkpmap(void)                    /* run mkpmap if indicated */
637   {
638 +        char    combuf[2048], *cp;
639 +        time_t  tnow;
640 +                                /* nothing to do? */
641 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
642 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
643 +                return;
644 +                                /* just update existing file dates? */
645 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
646 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
647 +                if (pgmapname != NULL)
648 +                        touch(pgmapname);
649 +                if (pcmapname != NULL)
650 +                        touch(pcmapname);
651 +        } else {                /* else need to (re)run pkpmap */
652 +                strcpy(combuf, c_mkpmap);
653 +                for (cp = combuf; *cp; cp++)
654 +                        ;
655 +                mkpmapopts(cp);
656 +                                /* force file overwrite */
657 +                cp = addarg(cp, "-fo+");
658 +                if (vdef(REPORT)) {
659 +                        char    errfile[256];
660 +                        int     n;
661 +                        double  minutes;
662 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
663 +                        if (n == 2)
664 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
665 +                        else if (n == 1)
666 +                                sprintf(cp, " -t %d", (int)(minutes*60));
667 +                        else
668 +                                badvalue(REPORT);
669 +                }
670 +                if (pgmapname != NULL && pgmapdate < oct1date) {
671 +                        cp = addarg(cp, "-apg");
672 +                        addarg(cp, vval(PGMAP));
673 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
674 +                        *cp = '\0';
675 +                }
676 +                if (pcmapname != NULL && pcmapdate < oct1date) {
677 +                        cp = addarg(cp, "-apc");
678 +                        addarg(cp, vval(PCMAP));
679 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
680 +                        *cp = '\0';
681 +                }
682 +                cp = addarg(cp, oct1name);
683 +                if (runcom(combuf)) {
684 +                        fprintf(stderr, "%s: error running %s\n",
685 +                                        progname, c_mkpmap);
686 +                        if (pgmapname != NULL && pgmapdate < oct1date)
687 +                                unlink(pgmapname);
688 +                        if (pcmapname != NULL && pcmapdate < oct1date)
689 +                                unlink(pcmapname);
690 +                        quit(1);
691 +                }
692 +        }
693 +        tnow = time((time_t *)NULL);
694 +        if (pgmapname != NULL)
695 +                pgmapdate = tnow;
696 +        if (pcmapname != NULL)
697 +                pcmapdate = tnow;
698 +        oct1date = tnow;        /* trigger ambient file removal if needed */
699 + }
700 +
701 +
702 + static char *
703 + addarg(                         /* append argument and advance pointer */
704 + char    *op,
705 + char    *arg
706 + )
707 + {
708 +        while (*op)
709 +                op++;
710          *op = ' ';
711 <        while (*++op = *arg++)
711 >        while ( (*++op = *arg++) )
712                  ;
713          return(op);
714   }
715  
716  
717 < oconvopts(oo)                           /* get oconv options */
718 < register char   *oo;
717 > static void
718 > oconvopts(                              /* get oconv options */
719 >        char    *oo
720 > )
721   {
722          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
723  
724          *oo = '\0';
725 <        if (vdef(OCONV))
726 <                addarg(oo, vval(OCONV));
725 >        if (!vdef(OCONV))
726 >                return;
727 >        if (vval(OCONV)[0] != '-') {
728 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
729 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
730 >        } else
731 >                oo = addarg(oo, vval(OCONV));
732   }
733  
734  
735 < mkillumopts(mo)                         /* get mkillum options */
736 < register char   *mo;
735 > static void
736 > mkillumopts(                            /* get mkillum options */
737 >        char    *mo
738 > )
739   {
740          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
741  
742 <        *mo = '\0';
743 <        if (vdef(MKILLUM))
744 <                addarg(mo, vval(MKILLUM));
742 >        if (nprocs > 1)
743 >                sprintf(mo, " -n %d", nprocs);
744 >        else
745 >                *mo = '\0';
746 >        if (!vdef(MKILLUM))
747 >                return;
748 >        if (vval(MKILLUM)[0] != '-') {
749 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
750 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
751 >        } else
752 >                mo = addarg(mo, vval(MKILLUM));
753   }
754  
755  
756 < checkambfile()                  /* check date on ambient file */
756 > static void
757 > mkpmapopts(                             /* get mkpmap options */
758 >        char    *mo
759 > )
760   {
761 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
762 +
763 +        if (nprocs > 1)
764 +                sprintf(mo, " -n %d", nprocs);
765 +        else
766 +                *mo = '\0';
767 +        if (!vdef(MKPMAP))
768 +                return;
769 +        if (vval(MKPMAP)[0] != '-') {
770 +                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
771 +                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
772 +        } else
773 +                mo = addarg(mo, vval(MKPMAP));
774 + }
775 +
776 +
777 + static void
778 + checkambfile(void)                      /* check date on ambient file */
779 + {
780          time_t  afdate;
781  
782          if (!vdef(AMBFILE))
783                  return;
784          if (!(afdate = fdate(vval(AMBFILE))))
785                  return;
786 <        if (oct1date > afdate)
787 <                rmfile(vval(AMBFILE));
786 >        if (oct1date > afdate) {
787 >                if (touchonly)
788 >                        touch(vval(AMBFILE));
789 >                else
790 >                        rmfile(vval(AMBFILE));
791 >        }
792   }
793  
794  
795 < double
796 < ambval()                                /* compute ambient value */
795 > static double
796 > ambval(void)                            /* compute ambient value */
797   {
798          if (vdef(EXPOSURE)) {
799                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
800 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
801 <                return(.5/atof(vval(EXPOSURE)));
800 >                        return(.18/pow(2.,vflt(EXPOSURE)));
801 >                return(.18/vflt(EXPOSURE));
802          }
803          if (vlet(ZONE) == 'E')
804                  return(10.);
805          if (vlet(ZONE) == 'I')
806                  return(.01);
807          badvalue(ZONE);
808 +        return 0; /* pro forma return */
809   }
810  
811  
812 < renderopts(op)                          /* set rendering options */
813 < char    *op;
812 > static void
813 > renderopts(                     /* set rendering options */
814 >        char    *op,
815 >        char    *po
816 > )
817   {
818 +        char    pmapf[256], *bw;
819 +
820 +        if (vdef(PGMAP)) {
821 +                *op = '\0';
822 +                bw = sskip2(vval(PGMAP), 2);
823 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
824 +                op = addarg(addarg(op, "-ap"), pmapf);
825 +                if (atoi(bw) > 0) op = addarg(op, bw);
826 +        }
827          switch(vscale(QUALITY)) {
828          case LOW:
829 <                lowqopts(op);
829 >                lowqopts(op, po);
830                  break;
831          case MEDIUM:
832 <                medqopts(op);
832 >                medqopts(op, po);
833                  break;
834          case HIGH:
835 <                hiqopts(op);
835 >                hiqopts(op, po);
836                  break;
837          }
838 +        if (vdef(PCMAP)) {
839 +                bw = sskip2(vval(PCMAP), 2);
840 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
841 +                op = addarg(addarg(op, "-ap"), pmapf);
842 +                if (atoi(bw) > 0) op = addarg(op, bw);
843 +        }
844 +        if (vdef(RENDER)) {
845 +                op = addarg(op, vval(RENDER));
846 +                bw = strstr(vval(RENDER), "-aa ");
847 +                if (bw != NULL && atof(bw+4) <= FTINY)
848 +                        overture = 0;
849 +        }
850 +        if (rvdevice != NULL) {
851 +                if (vdef(RVU)) {
852 +                        if (vval(RVU)[0] != '-') {
853 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
854 +                                po = addarg(po, sskip2(vval(RVU), 1));
855 +                        } else
856 +                                po = addarg(po, vval(RVU));
857 +                }
858 +        } else {
859 +                if (vdef(RPICT)) {
860 +                        if (vval(RPICT)[0] != '-') {
861 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
862 +                                po = addarg(po, sskip2(vval(RPICT), 1));
863 +                        } else
864 +                                po = addarg(po, vval(RPICT));
865 +                }
866 +        }
867   }
868  
869  
870 < lowqopts(op)                            /* low quality rendering options */
871 < register char   *op;
870 > static void
871 > lowqopts(                       /* low quality rendering options */
872 >        char    *op,
873 >        char    *po
874 > )
875   {
876          double  d, org[3], siz[3];
877  
878          *op = '\0';
879 +        *po = '\0';
880          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
881                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
882                  badvalue(ZONE);
883          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
884 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
885 +                badvalue(ZONE);
886          getoctcube(org, &d);
887          d *= 3./(siz[0]+siz[1]+siz[2]);
888          switch (vscale(DETAIL)) {
889          case LOW:
890 <                op = addarg(op, "-ps 16 -dp 64");
891 <                sprintf(op, " -ar %d", (int)(4*d));
890 >                po = addarg(po, "-ps 16");
891 >                op = addarg(op, "-dp 64");
892 >                sprintf(op, " -ar %d", (int)(8*d));
893                  op += strlen(op);
894                  break;
895          case MEDIUM:
896 <                op = addarg(op, "-ps 8 -dp 128");
897 <                sprintf(op, " -ar %d", (int)(8*d));
896 >                po = addarg(po, "-ps 8");
897 >                op = addarg(op, "-dp 128");
898 >                sprintf(op, " -ar %d", (int)(16*d));
899                  op += strlen(op);
900                  break;
901          case HIGH:
902 <                op = addarg(op, "-ps 4 -dp 256");
903 <                sprintf(op, " -ar %d", (int)(16*d));
902 >                po = addarg(po, "-ps 4");
903 >                op = addarg(op, "-dp 256");
904 >                sprintf(op, " -ar %d", (int)(32*d));
905                  op += strlen(op);
906                  break;
907          }
908 <        op = addarg(op, "-pt .16");
908 >        po = addarg(po, "-pt .16");
909          if (vbool(PENUMBRAS))
910                  op = addarg(op, "-ds .4");
911          else
912                  op = addarg(op, "-ds 0");
913 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
913 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
914          if (vdef(AMBFILE)) {
915                  sprintf(op, " -af %s", vval(AMBFILE));
916                  op += strlen(op);
# Line 879 | Line 918 | register char  *op;
918                  overture = 0;
919          switch (vscale(VARIABILITY)) {
920          case LOW:
921 <                op = addarg(op, "-aa .4 -ad 64");
921 >                op = addarg(op, "-aa .3 -ad 256");
922                  break;
923          case MEDIUM:
924 <                op = addarg(op, "-aa .3 -ad 128");
924 >                op = addarg(op, "-aa .25 -ad 512");
925                  break;
926          case HIGH:
927 <                op = addarg(op, "-aa .25 -ad 256");
927 >                op = addarg(op, "-aa .2 -ad 1024");
928                  break;
929          }
930          op = addarg(op, "-as 0");
931          d = ambval();
932          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
933          op += strlen(op);
934 <        op = addarg(op, "-lr 3 -lw .02");
896 <        if (vdef(RENDER))
897 <                op = addarg(op, vval(RENDER));
934 >        op = addarg(op, "-lr 6 -lw .001");
935   }
936  
937  
938 < medqopts(op)                            /* medium quality rendering options */
939 < register char   *op;
938 > static void
939 > medqopts(                       /* medium quality rendering options */
940 >        char    *op,
941 >        char    *po
942 > )
943   {
944 <        double  d, org[3], siz[3];
944 >        double  d, org[3], siz[3], asz;
945  
946          *op = '\0';
947 +        *po = '\0';
948          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
949                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
950                  badvalue(ZONE);
951          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
952 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
953 +                badvalue(ZONE);
954          getoctcube(org, &d);
955 <        d *= 3./(siz[0]+siz[1]+siz[2]);
955 >        asz = (siz[0]+siz[1]+siz[2])/3.;
956 >        d /= asz;
957          switch (vscale(DETAIL)) {
958          case LOW:
959 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
959 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
960                  op = addarg(op, "-dp 256");
961 <                sprintf(op, " -ar %d", (int)(8*d));
961 >                sprintf(op, " -ar %d", (int)(16*d));
962                  op += strlen(op);
963 +                sprintf(op, " -ms %.2g", asz/20.);
964 +                op += strlen(op);
965                  break;
966          case MEDIUM:
967 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
967 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
968                  op = addarg(op, "-dp 512");
969 <                sprintf(op, " -ar %d", (int)(16*d));
969 >                sprintf(op, " -ar %d", (int)(32*d));
970                  op += strlen(op);
971 +                sprintf(op, " -ms %.2g", asz/40.);
972 +                op += strlen(op);
973                  break;
974          case HIGH:
975 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
975 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
976                  op = addarg(op, "-dp 1024");
977 <                sprintf(op, " -ar %d", (int)(32*d));
977 >                sprintf(op, " -ar %d", (int)(64*d));
978                  op += strlen(op);
979 +                sprintf(op, " -ms %.2g", asz/80.);
980 +                op += strlen(op);
981                  break;
982          }
983 <        op = addarg(op, "-pt .08");
983 >        po = addarg(po, "-pt .08");
984          if (vbool(PENUMBRAS))
985 <                op = addarg(op, "-ds .2 -dj .5");
985 >                op = addarg(op, "-ds .2 -dj .9");
986          else
987                  op = addarg(op, "-ds .3");
988 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
989 <        if (overture = vint(INDIRECT)) {
988 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
989 >        if ( (overture = vint(INDIRECT)) ) {
990                  sprintf(op, " -ab %d", overture);
991                  op += strlen(op);
992          }
# Line 947 | Line 997 | register char  *op;
997                  overture = 0;
998          switch (vscale(VARIABILITY)) {
999          case LOW:
1000 <                op = addarg(op, "-aa .25 -ad 196 -as 0");
1000 >                op = addarg(op, "-aa .2 -ad 329 -as 42");
1001                  break;
1002          case MEDIUM:
1003 <                op = addarg(op, "-aa .2 -ad 400 -as 64");
1003 >                op = addarg(op, "-aa .15 -ad 800 -as 128");
1004                  break;
1005          case HIGH:
1006 <                op = addarg(op, "-aa .15 -ad 768 -as 196");
1006 >                op = addarg(op, "-aa .1 -ad 1536 -as 392");
1007                  break;
1008          }
1009          d = ambval();
1010          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1011          op += strlen(op);
1012 <        op = addarg(op, "-lr 6 -lw .002");
963 <        if (vdef(RENDER))
964 <                op = addarg(op, vval(RENDER));
1012 >        op = addarg(op, "-lr 8 -lw 1e-4");
1013   }
1014  
1015  
1016 < hiqopts(op)                             /* high quality rendering options */
1017 < register char   *op;
1016 > static void
1017 > hiqopts(                                /* high quality rendering options */
1018 >        char    *op,
1019 >        char    *po
1020 > )
1021   {
1022 <        double  d, org[3], siz[3];
1022 >        double  d, org[3], siz[3], asz;
1023  
1024          *op = '\0';
1025 +        *po = '\0';
1026          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
1027                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
1028                  badvalue(ZONE);
1029          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
1030 +        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
1031 +                badvalue(ZONE);
1032          getoctcube(org, &d);
1033 <        d *= 3./(siz[0]+siz[1]+siz[2]);
1033 >        asz = (siz[0]+siz[1]+siz[2])/3.;
1034 >        d /= asz;
1035          switch (vscale(DETAIL)) {
1036          case LOW:
1037 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1037 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1038                  op = addarg(op, "-dp 1024");
1039 <                sprintf(op, " -ar %d", (int)(16*d));
1039 >                sprintf(op, " -ar %d", (int)(32*d));
1040                  op += strlen(op);
1041 +                sprintf(op, " -ms %.2g", asz/40.);
1042 +                op += strlen(op);
1043                  break;
1044          case MEDIUM:
1045 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1045 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1046                  op = addarg(op, "-dp 2048");
1047 <                sprintf(op, " -ar %d", (int)(32*d));
1047 >                sprintf(op, " -ar %d", (int)(64*d));
1048                  op += strlen(op);
1049 +                sprintf(op, " -ms %.2g", asz/80.);
1050 +                op += strlen(op);
1051                  break;
1052          case HIGH:
1053 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1053 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1054                  op = addarg(op, "-dp 4096");
1055 <                sprintf(op, " -ar %d", (int)(64*d));
1055 >                sprintf(op, " -ar %d", (int)(128*d));
1056                  op += strlen(op);
1057 +                sprintf(op, " -ms %.2g", asz/160.);
1058 +                op += strlen(op);
1059                  break;
1060          }
1061 <        op = addarg(op, "-pt .04");
1061 >        po = addarg(po, "-pt .04");
1062          if (vbool(PENUMBRAS))
1063 <                op = addarg(op, "-ds .1 -dj .7");
1063 >                op = addarg(op, "-ds .1 -dj .9");
1064          else
1065                  op = addarg(op, "-ds .2");
1066 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1066 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1067          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1068          op += strlen(op);
1069          if (vdef(AMBFILE)) {
# Line 1012 | Line 1073 | register char  *op;
1073                  overture = 0;
1074          switch (vscale(VARIABILITY)) {
1075          case LOW:
1076 <                op = addarg(op, "-aa .15 -ad 256 -as 0");
1076 >                op = addarg(op, "-aa .125 -ad 512 -as 64");
1077                  break;
1078          case MEDIUM:
1079 <                op = addarg(op, "-aa .125 -ad 512 -as 256");
1079 >                op = addarg(op, "-aa .1 -ad 1536 -as 768");
1080                  break;
1081          case HIGH:
1082 <                op = addarg(op, "-aa .08 -ad 1024 -as 512");
1082 >                op = addarg(op, "-aa .075 -ad 4096 -as 2048");
1083                  break;
1084          }
1085          d = ambval();
1086          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1087          op += strlen(op);
1088 <        op = addarg(op, "-lr 12 -lw .0005");
1028 <        if (vdef(RENDER))
1029 <                op = addarg(op, vval(RENDER));
1088 >        op = addarg(op, "-lr 12 -lw 5e-6");
1089   }
1090  
1091  
1092 < xferopts(ro)                            /* transfer options if indicated */
1093 < char    *ro;
1092 > #if defined(_WIN32) || defined(_WIN64)
1093 > static void
1094 > setenv(                 /* set an environment variable */
1095 >        char    *vname,
1096 >        char    *value
1097 > )
1098   {
1099 +        char    *evp;
1100 +
1101 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1102 +        if (evp == NULL)
1103 +                syserr(progname);
1104 +        sprintf(evp, "%s=%s", vname, value);
1105 +        if (putenv(evp) != 0) {
1106 +                fprintf(stderr, "%s: out of environment space\n", progname);
1107 +                quit(1);
1108 +        }
1109 +        if (!silent)
1110 +                printf("set %s\n", evp);
1111 + }
1112 + #endif
1113 +
1114 +
1115 + static void
1116 + xferopts(                               /* transfer options if indicated */
1117 +        char    *ro
1118 + )
1119 + {
1120          int     fd, n;
1121 <        register char   *cp;
1121 >        char    *cp;
1122          
1123          n = strlen(ro);
1124          if (n < 2)
1125                  return;
1126          if (vdef(OPTFILE)) {
1127                  for (cp = ro; cp[1]; cp++)
1128 <                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1128 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
1129 >                                        (cp[2] == '-' && isalpha(cp[3]))))
1130                                  *cp = '\n';
1131                          else
1132                                  *cp = cp[1];
# Line 1051 | Line 1136 | char   *ro;
1136                          syserr(vval(OPTFILE));
1137                  sprintf(ro, " @%s", vval(OPTFILE));
1138          }
1139 < #ifdef MSDOS
1139 > #if defined(_WIN32) || defined(_WIN64)
1140          else if (n > 50) {
1141                  setenv("ROPT", ro+1);
1142                  strcpy(ro, " $ROPT");
# Line 1060 | Line 1145 | char   *ro;
1145   }
1146  
1147  
1148 < pfiltopts(po)                           /* get pfilt options */
1149 < register char   *po;
1148 > static void
1149 > pfiltopts(                              /* get pfilt options */
1150 >        char    *po
1151 > )
1152   {
1153          *po = '\0';
1154          if (vdef(EXPOSURE)) {
# Line 1070 | Line 1157 | register char  *po;
1157          }
1158          switch (vscale(QUALITY)) {
1159          case MEDIUM:
1160 <                po = addarg(po, "-r 1");
1160 >                po = addarg(po, "-r .6");
1161                  break;
1162          case HIGH:
1163                  po = addarg(po, "-m .25");
1164                  break;
1165          }
1166 <        if (vdef(PFILT))
1167 <                po = addarg(po, vval(PFILT));
1166 >        if (vdef(PFILT)) {
1167 >                if (vval(PFILT)[0] != '-') {
1168 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1169 >                        po = addarg(po, sskip2(vval(PFILT), 1));
1170 >                } else
1171 >                        po = addarg(po, vval(PFILT));
1172 >        }
1173   }
1174  
1175  
1176 < matchword(s1, s2)                       /* match white-delimited words */
1177 < register char   *s1, *s2;
1176 > static int
1177 > matchword(                      /* match white-delimited words */
1178 >        char    *s1,
1179 >        char    *s2
1180 > )
1181   {
1182          while (isspace(*s1)) s1++;
1183          while (isspace(*s2)) s2++;
# Line 1093 | Line 1188 | register char  *s1, *s2;
1188   }
1189  
1190  
1191 < char *
1192 < specview(vs)                            /* get proper view spec from vs */
1193 < register char   *vs;
1191 > static char *
1192 > specview(                               /* get proper view spec from vs */
1193 >        char    *vs
1194 > )
1195   {
1196          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1197                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1198          static char     viewopts[128];
1199 <        register char   *cp;
1199 >        char    *cp;
1200          int     xpos, ypos, zpos, viewtype, upax;
1201 <        register int    i;
1201 >        int     i;
1202          double  cent[3], dim[3], mult, d;
1203  
1204          if (vs == NULL || *vs == '-')
# Line 1113 | Line 1209 | register char  *vs;
1209                          upax = 1-'X'+UPPER(vval(UP)[1]);
1210                  else
1211                          upax = 1-'X'+vlet(UP);
1212 <                if (upax < 1 | upax > 3)
1212 >                if ((upax < 1) | (upax > 3))
1213                          badvalue(UP);
1214                  if (vval(UP)[0] == '-')
1215                          upax = -upax;
# Line 1135 | Line 1231 | register char  *vs;
1231          } else if (*vs == 'z') {
1232                  zpos = -1; vs++;
1233          }
1234 <        viewtype = 'v';
1235 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1234 >        switch (*vs) {
1235 >        case VT_PER:
1236 >        case VT_PAR:
1237 >        case VT_ANG:
1238 >        case VT_HEM:
1239 >        case VT_PLS:
1240 >        case VT_CYL:
1241                  viewtype = *vs++;
1242 +                break;
1243 +        default:
1244 +                viewtype = VT_PER;
1245 +                break;
1246 +        }
1247          cp = viewopts;
1248          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1249                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 1147 | Line 1253 | register char  *vs;
1253                          badvalue(ZONE);
1254                  for (i = 0; i < 3; i++) {
1255                          dim[i] -= cent[i];
1256 +                        if (dim[i] <= FTINY)
1257 +                                badvalue(ZONE);
1258                          cent[i] += .5*dim[i];
1259                  }
1260                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1261 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1261 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1262                                  cent[0]+xpos*mult*dim[0],
1263                                  cent[1]+ypos*mult*dim[1],
1264                                  cent[2]+zpos*mult*dim[2],
# Line 1177 | Line 1285 | register char  *vs;
1285                  }
1286                  cp = addarg(cp, vup[upax+3]);
1287                  switch (viewtype) {
1288 <                case 'v':
1288 >                case VT_PER:
1289                          cp = addarg(cp, "-vh 45 -vv 45");
1290                          break;
1291 <                case 'l':
1291 >                case VT_PAR:
1292                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1293 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1293 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1294                          cp += strlen(cp);
1295                          break;
1296 <                case 'a':
1297 <                case 'h':
1296 >                case VT_ANG:
1297 >                case VT_HEM:
1298 >                case VT_PLS:
1299                          cp = addarg(cp, "-vh 180 -vv 180");
1300                          break;
1301 +                case VT_CYL:
1302 +                        cp = addarg(cp, "-vh 180 -vv 90");
1303 +                        break;
1304                  }
1305          } else {
1306                  while (!isspace(*vs))           /* else skip id */
1307                          if (!*vs++)
1308                                  return(NULL);
1309 <                if (upax) {                     /* specify up vector */
1309 >                if (upax) {                     /* prepend up vector */
1310                          strcpy(cp, vup[upax+3]);
1311                          cp += strlen(cp);
1312                  }
# Line 1202 | Line 1314 | register char  *vs;
1314          if (cp == viewopts)             /* append any additional options */
1315                  vs++;           /* skip prefixed space if unneeded */
1316          strcpy(cp, vs);
1317 < #ifdef MSDOS
1317 > #if defined(_WIN32) || defined(_WIN64)
1318          if (strlen(viewopts) > 40) {
1319                  setenv("VIEW", viewopts);
1320                  return("$VIEW");
# Line 1212 | Line 1324 | register char  *vs;
1324   }
1325  
1326  
1327 < char *
1328 < getview(n, vn)                          /* get view n, or NULL if none */
1329 < int     n;
1330 < char    *vn;            /* returned view name */
1327 > static char *
1328 > getview(                                /* get view n, or NULL if none */
1329 >        int     n,
1330 >        char    *vn             /* returned view name */
1331 > )
1332   {
1333 <        register char   *mv;
1333 >        char    *mv;
1334  
1335          if (viewselect != NULL) {               /* command-line selected */
1336                  if (n)                          /* only do one */
1337                          return(NULL);
1338 +                                        
1339 +                if (isint(viewselect)) {        /* view number? */
1340 +                        n = atoi(viewselect)-1;
1341 +                        goto numview;
1342 +                }
1343                  if (viewselect[0] == '-') {     /* already specified */
1344 <                        if (vn != NULL) *vn = '\0';
1344 >                        if (vn != NULL)
1345 >                                strcpy(vn, "0");
1346                          return(viewselect);
1347                  }
1348                  if (vn != NULL) {
# Line 1232 | Line 1351 | char   *vn;            /* returned view name */
1351                                  ;
1352                          *vn = '\0';
1353                  }
1235                                                /* view number? */
1236                if (isint(viewselect))
1237                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1354                                                  /* check list */
1355 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1355 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1356                          if (matchword(viewselect, mv))
1357                                  return(specview(mv));
1358 +
1359                  return(specview(viewselect));   /* standard view? */
1360          }
1361 <        mv = nvalue(vv+VIEW, n);                /* use view n */
1362 <        if (vn != NULL & mv != NULL) {
1363 <                register char   *mv2 = mv;
1364 <                if (*mv2 != '-')
1361 > numview:
1362 >        mv = nvalue(VIEWS, n);          /* use view n */
1363 >        if ((vn != NULL) & (mv != NULL)) {
1364 >                if (*mv != '-') {
1365 >                        char    *mv2 = mv;
1366                          while (*mv2 && !isspace(*mv2))
1367                                  *vn++ = *mv2++;
1368 <                *vn = '\0';
1368 >                        *vn = '\0';
1369 >                } else
1370 >                        sprintf(vn, "%d", n+1);
1371          }
1372          return(specview(mv));
1373   }
1374  
1375  
1376 < printview(vopts)                        /* print out selected view */
1377 < register char   *vopts;
1376 > static int
1377 > myprintview(                    /* print out selected view */
1378 >        char    *vopts,
1379 >        FILE    *fp
1380 > )
1381   {
1382 <        extern char     *atos(), *getenv();
1383 <        char    buf[256];
1384 <        FILE    *fp;
1385 <        register char   *cp;
1386 <
1382 >        VIEW    vwr;
1383 >        char    buf[128];
1384 >        char    *cp;
1385 > #if defined(_WIN32) || defined(_WIN64)
1386 > /* XXX Should we allow something like this for all platforms? */
1387 > /* XXX Or is it still required at all? */
1388 > again:
1389 > #endif
1390          if (vopts == NULL)
1391                  return(-1);
1392 <        fputs("VIEW=", stdout);
1393 <        do {
1394 <                if (matchword(vopts, "-vf")) {          /* expand view file */
1395 <                        vopts = sskip(vopts);
1396 <                        if (!*atos(buf, sizeof(buf), vopts))
1271 <                                return(-1);
1272 <                        if ((fp = fopen(buf, "r")) == NULL)
1273 <                                return(-1);
1274 <                        for (buf[sizeof(buf)-2] = '\n';
1275 <                                        fgets(buf, sizeof(buf), fp) != NULL &&
1276 <                                                buf[0] != '\n';
1277 <                                        buf[sizeof(buf)-2] = '\n') {
1278 <                                if (buf[sizeof(buf)-2] != '\n') {
1279 <                                        ungetc(buf[sizeof(buf)-2], fp);
1280 <                                        buf[sizeof(buf)-2] = '\0';
1281 <                                }
1282 <                                if (matchword(buf, "VIEW=") ||
1283 <                                                matchword(buf, "rview")) {
1284 <                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1285 <                                                putchar(*cp);
1286 <                                }
1287 <                        }
1288 <                        fclose(fp);
1289 <                        vopts = sskip(vopts);
1290 <                } else {
1291 <                        while (isspace(*vopts))
1292 <                                vopts++;
1293 <                        putchar(' ');
1294 < #ifdef MSDOS
1295 <                        if (*vopts == '$') {            /* expand env. var. */
1296 <                                if (!*atos(buf, sizeof(buf), vopts+1))
1297 <                                        return(-1);
1298 <                                if ((cp = getenv(buf)) == NULL)
1299 <                                        return(-1);
1300 <                                fputs(cp, stdout);
1301 <                                vopts = sskip(vopts);
1302 <                        } else
1392 > #if defined(_WIN32) || defined(_WIN64)
1393 >        if (vopts[0] == '$') {
1394 >                vopts = getenv(vopts+1);
1395 >                goto again;
1396 >        }
1397   #endif
1398 <                                while (*vopts && !isspace(*vopts))
1399 <                                        putchar(*vopts++);
1400 <                }
1401 <        } while (*vopts++);
1402 <        putchar('\n');
1398 >        vwr = stdview;
1399 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1400 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1401 >                        *atos(buf, sizeof(buf), cp += 4)) {
1402 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1403 >                sscanview(&vwr, cp);            /* reset tail */
1404 >        }
1405 >        fputs(VIEWSTR, fp);
1406 >        fprintview(&vwr, fp);                   /* print full spec. */
1407 >        fputc('\n', fp);
1408          return(0);
1409   }
1410  
1411  
1412 < rview(opts)                             /* run rview with first view */
1413 < char    *opts;
1412 > static void
1413 > rvu(                            /* run rvu with first view */
1414 >        char    *opts,
1415 >        char    *po
1416 > )
1417   {
1418          char    *vw;
1419 <        char    combuf[512];
1419 >        char    combuf[R_CMDMAX];
1420                                          /* build command */
1421 <        if ((vw = getview(0, NULL)) == NULL)
1421 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1422                  return;
1423          if (sayview)
1424 <                printview(vw);
1425 <        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1424 >                myprintview(vw, stdout);
1425 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1426 >        if (nprocs > 1)
1427 >                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1428          if (rvdevice != NULL)
1429                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1430          if (vdef(EXPOSURE))
1431                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1432          strcat(combuf, oct1name);
1433          if (runcom(combuf)) {           /* run it */
1434 <                fprintf(stderr, "%s: error running rview\n", progname);
1435 <                exit(1);
1434 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1435 >                quit(1);
1436          }
1437   }
1438  
1439  
1440 < rpict(opts)                             /* run rpict and pfilt for each view */
1441 < char    *opts;
1440 > static int
1441 > syncf_done(                     /* check if an rpiece sync file is complete */
1442 >        char *sfname
1443 > )
1444   {
1445 <        char    combuf[1024];
1446 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1445 >        FILE    *fp = fopen(sfname, "r");
1446 >        int     todo = 1;
1447 >        int     x, y;
1448 >
1449 >        if (fp == NULL)
1450 >                return(0);
1451 >        if (fscanf(fp, "%d %d", &x, &y) != 2)
1452 >                goto checked;
1453 >        todo = x*y;             /* total number of tiles */
1454 >        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1455 >                goto checked;
1456 >                                /* XXX assume no redundant tiles */
1457 >        while (fscanf(fp, "%d %d", &x, &y) == 2)
1458 >                if (!--todo)
1459 >                        break;
1460 > checked:
1461 >        fclose(fp);
1462 >        return(!todo);
1463 > }
1464 >
1465 >
1466 > static void
1467 > rpict(                          /* run rpict and pfilt for each view */
1468 >        char    *opts,
1469 >        char    *po
1470 > )
1471 > {
1472 > #define do_rpiece       (sfile[0]!='\0')
1473 >        char    combuf[5*PATH_MAX+512];
1474 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1475 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1476 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1477          char    pfopts[128];
1478          char    vs[32], *vw;
1479          int     vn, mult;
1480 +        FILE    *fp;
1481 +        time_t  rfdt, pfdt;
1482 +        int     xres, yres;
1483 +        double  aspect;
1484 +        int     n;
1485                                          /* get pfilt options */
1486          pfiltopts(pfopts);
1487                                          /* get resolution, reporting */
# Line 1355 | Line 1496 | char   *opts;
1496                  mult = 3;
1497                  break;
1498          }
1499 <        {
1500 <                int     xres, yres;
1501 <                double  aspect;
1502 <                int     n;
1503 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1504 <                if (n == 3)
1505 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1506 <                                        mult*xres, mult*yres, aspect);
1507 <                else if (n) {
1508 <                        if (n == 1) yres = xres;
1368 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1369 <                } else
1370 <                        badvalue(RESOLUTION);
1371 <        }
1499 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1500 >        if (n == 3)
1501 >                sprintf(res, "-x %d -y %d -pa %.3f",
1502 >                                mult*xres, mult*yres, aspect);
1503 >        else if (n) {
1504 >                aspect = 1.;
1505 >                if (n == 1) yres = xres;
1506 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1507 >        } else
1508 >                badvalue(RESOLUTION);
1509          rep[0] = '\0';
1510          if (vdef(REPORT)) {
1511                  double  minutes;
1375                int     n;
1512                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1513                  if (n == 2)
1514                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1381 | Line 1517 | char   *opts;
1517                  else
1518                          badvalue(REPORT);
1519          }
1520 <                                        /* do each view */
1521 <        vn = 0;
1520 >                                        /* set up parallel rendering */
1521 >        sfile[0] = '\0';
1522 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1523 >                                        getview(0, vs) != NULL) {
1524 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1525 >                                getview(1, NULL) == NULL) {
1526 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1527 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1528 >                                        vs);
1529 >                        strcpy(rppopt, "-PP pfXXXXXX");
1530 >                } else {
1531 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1532 >                }
1533 >                pfile = rppopt + strlen(rppopt) - 8;
1534 >                if (mktemp(pfile) == NULL) {
1535 >                        if (do_rpiece) {
1536 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1537 >                                quit(1);
1538 >                        }
1539 >                        pfile[-5] = '\0';
1540 >                        pfile = NULL;
1541 >                }
1542 >        }
1543 >        vn = 0;                                 /* do each view */
1544          while ((vw = getview(vn++, vs)) != NULL) {
1545                  if (sayview)
1546 <                        printview(vw);
1547 <                if (!vs[0])
1548 <                        sprintf(vs, "%d", vn);
1549 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1546 >                        myprintview(vw, stdout);
1547 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1548 >                if (vdef(ZFILE))
1549 >                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1550 >                else
1551 >                        zopt[0] = '\0';
1552                                                  /* check date on picture */
1553 <                if (fdate(picfile) >= oct1date)
1553 >                pfdt = fdate(picfile);
1554 >                if (pfdt >= oct1date)
1555                          continue;
1556 +                                                /* get raw file name */
1557 +                sprintf(rawfile, "%s_%s.unf",
1558 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1559 +                rfdt = fdate(rawfile);
1560 +                if (touchonly) {                /* update times only */
1561 +                        if (rfdt) {
1562 +                                if (rfdt < oct1date)
1563 +                                        touch(rawfile);
1564 +                        } else if (pfdt && pfdt < oct1date)
1565 +                                touch(picfile);
1566 +                        continue;
1567 +                }
1568 +                                                /* parallel running? */
1569 +                if (do_rpiece) {
1570 +                        if (rfdt < oct1date || !fdate(sfile)) {
1571 +                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1572 +                                if (rfdt >= oct1date) {
1573 +                                        fprintf(stderr,
1574 +                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1575 +                                        quit(1);
1576 +                                }
1577 +                                if (rfdt) {     /* start fresh */
1578 +                                        rmfile(rawfile);
1579 +                                        rfdt = 0;
1580 +                                }
1581 +                                if (!silent)
1582 +                                        printf("\techo %d %d > %s\n",
1583 +                                                        xdiv, ydiv, sfile);
1584 +                                if ((fp = fopen(sfile, "w")) == NULL) {
1585 +                                        fprintf(stderr, "%s: cannot create\n",
1586 +                                                        sfile);
1587 +                                        quit(1);
1588 +                                }
1589 +                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1590 +                                fclose(fp);
1591 +                        }
1592 +                } else if (next_process(0)) {
1593 +                        if (pfile != NULL)
1594 +                                sleep(10);
1595 +                        continue;
1596 +                } else if (!inchild())
1597 +                        pfile = NULL;
1598 +                /* XXX Remember to call finish_process() */
1599                                                  /* build rpict command */
1600 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1601 <                if (fdate(rawfile) >= oct1date)         /* recover */
1602 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1603 <                                        rep, opts, rawfile, oct1name);
1604 <                else {
1600 >                if (rfdt >= oct1date) {         /* already in progress */
1601 >                        if (do_rpiece) {
1602 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1603 >                                                c_rpiece, sfile, rppopt, rep, vw,
1604 >                                                res, opts, po, rawfile, oct1name);
1605 >                                while (next_process(1)) {
1606 >                                        sleep(10);
1607 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1608 >                                }
1609 >                        } else
1610 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1611 >                                        rep, opts, po, zopt, rawfile, oct1name);
1612 >                        if (runcom(combuf))     /* run rpict/rpiece */
1613 >                                goto rperror;
1614 >                } else {
1615                          if (overture) {         /* run overture calculation */
1616                                  sprintf(combuf,
1617 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1618 <                                                rep, vw, opts,
1617 >                                        "%s%s %s%s%s -x 64 -y 64 -ps 1 %s > %s",
1618 >                                                c_rpict, rep, vw, opts, po,
1619                                                  oct1name, overfile);
1620 <                                if (runcom(combuf)) {
1621 <                                        fprintf(stderr,
1620 >                                if (!do_rpiece || !next_process(0)) {
1621 >                                        if (runcom(combuf)) {
1622 >                                                fprintf(stderr,
1623                                          "%s: error in overture for view %s\n",
1624 <                                                progname, vs);
1625 <                                        exit(1);
1626 <                                }
1627 < #ifdef NIX
1628 <                                rmfile(overfile);
1624 >                                                        progname, vs);
1625 >                                                quit(1);
1626 >                                        }
1627 > #ifndef NULL_DEVICE
1628 >                                        rmfile(overfile);
1629   #endif
1630 +                                } else if (do_rpiece)
1631 +                                        sleep(20);
1632                          }
1633 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1634 <                                        rep, vw, res, opts,
1635 <                                oct1name, rawfile);
1633 >                        if (do_rpiece) {
1634 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1635 >                                                c_rpiece, sfile, rppopt, rep, vw,
1636 >                                                res, opts, po, rawfile, oct1name);
1637 >                                while (next_process(1))
1638 >                                        sleep(10);
1639 >                        } else {
1640 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1641 >                                                c_rpict, rep, vw, res, opts, po,
1642 >                                                zopt, oct1name, rawfile);
1643 >                        }
1644 >                        if ((pfile != NULL) & !do_rpiece) {
1645 >                                if (!silent)
1646 >                                        printf("\t%s\n", combuf);
1647 >                                fflush(stdout);
1648 >                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1649 >                                                c_rpict, rep, rppopt, res,
1650 >                                                opts, po, oct1name, rawfile);
1651 >                                fp = popen(combuf, "w");
1652 >                                if (fp == NULL)
1653 >                                        goto rperror;
1654 >                                myprintview(vw, fp);
1655 >                                if (pclose(fp))
1656 >                                        goto rperror;
1657 >                        } else if (runcom(combuf))
1658 >                                goto rperror;
1659                  }
1660 <                if (runcom(combuf)) {           /* run rpict */
1661 <                        fprintf(stderr, "%s: error rendering view %s\n",
1662 <                                        progname, vs);
1663 <                        exit(1);
1660 >                if (do_rpiece) {                /* need to finish raw, first */
1661 >                        finish_process();
1662 >                        wait_process(1);
1663 >                        if (!syncf_done(sfile)) {
1664 >                                fprintf(stderr,
1665 >                        "%s: %s did not complete rendering of view %s\n",
1666 >                                                progname, c_rpiece, vs);
1667 >                                quit(1);
1668 >                        }
1669                  }
1670 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1671                                                  /* build pfilt command */
1672 <                if (mult > 1)
1673 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1674 <                                        pfopts, mult, mult, rawfile, picfile);
1675 <                else
1430 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1672 >                        if (do_rpiece)
1673 >                                sprintf(combuf,
1674 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1675 >                                        c_pfilt, pfopts, xres, yres, aspect,
1676                                          rawfile, picfile);
1677 <                if (runcom(combuf)) {           /* run pfilt */
1678 <                        fprintf(stderr,
1679 <                        "%s: error filtering view %s\n\t%s removed\n",
1680 <                                        progname, vs, picfile);
1681 <                        unlink(picfile);
1682 <                        exit(1);
1677 >                        else if (mult > 1)
1678 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1679 >                                        c_pfilt, pfopts, mult, mult,
1680 >                                        rawfile, picfile);
1681 >                        else
1682 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1683 >                                        pfopts, rawfile, picfile);
1684 >                        if (runcom(combuf)) {   /* run pfilt */
1685 >                                fprintf(stderr,
1686 >                                "%s: error filtering view %s\n\t%s removed\n",
1687 >                                                progname, vs, picfile);
1688 >                                unlink(picfile);
1689 >                                quit(1);
1690 >                        }
1691                  }
1692 <                                                /* remove raw file */
1693 <                rmfile(rawfile);
1692 >                                                /* remove/rename raw file */
1693 >                if (vdef(RAWFILE)) {
1694 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1695 >                        mvfile(rawfile, combuf);
1696 >                } else
1697 >                        rmfile(rawfile);
1698 >                if (do_rpiece)                  /* done with sync file */
1699 >                        rmfile(sfile);
1700 >                else
1701 >                        finish_process();       /* exit if child */
1702          }
1703 +        wait_process(1);                /* wait for children to finish */
1704 +        if (pfile != NULL) {            /* clean up persistent rpict */
1705 +                RT_PID  pid;
1706 +                fp = fopen(pfile, "r");
1707 +                if (fp != NULL) {
1708 +                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1709 +                                        kill(pid, 1) < 0)
1710 +                                unlink(pfile);
1711 +                        fclose(fp);
1712 +                }
1713 +        }
1714 +        return;
1715 + rperror:
1716 +        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1717 +        quit(1);
1718 + #undef do_rpiece
1719   }
1720  
1721  
1722 < runcom(cs)                      /* run command */
1723 < char    *cs;
1722 > static int
1723 > touch(                  /* update a file */
1724 >        char    *fn
1725 > )
1726   {
1727 +        if (!silent)
1728 +                printf("\ttouch %s\n", fn);
1729 +        if (!nprocs)
1730 +                return(0);
1731 +        return(setfdate(fn, time((time_t *)NULL)));
1732 + }
1733 +
1734 +
1735 + static int
1736 + runcom(                 /* run command */
1737 +        char    *cs
1738 + )
1739 + {
1740          if (!silent)            /* echo it */
1741                  printf("\t%s\n", cs);
1742 <        if (noaction)
1742 >        if (!nprocs)
1743                  return(0);
1744 <        fflush(stdout);         /* flush output and pass to shell */
1744 >        fflush(NULL);           /* flush output and pass to shell */
1745          return(system(cs));
1746   }
1747  
1748  
1749 < rmfile(fn)                      /* remove a file */
1750 < char    *fn;
1749 > static int
1750 > rmfile(                 /* remove a file */
1751 >        char    *fn
1752 > )
1753   {
1754          if (!silent)
1755 < #ifdef MSDOS
1756 <                printf("\tdel %s\n", fn);
1463 < #else
1464 <                printf("\trm -f %s\n", fn);
1465 < #endif
1466 <        if (noaction)
1755 >                printf("\t%s %s\n", DELCMD, fn);
1756 >        if (!nprocs)
1757                  return(0);
1758          return(unlink(fn));
1759   }
1760  
1761  
1762 < #ifdef MSDOS
1763 < setenv(vname, value)            /* set an environment variable */
1764 < char    *vname, *value;
1762 > static int
1763 > mvfile(         /* move a file */
1764 >        char    *fold,
1765 >        char    *fnew
1766 > )
1767   {
1768 <        register char   *evp;
1768 >        if (!silent)
1769 >                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1770 >        if (!nprocs)
1771 >                return(0);
1772 >        return(rename(fold, fnew));
1773 > }
1774  
1775 <        evp = bmalloc(strlen(vname)+strlen(value)+2);
1776 <        if (evp == NULL)
1777 <                syserr(progname);
1778 <        sprintf(evp, "%s=%s", vname, value);
1779 <        if (putenv(evp) != 0) {
1780 <                fprintf(stderr, "%s: out of environment space\n", progname);
1781 <                exit(1);
1775 >
1776 > #ifdef RHAS_FORK_EXEC
1777 > static int
1778 > next_process(int reserve)               /* fork the next process */
1779 > {
1780 >        RT_PID  child_pid;
1781 >
1782 >        if (nprocs <= 1)
1783 >                return(0);              /* it's us or no one */
1784 >        if (inchild()) {
1785 >                fprintf(stderr, "%s: internal error 1 in next_process()\n",
1786 >                                progname);
1787 >                quit(1);
1788          }
1789 <        if (!silent)
1790 <                printf("set %s\n", evp);
1789 >        if (reserve > 0 && children_running >= nprocs-reserve)
1790 >                return(0);              /* caller holding back process(es) */
1791 >        if (children_running >= nprocs)
1792 >                wait_process(0);        /* wait for someone to finish */
1793 >        fflush(NULL);                   /* flush output */
1794 >        child_pid = fork();             /* split process */
1795 >        if (child_pid == 0) {           /* we're the child */
1796 >                children_running = -1;
1797 >                nprocs = 1;
1798 >                return(0);
1799 >        }
1800 >        if (child_pid > 0) {            /* we're the parent */
1801 >                ++children_running;
1802 >                return(1);
1803 >        }
1804 >        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1805 >        return(0);
1806   }
1489 #endif
1807  
1808 + static void
1809 + wait_process(                   /* wait for process(es) to finish */
1810 +        int     all
1811 + )
1812 + {
1813 +        int     ourstatus = 0, status;
1814 +        RT_PID  pid;
1815  
1816 < badvalue(vc)                    /* report bad variable value and exit */
1817 < int     vc;
1816 >        if (all)
1817 >                all = children_running;
1818 >        else if (children_running > 0)
1819 >                all = 1;
1820 >        while (all-- > 0) {
1821 >                pid = wait(&status);
1822 >                if (pid < 0)
1823 >                        syserr(progname);
1824 >                status = status>>8 & 0xff;
1825 >                --children_running;
1826 >                if (status != 0) {      /* child's problem is our problem */
1827 >                        if ((ourstatus == 0) & (children_running > 0))
1828 >                                fprintf(stderr, "%s: waiting for remaining processes\n",
1829 >                                                progname);
1830 >                        ourstatus = status;
1831 >                        all = children_running;
1832 >                }
1833 >        }
1834 >        if (ourstatus != 0)
1835 >                quit(ourstatus);        /* bad status from child */
1836 > }
1837 > #else   /* ! RHAS_FORK_EXEC */
1838 > static int
1839 > next_process(int reserve)
1840   {
1841 +        return(0);                      /* cannot start new process */
1842 + }
1843 + static void
1844 + wait_process(all)
1845 + int     all;
1846 + {
1847 +        (void)all;                      /* no one to wait for */
1848 + }
1849 + int
1850 + kill(pid, sig) /* win|unix_process.c should also wait and kill */
1851 + RT_PID pid;
1852 + int sig;
1853 + {
1854 +        return 0;
1855 + }
1856 + #endif  /* ! RHAS_FORK_EXEC */
1857 +
1858 + static void
1859 + finish_process(void)                    /* exit a child process */
1860 + {
1861 +        if (!inchild())
1862 +                return;                 /* in parent -- noop */
1863 +        exit(0);
1864 + }
1865 +
1866 +
1867 + static void
1868 + badvalue(                       /* report bad variable value and exit */
1869 +        int     vc
1870 + )
1871 + {
1872          fprintf(stderr, "%s: bad value for variable '%s'\n",
1873                          progname, vnam(vc));
1874 <        exit(1);
1874 >        quit(1);
1875   }
1876  
1877  
1878 < syserr(s)                       /* report a system error and exit */
1879 < char    *s;
1878 > static void
1879 > syserr(                 /* report a system error and exit */
1880 >        char    *s
1881 > )
1882   {
1883          perror(s);
1884 <        exit(1);
1884 >        quit(1);
1885 > }
1886 >
1887 >
1888 > void
1889 > quit(ec)                        /* exit program */
1890 > int     ec;
1891 > {
1892 >        exit(ec);
1893   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines