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.40 by greg, Thu Apr 21 12:22:44 1994 UTC vs.
Revision 2.71 by schorsch, Sun Jul 27 22:12:03 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines