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.53 by greg, Thu Mar 20 12:50:07 1997 UTC vs.
Revision 2.126 by greg, Tue Feb 26 23:31:11 2019 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines