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.2 by greg, Thu Mar 11 11:39:48 1993 UTC vs.
Revision 2.4 by greg, Fri Mar 12 13:37:03 1993 UTC

# Line 76 | Line 76 | VARIABLE       *matchvar();
76   char    *nvalue();
77   int     vscale();
78  
79 + #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
80 +
81   #define vnam(vc)        (vv[vc].name)
82   #define vdef(vc)        (vv[vc].nass)
83   #define vval(vc)        (vv[vc].value)
84   #define vint(vc)        atoi(vval(vc))
85 < #define vlet(vc)        (vval(vc)[0]&~0x20)
85 > #define vlet(vc)        UPPER(vval(vc)[0])
86   #define vbool(vc)       (vlet(vc)=='T')
87  
88   #define HIGH            2
# Line 168 | Line 170 | char   *argv[];
170          exit(0);
171   userr:
172          fprintf(stderr,
173 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
173 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
174                          progname);
175          exit(1);
176   }
# Line 193 | Line 195 | load(rfname)                   /* load Radiance simulation file */
195   char    *rfname;
196   {
197          FILE    *fp;
198 <        char    buf[256];
198 >        char    buf[512];
199          register char   *cp;
200  
201          if (rfname == NULL)
202                  fp = stdin;
203 <        else if ((fp = fopen(rfname, "r")) == NULL) {
204 <                perror(rfname);
203 <                exit(1);
204 <        }
203 >        else if ((fp = fopen(rfname, "r")) == NULL)
204 >                syserr(rfname);
205          while (fgetline(buf, sizeof(buf), fp) != NULL) {
206                  for (cp = buf; *cp; cp++) {
207                          switch (*cp) {
# Line 212 | Line 212 | char   *rfname;
212                          case '#':
213                                  *cp = '\0';
214                                  break;
215 +                        default:
216 +                                continue;
217                          }
218                          break;
219                  }
# Line 260 | Line 262 | register char  *ass;
262                  exit(1);
263          }
264                                          /* assign new value */
265 <        cp = vp->value; i = vp->nass;
266 <        while (i--)
267 <                while (*cp++)
268 <                        ;
269 <        i = cp - vp->value;
270 <        vp->value = realloc(vp->value, i+n+1);
271 <        if (vp->value == NULL) {
272 <                perror(progname);
273 <                exit(1);
274 <        }
265 >        if (i = vp->nass) {
266 >                cp = vp->value;
267 >                while (i--)
268 >                        while (*cp++)
269 >                                ;
270 >                i = cp - vp->value;
271 >                vp->value = realloc(vp->value, i+n+1);
272 >        } else
273 >                vp->value = malloc(n+1);
274 >        if (vp->value == NULL)
275 >                syserr(progname);
276          strcpy(vp->value+i, ass);
277          vp->nass++;
278   }
# Line 318 | Line 321 | int    vc;
321          case 'L':
322                  return(LOW);
323          }
324 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
324 >        badvalue(vc);
325   }
326  
327  
# Line 373 | Line 374 | register char  *fnames;
374          while (*fnames) {
375                  while (isspace(*fnames)) fnames++;
376                  cp = thisfile;
377 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
377 >                while (*fnames && !isspace(*fnames))
378 >                        *cp++ = *fnames++;
379                  *cp = '\0';
380 <                if ((thisdate = fdate(thisfile)) < 0) {
381 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
380 >                if ((thisdate = fdate(thisfile)) < 0)
381 >                        syserr(thisfile);
382                  if (thisdate > lastdate)
383                          lastdate = thisdate;
384          }
# Line 392 | Line 392 | checkfiles()                   /* check for existence and modified tim
392          long    objdate;
393  
394          if (!vdef(OCTREE)) {
395 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
396 <                        perror(progname);
397 <                        exit(1);
398 <                }
395 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
396 >                        syserr(progname);
397                  sprintf(cp, "%s.oct", radname);
398                  vval(OCTREE) = cp;
399                  vdef(OCTREE)++;
# Line 429 | Line 427 | double org[3], *sizp;
427          if (osiz <= FTINY) {
428                  oconv();                /* does nothing if done already */
429                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
430 <                if ((fp = popen(buf, "r")) == NULL) {
431 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
430 >                if ((fp = popen(buf, "r")) == NULL)
431 >                        syserr("getinfo");
432                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
433                                  &oorg[2], &osiz) != 4) {
434                          fprintf(stderr,
# Line 458 | Line 454 | setdefaults()                  /* set default values for unassigned v
454                  vval(ZONE) = savqstr(buf);
455                  vdef(ZONE)++;
456          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
457          if (!vdef(INDIRECT)) {
458                  vval(INDIRECT) = "0";
459                  vdef(INDIRECT)++;
# Line 502 | Line 494 | printvals()                    /* print variable values */
494          register int    i, j;
495  
496          for (i = 0; i < NVARS; i++)
497 <                for (j = 0; j < vv[i].nass; j++)
498 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
497 >                for (j = 0; j < vdef(i); j++)
498 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
499          fflush(stdout);
500   }
501  
# Line 516 | Line 508 | oconv()                                /* run oconv if necessary */
508                  return;
509                                          /* build command */
510          oconvopts(ocopts);
511 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
512 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
513 <                        vval(SCENE), vval(OCTREE));
514 <        if (!silent) {                  /* echo it */
515 <                printf("\t%s\n", combuf);
516 <                fflush(stdout);
517 <        }
518 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
511 >        if (vdef(MATERIAL))
512 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
513 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
514 >        else
515 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
516 >                                vval(SCENE), vval(OCTREE));
517 >        
518 >        if (runcom(combuf)) {           /* run it */
519                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
520                                  progname, vval(OCTREE));
521                  unlink(vval(OCTREE));
# Line 560 | Line 550 | register char  *oo;
550   double
551   ambval()                                /* compute ambient value */
552   {
553 <        if (vdef(EXPOSURE))
553 >        if (vdef(EXPOSURE)) {
554                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
555                          return(.5/pow(2.,atof(vval(EXPOSURE))));
556 <                else
556 >                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
557                          return(.5/atof(vval(EXPOSURE)));
558 +                badvalue(EXPOSURE);
559 +        }
560          if (vlet(ZONE) == 'E')
561                  return(10.);
562 <        else
562 >        if (vlet(ZONE) == 'I')
563                  return(.01);
564 +        badvalue(ZONE);
565   }
566  
567  
# Line 579 | Line 572 | register char  *op;
572  
573          *op = '\0';
574          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
575 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
576 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
575 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
576 >                badvalue(ZONE);
577          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
578          getoctcube(org, &d);
579          d *= 3./(siz[0]+siz[1]+siz[2]);
580          switch (vscale(DETAIL)) {
581          case LOW:
582 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
582 >                op = addarg(op, "-ps 16 -dp 16");
583                  sprintf(op, " -ar %d", (int)(4*d));
584                  op += strlen(op);
585                  break;
586          case MEDIUM:
587 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
587 >                op = addarg(op, "-ps 8 -dp 32");
588                  sprintf(op, " -ar %d", (int)(8*d));
589                  op += strlen(op);
590                  break;
591          case HIGH:
592 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
592 >                op = addarg(op, "-ps 4 -dp 64");
593                  sprintf(op, " -ar %d", (int)(16*d));
594                  op += strlen(op);
595                  break;
# Line 610 | Line 597 | register char  *op;
597          op = addarg(op, "-pt .16");
598          if (vbool(PENUMBRAS))
599                  op = addarg(op, "-ds .4");
600 <        op = addarg(op, "-dt .2");
601 <        op = addarg(op, "-dc .25");
602 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
600 >        else
601 >                op = addarg(op, "-ds 0");
602 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
603          if (vdef(AMBFILE)) {
604                  sprintf(op, " -af %s", vval(AMBFILE));
605                  op += strlen(op);
# Line 623 | Line 607 | register char  *op;
607                  overture = 0;
608          switch (vscale(VARIABILITY)) {
609          case LOW:
610 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
610 >                op = addarg(op, "-aa .4 -ad 32");
611                  break;
612          case MEDIUM:
613 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
613 >                op = addarg(op, "-aa .3 -ad 64");
614                  break;
615          case HIGH:
616 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
616 >                op = addarg(op, "-aa .25 -ad 128");
617                  break;
618          }
619          op = addarg(op, "-as 0");
620          d = ambval();
621          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
622          op += strlen(op);
623 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
623 >        op = addarg(op, "-lr 3 -lw .02");
624          if (vdef(RENDER))
625                  op = addarg(op, vval(RENDER));
626   }
# Line 653 | Line 633 | register char  *op;
633  
634          *op = '\0';
635          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
636 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
637 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
636 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
637 >                badvalue(ZONE);
638          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
639          getoctcube(org, &d);
640          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 682 | Line 659 | register char  *op;
659                  break;
660          }
661          op = addarg(op, "-pt .08");
662 <        if (vbool(PENUMBRAS)) {
663 <                op = addarg(op, "-ds .2");
664 <                op = addarg(op, "-dj .35");
688 <        } else
662 >        if (vbool(PENUMBRAS))
663 >                op = addarg(op, "-ds .2 -dj .35");
664 >        else
665                  op = addarg(op, "-ds .3");
666 <        op = addarg(op, "-dt .1");
691 <        op = addarg(op, "-dc .5");
692 <        op = addarg(op, "-dr 1");
693 <        op = addarg(op, "-sj .7");
694 <        op = addarg(op, "-st .15");
666 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
667          sprintf(op, " -ab %d", overture=vint(INDIRECT));
668          op += strlen(op);
669          if (vdef(AMBFILE)) {
# Line 701 | Line 673 | register char  *op;
673                  overture = 0;
674          switch (vscale(VARIABILITY)) {
675          case LOW:
676 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
676 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
677                  break;
678          case MEDIUM:
679 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
679 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
680                  break;
681          case HIGH:
682 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
682 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
683                  break;
684          }
685          d = ambval();
686          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
687          op += strlen(op);
688 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
688 >        op = addarg(op, "-lr 6 -lw .002");
689          if (vdef(RENDER))
690                  op = addarg(op, vval(RENDER));
691   }
# Line 733 | Line 698 | register char  *op;
698  
699          *op = '\0';
700          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
701 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
702 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
701 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
702 >                badvalue(ZONE);
703          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
704          getoctcube(org, &d);
705          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 724 | register char  *op;
724                  break;
725          }
726          op = addarg(op, "-pt .04");
727 <        if (vbool(PENUMBRAS)) {
728 <                op = addarg(op, "-ds .1");
729 <                op = addarg(op, "-dj .7");
768 <        } else
727 >        if (vbool(PENUMBRAS))
728 >                op = addarg(op, "-ds .1 -dj .7");
729 >        else
730                  op = addarg(op, "-ds .2");
731 <        op = addarg(op, "-dt .05");
771 <        op = addarg(op, "-dc .75");
772 <        op = addarg(op, "-dr 3");
773 <        op = addarg(op, "-sj 1");
774 <        op = addarg(op, "-st .03");
731 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
732          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
733          op += strlen(op);
734          if (vdef(AMBFILE)) {
# Line 781 | Line 738 | register char  *op;
738                  overture = 0;
739          switch (vscale(VARIABILITY)) {
740          case LOW:
741 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
741 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
742                  break;
743          case MEDIUM:
744 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
744 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
745                  break;
746          case HIGH:
747 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
747 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
748                  break;
749          }
750          d = ambval();
751          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
752          op += strlen(op);
753 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
753 >        op = addarg(op, "-lr 12 -lw .0005");
754          if (vdef(RENDER))
755                  op = addarg(op, vval(RENDER));
756   }
# Line 815 | Line 765 | char   *ro;
765          if (n < 2)
766                  return;
767          if (vdef(OPTFILE)) {
768 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
769 <                        perror(vval(OPTFILE));
770 <                        exit(1);
771 <                }
822 <                if (write(fd, ro+1, n-1) != n-1) {
823 <                        perror(vval(OPTFILE));
824 <                        exit(1);
825 <                }
768 >                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
769 >                        syserr(vval(OPTFILE));
770 >                if (write(fd, ro+1, n-1) != n-1)
771 >                        syserr(vval(OPTFILE));
772                  write(fd, "\n", 1);
773                  close(fd);
774 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
774 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
775          }
776   #ifdef MSDOS
777          else if (n > 50) {
778                  register char   *evp = bmalloc(n+6);
779 <                if (evp == NULL) {
780 <                        perror(progname);
837 <                        exit(1);
838 <                }
779 >                if (evp == NULL)
780 >                        syserr(progname);
781                  strcpy(evp, "ROPT=");
782                  strcat(evp, ro);
783                  if (putenv(evp) != 0) {
# Line 880 | Line 822 | char *
822   specview(vs)                            /* get proper view spec from vs */
823   register char   *vs;
824   {
825 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
826 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
827          static char     viewopts[128];
828          register char   *cp;
829 <        int     xpos, ypos, zpos, viewtype;
830 <        int     exterior;
829 >        int     xpos, ypos, zpos, viewtype, upax;
830 >        register int    i;
831          double  cent[3], dim[3], mult, d;
832  
833          if (vs == NULL || *vs == '-')
834                  return(vs);
835 +        upax = 0;                       /* get the up vector */
836 +        if (vdef(UP)) {
837 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
838 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
839 +                else
840 +                        upax = 1-'X'+vlet(UP);
841 +                if (upax < 1 | upax > 3)
842 +                        badvalue(UP);
843 +                if (vval(UP)[0] == '-')
844 +                        upax = -upax;
845 +        }
846                                          /* check standard view names */
847          xpos = ypos = zpos = 0;
893        viewtype = 0;
848          if (*vs == 'X') {
849                  xpos = 1; vs++;
850          } else if (*vs == 'x') {
# Line 906 | Line 860 | register char  *vs;
860          } else if (*vs == 'z') {
861                  zpos = -1; vs++;
862          }
863 +        viewtype = 'v';
864          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
865                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
866          cp = viewopts;
867 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
867 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
868                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
869                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
870                                  &cent[0], &dim[0], &cent[1], &dim[1],
871 <                                &cent[2], &dim[2]) != 6) {
872 <                        fprintf(stderr, "%s: bad zone specification\n",
873 <                                        progname);
874 <                        exit(1);
871 >                                &cent[2], &dim[2]) != 6)
872 >                        badvalue(ZONE);
873 >                for (i = 0; i < 3; i++) {
874 >                        dim[i] -= cent[i];
875 >                        cent[i] += .5*dim[i];
876                  }
877 <                dim[0] -= cent[0]; cent[0] += .5*dim[0];
924 <                dim[1] -= cent[1]; cent[1] += .5*dim[1];
925 <                dim[2] -= cent[2]; cent[2] += .5*dim[2];
926 <                exterior = vlet(ZONE) == 'E';
927 <                mult = exterior ? 2. : .45 ;
877 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
878                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
879                                  cent[0]+xpos*mult*dim[0],
880                                  cent[1]+ypos*mult*dim[1],
881                                  cent[2]+zpos*mult*dim[2],
882                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
883                  cp += strlen(cp);
884 <                switch (vlet(UP)) {
885 <                case 'Z':
886 <                        if (xpos|ypos) {
887 <                                cp = addarg(cp, "-vu 0 0 1");
888 <                                break;
889 <                        }
890 <                /* fall through */
941 <                case 'Y':
942 <                        if (xpos|zpos) {
943 <                                cp = addarg(cp, "-vu 0 1 0");
944 <                                break;
945 <                        }
946 <                /* fall through */
947 <                case 'X':
948 <                        if (ypos|zpos)
949 <                                cp = addarg(cp, "-vu 1 0 0");
950 <                        else
951 <                                cp = addarg(cp, "-vu 0 0 1");
884 >                                        /* redirect up axis if necessary */
885 >                switch (upax) {
886 >                case 3:                 /* plus or minus Z axis */
887 >                case -3:
888 >                case 0:
889 >                        if (!(xpos|ypos))
890 >                                upax = 2;
891                          break;
892 <                default:
893 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
894 <                                        progname, vnam(UP));
895 <                        exit(1);
892 >                case 2:                 /* plus or minus Y axis */
893 >                case -2:
894 >                        if (!(xpos|zpos))
895 >                                upax = 1;
896 >                        break;
897 >                case 1:                 /* plus or minus X axis */
898 >                case -1:
899 >                        if (!(ypos|zpos))
900 >                                upax = 3;
901 >                        break;
902                  }
903 +                cp = addarg(cp, vup[upax+3]);
904                  switch (viewtype) {
905                  case 'v':
906                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 915 | register char  *vs;
915                          cp = addarg(cp, "-vh 180 -vv 180");
916                          break;
917                  }
918 <        } else
919 <                while (*vs && !isspace(*vs))    /* else skip id */
920 <                        vs++;
918 >        } else {
919 >                while (!isspace(*vs))           /* else skip id */
920 >                        if (!*vs++)
921 >                                return(NULL);
922 >                if (upax) {                     /* specify up vector */
923 >                        strcpy(cp, vup[upax+3]);
924 >                        cp += strlen(cp);
925 >                }
926 >        }
927                                          /* append any additional options */
976        while (isspace(*vs)) vs++;
928          strcpy(cp, vs);
929          return(viewopts);
930   }
# Line 1024 | Line 975 | char   *opts;
975          if (rvdevice != NULL)
976                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
977          strcat(combuf, vval(OCTREE));
978 <        if (!silent) {                  /* echo it */
1028 <                printf("\t%s\n", combuf);
1029 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
978 >        if (runcom(combuf)) {           /* run it */
979                  fprintf(stderr, "%s: error running rview\n", progname);
980                  exit(1);
981          }
# Line 1041 | Line 986 | rpict(opts)                            /* run rpict and pfilt for each view */
986   char    *opts;
987   {
988          char    combuf[1024];
989 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
990 <        char    pfopts[64];
989 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
990 >        char    pfopts[128];
991          char    vs[32], *vw;
992          int     vn, mult;
993                                          /* get pfilt options */
# Line 1060 | Line 1005 | char   *opts;
1005                  else if (n) {
1006                          if (n == 1) yres = xres;
1007                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1008 <                } else {
1009 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1008 >                } else
1009 >                        badvalue(RESOLUTION);
1010          }
1011          rep[0] = '\0';
1012          if (vdef(REPORT)) {
# Line 1075 | Line 1017 | char   *opts;
1017                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1018                  else if (n == 1)
1019                          sprintf(rep, " -t %d", (int)(minutes*60));
1020 <                else {
1021 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1020 >                else
1021 >                        badvalue(REPORT);
1022          }
1023 +                                        /* check date on ambient file */
1024 +        if (vdef(AMBFILE)) {
1025 +                long    afdate = fdate(vval(AMBFILE));
1026 +                if (afdate >= 0 & octreedate > afdate)
1027 +                        rmfile(vval(AMBFILE));
1028 +        }
1029                                          /* do each view */
1030          vn = 0;
1031          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1101 | Line 1046 | char   *opts;
1046                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1047                                                  rep, vw, opts,
1048                                                  vval(OCTREE), rawfile);
1049 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1049 >                                if (runcom(combuf)) {
1050                                          fprintf(stderr,
1051                          "%s: error in overture for view %s\n\t%s removed\n",
1052                                                  progname, vs, rawfile);
# Line 1117 | Line 1058 | char   *opts;
1058                                          rep, vw, res, opts,
1059                                          vval(OCTREE), rawfile);
1060                  }
1061 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1061 >                if (runcom(combuf)) {           /* run rpict */
1062                          fprintf(stderr, "%s: error rendering view %s\n",
1063                                          progname, vs);
1064                          exit(1);
# Line 1133 | Line 1070 | char   *opts;
1070                  else
1071                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1072                                          rawfile, picfile);
1073 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1073 >                if (runcom(combuf)) {           /* run pfilt */
1074                          fprintf(stderr,
1075                          "%s: error filtering view %s\n\t%s removed\n",
1076                                          progname, vs, picfile);
# Line 1145 | Line 1078 | char   *opts;
1078                          exit(1);
1079                  }
1080                                                  /* remove raw file */
1081 <                if (!silent)
1081 >                rmfile(rawfile);
1082 >        }
1083 > }
1084 >
1085 >
1086 > runcom(cs)                      /* run command */
1087 > char    *cs;
1088 > {
1089 >        if (!silent)            /* echo it */
1090 >                printf("\t%s\n", cs);
1091 >        if (noaction)
1092 >                return(0);
1093 >        fflush(stdout);         /* flush output and pass to shell */
1094 >        return(system(cs));
1095 > }
1096 >
1097 >
1098 > rmfile(fn)                      /* remove a file */
1099 > char    *fn;
1100 > {
1101 >        if (!silent)
1102   #ifdef MSDOS
1103 <                        printf("\tdel %s\n", rawfile);
1103 >                printf("\tdel %s\n", fn);
1104   #else
1105 <                        printf("\trm %s\n", rawfile);
1105 >                printf("\trm -f %s\n", fn);
1106   #endif
1107 <                if (!noaction)
1108 <                        unlink(rawfile);
1109 <        }
1107 >        if (noaction)
1108 >                return(0);
1109 >        return(unlink(fn));
1110 > }
1111 >
1112 >
1113 > badvalue(vc)                    /* report bad variable value and exit */
1114 > int     vc;
1115 > {
1116 >        fprintf(stderr, "%s: bad value for variable '%s'\n",
1117 >                        progname, vnam(vc));
1118 >        exit(1);
1119 > }
1120 >
1121 >
1122 > syserr(s)                       /* report a system error and exit */
1123 > char    *s;
1124 > {
1125 >        perror(s);
1126 >        exit(1);
1127   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines