ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
Revision: 2.39
Committed: Thu Mar 24 12:28:22 1994 UTC (30 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.38: +8 -0 lines
Log Message:
improved checking of ZONE arguments

File Contents

# Content
1 /* Copyright (c) 1994 Regents of the University of California */
2
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 #include <ctype.h>
14 #include <sys/types.h>
15
16
17 typedef struct {
18 char *name; /* variable name */
19 short nick; /* # characters required for nickname */
20 short nass; /* # assignments made */
21 char *value; /* assigned value(s) */
22 int (*fixval)(); /* assignment checking function */
23 } VARIABLE;
24
25 int onevalue(), catvalues(), boolvalue(),
26 qualvalue(), fltvalue(), intvalue();
27
28 /* variables */
29 #define OBJECT 0 /* object files */
30 #define SCENE 1 /* scene files */
31 #define MATERIAL 2 /* material files */
32 #define ILLUM 3 /* mkillum input files */
33 #define MKILLUM 4 /* mkillum options */
34 #define RENDER 5 /* rendering options */
35 #define OCONV 6 /* oconv options */
36 #define PFILT 7 /* pfilt options */
37 #define VIEW 8 /* view(s) for picture(s) */
38 #define ZONE 9 /* simulation zone */
39 #define QUALITY 10 /* desired rendering quality */
40 #define OCTREE 11 /* octree file name */
41 #define PICTURE 12 /* picture file name */
42 #define AMBFILE 13 /* ambient file name */
43 #define OPTFILE 14 /* rendering options file */
44 #define EXPOSURE 15 /* picture exposure setting */
45 #define RESOLUTION 16 /* maximum picture resolution */
46 #define UP 17 /* view up (X, Y or Z) */
47 #define INDIRECT 18 /* indirection in lighting */
48 #define DETAIL 19 /* level of scene detail */
49 #define PENUMBRAS 20 /* shadow penumbras are desired */
50 #define VARIABILITY 21 /* level of light variability */
51 #define REPORT 22 /* report frequency and errfile */
52 /* total number of variables */
53 #define NVARS 23
54
55 VARIABLE vv[NVARS] = { /* variable-value pairs */
56 {"objects", 3, 0, NULL, catvalues},
57 {"scene", 3, 0, NULL, catvalues},
58 {"materials", 3, 0, NULL, catvalues},
59 {"illum", 3, 0, NULL, catvalues},
60 {"mkillum", 3, 0, NULL, catvalues},
61 {"render", 3, 0, NULL, catvalues},
62 {"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},
70 {"OPTFILE", 3, 0, NULL, onevalue},
71 {"EXPOSURE", 3, 0, NULL, fltvalue},
72 {"RESOLUTION", 3, 0, NULL, onevalue},
73 {"UP", 2, 0, NULL, onevalue},
74 {"INDIRECT", 3, 0, NULL, intvalue},
75 {"DETAIL", 3, 0, NULL, qualvalue},
76 {"PENUMBRAS", 3, 0, NULL, boolvalue},
77 {"VARIABILITY", 3, 0, NULL, qualvalue},
78 {"REPORT", 3, 0, NULL, onevalue},
79 };
80
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
98 /* overture calculation file */
99 #ifdef NIX
100 char overfile[] = "overture.raw";
101 #else
102 char overfile[] = "/dev/null";
103 #endif
104
105 extern time_t fdate(), time();
106
107 time_t scenedate; /* date of latest scene or object file */
108 time_t octreedate; /* date of octree */
109 time_t matdate; /* date of latest material file */
110 time_t illumdate; /* date of last illum file */
111
112 char *oct0name; /* name of pre-mkillum octree */
113 time_t oct0date; /* date of pre-mkillum octree */
114 char *oct1name; /* name of post-mkillum octree */
115 time_t oct1date; /* date of post-mkillum octree (>= matdate) */
116
117 int nowarn = 0; /* no warnings */
118 int explicate = 0; /* explicate variables */
119 int silent = 0; /* do work silently */
120 int noaction = 0; /* don't do anything */
121 int sayview = 0; /* print view out */
122 char *rvdevice = NULL; /* rview output device */
123 char *viewselect = NULL; /* specific view only */
124
125 int overture = 0; /* overture calculation needed */
126
127 char *progname; /* global argv[0] */
128 char *rifname; /* global rad input file name */
129
130 char radname[MAXPATH]; /* root Radiance file name */
131
132
133 main(argc, argv)
134 int argc;
135 char *argv[];
136 {
137 char ropts[512];
138 char popts[64];
139 int i;
140
141 progname = argv[0];
142 /* get options */
143 for (i = 1; i < argc && argv[i][0] == '-'; i++)
144 switch (argv[i][1]) {
145 case 's':
146 silent++;
147 break;
148 case 'n':
149 noaction++;
150 break;
151 case 'e':
152 explicate++;
153 break;
154 case 'o':
155 rvdevice = argv[++i];
156 break;
157 case 'V':
158 sayview++;
159 break;
160 case 'v':
161 viewselect = argv[++i];
162 break;
163 case 'w':
164 nowarn++;
165 break;
166 default:
167 goto userr;
168 }
169 if (i >= argc)
170 goto userr;
171 rifname = argv[i];
172 /* assign Radiance root file name */
173 rootname(radname, rifname);
174 /* load variable values */
175 load(rifname);
176 /* get any additional assignments */
177 for (i++; i < argc; i++)
178 setvariable(argv[i]);
179 /* check assignments */
180 checkvalues();
181 /* check files and dates */
182 checkfiles();
183 /* set default values as necessary */
184 setdefaults();
185 /* print all values if requested */
186 if (explicate)
187 printvals();
188 /* build octree (and run mkillum) */
189 oconv();
190 /* check date on ambient file */
191 checkambfile();
192 /* run simulation */
193 renderopts(ropts, popts);
194 xferopts(ropts);
195 if (rvdevice != NULL)
196 rview(ropts, popts);
197 else
198 rpict(ropts, popts);
199 exit(0);
200 userr:
201 fprintf(stderr,
202 "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
203 progname);
204 exit(1);
205 }
206
207
208 rootname(rn, fn) /* remove tail from end of fn */
209 register char *rn, *fn;
210 {
211 char *tp, *dp;
212
213 for (tp = NULL, dp = rn; *rn = *fn++; rn++)
214 if (ISDIRSEP(*rn))
215 dp = rn;
216 else if (*rn == '.')
217 tp = rn;
218 if (tp != NULL && tp > dp)
219 *tp = '\0';
220 }
221
222
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
470 time_t
471 checklast(fnames) /* check files and find most recent */
472 register char *fnames;
473 {
474 char thisfile[MAXPATH];
475 time_t thisdate, lastdate = 0;
476 register char *cp;
477
478 if (fnames == NULL)
479 return(0);
480 while (*fnames) {
481 while (isspace(*fnames)) fnames++;
482 cp = thisfile;
483 while (*fnames && !isspace(*fnames))
484 *cp++ = *fnames++;
485 *cp = '\0';
486 if (!(thisdate = fdate(thisfile)))
487 syserr(thisfile);
488 if (thisdate > lastdate)
489 lastdate = thisdate;
490 }
491 return(lastdate);
492 }
493
494
495 char *
496 newfname(orig, pred) /* create modified file name */
497 char *orig;
498 int pred;
499 {
500 extern char *rindex();
501 register char *cp;
502 register int n;
503 int suffix;
504
505 n = 0; cp = orig; suffix = -1; /* suffix position, length */
506 while (*cp) {
507 if (*cp == '.') suffix = n;
508 else if (ISDIRSEP(*cp)) suffix = -1;
509 cp++; n++;
510 }
511 if (suffix == -1) suffix = n;
512 if ((cp = bmalloc(n+2)) == NULL)
513 syserr(progname);
514 strncpy(cp, orig, suffix);
515 cp[suffix] = pred; /* root name + pred + suffix */
516 strcpy(cp+suffix+1, orig+suffix);
517 return(cp);
518 }
519
520
521 checkfiles() /* check for existence and modified times */
522 {
523 time_t objdate;
524
525 if (!vdef(OCTREE)) {
526 if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
527 syserr(progname);
528 sprintf(vval(OCTREE), "%s.oct", radname);
529 vdef(OCTREE)++;
530 }
531 octreedate = fdate(vval(OCTREE));
532 if (vdef(ILLUM)) { /* illum requires secondary octrees */
533 oct0name = newfname(vval(OCTREE), '0');
534 oct1name = newfname(vval(OCTREE), '1');
535 oct0date = fdate(oct0name);
536 oct1date = fdate(oct1name);
537 } else
538 oct0name = oct1name = vval(OCTREE);
539 if ((scenedate = checklast(vval(SCENE))) &&
540 (objdate = checklast(vval(OBJECT))) > scenedate)
541 scenedate = objdate;
542 illumdate = checklast(vval(ILLUM));
543 if (!octreedate & !scenedate & !illumdate) {
544 fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
545 vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
546 exit(1);
547 }
548 matdate = checklast(vval(MATERIAL));
549 }
550
551
552 getoctcube(org, sizp) /* get octree bounding cube */
553 double org[3], *sizp;
554 {
555 extern FILE *popen();
556 static double oorg[3], osiz = 0.;
557 double min[3], max[3];
558 char buf[512];
559 FILE *fp;
560 register int i;
561
562 if (osiz <= FTINY)
563 if (noaction && fdate(oct1name) <
564 (scenedate>illumdate?scenedate:illumdate)) {
565 /* run getbbox */
566 sprintf(buf, "getbbox -w -h %s",
567 vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
568 if ((fp = popen(buf, "r")) == NULL)
569 syserr("getbbox");
570 if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
571 &min[0], &max[0], &min[1], &max[1],
572 &min[2], &max[2]) != 6) {
573 fprintf(stderr,
574 "%s: error reading bounding box from getbbox\n",
575 progname);
576 exit(1);
577 }
578 for (i = 0; i < 3; i++)
579 if (max[i] - min[i] > osiz)
580 osiz = max[i] - min[i];
581 for (i = 0; i < 3; i++)
582 oorg[i] = (max[i]+min[i]-osiz)*.5;
583 pclose(fp);
584 } else { /* from octree */
585 oconv(); /* does nothing if done already */
586 sprintf(buf, "getinfo -d < %s", oct1name);
587 if ((fp = popen(buf, "r")) == NULL)
588 syserr("getinfo");
589 if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
590 &oorg[2], &osiz) != 4) {
591 fprintf(stderr,
592 "%s: error reading bounding cube from getinfo\n",
593 progname);
594 exit(1);
595 }
596 pclose(fp);
597 }
598 org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
599 }
600
601
602 setdefaults() /* set default values for unassigned var's */
603 {
604 double org[3], size;
605 char buf[128];
606
607 if (!vdef(ZONE)) {
608 getoctcube(org, &size);
609 sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
610 org[1], org[1]+size, org[2], org[2]+size);
611 vval(ZONE) = savqstr(buf);
612 vdef(ZONE)++;
613 }
614 if (!vdef(INDIRECT)) {
615 vval(INDIRECT) = "0";
616 vdef(INDIRECT)++;
617 }
618 if (!vdef(QUALITY)) {
619 vval(QUALITY) = "L";
620 vdef(QUALITY)++;
621 }
622 if (!vdef(RESOLUTION)) {
623 vval(RESOLUTION) = "512";
624 vdef(RESOLUTION)++;
625 }
626 if (!vdef(PICTURE)) {
627 vval(PICTURE) = radname;
628 vdef(PICTURE)++;
629 }
630 if (!vdef(VIEW)) {
631 vval(VIEW) = "X";
632 vdef(VIEW)++;
633 }
634 if (!vdef(DETAIL)) {
635 vval(DETAIL) = "M";
636 vdef(DETAIL)++;
637 }
638 if (!vdef(PENUMBRAS)) {
639 vval(PENUMBRAS) = "F";
640 vdef(PENUMBRAS)++;
641 }
642 if (!vdef(VARIABILITY)) {
643 vval(VARIABILITY) = "L";
644 vdef(VARIABILITY)++;
645 }
646 }
647
648
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
681 oconv() /* run oconv and mkillum if necessary */
682 {
683 static char illumtmp[] = "ilXXXXXX";
684 char combuf[512], ocopts[64], mkopts[64];
685
686 oconvopts(ocopts); /* get options */
687 if (octreedate < scenedate) { /* check date on original octree */
688 /* build command */
689 if (vdef(MATERIAL))
690 sprintf(combuf, "oconv%s %s %s > %s", ocopts,
691 vval(MATERIAL), vval(SCENE), vval(OCTREE));
692 else
693 sprintf(combuf, "oconv%s %s > %s", ocopts,
694 vval(SCENE), vval(OCTREE));
695
696 if (runcom(combuf)) { /* run it */
697 fprintf(stderr,
698 "%s: error generating octree\n\t%s removed\n",
699 progname, vval(OCTREE));
700 unlink(vval(OCTREE));
701 exit(1);
702 }
703 octreedate = time((time_t *)NULL);
704 }
705 if (oct1name == vval(OCTREE)) /* no mkillum? */
706 oct1date = octreedate > matdate ? octreedate : matdate;
707 if (oct1date >= octreedate & oct1date >= matdate
708 & oct1date >= illumdate) /* all done */
709 return;
710 /* make octree0 */
711 if (oct0date < scenedate | oct0date < illumdate) {
712 /* build command */
713 if (octreedate)
714 sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
715 vval(OCTREE), vval(ILLUM), oct0name);
716 else if (vdef(MATERIAL))
717 sprintf(combuf, "oconv%s %s %s > %s", ocopts,
718 vval(MATERIAL), vval(ILLUM), oct0name);
719 else
720 sprintf(combuf, "oconv%s %s > %s", ocopts,
721 vval(ILLUM), oct0name);
722 if (runcom(combuf)) { /* run it */
723 fprintf(stderr,
724 "%s: error generating octree\n\t%s removed\n",
725 progname, oct0name);
726 unlink(oct0name);
727 exit(1);
728 }
729 oct0date = time((time_t *)NULL);
730 }
731 mkillumopts(mkopts); /* build mkillum command */
732 mktemp(illumtmp);
733 sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
734 oct0name, vval(ILLUM), illumtmp);
735 if (runcom(combuf)) { /* run it */
736 fprintf(stderr, "%s: error running mkillum\n", progname);
737 unlink(illumtmp);
738 exit(1);
739 }
740 /* make octree1 (frozen) */
741 if (octreedate)
742 sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
743 vval(OCTREE), illumtmp, oct1name);
744 else if (vdef(MATERIAL))
745 sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
746 vval(MATERIAL), illumtmp, oct1name);
747 else
748 sprintf(combuf, "oconv%s -f %s > %s", ocopts,
749 illumtmp, oct1name);
750 if (runcom(combuf)) { /* run it */
751 fprintf(stderr,
752 "%s: error generating octree\n\t%s removed\n",
753 progname, oct1name);
754 unlink(oct1name);
755 exit(1);
756 }
757 oct1date = time((time_t *)NULL);
758 rmfile(illumtmp);
759 }
760
761
762 char *
763 addarg(op, arg) /* add argument and advance pointer */
764 register char *op, *arg;
765 {
766 *op = ' ';
767 while (*++op = *arg++)
768 ;
769 return(op);
770 }
771
772
773 oconvopts(oo) /* get oconv options */
774 register char *oo;
775 {
776 /* BEWARE: This may be called via setdefaults(), so no assumptions */
777
778 *oo = '\0';
779 if (vdef(OCONV))
780 addarg(oo, vval(OCONV));
781 }
782
783
784 mkillumopts(mo) /* get mkillum options */
785 register char *mo;
786 {
787 /* BEWARE: This may be called via setdefaults(), so no assumptions */
788
789 *mo = '\0';
790 if (vdef(MKILLUM))
791 addarg(mo, vval(MKILLUM));
792 }
793
794
795 checkambfile() /* check date on ambient file */
796 {
797 time_t afdate;
798
799 if (!vdef(AMBFILE))
800 return;
801 if (!(afdate = fdate(vval(AMBFILE))))
802 return;
803 if (oct1date > afdate)
804 rmfile(vval(AMBFILE));
805 }
806
807
808 double
809 ambval() /* compute ambient value */
810 {
811 if (vdef(EXPOSURE)) {
812 if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
813 return(.5/pow(2.,atof(vval(EXPOSURE))));
814 return(.5/atof(vval(EXPOSURE)));
815 }
816 if (vlet(ZONE) == 'E')
817 return(10.);
818 if (vlet(ZONE) == 'I')
819 return(.01);
820 badvalue(ZONE);
821 }
822
823
824 renderopts(op, po) /* set rendering options */
825 char *op, *po;
826 {
827 switch(vscale(QUALITY)) {
828 case LOW:
829 lowqopts(op, po);
830 break;
831 case MEDIUM:
832 medqopts(op, po);
833 break;
834 case HIGH:
835 hiqopts(op, po);
836 break;
837 }
838 }
839
840
841 lowqopts(op, po) /* low quality rendering options */
842 register char *op;
843 char *po;
844 {
845 double d, org[3], siz[3];
846
847 *op = '\0';
848 *po = '\0';
849 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
850 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
851 badvalue(ZONE);
852 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
853 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
854 badvalue(ZONE);
855 getoctcube(org, &d);
856 d *= 3./(siz[0]+siz[1]+siz[2]);
857 switch (vscale(DETAIL)) {
858 case LOW:
859 po = addarg(po, "-ps 16");
860 op = addarg(op, "-dp 64");
861 sprintf(op, " -ar %d", (int)(4*d));
862 op += strlen(op);
863 break;
864 case MEDIUM:
865 po = addarg(po, "-ps 8");
866 op = addarg(op, "-dp 128");
867 sprintf(op, " -ar %d", (int)(8*d));
868 op += strlen(op);
869 break;
870 case HIGH:
871 po = addarg(po, "-ps 4");
872 op = addarg(op, "-dp 256");
873 sprintf(op, " -ar %d", (int)(16*d));
874 op += strlen(op);
875 break;
876 }
877 po = addarg(po, "-pt .16");
878 if (vbool(PENUMBRAS))
879 op = addarg(op, "-ds .4");
880 else
881 op = addarg(op, "-ds 0");
882 op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
883 if (vdef(AMBFILE)) {
884 sprintf(op, " -af %s", vval(AMBFILE));
885 op += strlen(op);
886 } else
887 overture = 0;
888 switch (vscale(VARIABILITY)) {
889 case LOW:
890 op = addarg(op, "-aa .4 -ad 64");
891 break;
892 case MEDIUM:
893 op = addarg(op, "-aa .3 -ad 128");
894 break;
895 case HIGH:
896 op = addarg(op, "-aa .25 -ad 256");
897 break;
898 }
899 op = addarg(op, "-as 0");
900 d = ambval();
901 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
902 op += strlen(op);
903 op = addarg(op, "-lr 3 -lw .02");
904 if (vdef(RENDER))
905 op = addarg(op, vval(RENDER));
906 }
907
908
909 medqopts(op, po) /* medium quality rendering options */
910 register char *op;
911 char *po;
912 {
913 double d, org[3], siz[3];
914
915 *op = '\0';
916 *po = '\0';
917 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
918 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
919 badvalue(ZONE);
920 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
921 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
922 badvalue(ZONE);
923 getoctcube(org, &d);
924 d *= 3./(siz[0]+siz[1]+siz[2]);
925 switch (vscale(DETAIL)) {
926 case LOW:
927 po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
928 op = addarg(op, "-dp 256");
929 sprintf(op, " -ar %d", (int)(8*d));
930 op += strlen(op);
931 break;
932 case MEDIUM:
933 po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
934 op = addarg(op, "-dp 512");
935 sprintf(op, " -ar %d", (int)(16*d));
936 op += strlen(op);
937 break;
938 case HIGH:
939 po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
940 op = addarg(op, "-dp 1024");
941 sprintf(op, " -ar %d", (int)(32*d));
942 op += strlen(op);
943 break;
944 }
945 po = addarg(po, "-pt .08");
946 if (vbool(PENUMBRAS))
947 op = addarg(op, "-ds .2 -dj .5");
948 else
949 op = addarg(op, "-ds .3");
950 op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
951 if (overture = vint(INDIRECT)) {
952 sprintf(op, " -ab %d", overture);
953 op += strlen(op);
954 }
955 if (vdef(AMBFILE)) {
956 sprintf(op, " -af %s", vval(AMBFILE));
957 op += strlen(op);
958 } else
959 overture = 0;
960 switch (vscale(VARIABILITY)) {
961 case LOW:
962 op = addarg(op, "-aa .25 -ad 196 -as 0");
963 break;
964 case MEDIUM:
965 op = addarg(op, "-aa .2 -ad 400 -as 64");
966 break;
967 case HIGH:
968 op = addarg(op, "-aa .15 -ad 768 -as 196");
969 break;
970 }
971 d = ambval();
972 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
973 op += strlen(op);
974 op = addarg(op, "-lr 6 -lw .002");
975 if (vdef(RENDER))
976 op = addarg(op, vval(RENDER));
977 }
978
979
980 hiqopts(op, po) /* high quality rendering options */
981 register char *op;
982 char *po;
983 {
984 double d, org[3], siz[3];
985
986 *op = '\0';
987 *po = '\0';
988 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
989 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
990 badvalue(ZONE);
991 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
992 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
993 badvalue(ZONE);
994 getoctcube(org, &d);
995 d *= 3./(siz[0]+siz[1]+siz[2]);
996 switch (vscale(DETAIL)) {
997 case LOW:
998 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
999 op = addarg(op, "-dp 1024");
1000 sprintf(op, " -ar %d", (int)(16*d));
1001 op += strlen(op);
1002 break;
1003 case MEDIUM:
1004 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1005 op = addarg(op, "-dp 2048");
1006 sprintf(op, " -ar %d", (int)(32*d));
1007 op += strlen(op);
1008 break;
1009 case HIGH:
1010 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1011 op = addarg(op, "-dp 4096");
1012 sprintf(op, " -ar %d", (int)(64*d));
1013 op += strlen(op);
1014 break;
1015 }
1016 po = addarg(po, "-pt .04");
1017 if (vbool(PENUMBRAS))
1018 op = addarg(op, "-ds .1 -dj .7");
1019 else
1020 op = addarg(op, "-ds .2");
1021 op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1022 sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1023 op += strlen(op);
1024 if (vdef(AMBFILE)) {
1025 sprintf(op, " -af %s", vval(AMBFILE));
1026 op += strlen(op);
1027 } else
1028 overture = 0;
1029 switch (vscale(VARIABILITY)) {
1030 case LOW:
1031 op = addarg(op, "-aa .15 -ad 256 -as 0");
1032 break;
1033 case MEDIUM:
1034 op = addarg(op, "-aa .125 -ad 512 -as 256");
1035 break;
1036 case HIGH:
1037 op = addarg(op, "-aa .08 -ad 1024 -as 512");
1038 break;
1039 }
1040 d = ambval();
1041 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1042 op += strlen(op);
1043 op = addarg(op, "-lr 12 -lw .0005");
1044 if (vdef(RENDER))
1045 op = addarg(op, vval(RENDER));
1046 }
1047
1048
1049 xferopts(ro) /* transfer options if indicated */
1050 char *ro;
1051 {
1052 int fd, n;
1053 register char *cp;
1054
1055 n = strlen(ro);
1056 if (n < 2)
1057 return;
1058 if (vdef(OPTFILE)) {
1059 for (cp = ro; cp[1]; cp++)
1060 if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1061 *cp = '\n';
1062 else
1063 *cp = cp[1];
1064 *cp = '\n';
1065 fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1066 if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1067 syserr(vval(OPTFILE));
1068 sprintf(ro, " @%s", vval(OPTFILE));
1069 }
1070 #ifdef MSDOS
1071 else if (n > 50) {
1072 setenv("ROPT", ro+1);
1073 strcpy(ro, " $ROPT");
1074 }
1075 #endif
1076 }
1077
1078
1079 pfiltopts(po) /* get pfilt options */
1080 register char *po;
1081 {
1082 *po = '\0';
1083 if (vdef(EXPOSURE)) {
1084 po = addarg(po, "-1 -e");
1085 po = addarg(po, vval(EXPOSURE));
1086 }
1087 switch (vscale(QUALITY)) {
1088 case MEDIUM:
1089 po = addarg(po, "-r 1");
1090 break;
1091 case HIGH:
1092 po = addarg(po, "-m .25");
1093 break;
1094 }
1095 if (vdef(PFILT))
1096 po = addarg(po, vval(PFILT));
1097 }
1098
1099
1100 matchword(s1, s2) /* match white-delimited words */
1101 register char *s1, *s2;
1102 {
1103 while (isspace(*s1)) s1++;
1104 while (isspace(*s2)) s2++;
1105 while (*s1 && !isspace(*s1))
1106 if (*s1++ != *s2++)
1107 return(0);
1108 return(!*s2 || isspace(*s2));
1109 }
1110
1111
1112 char *
1113 specview(vs) /* get proper view spec from vs */
1114 register char *vs;
1115 {
1116 static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1117 "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1118 static char viewopts[128];
1119 register char *cp;
1120 int xpos, ypos, zpos, viewtype, upax;
1121 register int i;
1122 double cent[3], dim[3], mult, d;
1123
1124 if (vs == NULL || *vs == '-')
1125 return(vs);
1126 upax = 0; /* get the up vector */
1127 if (vdef(UP)) {
1128 if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
1129 upax = 1-'X'+UPPER(vval(UP)[1]);
1130 else
1131 upax = 1-'X'+vlet(UP);
1132 if (upax < 1 | upax > 3)
1133 badvalue(UP);
1134 if (vval(UP)[0] == '-')
1135 upax = -upax;
1136 }
1137 /* check standard view names */
1138 xpos = ypos = zpos = 0;
1139 if (*vs == 'X') {
1140 xpos = 1; vs++;
1141 } else if (*vs == 'x') {
1142 xpos = -1; vs++;
1143 }
1144 if (*vs == 'Y') {
1145 ypos = 1; vs++;
1146 } else if (*vs == 'y') {
1147 ypos = -1; vs++;
1148 }
1149 if (*vs == 'Z') {
1150 zpos = 1; vs++;
1151 } else if (*vs == 'z') {
1152 zpos = -1; vs++;
1153 }
1154 viewtype = 'v';
1155 if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1156 viewtype = *vs++;
1157 cp = viewopts;
1158 if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */
1159 *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
1160 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
1161 &cent[0], &dim[0], &cent[1], &dim[1],
1162 &cent[2], &dim[2]) != 6)
1163 badvalue(ZONE);
1164 for (i = 0; i < 3; i++) {
1165 dim[i] -= cent[i];
1166 if (dim[i] <= FTINY)
1167 badvalue(ZONE);
1168 cent[i] += .5*dim[i];
1169 }
1170 mult = vlet(ZONE)=='E' ? 2. : .45 ;
1171 sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1172 cent[0]+xpos*mult*dim[0],
1173 cent[1]+ypos*mult*dim[1],
1174 cent[2]+zpos*mult*dim[2],
1175 -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
1176 cp += strlen(cp);
1177 /* redirect up axis if necessary */
1178 switch (upax) {
1179 case 3: /* plus or minus Z axis */
1180 case -3:
1181 case 0:
1182 if (!(xpos|ypos))
1183 upax = 2;
1184 break;
1185 case 2: /* plus or minus Y axis */
1186 case -2:
1187 if (!(xpos|zpos))
1188 upax = 1;
1189 break;
1190 case 1: /* plus or minus X axis */
1191 case -1:
1192 if (!(ypos|zpos))
1193 upax = 3;
1194 break;
1195 }
1196 cp = addarg(cp, vup[upax+3]);
1197 switch (viewtype) {
1198 case 'v':
1199 cp = addarg(cp, "-vh 45 -vv 45");
1200 break;
1201 case 'l':
1202 d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1203 sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1204 cp += strlen(cp);
1205 break;
1206 case 'a':
1207 case 'h':
1208 cp = addarg(cp, "-vh 180 -vv 180");
1209 break;
1210 }
1211 } else {
1212 while (!isspace(*vs)) /* else skip id */
1213 if (!*vs++)
1214 return(NULL);
1215 if (upax) { /* specify up vector */
1216 strcpy(cp, vup[upax+3]);
1217 cp += strlen(cp);
1218 }
1219 }
1220 if (cp == viewopts) /* append any additional options */
1221 vs++; /* skip prefixed space if unneeded */
1222 strcpy(cp, vs);
1223 #ifdef MSDOS
1224 if (strlen(viewopts) > 40) {
1225 setenv("VIEW", viewopts);
1226 return("$VIEW");
1227 }
1228 #endif
1229 return(viewopts);
1230 }
1231
1232
1233 char *
1234 getview(n, vn) /* get view n, or NULL if none */
1235 int n;
1236 char *vn; /* returned view name */
1237 {
1238 register char *mv;
1239
1240 if (viewselect != NULL) { /* command-line selected */
1241 if (n) /* only do one */
1242 return(NULL);
1243 if (viewselect[0] == '-') { /* already specified */
1244 if (vn != NULL) *vn = '\0';
1245 return(viewselect);
1246 }
1247 if (vn != NULL) {
1248 for (mv = viewselect; *mv && !isspace(*mv);
1249 *vn++ = *mv++)
1250 ;
1251 *vn = '\0';
1252 }
1253 /* view number? */
1254 if (isint(viewselect))
1255 return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1256 /* check list */
1257 while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1258 if (matchword(viewselect, mv))
1259 return(specview(mv));
1260 return(specview(viewselect)); /* standard view? */
1261 }
1262 mv = nvalue(vv+VIEW, n); /* use view n */
1263 if (vn != NULL & mv != NULL) {
1264 register char *mv2 = mv;
1265 if (*mv2 != '-')
1266 while (*mv2 && !isspace(*mv2))
1267 *vn++ = *mv2++;
1268 *vn = '\0';
1269 }
1270 return(specview(mv));
1271 }
1272
1273
1274 printview(vopts) /* print out selected view */
1275 register char *vopts;
1276 {
1277 extern char *atos(), *getenv();
1278 char buf[256];
1279 FILE *fp;
1280 register char *cp;
1281
1282 if (vopts == NULL)
1283 return(-1);
1284 fputs("VIEW=", stdout);
1285 do {
1286 if (matchword(vopts, "-vf")) { /* expand view file */
1287 vopts = sskip(vopts);
1288 if (!*atos(buf, sizeof(buf), vopts))
1289 return(-1);
1290 if ((fp = fopen(buf, "r")) == NULL)
1291 return(-1);
1292 for (buf[sizeof(buf)-2] = '\n';
1293 fgets(buf, sizeof(buf), fp) != NULL &&
1294 buf[0] != '\n';
1295 buf[sizeof(buf)-2] = '\n') {
1296 if (buf[sizeof(buf)-2] != '\n') {
1297 ungetc(buf[sizeof(buf)-2], fp);
1298 buf[sizeof(buf)-2] = '\0';
1299 }
1300 if (matchword(buf, "VIEW=") ||
1301 matchword(buf, "rview")) {
1302 for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1303 putchar(*cp);
1304 }
1305 }
1306 fclose(fp);
1307 vopts = sskip(vopts);
1308 } else {
1309 while (isspace(*vopts))
1310 vopts++;
1311 putchar(' ');
1312 #ifdef MSDOS
1313 if (*vopts == '$') { /* expand env. var. */
1314 if (!*atos(buf, sizeof(buf), vopts+1))
1315 return(-1);
1316 if ((cp = getenv(buf)) == NULL)
1317 return(-1);
1318 fputs(cp, stdout);
1319 vopts = sskip(vopts);
1320 } else
1321 #endif
1322 while (*vopts && !isspace(*vopts))
1323 putchar(*vopts++);
1324 }
1325 } while (*vopts++);
1326 putchar('\n');
1327 return(0);
1328 }
1329
1330
1331 rview(opts, po) /* run rview with first view */
1332 char *opts, *po;
1333 {
1334 char *vw;
1335 char combuf[512];
1336 /* build command */
1337 if ((vw = getview(0, NULL)) == NULL)
1338 return;
1339 if (sayview)
1340 printview(vw);
1341 sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1342 if (rvdevice != NULL)
1343 sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1344 if (vdef(EXPOSURE))
1345 sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1346 strcat(combuf, oct1name);
1347 if (runcom(combuf)) { /* run it */
1348 fprintf(stderr, "%s: error running rview\n", progname);
1349 exit(1);
1350 }
1351 }
1352
1353
1354 rpict(opts, po) /* run rpict and pfilt for each view */
1355 char *opts, *po;
1356 {
1357 char combuf[1024];
1358 char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1359 char pfopts[128];
1360 char vs[32], *vw;
1361 int vn, mult;
1362 /* get pfilt options */
1363 pfiltopts(pfopts);
1364 /* get resolution, reporting */
1365 switch (vscale(QUALITY)) {
1366 case LOW:
1367 mult = 1;
1368 break;
1369 case MEDIUM:
1370 mult = 2;
1371 break;
1372 case HIGH:
1373 mult = 3;
1374 break;
1375 }
1376 {
1377 int xres, yres;
1378 double aspect;
1379 int n;
1380 n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1381 if (n == 3)
1382 sprintf(res, "-x %d -y %d -pa %.3f",
1383 mult*xres, mult*yres, aspect);
1384 else if (n) {
1385 if (n == 1) yres = xres;
1386 sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1387 } else
1388 badvalue(RESOLUTION);
1389 }
1390 rep[0] = '\0';
1391 if (vdef(REPORT)) {
1392 double minutes;
1393 int n;
1394 n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1395 if (n == 2)
1396 sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1397 else if (n == 1)
1398 sprintf(rep, " -t %d", (int)(minutes*60));
1399 else
1400 badvalue(REPORT);
1401 }
1402 /* do each view */
1403 vn = 0;
1404 while ((vw = getview(vn++, vs)) != NULL) {
1405 if (sayview)
1406 printview(vw);
1407 if (!vs[0])
1408 sprintf(vs, "%d", vn);
1409 sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1410 /* check date on picture */
1411 if (fdate(picfile) >= oct1date)
1412 continue;
1413 /* build rpict command */
1414 sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1415 if (fdate(rawfile) >= oct1date) /* recover */
1416 sprintf(combuf, "rpict%s%s%s -ro %s %s",
1417 rep, po, opts, rawfile, oct1name);
1418 else {
1419 if (overture) { /* run overture calculation */
1420 sprintf(combuf,
1421 "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1422 rep, vw, opts,
1423 oct1name, overfile);
1424 if (runcom(combuf)) {
1425 fprintf(stderr,
1426 "%s: error in overture for view %s\n",
1427 progname, vs);
1428 exit(1);
1429 }
1430 #ifdef NIX
1431 rmfile(overfile);
1432 #endif
1433 }
1434 sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1435 rep, vw, res, po, opts,
1436 oct1name, rawfile);
1437 }
1438 if (runcom(combuf)) { /* run rpict */
1439 fprintf(stderr, "%s: error rendering view %s\n",
1440 progname, vs);
1441 exit(1);
1442 }
1443 /* build pfilt command */
1444 if (mult > 1)
1445 sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1446 pfopts, mult, mult, rawfile, picfile);
1447 else
1448 sprintf(combuf, "pfilt%s %s > %s", pfopts,
1449 rawfile, picfile);
1450 if (runcom(combuf)) { /* run pfilt */
1451 fprintf(stderr,
1452 "%s: error filtering view %s\n\t%s removed\n",
1453 progname, vs, picfile);
1454 unlink(picfile);
1455 exit(1);
1456 }
1457 /* remove raw file */
1458 rmfile(rawfile);
1459 }
1460 }
1461
1462
1463 runcom(cs) /* run command */
1464 char *cs;
1465 {
1466 if (!silent) /* echo it */
1467 printf("\t%s\n", cs);
1468 if (noaction)
1469 return(0);
1470 fflush(stdout); /* flush output and pass to shell */
1471 return(system(cs));
1472 }
1473
1474
1475 rmfile(fn) /* remove a file */
1476 char *fn;
1477 {
1478 if (!silent)
1479 #ifdef MSDOS
1480 printf("\tdel %s\n", fn);
1481 #else
1482 printf("\trm -f %s\n", fn);
1483 #endif
1484 if (noaction)
1485 return(0);
1486 return(unlink(fn));
1487 }
1488
1489
1490 #ifdef MSDOS
1491 setenv(vname, value) /* set an environment variable */
1492 char *vname, *value;
1493 {
1494 register char *evp;
1495
1496 evp = bmalloc(strlen(vname)+strlen(value)+2);
1497 if (evp == NULL)
1498 syserr(progname);
1499 sprintf(evp, "%s=%s", vname, value);
1500 if (putenv(evp) != 0) {
1501 fprintf(stderr, "%s: out of environment space\n", progname);
1502 exit(1);
1503 }
1504 if (!silent)
1505 printf("set %s\n", evp);
1506 }
1507 #endif
1508
1509
1510 badvalue(vc) /* report bad variable value and exit */
1511 int vc;
1512 {
1513 fprintf(stderr, "%s: bad value for variable '%s'\n",
1514 progname, vnam(vc));
1515 exit(1);
1516 }
1517
1518
1519 syserr(s) /* report a system error and exit */
1520 char *s;
1521 {
1522 perror(s);
1523 exit(1);
1524 }