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.27 by greg, Sat Sep 25 13:21:35 1993 UTC vs.
Revision 2.66 by greg, Thu Jul 3 15:00:19 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Executive program for oconv, rpict and pfilt
6   */
7  
8   #include "standard.h"
9 < #include "paths.h"
9 >
10   #include <ctype.h>
11  
12 + #include "platform.h"
13 + #include "view.h"
14 + #include "paths.h"
15 + #include "vars.h"
16  
17 < typedef struct {
18 <        char    *name;          /* variable name */
19 <        short   nick;           /* # characters required for nickname */
20 <        short   nass;           /* # assignments made */
21 <        char    *value;         /* assigned value(s) */
22 <        int     (*fixval)();    /* assignment checking function */
23 < } VARIABLE;
24 <
25 < int     onevalue(), catvalues();
26 <
27 <                                /* variables */
28 < #define OBJECT          0               /* object files */
29 < #define SCENE           1               /* scene files */
30 < #define MATERIAL        2               /* material files */
31 < #define ILLUM           3               /* mkillum input files */
32 < #define MKILLUM         4               /* mkillum options */
33 < #define RENDER          5               /* rendering options */
34 < #define OCONV           6               /* oconv options */
35 < #define PFILT           7               /* pfilt options */
36 < #define VIEW            8               /* view(s) for picture(s) */
37 < #define ZONE            9               /* simulation zone */
38 < #define QUALITY         10              /* desired rendering quality */
39 < #define OCTREE          11              /* octree file name */
40 < #define PICTURE         12              /* picture file name */
41 < #define AMBFILE         13              /* ambient file name */
42 < #define OPTFILE         14              /* rendering options file */
43 < #define EXPOSURE        15              /* picture exposure setting */
43 < #define RESOLUTION      16              /* maximum picture resolution */
44 < #define UP              17              /* view up (X, Y or Z) */
45 < #define INDIRECT        18              /* indirection in lighting */
46 < #define DETAIL          19              /* level of scene detail */
47 < #define PENUMBRAS       20              /* shadow penumbras are desired */
48 < #define VARIABILITY     21              /* level of light variability */
49 < #define REPORT          22              /* report frequency and errfile */
17 >                                /* variables (alphabetical by name) */
18 > #define AMBFILE         0               /* ambient file name */
19 > #define DETAIL          1               /* level of scene detail */
20 > #define EXPOSURE        2               /* picture exposure setting */
21 > #define EYESEP          3               /* interocular distance */
22 > #define ILLUM           4               /* mkillum input files */
23 > #define INDIRECT        5               /* indirection in lighting */
24 > #define MATERIAL        6               /* material files */
25 > #define MKILLUM         7               /* mkillum options */
26 > #define OBJECT          8               /* object files */
27 > #define OCONV           9               /* oconv options */
28 > #define OCTREE          10              /* octree file name */
29 > #define OPTFILE         11              /* rendering options file */
30 > #define PENUMBRAS       12              /* shadow penumbras are desired */
31 > #define PFILT           13              /* pfilt options */
32 > #define PICTURE         14              /* picture file root name */
33 > #define QUALITY         15              /* desired rendering quality */
34 > #define RAWFILE         16              /* raw picture file root name */
35 > #define RENDER          17              /* rendering options */
36 > #define REPORT          18              /* report frequency and errfile */
37 > #define RESOLUTION      19              /* maximum picture resolution */
38 > #define SCENE           20              /* scene files */
39 > #define UP              21              /* view up (X, Y or Z) */
40 > #define VARIABILITY     22              /* level of light variability */
41 > #define VIEWS           23              /* view(s) for picture(s) */
42 > #define ZFILE           24              /* distance file root name */
43 > #define ZONE            25              /* simulation zone */
44                                  /* total number of variables */
45 < #define NVARS           23
45 > int NVARS = 26;
46  
47 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
48 <        {"objects",     3,      0,      NULL,   catvalues},
49 <        {"scene",       3,      0,      NULL,   catvalues},
50 <        {"materials",   3,      0,      NULL,   catvalues},
47 > VARIABLE        vv[] = {                /* variable-value pairs */
48 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
49 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
50 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
51 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
52          {"illum",       3,      0,      NULL,   catvalues},
53 +        {"INDIRECT",    3,      0,      NULL,   intvalue},
54 +        {"materials",   3,      0,      NULL,   catvalues},
55          {"mkillum",     3,      0,      NULL,   catvalues},
56 <        {"render",      3,      0,      NULL,   catvalues},
56 >        {"objects",     3,      0,      NULL,   catvalues},
57          {"oconv",       3,      0,      NULL,   catvalues},
61        {"pfilt",       2,      0,      NULL,   catvalues},
62        {"view",        2,      0,      NULL,   NULL},
63        {"ZONE",        2,      0,      NULL,   onevalue},
64        {"QUALITY",     3,      0,      NULL,   onevalue},
58          {"OCTREE",      3,      0,      NULL,   onevalue},
66        {"PICTURE",     3,      0,      NULL,   onevalue},
67        {"AMBFILE",     3,      0,      NULL,   onevalue},
59          {"OPTFILE",     3,      0,      NULL,   onevalue},
60 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
60 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
61 >        {"pfilt",       2,      0,      NULL,   catvalues},
62 >        {"PICTURE",     3,      0,      NULL,   onevalue},
63 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
64 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
65 >        {"render",      3,      0,      NULL,   catvalues},
66 >        {"REPORT",      3,      0,      NULL,   onevalue},
67          {"RESOLUTION",  3,      0,      NULL,   onevalue},
68 +        {"scene",       3,      0,      NULL,   catvalues},
69          {"UP",          2,      0,      NULL,   onevalue},
70 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
71 <        {"DETAIL",      3,      0,      NULL,   onevalue},
72 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
73 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
76 <        {"REPORT",      3,      0,      NULL,   onevalue},
70 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
71 >        {"view",        2,      0,      NULL,   NULL},
72 >        {"ZFILE",       2,      0,      NULL,   onevalue},
73 >        {"ZONE",        2,      0,      NULL,   onevalue},
74   };
75  
79 VARIABLE        *matchvar();
80 char    *nvalue();
81 int     vscale();
82
83 #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
84
85 #define vnam(vc)        (vv[vc].name)
86 #define vdef(vc)        (vv[vc].nass)
87 #define vval(vc)        (vv[vc].value)
88 #define vint(vc)        atoi(vval(vc))
89 #define vlet(vc)        UPPER(vval(vc)[0])
90 #define vbool(vc)       (vlet(vc)=='T')
91
92 #define HIGH            2
93 #define MEDIUM          1
94 #define LOW             0
95
96 int     lowqopts(), medqopts(), hiqopts();
97 int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
98
99 #define renderopts      (*setqopts[vscale(QUALITY)])
100
76                                  /* overture calculation file */
77 < #ifdef NIX
78 < char    overfile[] = "overture.raw";
77 > #ifdef NULL_DEVICE
78 > char    overfile[] = NULL_DEVICE;
79   #else
80 < char    overfile[] = "/dev/null";
80 > char    overfile[] = "overture.unf";
81   #endif
82  
83 < extern unsigned long    fdate(), time();
83 > extern time_t   time();
84  
85 < unsigned long   scenedate;      /* date of latest scene or object file */
86 < unsigned long   octreedate;     /* date of octree */
87 < unsigned long   matdate;        /* date of latest material file */
88 < unsigned long   illumdate;      /* date of last illum file */
85 > time_t  scenedate;              /* date of latest scene or object file */
86 > time_t  octreedate;             /* date of octree */
87 > time_t  matdate;                /* date of latest material file */
88 > time_t  illumdate;              /* date of last illum file */
89  
90   char    *oct0name;              /* name of pre-mkillum octree */
91 < unsigned long   oct0date;       /* date of pre-mkillum octree */
91 > time_t  oct0date;               /* date of pre-mkillum octree */
92   char    *oct1name;              /* name of post-mkillum octree */
93 < unsigned long   oct1date;       /* date of post-mkillum octree (>= matdate) */
93 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
94  
95 + int     nowarn = 0;             /* no warnings */
96   int     explicate = 0;          /* explicate variables */
97   int     silent = 0;             /* do work silently */
98 < int     noaction = 0;           /* don't do anything */
98 > int     touchonly = 0;          /* touch files only */
99 > int     nprocs = 1;             /* maximum executing processes */
100   int     sayview = 0;            /* print view out */
101   char    *rvdevice = NULL;       /* rview output device */
102   char    *viewselect = NULL;     /* specific view only */
103  
104   int     overture = 0;           /* overture calculation needed */
105  
106 + int     children_running = 0;   /* set negative in children */
107 +
108   char    *progname;              /* global argv[0] */
109   char    *rifname;               /* global rad input file name */
110  
111 < char    radname[MAXPATH];       /* root Radiance file name */
111 > char    radname[PATH_MAX];      /* root Radiance file name */
112  
113  
114   main(argc, argv)
# Line 137 | Line 116 | int    argc;
116   char    *argv[];
117   {
118          char    ropts[512];
119 +        char    popts[64];
120          int     i;
121  
122          progname = argv[0];
# Line 147 | Line 127 | char   *argv[];
127                          silent++;
128                          break;
129                  case 'n':
130 <                        noaction++;
130 >                        nprocs = 0;
131                          break;
132 +                case 'N':
133 +                        nprocs = atoi(argv[++i]);
134 +                        if (nprocs < 0)
135 +                                nprocs = 0;
136 +                        break;
137 +                case 't':
138 +                        touchonly++;
139 +                        break;
140                  case 'e':
141                          explicate++;
142                          break;
# Line 161 | Line 149 | char   *argv[];
149                  case 'v':
150                          viewselect = argv[++i];
151                          break;
152 +                case 'w':
153 +                        nowarn++;
154 +                        break;
155                  default:
156                          goto userr;
157                  }
# Line 170 | Line 161 | char   *argv[];
161                                  /* assign Radiance root file name */
162          rootname(radname, rifname);
163                                  /* load variable values */
164 <        load(rifname);
164 >        loadvars(rifname);
165                                  /* get any additional assignments */
166          for (i++; i < argc; i++)
167 <                setvariable(argv[i]);
167 >                if (setvariable(argv[i], matchvar) < 0) {
168 >                        fprintf(stderr, "%s: unknown variable: %s\n",
169 >                                        progname, argv[i]);
170 >                        quit(1);
171 >                }
172                                  /* check assignments */
173          checkvalues();
174                                  /* check files and dates */
# Line 182 | Line 177 | char   *argv[];
177          setdefaults();
178                                  /* print all values if requested */
179          if (explicate)
180 <                printvals();
180 >                printvars(stdout);
181                                  /* build octree (and run mkillum) */
182          oconv();
183                                  /* check date on ambient file */
184          checkambfile();
185                                  /* run simulation */
186 <        renderopts(ropts);
186 >        renderopts(ropts, popts);
187          xferopts(ropts);
188          if (rvdevice != NULL)
189 <                rview(ropts);
189 >                rview(ropts, popts);
190          else
191 <                rpict(ropts);
192 <        exit(0);
191 >                rpict(ropts, popts);
192 >        quit(0);
193   userr:
194          fprintf(stderr,
195 <        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
195 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
196                          progname);
197 <        exit(1);
197 >        quit(1);
198   }
199  
200  
# Line 218 | Line 213 | register char  *rn, *fn;
213   }
214  
215  
216 < #define NOCHAR  127             /* constant for character to delete */
222 <
223 <
224 < load(rfname)                    /* load Radiance simulation file */
225 < char    *rfname;
226 < {
227 <        FILE    *fp;
228 <        char    buf[512];
229 <        register char   *cp;
230 <
231 <        if (rfname == NULL)
232 <                fp = stdin;
233 <        else if ((fp = fopen(rfname, "r")) == NULL)
234 <                syserr(rfname);
235 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
236 <                for (cp = buf; *cp; cp++) {
237 <                        switch (*cp) {
238 <                        case '\\':
239 <                                *cp++ = NOCHAR;
240 <                                continue;
241 <                        case '#':
242 <                                *cp = '\0';
243 <                                break;
244 <                        default:
245 <                                continue;
246 <                        }
247 <                        break;
248 <                }
249 <                setvariable(buf);
250 <        }
251 <        fclose(fp);
252 < }
253 <
254 <
255 < setvariable(ass)                /* assign variable according to string */
256 < register char   *ass;
257 < {
258 <        char    varname[32];
259 <        char    varval[512];
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) {
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 < int
352 < vscale(vc)                      /* return scale for variable vc */
353 < int     vc;
354 < {
355 <        switch(vlet(vc)) {
356 <        case 'H':
357 <                return(HIGH);
358 <        case 'M':
359 <                return(MEDIUM);
360 <        case 'L':
361 <                return(LOW);
362 <        }
363 <        badvalue(vc);
364 < }
365 <
366 <
367 < checkvalues()                   /* check assignments */
368 < {
369 <        register int    i;
370 <
371 <        for (i = 0; i < NVARS; i++)
372 <                if (vv[i].fixval != NULL)
373 <                        (*vv[i].fixval)(vv+i);
374 < }
375 <
376 <
377 < onevalue(vp)                    /* only one assignment for this variable */
378 < register VARIABLE       *vp;
379 < {
380 <        if (vp->nass < 2)
381 <                return;
382 <        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
383 <                        progname, vp->name);
384 <        do
385 <                vp->value += strlen(vp->value)+1;
386 <        while (--vp->nass > 1);
387 < }
388 <
389 <
390 < catvalues(vp)                   /* concatenate variable values */
391 < register VARIABLE       *vp;
392 < {
393 <        register char   *cp;
394 <
395 <        if (vp->nass < 2)
396 <                return;
397 <        for (cp = vp->value; vp->nass > 1; vp->nass--) {
398 <                while (*cp)
399 <                        cp++;
400 <                *cp++ = ' ';
401 <        }
402 < }
403 <
404 <
405 < unsigned long
216 > time_t
217   checklast(fnames)                       /* check files and find most recent */
218   register char   *fnames;
219   {
220 <        char    thisfile[MAXPATH];
221 <        unsigned long   thisdate, lastdate = 0;
411 <        register char   *cp;
220 >        char    thisfile[PATH_MAX];
221 >        time_t  thisdate, lastdate = 0;
222  
223          if (fnames == NULL)
224                  return(0);
225 <        while (*fnames) {
226 <                while (isspace(*fnames)) fnames++;
227 <                cp = thisfile;
228 <                while (*fnames && !isspace(*fnames))
419 <                        *cp++ = *fnames++;
420 <                *cp = '\0';
225 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
226 >                if (thisfile[0] == '!' ||
227 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
228 >                        continue;
229                  if (!(thisdate = fdate(thisfile)))
230                          syserr(thisfile);
231                  if (thisdate > lastdate)
# Line 432 | Line 240 | newfname(orig, pred)           /* create modified file name */
240   char    *orig;
241   int     pred;
242   {
435        extern char     *rindex();
243          register char   *cp;
244          register int    n;
245          int     suffix;
# Line 455 | Line 262 | int    pred;
262  
263   checkfiles()                    /* check for existence and modified times */
264   {
265 <        unsigned long   objdate;
265 >        time_t  objdate;
266  
267          if (!vdef(OCTREE)) {
268                  if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
269                          syserr(progname);
270                  sprintf(vval(OCTREE), "%s.oct", radname);
271                  vdef(OCTREE)++;
272 +        } else if (vval(OCTREE)[0] == '!') {
273 +                fprintf(stderr, "%s: illegal '%s' specification\n",
274 +                                progname, vnam(OCTREE));
275 +                quit(1);
276          }
277          octreedate = fdate(vval(OCTREE));
278          if (vdef(ILLUM)) {              /* illum requires secondary octrees */
# Line 478 | Line 289 | checkfiles()                   /* check for existence and modified tim
289          if (!octreedate & !scenedate & !illumdate) {
290                  fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
291                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
292 <                exit(1);
292 >                quit(1);
293          }
294          matdate = checklast(vval(MATERIAL));
295   }      
# Line 490 | Line 301 | double org[3], *sizp;
301          extern FILE     *popen();
302          static double   oorg[3], osiz = 0.;
303          double  min[3], max[3];
304 <        char    buf[512];
304 >        char    buf[1024];
305          FILE    *fp;
306          register int    i;
307  
308          if (osiz <= FTINY)
309 <                if (noaction && fdate(oct1name) <
309 >                if (!nprocs && fdate(oct1name) <
310                                  (scenedate>illumdate?scenedate:illumdate)) {
311                                                          /* run getbbox */
312                          sprintf(buf, "getbbox -w -h %s",
# Line 508 | Line 319 | double org[3], *sizp;
319                                  fprintf(stderr,
320                          "%s: error reading bounding box from getbbox\n",
321                                                  progname);
322 <                                exit(1);
322 >                                quit(1);
323                          }
324                          for (i = 0; i < 3; i++)
325                                  if (max[i] - min[i] > osiz)
# Line 526 | Line 337 | double org[3], *sizp;
337                                  fprintf(stderr,
338                          "%s: error reading bounding cube from getinfo\n",
339                                                  progname);
340 <                                exit(1);
340 >                                quit(1);
341                          }
342                          pclose(fp);
343                  }
# Line 536 | Line 347 | double org[3], *sizp;
347  
348   setdefaults()                   /* set default values for unassigned var's */
349   {
350 <        double  org[3], size;
350 >        double  org[3], lim[3], size;
351          char    buf[128];
352  
353          if (!vdef(ZONE)) {
# Line 546 | Line 357 | setdefaults()                  /* set default values for unassigned v
357                  vval(ZONE) = savqstr(buf);
358                  vdef(ZONE)++;
359          }
360 +        if (!vdef(EYESEP)) {
361 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
362 +                                &org[0], &lim[0], &org[1], &lim[1],
363 +                                &org[2], &lim[2]) != 6)
364 +                        badvalue(ZONE);
365 +                sprintf(buf, "%f",
366 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
367 +                vval(EYESEP) = savqstr(buf);
368 +                vdef(EYESEP)++;
369 +        }
370          if (!vdef(INDIRECT)) {
371                  vval(INDIRECT) = "0";
372                  vdef(INDIRECT)++;
# Line 562 | Line 383 | setdefaults()                  /* set default values for unassigned v
383                  vval(PICTURE) = radname;
384                  vdef(PICTURE)++;
385          }
386 <        if (!vdef(VIEW)) {
387 <                vval(VIEW) = "X";
388 <                vdef(VIEW)++;
386 >        if (!vdef(VIEWS)) {
387 >                vval(VIEWS) = "X";
388 >                vdef(VIEWS)++;
389          }
390          if (!vdef(DETAIL)) {
391                  vval(DETAIL) = "M";
# Line 581 | Line 402 | setdefaults()                  /* set default values for unassigned v
402   }
403  
404  
584 printvals()                     /* print variable values */
585 {
586        register int    i, j;
587
588        for (i = 0; i < NVARS; i++)
589                for (j = 0; j < vdef(i); j++)
590                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
591        fflush(stdout);
592 }
593
594
405   oconv()                         /* run oconv and mkillum if necessary */
406   {
407          static char     illumtmp[] = "ilXXXXXX";
408 <        char    combuf[512], ocopts[64], mkopts[64];
408 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
409  
410          oconvopts(ocopts);              /* get options */
411          if (octreedate < scenedate) {   /* check date on original octree */
412 <                                                /* build command */
413 <                if (vdef(MATERIAL))
414 <                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
415 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
416 <                else
417 <                        sprintf(combuf, "oconv%s %s > %s", ocopts,
418 <                                        vval(SCENE), vval(OCTREE));
419 <                
420 <                if (runcom(combuf)) {           /* run it */
421 <                        fprintf(stderr,
412 >                if (touchonly && octreedate)
413 >                        touch(vval(OCTREE));
414 >                else {                          /* build command */
415 >                        if (vdef(MATERIAL))
416 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
417 >                                                vval(MATERIAL), vval(SCENE),
418 >                                                vval(OCTREE));
419 >                        else
420 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
421 >                                                vval(SCENE), vval(OCTREE));
422 >                        
423 >                        if (runcom(combuf)) {           /* run it */
424 >                                fprintf(stderr,
425                                  "%s: error generating octree\n\t%s removed\n",
426 <                                        progname, vval(OCTREE));
427 <                        unlink(vval(OCTREE));
428 <                        exit(1);
426 >                                                progname, vval(OCTREE));
427 >                                unlink(vval(OCTREE));
428 >                                quit(1);
429 >                        }
430                  }
431 <                octreedate = time(0);
431 >                octreedate = time((time_t *)NULL);
432 >                if (octreedate < scenedate)     /* in case clock is off */
433 >                        octreedate = scenedate;
434          }
435          if (oct1name == vval(OCTREE))           /* no mkillum? */
436                  oct1date = octreedate > matdate ? octreedate : matdate;
# Line 623 | Line 439 | oconv()                                /* run oconv and mkillum if necessary */
439                  return;
440                                                  /* make octree0 */
441          if (oct0date < scenedate | oct0date < illumdate) {
442 <                                                /* build command */
442 >                if (touchonly && oct0date)
443 >                        touch(oct0name);
444 >                else {                          /* build command */
445 >                        if (octreedate)
446 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
447 >                                        vval(OCTREE), vval(ILLUM), oct0name);
448 >                        else if (vdef(MATERIAL))
449 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
450 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
451 >                        else
452 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
453 >                                        vval(ILLUM), oct0name);
454 >                        if (runcom(combuf)) {           /* run it */
455 >                                fprintf(stderr,
456 >                                "%s: error generating octree\n\t%s removed\n",
457 >                                                progname, oct0name);
458 >                                unlink(oct0name);
459 >                                quit(1);
460 >                        }
461 >                }
462 >                oct0date = time((time_t *)NULL);
463 >                if (oct0date < octreedate)      /* in case clock is off */
464 >                        oct0date = octreedate;
465 >                if (oct0date < illumdate)       /* ditto */
466 >                        oct0date = illumdate;
467 >                }
468 >        if (touchonly && oct1date)
469 >                touch(oct1name);
470 >        else {
471 >                mkillumopts(mkopts);            /* build mkillum command */
472 >                mktemp(illumtmp);
473 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
474 >                                oct0name, vval(ILLUM), illumtmp);
475 >                if (runcom(combuf)) {                   /* run it */
476 >                        fprintf(stderr, "%s: error running mkillum\n",
477 >                                        progname);
478 >                        unlink(illumtmp);
479 >                        quit(1);
480 >                }
481 >                                                /* make octree1 (frozen) */
482                  if (octreedate)
483 <                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
484 <                                vval(OCTREE), vval(ILLUM), oct0name);
483 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
484 >                                vval(OCTREE), illumtmp, oct1name);
485                  else if (vdef(MATERIAL))
486 <                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
487 <                                vval(MATERIAL), vval(ILLUM), oct0name);
486 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
487 >                                vval(MATERIAL), illumtmp, oct1name);
488                  else
489 <                        sprintf(combuf, "oconv%s %s > %s", ocopts,
490 <                                vval(ILLUM), oct0name);
489 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
490 >                                illumtmp, oct1name);
491                  if (runcom(combuf)) {           /* run it */
492                          fprintf(stderr,
493                                  "%s: error generating octree\n\t%s removed\n",
494 <                                        progname, oct0name);
495 <                        unlink(oct0name);
496 <                        exit(1);
494 >                                        progname, oct1name);
495 >                        unlink(oct1name);
496 >                        unlink(illumtmp);
497 >                        quit(1);
498                  }
499 <                oct0date = time(0);
499 >                rmfile(illumtmp);
500          }
501 <        mkillumopts(mkopts);                    /* build mkillum command */
502 <        mktemp(illumtmp);
503 <        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
648 <                        oct0name, vval(ILLUM), illumtmp);
649 <        if (runcom(combuf)) {                   /* run it */
650 <                fprintf(stderr, "%s: error running mkillum\n", progname);
651 <                unlink(illumtmp);
652 <                exit(1);
653 <        }
654 <                                                /* make octree1 (frozen) */
655 <        if (octreedate)
656 <                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
657 <                        vval(OCTREE), illumtmp, oct1name);
658 <        else if (vdef(MATERIAL))
659 <                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
660 <                        vval(MATERIAL), illumtmp, oct1name);
661 <        else
662 <                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
663 <                        illumtmp, oct1name);
664 <        if (runcom(combuf)) {           /* run it */
665 <                fprintf(stderr,
666 <                        "%s: error generating octree\n\t%s removed\n",
667 <                                progname, oct1name);
668 <                unlink(oct1name);
669 <                exit(1);
670 <        }
671 <        oct1date = time(0);
672 <        rmfile(illumtmp);
501 >        oct1date = time((time_t *)NULL);
502 >        if (oct1date < oct0date)        /* in case clock is off */
503 >                oct1date = oct0date;
504   }
505  
506  
# Line 708 | Line 539 | register char  *mo;
539  
540   checkambfile()                  /* check date on ambient file */
541   {
542 <        unsigned long   afdate;
542 >        time_t  afdate;
543  
544          if (!vdef(AMBFILE))
545                  return;
546          if (!(afdate = fdate(vval(AMBFILE))))
547                  return;
548          if (oct1date > afdate)
549 <                rmfile(vval(AMBFILE));
549 >                if (touchonly)
550 >                        touch(vval(AMBFILE));
551 >                else
552 >                        rmfile(vval(AMBFILE));
553   }
554  
555  
# Line 723 | Line 557 | double
557   ambval()                                /* compute ambient value */
558   {
559          if (vdef(EXPOSURE)) {
726                if (!isflt(vval(EXPOSURE)))
727                        badvalue(EXPOSURE);
560                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
561 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
562 <                return(.5/atof(vval(EXPOSURE)));
561 >                        return(.5/pow(2.,vflt(EXPOSURE)));
562 >                return(.5/vflt(EXPOSURE));
563          }
564          if (vlet(ZONE) == 'E')
565                  return(10.);
# Line 737 | Line 569 | ambval()                               /* compute ambient value */
569   }
570  
571  
572 < lowqopts(op)                            /* low quality rendering options */
572 > renderopts(op, po)                      /* set rendering options */
573 > char    *op, *po;
574 > {
575 >        switch(vscale(QUALITY)) {
576 >        case LOW:
577 >                lowqopts(op, po);
578 >                break;
579 >        case MEDIUM:
580 >                medqopts(op, po);
581 >                break;
582 >        case HIGH:
583 >                hiqopts(op, po);
584 >                break;
585 >        }
586 > }
587 >
588 >
589 > lowqopts(op, po)                        /* low quality rendering options */
590   register char   *op;
591 + char    *po;
592   {
593          double  d, org[3], siz[3];
594  
595          *op = '\0';
596 +        *po = '\0';
597          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
598                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
599                  badvalue(ZONE);
600          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
601 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
602 +                badvalue(ZONE);
603          getoctcube(org, &d);
604          d *= 3./(siz[0]+siz[1]+siz[2]);
605          switch (vscale(DETAIL)) {
606          case LOW:
607 <                op = addarg(op, "-ps 16 -dp 64");
607 >                po = addarg(po, "-ps 16");
608 >                op = addarg(op, "-dp 64");
609                  sprintf(op, " -ar %d", (int)(4*d));
610                  op += strlen(op);
611                  break;
612          case MEDIUM:
613 <                op = addarg(op, "-ps 8 -dp 128");
613 >                po = addarg(po, "-ps 8");
614 >                op = addarg(op, "-dp 128");
615                  sprintf(op, " -ar %d", (int)(8*d));
616                  op += strlen(op);
617                  break;
618          case HIGH:
619 <                op = addarg(op, "-ps 4 -dp 256");
619 >                po = addarg(po, "-ps 4");
620 >                op = addarg(op, "-dp 256");
621                  sprintf(op, " -ar %d", (int)(16*d));
622                  op += strlen(op);
623                  break;
624          }
625 <        op = addarg(op, "-pt .16");
625 >        po = addarg(po, "-pt .16");
626          if (vbool(PENUMBRAS))
627                  op = addarg(op, "-ds .4");
628          else
# Line 798 | Line 654 | register char  *op;
654   }
655  
656  
657 < medqopts(op)                            /* medium quality rendering options */
657 > medqopts(op, po)                        /* medium quality rendering options */
658   register char   *op;
659 + char    *po;
660   {
661 <        double  d, org[3], siz[3];
661 >        double  d, org[3], siz[3], asz;
662  
663          *op = '\0';
664 +        *po = '\0';
665          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
666                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
667                  badvalue(ZONE);
668          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
669 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
670 +                badvalue(ZONE);
671          getoctcube(org, &d);
672 <        d *= 3./(siz[0]+siz[1]+siz[2]);
672 >        asz = (siz[0]+siz[1]+siz[2])/3.;
673 >        d /= asz;
674          switch (vscale(DETAIL)) {
675          case LOW:
676 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
676 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
677                  op = addarg(op, "-dp 256");
678                  sprintf(op, " -ar %d", (int)(8*d));
679                  op += strlen(op);
680 +                sprintf(op, " -ms %.2g", asz/20.);
681 +                op += strlen(op);
682                  break;
683          case MEDIUM:
684 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
684 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
685                  op = addarg(op, "-dp 512");
686                  sprintf(op, " -ar %d", (int)(16*d));
687                  op += strlen(op);
688 +                sprintf(op, " -ms %.2g", asz/40.);
689 +                op += strlen(op);
690                  break;
691          case HIGH:
692 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
692 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
693                  op = addarg(op, "-dp 1024");
694                  sprintf(op, " -ar %d", (int)(32*d));
695                  op += strlen(op);
696 +                sprintf(op, " -ms %.2g", asz/80.);
697 +                op += strlen(op);
698                  break;
699          }
700 <        op = addarg(op, "-pt .08");
700 >        po = addarg(po, "-pt .08");
701          if (vbool(PENUMBRAS))
702 <                op = addarg(op, "-ds .2 -dj .35");
702 >                op = addarg(op, "-ds .2 -dj .5");
703          else
704                  op = addarg(op, "-ds .3");
705          op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
# Line 865 | Line 732 | register char  *op;
732   }
733  
734  
735 < hiqopts(op)                             /* high quality rendering options */
735 > hiqopts(op, po)                         /* high quality rendering options */
736   register char   *op;
737 + char    *po;
738   {
739 <        double  d, org[3], siz[3];
739 >        double  d, org[3], siz[3], asz;
740  
741          *op = '\0';
742 +        *po = '\0';
743          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
744                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
745                  badvalue(ZONE);
746          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
747 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
748 +                badvalue(ZONE);
749          getoctcube(org, &d);
750 <        d *= 3./(siz[0]+siz[1]+siz[2]);
750 >        asz = (siz[0]+siz[1]+siz[2])/3.;
751 >        d /= asz;
752          switch (vscale(DETAIL)) {
753          case LOW:
754 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
754 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
755                  op = addarg(op, "-dp 1024");
756                  sprintf(op, " -ar %d", (int)(16*d));
757                  op += strlen(op);
758 +                sprintf(op, " -ms %.2g", asz/40.);
759 +                op += strlen(op);
760                  break;
761          case MEDIUM:
762 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
762 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
763                  op = addarg(op, "-dp 2048");
764                  sprintf(op, " -ar %d", (int)(32*d));
765                  op += strlen(op);
766 +                sprintf(op, " -ms %.2g", asz/80.);
767 +                op += strlen(op);
768                  break;
769          case HIGH:
770 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
770 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
771                  op = addarg(op, "-dp 4096");
772                  sprintf(op, " -ar %d", (int)(64*d));
773                  op += strlen(op);
774 +                sprintf(op, " -ms %.2g", asz/160.);
775 +                op += strlen(op);
776                  break;
777          }
778 <        op = addarg(op, "-pt .04");
778 >        po = addarg(po, "-pt .04");
779          if (vbool(PENUMBRAS))
780 <                op = addarg(op, "-ds .1 -dj .7");
780 >                op = addarg(op, "-ds .1 -dj .65");
781          else
782                  op = addarg(op, "-ds .2");
783          op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
# Line 941 | Line 819 | char   *ro;
819                  return;
820          if (vdef(OPTFILE)) {
821                  for (cp = ro; cp[1]; cp++)
822 <                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
822 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
823 >                                        (cp[2] == '-' && isalpha(cp[3]))))
824                                  *cp = '\n';
825                          else
826                                  *cp = cp[1];
# Line 951 | Line 830 | char   *ro;
830                          syserr(vval(OPTFILE));
831                  sprintf(ro, " @%s", vval(OPTFILE));
832          }
833 < #ifdef MSDOS
833 > #ifdef _WIN32
834          else if (n > 50) {
835                  setenv("ROPT", ro+1);
836                  strcpy(ro, " $ROPT");
# Line 970 | Line 849 | register char  *po;
849          }
850          switch (vscale(QUALITY)) {
851          case MEDIUM:
852 <                po = addarg(po, "-r 1");
852 >                po = addarg(po, "-r .6");
853                  break;
854          case HIGH:
855                  po = addarg(po, "-m .25");
# Line 1036 | Line 915 | register char  *vs;
915                  zpos = -1; vs++;
916          }
917          viewtype = 'v';
918 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
918 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
919                  viewtype = *vs++;
920          cp = viewopts;
921          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 1047 | Line 926 | register char  *vs;
926                          badvalue(ZONE);
927                  for (i = 0; i < 3; i++) {
928                          dim[i] -= cent[i];
929 +                        if (dim[i] <= FTINY)
930 +                                badvalue(ZONE);
931                          cent[i] += .5*dim[i];
932                  }
933                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
# Line 1089 | Line 970 | register char  *vs;
970                  case 'h':
971                          cp = addarg(cp, "-vh 180 -vv 180");
972                          break;
973 +                case 'c':
974 +                        cp = addarg(cp, "-vh 180 -vv 90");
975 +                        break;
976                  }
977          } else {
978                  while (!isspace(*vs))           /* else skip id */
# Line 1102 | Line 986 | register char  *vs;
986          if (cp == viewopts)             /* append any additional options */
987                  vs++;           /* skip prefixed space if unneeded */
988          strcpy(cp, vs);
989 < #ifdef MSDOS
989 > #ifdef _WIN32
990          if (strlen(viewopts) > 40) {
991                  setenv("VIEW", viewopts);
992                  return("$VIEW");
# Line 1134 | Line 1018 | char   *vn;            /* returned view name */
1018                  }
1019                                                  /* view number? */
1020                  if (isint(viewselect))
1021 <                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1021 >                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1022                                                  /* check list */
1023 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1023 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1024                          if (matchword(viewselect, mv))
1025                                  return(specview(mv));
1026                  return(specview(viewselect));   /* standard view? */
1027          }
1028 <        mv = nvalue(vv+VIEW, n);                /* use view n */
1028 >        mv = nvalue(VIEWS, n);          /* use view n */
1029          if (vn != NULL & mv != NULL) {
1030                  register char   *mv2 = mv;
1031                  if (*mv2 != '-')
# Line 1156 | Line 1040 | char   *vn;            /* returned view name */
1040   printview(vopts)                        /* print out selected view */
1041   register char   *vopts;
1042   {
1043 <        extern char     *atos(), *getenv();
1044 <        char    buf[256];
1161 <        FILE    *fp;
1043 >        VIEW    vwr;
1044 >        char    buf[128];
1045          register char   *cp;
1046 <
1046 > again:
1047          if (vopts == NULL)
1048                  return(-1);
1049 <        fputs("VIEW=", stdout);
1050 <        do {
1051 <                if (matchword(vopts, "-vf")) {          /* expand view file */
1052 <                        vopts = sskip(vopts);
1053 <                        if (!*atos(buf, sizeof(buf), vopts))
1171 <                                return(-1);
1172 <                        if ((fp = fopen(buf, "r")) == NULL)
1173 <                                return(-1);
1174 <                        for (buf[sizeof(buf)-2] = '\n';
1175 <                                        fgets(buf, sizeof(buf), fp) != NULL &&
1176 <                                                buf[0] != '\n';
1177 <                                        buf[sizeof(buf)-2] = '\n') {
1178 <                                if (buf[sizeof(buf)-2] != '\n') {
1179 <                                        ungetc(buf[sizeof(buf)-2], fp);
1180 <                                        buf[sizeof(buf)-2] = '\0';
1181 <                                }
1182 <                                if (matchword(buf, "VIEW=") ||
1183 <                                                matchword(buf, "rview")) {
1184 <                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1185 <                                                putchar(*cp);
1186 <                                }
1187 <                        }
1188 <                        fclose(fp);
1189 <                        vopts = sskip(vopts);
1190 <                } else {
1191 <                        while (isspace(*vopts))
1192 <                                vopts++;
1193 <                        putchar(' ');
1194 < #ifdef MSDOS
1195 <                        if (*vopts == '$') {            /* expand env. var. */
1196 <                                if (!*atos(buf, sizeof(buf), vopts+1))
1197 <                                        return(-1);
1198 <                                if ((cp = getenv(buf)) == NULL)
1199 <                                        return(-1);
1200 <                                fputs(cp, stdout);
1201 <                                vopts = sskip(vopts);
1202 <                        } else
1049 > #ifdef _WIN32
1050 >        if (vopts[0] == '$') {
1051 >                vopts = getenv(vopts+1);
1052 >                goto again;
1053 >        }
1054   #endif
1055 <                                while (*vopts && !isspace(*vopts))
1056 <                                        putchar(*vopts++);
1057 <                }
1058 <        } while (*vopts++);
1059 <        putchar('\n');
1055 >        copystruct(&vwr, &stdview);
1056 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1057 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1058 >                        *atos(buf, sizeof(buf), cp += 4)) {
1059 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1060 >                sscanview(&vwr, cp);            /* reset tail */
1061 >        }
1062 >        fputs(VIEWSTR, stdout);
1063 >        fprintview(&vwr, stdout);               /* print full spec. */
1064 >        fputc('\n', stdout);
1065          return(0);
1066   }
1067  
1068  
1069 < rview(opts)                             /* run rview with first view */
1070 < char    *opts;
1069 > rview(opts, po)                         /* run rview with first view */
1070 > char    *opts, *po;
1071   {
1072          char    *vw;
1073 <        char    combuf[512];
1073 >        char    combuf[PATH_MAX];
1074                                          /* build command */
1075 <        if ((vw = getview(0, NULL)) == NULL)
1075 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1076                  return;
1077          if (sayview)
1078                  printview(vw);
1079 <        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1079 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1080          if (rvdevice != NULL)
1081                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1082 +        if (vdef(EXPOSURE))
1083 +                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1084          strcat(combuf, oct1name);
1085          if (runcom(combuf)) {           /* run it */
1086                  fprintf(stderr, "%s: error running rview\n", progname);
1087 <                exit(1);
1087 >                quit(1);
1088          }
1089   }
1090  
1091  
1092 < rpict(opts)                             /* run rpict and pfilt for each view */
1093 < char    *opts;
1092 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1093 > char    *opts, *po;
1094   {
1095 <        char    combuf[1024];
1096 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1095 >        char    combuf[PATH_MAX];
1096 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1097 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1098          char    pfopts[128];
1099          char    vs[32], *vw;
1100          int     vn, mult;
1101 +        time_t  rfdt, pfdt;
1102                                          /* get pfilt options */
1103          pfiltopts(pfopts);
1104                                          /* get resolution, reporting */
1105 <        mult = vscale(QUALITY)+1;
1105 >        switch (vscale(QUALITY)) {
1106 >        case LOW:
1107 >                mult = 1;
1108 >                break;
1109 >        case MEDIUM:
1110 >                mult = 2;
1111 >                break;
1112 >        case HIGH:
1113 >                mult = 3;
1114 >                break;
1115 >        }
1116          {
1117                  int     xres, yres;
1118                  double  aspect;
# Line 1269 | Line 1139 | char   *opts;
1139                  else
1140                          badvalue(REPORT);
1141          }
1142 <                                        /* do each view */
1273 <        vn = 0;
1142 >        vn = 0;                                 /* do each view */
1143          while ((vw = getview(vn++, vs)) != NULL) {
1144                  if (sayview)
1145                          printview(vw);
1146                  if (!vs[0])
1147                          sprintf(vs, "%d", vn);
1148                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1149 +                if (vdef(ZFILE))
1150 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1151 +                else
1152 +                        zopt[0] = '\0';
1153                                                  /* check date on picture */
1154 <                if (fdate(picfile) >= oct1date)
1154 >                pfdt = fdate(picfile);
1155 >                if (pfdt >= oct1date)
1156                          continue;
1157 +                                                /* get raw file name */
1158 +                sprintf(rawfile, "%s_%s.unf",
1159 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1160 +                rfdt = fdate(rawfile);
1161 +                if (touchonly) {                /* update times only */
1162 +                        if (rfdt) {
1163 +                                if (rfdt < oct1date)
1164 +                                        touch(rawfile);
1165 +                        } else if (pfdt && pfdt < oct1date)
1166 +                                touch(picfile);
1167 +                        continue;
1168 +                }
1169 +                if (next_process())             /* parallel running? */
1170 +                        continue;
1171 +                /* XXX Remember to call finish_process() */
1172                                                  /* build rpict command */
1173 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1174 <                if (fdate(rawfile) >= oct1date)         /* recover */
1175 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1287 <                                        rep, opts, rawfile, oct1name);
1173 >                if (rfdt >= oct1date)           /* recover */
1174 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1175 >                                rep, po, opts, zopt, rawfile, oct1name);
1176                  else {
1177                          if (overture) {         /* run overture calculation */
1178                                  sprintf(combuf,
# Line 1295 | Line 1183 | char   *opts;
1183                                          fprintf(stderr,
1184                                          "%s: error in overture for view %s\n",
1185                                                  progname, vs);
1186 <                                        exit(1);
1186 >                                        quit(1);
1187                                  }
1188 < #ifdef NIX
1188 > #ifndef NULL_DEVICE
1189                                  rmfile(overfile);
1190   #endif
1191                          }
1192 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1193 <                                        rep, vw, res, opts,
1192 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1193 >                                        rep, vw, res, po, opts, zopt,
1194                                          oct1name, rawfile);
1195                  }
1196                  if (runcom(combuf)) {           /* run rpict */
1197                          fprintf(stderr, "%s: error rendering view %s\n",
1198                                          progname, vs);
1199 <                        exit(1);
1199 >                        quit(1);
1200                  }
1201 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1202                                                  /* build pfilt command */
1203 <                if (mult > 1)
1204 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1203 >                        if (mult > 1)
1204 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1205                                          pfopts, mult, mult, rawfile, picfile);
1206 <                else
1207 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 <                                        rawfile, picfile);
1209 <                if (runcom(combuf)) {           /* run pfilt */
1210 <                        fprintf(stderr,
1211 <                        "%s: error filtering view %s\n\t%s removed\n",
1212 <                                        progname, vs, picfile);
1213 <                        unlink(picfile);
1214 <                        exit(1);
1206 >                        else
1207 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 >                                                rawfile, picfile);
1209 >                        if (runcom(combuf)) {           /* run pfilt */
1210 >                                fprintf(stderr,
1211 >                                "%s: error filtering view %s\n\t%s removed\n",
1212 >                                                progname, vs, picfile);
1213 >                                unlink(picfile);
1214 >                                quit(1);
1215 >                        }
1216                  }
1217 <                                                /* remove raw file */
1218 <                rmfile(rawfile);
1217 >                                                /* remove/rename raw file */
1218 >                if (vdef(RAWFILE)) {
1219 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1220 >                        mvfile(rawfile, combuf);
1221 >                } else
1222 >                        rmfile(rawfile);
1223 >                finish_process();               /* leave if child */
1224          }
1225 +        wait_process(1);                /* wait for children to finish */
1226   }
1227  
1228  
1229 + touch(fn)                       /* update a file */
1230 + char    *fn;
1231 + {
1232 +        if (!silent)
1233 +                printf("\ttouch %s\n", fn);
1234 +        if (!nprocs)
1235 +                return(0);
1236 + #ifdef notused
1237 +        if (access(fn, F_OK) == -1)             /* create it */
1238 +                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1239 +                        return(-1);
1240 + #endif
1241 +        return(setfdate(fn, time((time_t *)NULL)));
1242 + }
1243 +
1244 +
1245   runcom(cs)                      /* run command */
1246   char    *cs;
1247   {
1248          if (!silent)            /* echo it */
1249                  printf("\t%s\n", cs);
1250 <        if (noaction)
1250 >        if (!nprocs)
1251                  return(0);
1252          fflush(stdout);         /* flush output and pass to shell */
1253          return(system(cs));
# Line 1346 | Line 1258 | rmfile(fn)                     /* remove a file */
1258   char    *fn;
1259   {
1260          if (!silent)
1261 < #ifdef MSDOS
1261 > #ifdef _WIN32
1262                  printf("\tdel %s\n", fn);
1263   #else
1264                  printf("\trm -f %s\n", fn);
1265   #endif
1266 <        if (noaction)
1266 >        if (!nprocs)
1267                  return(0);
1268          return(unlink(fn));
1269   }
1270  
1271  
1272 < #ifdef MSDOS
1272 > mvfile(fold, fnew)              /* move a file */
1273 > char    *fold, *fnew;
1274 > {
1275 >        if (!silent)
1276 > #ifdef _WIN32
1277 >                printf("\trename %s %s\n", fold, fnew);
1278 > #else
1279 >                printf("\tmv %s %s\n", fold, fnew);
1280 > #endif
1281 >        if (!nprocs)
1282 >                return(0);
1283 >        return(rename(fold, fnew));
1284 > }
1285 >
1286 >
1287 > #ifdef RHAS_FORK_EXEC
1288 > int
1289 > next_process()                  /* fork the next process (max. nprocs) */
1290 > {
1291 >        int     child_pid;
1292 >
1293 >        if (nprocs <= 1)
1294 >                return(0);              /* it's us or no one */
1295 >        if (children_running < 0) {
1296 >                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1297 >                                progname);
1298 >                quit(1);
1299 >        }
1300 >        if (children_running >= nprocs)
1301 >                wait_process(0);        /* wait for someone to finish */
1302 >        fflush(stdout);
1303 >        child_pid = fork();             /* split process */
1304 >        if (child_pid == 0) {           /* we're the child */
1305 >                children_running = -1;
1306 >                return(0);
1307 >        }
1308 >        if (child_pid > 0) {            /* we're the parent */
1309 >                ++children_running;
1310 >                return(1);
1311 >        }
1312 >        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1313 >        return(0);
1314 > }
1315 >
1316 > wait_process(all)                       /* wait for process(es) to finish */
1317 > int     all;
1318 > {
1319 >        int     ourstatus = 0;
1320 >        int     pid, status;
1321 >
1322 >        if (all)
1323 >                all = children_running;
1324 >        else if (children_running > 0)
1325 >                all = 1;
1326 >        while (all-- > 0) {
1327 >                pid = wait(&status);
1328 >                if (pid < 0)
1329 >                        syserr(progname);
1330 >                status = status>>8 & 0xff;
1331 >                --children_running;
1332 >                if (status != 0) {      /* child's problem is our problem */
1333 >                        if (ourstatus == 0 & children_running > 0)
1334 >                                fprintf(stderr, "%s: waiting for remaining processes\n",
1335 >                                                progname);
1336 >                        ourstatus = status;
1337 >                        all = children_running;
1338 >                }
1339 >        }
1340 >        if (ourstatus != 0)
1341 >                quit(ourstatus);        /* bad status from child */
1342 > }
1343 > #else   /* ! RHAS_FORK_EXEC */
1344 > int
1345 > next_process()
1346 > {
1347 >        return(0);                      /* cannot start new process */
1348 > }
1349 > wait_process(all)
1350 > int     all;
1351 > {
1352 >        (void)all;                      /* no one to wait for */
1353 > }
1354 > #endif  /* ! RHAS_FORK_EXEC */
1355 >
1356 > finish_process()                        /* exit a child process */
1357 > {
1358 >        if (children_running >= 0)
1359 >                return;                 /* in parent -- noop */
1360 >        exit(0);
1361 > }
1362 >
1363 > #ifdef _WIN32
1364   setenv(vname, value)            /* set an environment variable */
1365   char    *vname, *value;
1366   {
# Line 1369 | Line 1372 | char   *vname, *value;
1372          sprintf(evp, "%s=%s", vname, value);
1373          if (putenv(evp) != 0) {
1374                  fprintf(stderr, "%s: out of environment space\n", progname);
1375 <                exit(1);
1375 >                quit(1);
1376          }
1377          if (!silent)
1378                  printf("set %s\n", evp);
# Line 1382 | Line 1385 | int    vc;
1385   {
1386          fprintf(stderr, "%s: bad value for variable '%s'\n",
1387                          progname, vnam(vc));
1388 <        exit(1);
1388 >        quit(1);
1389   }
1390  
1391  
# Line 1390 | Line 1393 | syserr(s)                      /* report a system error and exit */
1393   char    *s;
1394   {
1395          perror(s);
1396 <        exit(1);
1396 >        quit(1);
1397 > }
1398 >
1399 >
1400 > void
1401 > quit(ec)                        /* exit program */
1402 > int     ec;
1403 > {
1404 >        exit(ec);
1405   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines