ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
Revision: 2.48
Committed: Tue Dec 12 13:30:14 1995 UTC (28 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.47: +5 -312 lines
Log Message:
moved variable loading and checking to loadvars.c

File Contents

# User Rev Content
1 greg 2.46 /* Copyright (c) 1995 Regents of the University of California */
2 greg 2.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Executive program for oconv, rpict and pfilt
9     */
10    
11     #include "standard.h"
12     #include "paths.h"
13 greg 2.48 #include "vars.h"
14 greg 2.1 #include <ctype.h>
15 greg 2.35 #include <sys/types.h>
16 greg 2.1
17     /* variables */
18     #define OBJECT 0 /* object files */
19     #define SCENE 1 /* scene files */
20     #define MATERIAL 2 /* material files */
21 greg 2.26 #define ILLUM 3 /* mkillum input files */
22     #define MKILLUM 4 /* mkillum options */
23     #define RENDER 5 /* rendering options */
24     #define OCONV 6 /* oconv options */
25     #define PFILT 7 /* pfilt options */
26     #define VIEW 8 /* view(s) for picture(s) */
27     #define ZONE 9 /* simulation zone */
28     #define QUALITY 10 /* desired rendering quality */
29     #define OCTREE 11 /* octree file name */
30 greg 2.45 #define PICTURE 12 /* picture file root name */
31 greg 2.26 #define AMBFILE 13 /* ambient file name */
32     #define OPTFILE 14 /* rendering options file */
33     #define EXPOSURE 15 /* picture exposure setting */
34     #define RESOLUTION 16 /* maximum picture resolution */
35     #define UP 17 /* view up (X, Y or Z) */
36     #define INDIRECT 18 /* indirection in lighting */
37     #define DETAIL 19 /* level of scene detail */
38     #define PENUMBRAS 20 /* shadow penumbras are desired */
39     #define VARIABILITY 21 /* level of light variability */
40     #define REPORT 22 /* report frequency and errfile */
41 greg 2.45 #define RAWFILE 23 /* raw picture file root name */
42     #define ZFILE 24 /* distance file root name */
43 greg 2.1 /* total number of variables */
44 greg 2.48 int NVARS = 25;
45 greg 2.1
46 greg 2.48 VARIABLE vv[] = { /* variable-value pairs */
47 greg 2.1 {"objects", 3, 0, NULL, catvalues},
48     {"scene", 3, 0, NULL, catvalues},
49     {"materials", 3, 0, NULL, catvalues},
50 greg 2.26 {"illum", 3, 0, NULL, catvalues},
51     {"mkillum", 3, 0, NULL, catvalues},
52 greg 2.1 {"render", 3, 0, NULL, catvalues},
53     {"oconv", 3, 0, NULL, catvalues},
54     {"pfilt", 2, 0, NULL, catvalues},
55     {"view", 2, 0, NULL, NULL},
56     {"ZONE", 2, 0, NULL, onevalue},
57 greg 2.30 {"QUALITY", 3, 0, NULL, qualvalue},
58 greg 2.1 {"OCTREE", 3, 0, NULL, onevalue},
59     {"PICTURE", 3, 0, NULL, onevalue},
60     {"AMBFILE", 3, 0, NULL, onevalue},
61     {"OPTFILE", 3, 0, NULL, onevalue},
62 greg 2.30 {"EXPOSURE", 3, 0, NULL, fltvalue},
63 greg 2.1 {"RESOLUTION", 3, 0, NULL, onevalue},
64     {"UP", 2, 0, NULL, onevalue},
65 greg 2.30 {"INDIRECT", 3, 0, NULL, intvalue},
66     {"DETAIL", 3, 0, NULL, qualvalue},
67     {"PENUMBRAS", 3, 0, NULL, boolvalue},
68     {"VARIABILITY", 3, 0, NULL, qualvalue},
69 greg 2.1 {"REPORT", 3, 0, NULL, onevalue},
70 greg 2.45 {"RAWFILE", 3, 0, NULL, onevalue},
71     {"ZFILE", 2, 0, NULL, onevalue},
72 greg 2.1 };
73    
74 greg 2.6 /* overture calculation file */
75     #ifdef NIX
76 greg 2.45 char overfile[] = "overture.unf";
77 greg 2.6 #else
78     char overfile[] = "/dev/null";
79     #endif
80    
81 greg 2.35 extern time_t fdate(), time();
82 greg 2.1
83 greg 2.35 time_t scenedate; /* date of latest scene or object file */
84     time_t octreedate; /* date of octree */
85     time_t matdate; /* date of latest material file */
86     time_t illumdate; /* date of last illum file */
87 greg 2.1
88 greg 2.26 char *oct0name; /* name of pre-mkillum octree */
89 greg 2.35 time_t oct0date; /* date of pre-mkillum octree */
90 greg 2.26 char *oct1name; /* name of post-mkillum octree */
91 greg 2.35 time_t oct1date; /* date of post-mkillum octree (>= matdate) */
92 greg 2.26
93 greg 2.37 int nowarn = 0; /* no warnings */
94 greg 2.1 int explicate = 0; /* explicate variables */
95     int silent = 0; /* do work silently */
96 greg 2.41 int touchonly = 0; /* touch files only */
97 greg 2.1 int noaction = 0; /* don't do anything */
98 greg 2.21 int sayview = 0; /* print view out */
99 greg 2.1 char *rvdevice = NULL; /* rview output device */
100     char *viewselect = NULL; /* specific view only */
101    
102     int overture = 0; /* overture calculation needed */
103    
104     char *progname; /* global argv[0] */
105 greg 2.22 char *rifname; /* global rad input file name */
106 greg 2.1
107     char radname[MAXPATH]; /* root Radiance file name */
108    
109    
110     main(argc, argv)
111     int argc;
112     char *argv[];
113     {
114     char ropts[512];
115 greg 2.38 char popts[64];
116 greg 2.1 int i;
117    
118     progname = argv[0];
119     /* get options */
120     for (i = 1; i < argc && argv[i][0] == '-'; i++)
121     switch (argv[i][1]) {
122     case 's':
123     silent++;
124     break;
125     case 'n':
126     noaction++;
127     break;
128 greg 2.41 case 't':
129     touchonly++;
130     break;
131 greg 2.1 case 'e':
132     explicate++;
133     break;
134     case 'o':
135     rvdevice = argv[++i];
136     break;
137 greg 2.20 case 'V':
138 greg 2.21 sayview++;
139     break;
140 greg 2.1 case 'v':
141     viewselect = argv[++i];
142     break;
143 greg 2.37 case 'w':
144     nowarn++;
145     break;
146 greg 2.1 default:
147     goto userr;
148     }
149     if (i >= argc)
150     goto userr;
151 greg 2.22 rifname = argv[i];
152 greg 2.1 /* assign Radiance root file name */
153 greg 2.22 rootname(radname, rifname);
154 greg 2.1 /* load variable values */
155 greg 2.48 loadvars(rifname);
156 greg 2.1 /* get any additional assignments */
157     for (i++; i < argc; i++)
158     setvariable(argv[i]);
159     /* check assignments */
160     checkvalues();
161     /* check files and dates */
162     checkfiles();
163     /* set default values as necessary */
164     setdefaults();
165     /* print all values if requested */
166     if (explicate)
167 greg 2.48 printvars(stdout);
168 greg 2.26 /* build octree (and run mkillum) */
169 greg 2.7 oconv();
170     /* check date on ambient file */
171     checkambfile();
172 greg 2.1 /* run simulation */
173 greg 2.38 renderopts(ropts, popts);
174 greg 2.1 xferopts(ropts);
175     if (rvdevice != NULL)
176 greg 2.38 rview(ropts, popts);
177 greg 2.1 else
178 greg 2.38 rpict(ropts, popts);
179 greg 2.1 exit(0);
180     userr:
181     fprintf(stderr,
182 greg 2.41 "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
183 greg 2.1 progname);
184     exit(1);
185     }
186    
187    
188     rootname(rn, fn) /* remove tail from end of fn */
189     register char *rn, *fn;
190     {
191     char *tp, *dp;
192    
193     for (tp = NULL, dp = rn; *rn = *fn++; rn++)
194     if (ISDIRSEP(*rn))
195     dp = rn;
196     else if (*rn == '.')
197     tp = rn;
198     if (tp != NULL && tp > dp)
199     *tp = '\0';
200     }
201    
202    
203 greg 2.35 time_t
204 greg 2.1 checklast(fnames) /* check files and find most recent */
205     register char *fnames;
206     {
207     char thisfile[MAXPATH];
208 greg 2.35 time_t thisdate, lastdate = 0;
209 greg 2.1 register char *cp;
210    
211 greg 2.26 if (fnames == NULL)
212     return(0);
213 greg 2.1 while (*fnames) {
214     while (isspace(*fnames)) fnames++;
215     cp = thisfile;
216 greg 2.4 while (*fnames && !isspace(*fnames))
217     *cp++ = *fnames++;
218 greg 2.1 *cp = '\0';
219 greg 2.26 if (!(thisdate = fdate(thisfile)))
220 greg 2.3 syserr(thisfile);
221 greg 2.1 if (thisdate > lastdate)
222     lastdate = thisdate;
223     }
224     return(lastdate);
225     }
226    
227    
228 greg 2.26 char *
229     newfname(orig, pred) /* create modified file name */
230     char *orig;
231     int pred;
232     {
233     extern char *rindex();
234     register char *cp;
235     register int n;
236     int suffix;
237    
238 greg 2.27 n = 0; cp = orig; suffix = -1; /* suffix position, length */
239     while (*cp) {
240     if (*cp == '.') suffix = n;
241     else if (ISDIRSEP(*cp)) suffix = -1;
242     cp++; n++;
243     }
244     if (suffix == -1) suffix = n;
245 greg 2.26 if ((cp = bmalloc(n+2)) == NULL)
246     syserr(progname);
247     strncpy(cp, orig, suffix);
248     cp[suffix] = pred; /* root name + pred + suffix */
249     strcpy(cp+suffix+1, orig+suffix);
250     return(cp);
251     }
252    
253    
254 greg 2.1 checkfiles() /* check for existence and modified times */
255     {
256 greg 2.35 time_t objdate;
257 greg 2.1
258 greg 2.2 if (!vdef(OCTREE)) {
259 greg 2.26 if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
260 greg 2.3 syserr(progname);
261 greg 2.26 sprintf(vval(OCTREE), "%s.oct", radname);
262 greg 2.2 vdef(OCTREE)++;
263     }
264     octreedate = fdate(vval(OCTREE));
265 greg 2.26 if (vdef(ILLUM)) { /* illum requires secondary octrees */
266     oct0name = newfname(vval(OCTREE), '0');
267     oct1name = newfname(vval(OCTREE), '1');
268     oct0date = fdate(oct0name);
269     oct1date = fdate(oct1name);
270     } else
271     oct0name = oct1name = vval(OCTREE);
272     if ((scenedate = checklast(vval(SCENE))) &&
273     (objdate = checklast(vval(OBJECT))) > scenedate)
274     scenedate = objdate;
275     illumdate = checklast(vval(ILLUM));
276     if (!octreedate & !scenedate & !illumdate) {
277     fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
278     vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
279 greg 2.1 exit(1);
280     }
281 greg 2.26 matdate = checklast(vval(MATERIAL));
282 greg 2.1 }
283    
284    
285 greg 2.2 getoctcube(org, sizp) /* get octree bounding cube */
286     double org[3], *sizp;
287 greg 2.1 {
288 greg 2.2 extern FILE *popen();
289     static double oorg[3], osiz = 0.;
290 greg 2.26 double min[3], max[3];
291 greg 2.46 char buf[1024];
292 greg 2.1 FILE *fp;
293 greg 2.26 register int i;
294 greg 2.1
295 greg 2.26 if (osiz <= FTINY)
296     if (noaction && fdate(oct1name) <
297     (scenedate>illumdate?scenedate:illumdate)) {
298     /* run getbbox */
299     sprintf(buf, "getbbox -w -h %s",
300     vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
301     if ((fp = popen(buf, "r")) == NULL)
302     syserr("getbbox");
303     if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
304     &min[0], &max[0], &min[1], &max[1],
305     &min[2], &max[2]) != 6) {
306     fprintf(stderr,
307     "%s: error reading bounding box from getbbox\n",
308     progname);
309     exit(1);
310     }
311     for (i = 0; i < 3; i++)
312     if (max[i] - min[i] > osiz)
313     osiz = max[i] - min[i];
314     for (i = 0; i < 3; i++)
315     oorg[i] = (max[i]+min[i]-osiz)*.5;
316     pclose(fp);
317     } else { /* from octree */
318     oconv(); /* does nothing if done already */
319     sprintf(buf, "getinfo -d < %s", oct1name);
320     if ((fp = popen(buf, "r")) == NULL)
321     syserr("getinfo");
322     if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
323     &oorg[2], &osiz) != 4) {
324     fprintf(stderr,
325 greg 2.2 "%s: error reading bounding cube from getinfo\n",
326 greg 2.26 progname);
327     exit(1);
328     }
329     pclose(fp);
330 greg 2.2 }
331     org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
332     }
333    
334    
335     setdefaults() /* set default values for unassigned var's */
336     {
337     double org[3], size;
338     char buf[128];
339    
340 greg 2.1 if (!vdef(ZONE)) {
341 greg 2.2 getoctcube(org, &size);
342     sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
343     org[1], org[1]+size, org[2], org[2]+size);
344 greg 2.1 vval(ZONE) = savqstr(buf);
345     vdef(ZONE)++;
346     }
347     if (!vdef(INDIRECT)) {
348     vval(INDIRECT) = "0";
349     vdef(INDIRECT)++;
350     }
351     if (!vdef(QUALITY)) {
352     vval(QUALITY) = "L";
353     vdef(QUALITY)++;
354     }
355     if (!vdef(RESOLUTION)) {
356     vval(RESOLUTION) = "512";
357     vdef(RESOLUTION)++;
358     }
359     if (!vdef(PICTURE)) {
360     vval(PICTURE) = radname;
361     vdef(PICTURE)++;
362     }
363     if (!vdef(VIEW)) {
364     vval(VIEW) = "X";
365     vdef(VIEW)++;
366     }
367     if (!vdef(DETAIL)) {
368     vval(DETAIL) = "M";
369     vdef(DETAIL)++;
370     }
371     if (!vdef(PENUMBRAS)) {
372     vval(PENUMBRAS) = "F";
373     vdef(PENUMBRAS)++;
374     }
375     if (!vdef(VARIABILITY)) {
376     vval(VARIABILITY) = "L";
377     vdef(VARIABILITY)++;
378     }
379     }
380    
381    
382 greg 2.26 oconv() /* run oconv and mkillum if necessary */
383 greg 2.1 {
384 greg 2.26 static char illumtmp[] = "ilXXXXXX";
385 greg 2.46 char combuf[1024], ocopts[64], mkopts[64];
386 greg 2.1
387 greg 2.26 oconvopts(ocopts); /* get options */
388     if (octreedate < scenedate) { /* check date on original octree */
389 greg 2.41 if (touchonly && octreedate)
390     touch(vval(OCTREE));
391     else { /* build command */
392     if (vdef(MATERIAL))
393     sprintf(combuf, "oconv%s %s %s > %s", ocopts,
394     vval(MATERIAL), vval(SCENE),
395     vval(OCTREE));
396     else
397     sprintf(combuf, "oconv%s %s > %s", ocopts,
398     vval(SCENE), vval(OCTREE));
399    
400     if (runcom(combuf)) { /* run it */
401     fprintf(stderr,
402 greg 2.26 "%s: error generating octree\n\t%s removed\n",
403 greg 2.41 progname, vval(OCTREE));
404     unlink(vval(OCTREE));
405     exit(1);
406     }
407 greg 2.26 }
408 greg 2.35 octreedate = time((time_t *)NULL);
409 greg 2.40 if (octreedate < scenedate) /* in case clock is off */
410     octreedate = scenedate;
411 greg 2.26 }
412     if (oct1name == vval(OCTREE)) /* no mkillum? */
413     oct1date = octreedate > matdate ? octreedate : matdate;
414     if (oct1date >= octreedate & oct1date >= matdate
415     & oct1date >= illumdate) /* all done */
416 greg 2.1 return;
417 greg 2.26 /* make octree0 */
418     if (oct0date < scenedate | oct0date < illumdate) {
419 greg 2.41 if (touchonly && oct0date)
420     touch(oct0name);
421     else { /* build command */
422     if (octreedate)
423     sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
424     vval(OCTREE), vval(ILLUM), oct0name);
425     else if (vdef(MATERIAL))
426     sprintf(combuf, "oconv%s %s %s > %s", ocopts,
427     vval(MATERIAL), vval(ILLUM), oct0name);
428     else
429     sprintf(combuf, "oconv%s %s > %s", ocopts,
430     vval(ILLUM), oct0name);
431     if (runcom(combuf)) { /* run it */
432     fprintf(stderr,
433     "%s: error generating octree\n\t%s removed\n",
434     progname, oct0name);
435     unlink(oct0name);
436     exit(1);
437     }
438     }
439     oct0date = time((time_t *)NULL);
440     if (oct0date < octreedate) /* in case clock is off */
441     oct0date = octreedate;
442     if (oct0date < illumdate) /* ditto */
443     oct0date = illumdate;
444     }
445     if (touchonly && oct1date)
446     touch(oct1name);
447     else {
448     mkillumopts(mkopts); /* build mkillum command */
449     mktemp(illumtmp);
450     sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
451     oct0name, vval(ILLUM), illumtmp);
452     if (runcom(combuf)) { /* run it */
453     fprintf(stderr, "%s: error running mkillum\n",
454     progname);
455     unlink(illumtmp);
456     exit(1);
457     }
458     /* make octree1 (frozen) */
459 greg 2.26 if (octreedate)
460 greg 2.41 sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
461     vval(OCTREE), illumtmp, oct1name);
462 greg 2.26 else if (vdef(MATERIAL))
463 greg 2.41 sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
464     vval(MATERIAL), illumtmp, oct1name);
465 greg 2.26 else
466 greg 2.41 sprintf(combuf, "oconv%s -f %s > %s", ocopts,
467     illumtmp, oct1name);
468 greg 2.26 if (runcom(combuf)) { /* run it */
469     fprintf(stderr,
470     "%s: error generating octree\n\t%s removed\n",
471 greg 2.41 progname, oct1name);
472     unlink(oct1name);
473 greg 2.46 unlink(illumtmp);
474 greg 2.26 exit(1);
475     }
476 greg 2.41 rmfile(illumtmp);
477 greg 2.26 }
478 greg 2.35 oct1date = time((time_t *)NULL);
479 greg 2.40 if (oct1date < oct0date) /* in case clock is off */
480     oct1date = oct0date;
481 greg 2.1 }
482    
483    
484     char *
485     addarg(op, arg) /* add argument and advance pointer */
486     register char *op, *arg;
487     {
488     *op = ' ';
489     while (*++op = *arg++)
490     ;
491     return(op);
492     }
493    
494    
495     oconvopts(oo) /* get oconv options */
496 greg 2.2 register char *oo;
497 greg 2.1 {
498 greg 2.2 /* BEWARE: This may be called via setdefaults(), so no assumptions */
499    
500 greg 2.1 *oo = '\0';
501     if (vdef(OCONV))
502     addarg(oo, vval(OCONV));
503     }
504    
505    
506 greg 2.26 mkillumopts(mo) /* get mkillum options */
507     register char *mo;
508     {
509     /* BEWARE: This may be called via setdefaults(), so no assumptions */
510    
511     *mo = '\0';
512     if (vdef(MKILLUM))
513     addarg(mo, vval(MKILLUM));
514     }
515    
516    
517 greg 2.7 checkambfile() /* check date on ambient file */
518     {
519 greg 2.35 time_t afdate;
520 greg 2.7
521 greg 2.11 if (!vdef(AMBFILE))
522     return;
523 greg 2.26 if (!(afdate = fdate(vval(AMBFILE))))
524 greg 2.11 return;
525 greg 2.26 if (oct1date > afdate)
526 greg 2.41 if (touchonly)
527     touch(vval(AMBFILE));
528     else
529     rmfile(vval(AMBFILE));
530 greg 2.7 }
531    
532    
533 greg 2.2 double
534     ambval() /* compute ambient value */
535 greg 2.1 {
536 greg 2.3 if (vdef(EXPOSURE)) {
537 greg 2.2 if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
538     return(.5/pow(2.,atof(vval(EXPOSURE))));
539 greg 2.20 return(.5/atof(vval(EXPOSURE)));
540 greg 2.3 }
541 greg 2.2 if (vlet(ZONE) == 'E')
542     return(10.);
543 greg 2.3 if (vlet(ZONE) == 'I')
544 greg 2.2 return(.01);
545 greg 2.3 badvalue(ZONE);
546 greg 2.30 }
547    
548    
549 greg 2.38 renderopts(op, po) /* set rendering options */
550     char *op, *po;
551 greg 2.30 {
552     switch(vscale(QUALITY)) {
553     case LOW:
554 greg 2.38 lowqopts(op, po);
555 greg 2.30 break;
556     case MEDIUM:
557 greg 2.38 medqopts(op, po);
558 greg 2.30 break;
559     case HIGH:
560 greg 2.38 hiqopts(op, po);
561 greg 2.30 break;
562     }
563 greg 2.2 }
564 greg 2.1
565 greg 2.2
566 greg 2.38 lowqopts(op, po) /* low quality rendering options */
567 greg 2.2 register char *op;
568 greg 2.38 char *po;
569 greg 2.2 {
570     double d, org[3], siz[3];
571    
572 greg 2.1 *op = '\0';
573 greg 2.38 *po = '\0';
574 greg 2.2 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
575 greg 2.3 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
576     badvalue(ZONE);
577 greg 2.2 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
578 greg 2.39 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
579     badvalue(ZONE);
580 greg 2.2 getoctcube(org, &d);
581     d *= 3./(siz[0]+siz[1]+siz[2]);
582     switch (vscale(DETAIL)) {
583     case LOW:
584 greg 2.38 po = addarg(po, "-ps 16");
585     op = addarg(op, "-dp 64");
586 greg 2.2 sprintf(op, " -ar %d", (int)(4*d));
587     op += strlen(op);
588     break;
589     case MEDIUM:
590 greg 2.38 po = addarg(po, "-ps 8");
591     op = addarg(op, "-dp 128");
592 greg 2.2 sprintf(op, " -ar %d", (int)(8*d));
593     op += strlen(op);
594     break;
595     case HIGH:
596 greg 2.38 po = addarg(po, "-ps 4");
597     op = addarg(op, "-dp 256");
598 greg 2.2 sprintf(op, " -ar %d", (int)(16*d));
599     op += strlen(op);
600     break;
601     }
602 greg 2.38 po = addarg(po, "-pt .16");
603 greg 2.2 if (vbool(PENUMBRAS))
604     op = addarg(op, "-ds .4");
605 greg 2.4 else
606     op = addarg(op, "-ds 0");
607 greg 2.17 op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
608 greg 2.2 if (vdef(AMBFILE)) {
609     sprintf(op, " -af %s", vval(AMBFILE));
610     op += strlen(op);
611     } else
612     overture = 0;
613     switch (vscale(VARIABILITY)) {
614     case LOW:
615 greg 2.16 op = addarg(op, "-aa .4 -ad 64");
616 greg 2.2 break;
617     case MEDIUM:
618 greg 2.16 op = addarg(op, "-aa .3 -ad 128");
619 greg 2.2 break;
620     case HIGH:
621 greg 2.16 op = addarg(op, "-aa .25 -ad 256");
622 greg 2.2 break;
623     }
624     op = addarg(op, "-as 0");
625     d = ambval();
626     sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
627     op += strlen(op);
628 greg 2.4 op = addarg(op, "-lr 3 -lw .02");
629 greg 2.1 if (vdef(RENDER))
630     op = addarg(op, vval(RENDER));
631     }
632    
633    
634 greg 2.38 medqopts(op, po) /* medium quality rendering options */
635 greg 2.2 register char *op;
636 greg 2.38 char *po;
637 greg 2.1 {
638 greg 2.47 double d, org[3], siz[3], asz;
639 greg 2.1
640     *op = '\0';
641 greg 2.38 *po = '\0';
642 greg 2.2 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
643 greg 2.3 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
644     badvalue(ZONE);
645 greg 2.2 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
646 greg 2.39 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
647     badvalue(ZONE);
648 greg 2.2 getoctcube(org, &d);
649 greg 2.47 asz = (siz[0]+siz[1]+siz[2])/3.;
650     d /= asz;
651 greg 2.2 switch (vscale(DETAIL)) {
652     case LOW:
653 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
654 greg 2.23 op = addarg(op, "-dp 256");
655 greg 2.2 sprintf(op, " -ar %d", (int)(8*d));
656     op += strlen(op);
657 greg 2.47 sprintf(op, " -ms %.2g", asz/20.);
658     op += strlen(op);
659 greg 2.2 break;
660     case MEDIUM:
661 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
662 greg 2.23 op = addarg(op, "-dp 512");
663 greg 2.2 sprintf(op, " -ar %d", (int)(16*d));
664     op += strlen(op);
665 greg 2.47 sprintf(op, " -ms %.2g", asz/40.);
666     op += strlen(op);
667 greg 2.2 break;
668     case HIGH:
669 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
670 greg 2.23 op = addarg(op, "-dp 1024");
671 greg 2.2 sprintf(op, " -ar %d", (int)(32*d));
672     op += strlen(op);
673 greg 2.47 sprintf(op, " -ms %.2g", asz/80.);
674     op += strlen(op);
675 greg 2.2 break;
676     }
677 greg 2.38 po = addarg(po, "-pt .08");
678 greg 2.4 if (vbool(PENUMBRAS))
679 greg 2.28 op = addarg(op, "-ds .2 -dj .5");
680 greg 2.4 else
681 greg 2.2 op = addarg(op, "-ds .3");
682 greg 2.17 op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
683 greg 2.5 if (overture = vint(INDIRECT)) {
684     sprintf(op, " -ab %d", overture);
685     op += strlen(op);
686     }
687 greg 2.2 if (vdef(AMBFILE)) {
688     sprintf(op, " -af %s", vval(AMBFILE));
689     op += strlen(op);
690     } else
691     overture = 0;
692     switch (vscale(VARIABILITY)) {
693     case LOW:
694 greg 2.16 op = addarg(op, "-aa .25 -ad 196 -as 0");
695 greg 2.2 break;
696     case MEDIUM:
697 greg 2.16 op = addarg(op, "-aa .2 -ad 400 -as 64");
698 greg 2.2 break;
699     case HIGH:
700 greg 2.16 op = addarg(op, "-aa .15 -ad 768 -as 196");
701 greg 2.2 break;
702     }
703     d = ambval();
704     sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
705     op += strlen(op);
706 greg 2.4 op = addarg(op, "-lr 6 -lw .002");
707 greg 2.1 if (vdef(RENDER))
708     op = addarg(op, vval(RENDER));
709     }
710    
711    
712 greg 2.38 hiqopts(op, po) /* high quality rendering options */
713 greg 2.2 register char *op;
714 greg 2.38 char *po;
715 greg 2.1 {
716 greg 2.47 double d, org[3], siz[3], asz;
717 greg 2.1
718     *op = '\0';
719 greg 2.38 *po = '\0';
720 greg 2.2 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
721 greg 2.3 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
722     badvalue(ZONE);
723 greg 2.2 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
724 greg 2.39 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
725     badvalue(ZONE);
726 greg 2.2 getoctcube(org, &d);
727 greg 2.47 asz = (siz[0]+siz[1]+siz[2])/3.;
728     d /= asz;
729 greg 2.2 switch (vscale(DETAIL)) {
730     case LOW:
731 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
732 greg 2.23 op = addarg(op, "-dp 1024");
733 greg 2.2 sprintf(op, " -ar %d", (int)(16*d));
734     op += strlen(op);
735 greg 2.47 sprintf(op, " -ms %.2g", asz/40.);
736     op += strlen(op);
737 greg 2.2 break;
738     case MEDIUM:
739 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
740 greg 2.23 op = addarg(op, "-dp 2048");
741 greg 2.2 sprintf(op, " -ar %d", (int)(32*d));
742     op += strlen(op);
743 greg 2.47 sprintf(op, " -ms %.2g", asz/80.);
744     op += strlen(op);
745 greg 2.2 break;
746     case HIGH:
747 greg 2.38 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
748 greg 2.23 op = addarg(op, "-dp 4096");
749 greg 2.2 sprintf(op, " -ar %d", (int)(64*d));
750 greg 2.47 op += strlen(op);
751     sprintf(op, " -ms %.2g", asz/160.);
752 greg 2.2 op += strlen(op);
753     break;
754     }
755 greg 2.38 po = addarg(po, "-pt .04");
756 greg 2.4 if (vbool(PENUMBRAS))
757 greg 2.42 op = addarg(op, "-ds .1 -dj .65");
758 greg 2.4 else
759 greg 2.2 op = addarg(op, "-ds .2");
760 greg 2.17 op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
761 greg 2.2 sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
762     op += strlen(op);
763     if (vdef(AMBFILE)) {
764     sprintf(op, " -af %s", vval(AMBFILE));
765     op += strlen(op);
766     } else
767     overture = 0;
768     switch (vscale(VARIABILITY)) {
769     case LOW:
770 greg 2.16 op = addarg(op, "-aa .15 -ad 256 -as 0");
771 greg 2.2 break;
772     case MEDIUM:
773 greg 2.16 op = addarg(op, "-aa .125 -ad 512 -as 256");
774 greg 2.2 break;
775     case HIGH:
776 greg 2.16 op = addarg(op, "-aa .08 -ad 1024 -as 512");
777 greg 2.2 break;
778     }
779     d = ambval();
780     sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
781     op += strlen(op);
782 greg 2.4 op = addarg(op, "-lr 12 -lw .0005");
783 greg 2.1 if (vdef(RENDER))
784     op = addarg(op, vval(RENDER));
785     }
786    
787    
788     xferopts(ro) /* transfer options if indicated */
789     char *ro;
790     {
791     int fd, n;
792 greg 2.10 register char *cp;
793 greg 2.1
794     n = strlen(ro);
795     if (n < 2)
796     return;
797     if (vdef(OPTFILE)) {
798 greg 2.10 for (cp = ro; cp[1]; cp++)
799     if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
800     *cp = '\n';
801     else
802     *cp = cp[1];
803     *cp = '\n';
804     fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
805     if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
806 greg 2.3 syserr(vval(OPTFILE));
807 greg 2.15 sprintf(ro, " @%s", vval(OPTFILE));
808 greg 2.1 }
809     #ifdef MSDOS
810     else if (n > 50) {
811 greg 2.8 setenv("ROPT", ro+1);
812 greg 2.1 strcpy(ro, " $ROPT");
813     }
814     #endif
815     }
816    
817    
818     pfiltopts(po) /* get pfilt options */
819     register char *po;
820     {
821     *po = '\0';
822     if (vdef(EXPOSURE)) {
823     po = addarg(po, "-1 -e");
824     po = addarg(po, vval(EXPOSURE));
825     }
826 greg 2.12 switch (vscale(QUALITY)) {
827     case MEDIUM:
828     po = addarg(po, "-r 1");
829     break;
830     case HIGH:
831 greg 2.14 po = addarg(po, "-m .25");
832 greg 2.12 break;
833     }
834 greg 2.1 if (vdef(PFILT))
835     po = addarg(po, vval(PFILT));
836     }
837    
838    
839     matchword(s1, s2) /* match white-delimited words */
840     register char *s1, *s2;
841     {
842     while (isspace(*s1)) s1++;
843     while (isspace(*s2)) s2++;
844     while (*s1 && !isspace(*s1))
845     if (*s1++ != *s2++)
846     return(0);
847     return(!*s2 || isspace(*s2));
848     }
849    
850    
851     char *
852     specview(vs) /* get proper view spec from vs */
853     register char *vs;
854     {
855 greg 2.3 static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
856     "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
857 greg 2.1 static char viewopts[128];
858     register char *cp;
859 greg 2.3 int xpos, ypos, zpos, viewtype, upax;
860     register int i;
861 greg 2.1 double cent[3], dim[3], mult, d;
862    
863 greg 2.9 if (vs == NULL || *vs == '-')
864 greg 2.1 return(vs);
865 greg 2.3 upax = 0; /* get the up vector */
866     if (vdef(UP)) {
867     if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
868     upax = 1-'X'+UPPER(vval(UP)[1]);
869     else
870     upax = 1-'X'+vlet(UP);
871     if (upax < 1 | upax > 3)
872     badvalue(UP);
873     if (vval(UP)[0] == '-')
874     upax = -upax;
875     }
876 greg 2.1 /* check standard view names */
877     xpos = ypos = zpos = 0;
878     if (*vs == 'X') {
879     xpos = 1; vs++;
880     } else if (*vs == 'x') {
881     xpos = -1; vs++;
882     }
883     if (*vs == 'Y') {
884     ypos = 1; vs++;
885     } else if (*vs == 'y') {
886     ypos = -1; vs++;
887     }
888     if (*vs == 'Z') {
889     zpos = 1; vs++;
890     } else if (*vs == 'z') {
891     zpos = -1; vs++;
892     }
893 greg 2.3 viewtype = 'v';
894 greg 2.44 if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
895 greg 2.1 viewtype = *vs++;
896     cp = viewopts;
897 greg 2.3 if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */
898 greg 2.1 *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
899     if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
900     &cent[0], &dim[0], &cent[1], &dim[1],
901 greg 2.3 &cent[2], &dim[2]) != 6)
902     badvalue(ZONE);
903     for (i = 0; i < 3; i++) {
904     dim[i] -= cent[i];
905 greg 2.39 if (dim[i] <= FTINY)
906     badvalue(ZONE);
907 greg 2.3 cent[i] += .5*dim[i];
908 greg 2.1 }
909 greg 2.3 mult = vlet(ZONE)=='E' ? 2. : .45 ;
910 greg 2.1 sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
911     cent[0]+xpos*mult*dim[0],
912     cent[1]+ypos*mult*dim[1],
913     cent[2]+zpos*mult*dim[2],
914     -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
915     cp += strlen(cp);
916 greg 2.3 /* redirect up axis if necessary */
917     switch (upax) {
918     case 3: /* plus or minus Z axis */
919     case -3:
920     case 0:
921     if (!(xpos|ypos))
922     upax = 2;
923 greg 2.1 break;
924 greg 2.3 case 2: /* plus or minus Y axis */
925     case -2:
926     if (!(xpos|zpos))
927     upax = 1;
928     break;
929     case 1: /* plus or minus X axis */
930     case -1:
931     if (!(ypos|zpos))
932     upax = 3;
933     break;
934 greg 2.1 }
935 greg 2.3 cp = addarg(cp, vup[upax+3]);
936 greg 2.1 switch (viewtype) {
937     case 'v':
938     cp = addarg(cp, "-vh 45 -vv 45");
939     break;
940     case 'l':
941     d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
942     sprintf(cp, " -vh %.2g -vv %.2g", d, d);
943     cp += strlen(cp);
944     break;
945     case 'a':
946     case 'h':
947     cp = addarg(cp, "-vh 180 -vv 180");
948 greg 2.44 break;
949     case 'c':
950     cp = addarg(cp, "-vh 180 -vv 90");
951 greg 2.1 break;
952     }
953 greg 2.3 } else {
954 greg 2.4 while (!isspace(*vs)) /* else skip id */
955     if (!*vs++)
956     return(NULL);
957 greg 2.3 if (upax) { /* specify up vector */
958     strcpy(cp, vup[upax+3]);
959     cp += strlen(cp);
960     }
961     }
962 greg 2.26 if (cp == viewopts) /* append any additional options */
963     vs++; /* skip prefixed space if unneeded */
964     strcpy(cp, vs);
965 greg 2.8 #ifdef MSDOS
966     if (strlen(viewopts) > 40) {
967     setenv("VIEW", viewopts);
968     return("$VIEW");
969     }
970     #endif
971 greg 2.1 return(viewopts);
972     }
973    
974    
975     char *
976     getview(n, vn) /* get view n, or NULL if none */
977     int n;
978 greg 2.8 char *vn; /* returned view name */
979 greg 2.1 {
980 greg 2.19 register char *mv;
981 greg 2.1
982 greg 2.8 if (viewselect != NULL) { /* command-line selected */
983 greg 2.1 if (n) /* only do one */
984     return(NULL);
985     if (viewselect[0] == '-') { /* already specified */
986     if (vn != NULL) *vn = '\0';
987     return(viewselect);
988     }
989     if (vn != NULL) {
990     for (mv = viewselect; *mv && !isspace(*mv);
991     *vn++ = *mv++)
992     ;
993     *vn = '\0';
994     }
995 greg 2.19 /* view number? */
996 greg 2.20 if (isint(viewselect))
997 greg 2.19 return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
998 greg 2.1 /* check list */
999     while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1000     if (matchword(viewselect, mv))
1001     return(specview(mv));
1002     return(specview(viewselect)); /* standard view? */
1003     }
1004 greg 2.8 mv = nvalue(vv+VIEW, n); /* use view n */
1005     if (vn != NULL & mv != NULL) {
1006 greg 2.19 register char *mv2 = mv;
1007     if (*mv2 != '-')
1008     while (*mv2 && !isspace(*mv2))
1009     *vn++ = *mv2++;
1010 greg 2.1 *vn = '\0';
1011     }
1012 greg 2.8 return(specview(mv));
1013 greg 2.20 }
1014    
1015    
1016 greg 2.21 printview(vopts) /* print out selected view */
1017     register char *vopts;
1018 greg 2.20 {
1019 greg 2.24 extern char *atos(), *getenv();
1020 greg 2.20 char buf[256];
1021     FILE *fp;
1022 greg 2.21 register char *cp;
1023 greg 2.20
1024     if (vopts == NULL)
1025     return(-1);
1026     fputs("VIEW=", stdout);
1027     do {
1028     if (matchword(vopts, "-vf")) { /* expand view file */
1029     vopts = sskip(vopts);
1030     if (!*atos(buf, sizeof(buf), vopts))
1031     return(-1);
1032     if ((fp = fopen(buf, "r")) == NULL)
1033     return(-1);
1034     for (buf[sizeof(buf)-2] = '\n';
1035     fgets(buf, sizeof(buf), fp) != NULL &&
1036     buf[0] != '\n';
1037     buf[sizeof(buf)-2] = '\n') {
1038     if (buf[sizeof(buf)-2] != '\n') {
1039     ungetc(buf[sizeof(buf)-2], fp);
1040     buf[sizeof(buf)-2] = '\0';
1041     }
1042     if (matchword(buf, "VIEW=") ||
1043     matchword(buf, "rview")) {
1044     for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1045     putchar(*cp);
1046     }
1047     }
1048     fclose(fp);
1049     vopts = sskip(vopts);
1050     } else {
1051     while (isspace(*vopts))
1052     vopts++;
1053     putchar(' ');
1054 greg 2.24 #ifdef MSDOS
1055     if (*vopts == '$') { /* expand env. var. */
1056     if (!*atos(buf, sizeof(buf), vopts+1))
1057     return(-1);
1058     if ((cp = getenv(buf)) == NULL)
1059     return(-1);
1060     fputs(cp, stdout);
1061     vopts = sskip(vopts);
1062     } else
1063     #endif
1064     while (*vopts && !isspace(*vopts))
1065     putchar(*vopts++);
1066 greg 2.20 }
1067     } while (*vopts++);
1068     putchar('\n');
1069     return(0);
1070 greg 2.1 }
1071    
1072    
1073 greg 2.38 rview(opts, po) /* run rview with first view */
1074     char *opts, *po;
1075 greg 2.1 {
1076 greg 2.21 char *vw;
1077 greg 2.1 char combuf[512];
1078     /* build command */
1079 greg 2.41 if (touchonly || (vw = getview(0, NULL)) == NULL)
1080 greg 2.21 return;
1081     if (sayview)
1082     printview(vw);
1083 greg 2.38 sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1084 greg 2.1 if (rvdevice != NULL)
1085     sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1086 greg 2.29 if (vdef(EXPOSURE))
1087     sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1088 greg 2.26 strcat(combuf, oct1name);
1089 greg 2.4 if (runcom(combuf)) { /* run it */
1090 greg 2.1 fprintf(stderr, "%s: error running rview\n", progname);
1091     exit(1);
1092     }
1093     }
1094    
1095    
1096 greg 2.38 rpict(opts, po) /* run rpict and pfilt for each view */
1097     char *opts, *po;
1098 greg 2.1 {
1099 greg 2.2 char combuf[1024];
1100 greg 2.45 char rawfile[MAXPATH], picfile[MAXPATH];
1101     char zopt[MAXPATH+4], rep[MAXPATH+16], res[32];
1102 greg 2.3 char pfopts[128];
1103 greg 2.1 char vs[32], *vw;
1104     int vn, mult;
1105 greg 2.41 time_t rfdt, pfdt;
1106 greg 2.1 /* get pfilt options */
1107     pfiltopts(pfopts);
1108     /* get resolution, reporting */
1109 greg 2.31 switch (vscale(QUALITY)) {
1110     case LOW:
1111     mult = 1;
1112     break;
1113     case MEDIUM:
1114     mult = 2;
1115     break;
1116     case HIGH:
1117     mult = 3;
1118     break;
1119     }
1120 greg 2.1 {
1121     int xres, yres;
1122     double aspect;
1123     int n;
1124     n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1125     if (n == 3)
1126     sprintf(res, "-x %d -y %d -pa %.3f",
1127     mult*xres, mult*yres, aspect);
1128     else if (n) {
1129     if (n == 1) yres = xres;
1130     sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1131 greg 2.3 } else
1132     badvalue(RESOLUTION);
1133 greg 2.1 }
1134     rep[0] = '\0';
1135     if (vdef(REPORT)) {
1136     double minutes;
1137     int n;
1138     n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1139     if (n == 2)
1140     sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1141     else if (n == 1)
1142     sprintf(rep, " -t %d", (int)(minutes*60));
1143 greg 2.3 else
1144     badvalue(REPORT);
1145 greg 2.1 }
1146     /* do each view */
1147     vn = 0;
1148     while ((vw = getview(vn++, vs)) != NULL) {
1149 greg 2.21 if (sayview)
1150     printview(vw);
1151 greg 2.1 if (!vs[0])
1152     sprintf(vs, "%d", vn);
1153     sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1154 greg 2.45 if (vdef(ZFILE))
1155     sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1156     else
1157     zopt[0] = '\0';
1158 greg 2.1 /* check date on picture */
1159 greg 2.41 pfdt = fdate(picfile);
1160     if (pfdt >= oct1date)
1161 greg 2.1 continue;
1162 greg 2.41 /* get raw file name */
1163 greg 2.45 sprintf(rawfile, "%s_%s.unf",
1164     vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1165 greg 2.41 rfdt = fdate(rawfile);
1166     if (touchonly) { /* update times only */
1167     if (rfdt) {
1168     if (rfdt < oct1date)
1169     touch(rawfile);
1170     } else if (pfdt && pfdt < oct1date)
1171     touch(picfile);
1172     continue;
1173     }
1174 greg 2.1 /* build rpict command */
1175 greg 2.41 if (rfdt >= oct1date) /* recover */
1176 greg 2.45 sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1177     rep, po, opts, zopt, rawfile, oct1name);
1178 greg 2.1 else {
1179     if (overture) { /* run overture calculation */
1180     sprintf(combuf,
1181     "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1182     rep, vw, opts,
1183 greg 2.26 oct1name, overfile);
1184 greg 2.4 if (runcom(combuf)) {
1185 greg 2.1 fprintf(stderr,
1186 greg 2.6 "%s: error in overture for view %s\n",
1187     progname, vs);
1188 greg 2.1 exit(1);
1189     }
1190 greg 2.6 #ifdef NIX
1191     rmfile(overfile);
1192     #endif
1193 greg 2.1 }
1194 greg 2.45 sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1195     rep, vw, res, po, opts, zopt,
1196     oct1name, rawfile);
1197 greg 2.1 }
1198 greg 2.4 if (runcom(combuf)) { /* run rpict */
1199 greg 2.1 fprintf(stderr, "%s: error rendering view %s\n",
1200     progname, vs);
1201     exit(1);
1202     }
1203 greg 2.45 if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1204 greg 2.1 /* build pfilt command */
1205 greg 2.45 if (mult > 1)
1206     sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1207 greg 2.1 pfopts, mult, mult, rawfile, picfile);
1208 greg 2.45 else
1209     sprintf(combuf, "pfilt%s %s > %s", pfopts,
1210     rawfile, picfile);
1211     if (runcom(combuf)) { /* run pfilt */
1212     fprintf(stderr,
1213     "%s: error filtering view %s\n\t%s removed\n",
1214     progname, vs, picfile);
1215     unlink(picfile);
1216     exit(1);
1217     }
1218 greg 2.1 }
1219 greg 2.43 /* remove/rename raw file */
1220 greg 2.45 if (vdef(RAWFILE)) {
1221     sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1222 greg 2.43 mvfile(rawfile, combuf);
1223     } else
1224     rmfile(rawfile);
1225 greg 2.4 }
1226 greg 2.41 }
1227    
1228    
1229     touch(fn) /* update a file */
1230     char *fn;
1231     {
1232     if (!silent)
1233     printf("\ttouch %s\n", fn);
1234     if (noaction)
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 greg 2.4 }
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)
1251     return(0);
1252     fflush(stdout); /* flush output and pass to shell */
1253     return(system(cs));
1254     }
1255    
1256    
1257     rmfile(fn) /* remove a file */
1258     char *fn;
1259     {
1260     if (!silent)
1261 greg 2.1 #ifdef MSDOS
1262 greg 2.4 printf("\tdel %s\n", fn);
1263 greg 2.1 #else
1264 greg 2.4 printf("\trm -f %s\n", fn);
1265 greg 2.1 #endif
1266 greg 2.4 if (noaction)
1267     return(0);
1268     return(unlink(fn));
1269 greg 2.43 }
1270    
1271    
1272     mvfile(fold, fnew) /* move a file */
1273     char *fold, *fnew;
1274     {
1275     if (!silent)
1276     #ifdef MSDOS
1277     printf("\trename %s %s\n", fold, fnew);
1278     #else
1279     printf("\tmv %s %s\n", fold, fnew);
1280     #endif
1281     if (noaction)
1282     return(0);
1283     return(rename(fold, fnew));
1284 greg 2.3 }
1285 greg 2.8
1286    
1287     #ifdef MSDOS
1288     setenv(vname, value) /* set an environment variable */
1289     char *vname, *value;
1290     {
1291     register char *evp;
1292    
1293     evp = bmalloc(strlen(vname)+strlen(value)+2);
1294     if (evp == NULL)
1295     syserr(progname);
1296     sprintf(evp, "%s=%s", vname, value);
1297     if (putenv(evp) != 0) {
1298     fprintf(stderr, "%s: out of environment space\n", progname);
1299     exit(1);
1300     }
1301     if (!silent)
1302     printf("set %s\n", evp);
1303     }
1304     #endif
1305 greg 2.3
1306    
1307     badvalue(vc) /* report bad variable value and exit */
1308     int vc;
1309     {
1310     fprintf(stderr, "%s: bad value for variable '%s'\n",
1311     progname, vnam(vc));
1312     exit(1);
1313     }
1314    
1315    
1316     syserr(s) /* report a system error and exit */
1317     char *s;
1318     {
1319     perror(s);
1320     exit(1);
1321 greg 2.1 }