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.5 by greg, Sat Mar 13 09:33:17 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");
667 <        op = addarg(op, "-dc .5");
668 <        op = addarg(op, "-dr 1");
669 <        op = addarg(op, "-sj .7");
670 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
666 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
667 >        if (overture = vint(INDIRECT)) {
668 >                sprintf(op, " -ab %d", overture);
669 >                op += strlen(op);
670 >        }
671          if (vdef(AMBFILE)) {
672                  sprintf(op, " -af %s", vval(AMBFILE));
673                  op += strlen(op);
# Line 701 | Line 675 | register char  *op;
675                  overture = 0;
676          switch (vscale(VARIABILITY)) {
677          case LOW:
678 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
678 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
679                  break;
680          case MEDIUM:
681 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
681 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
682                  break;
683          case HIGH:
684 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
684 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
685                  break;
686          }
687          d = ambval();
688          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
689          op += strlen(op);
690 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
690 >        op = addarg(op, "-lr 6 -lw .002");
691          if (vdef(RENDER))
692                  op = addarg(op, vval(RENDER));
693   }
# Line 733 | Line 700 | register char  *op;
700  
701          *op = '\0';
702          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
703 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
704 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
703 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
704 >                badvalue(ZONE);
705          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
706          getoctcube(org, &d);
707          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 726 | register char  *op;
726                  break;
727          }
728          op = addarg(op, "-pt .04");
729 <        if (vbool(PENUMBRAS)) {
730 <                op = addarg(op, "-ds .1");
731 <                op = addarg(op, "-dj .7");
768 <        } else
729 >        if (vbool(PENUMBRAS))
730 >                op = addarg(op, "-ds .1 -dj .7");
731 >        else
732                  op = addarg(op, "-ds .2");
733 <        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");
733 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
734          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
735          op += strlen(op);
736          if (vdef(AMBFILE)) {
# Line 781 | Line 740 | register char  *op;
740                  overture = 0;
741          switch (vscale(VARIABILITY)) {
742          case LOW:
743 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
743 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
744                  break;
745          case MEDIUM:
746 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
746 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
747                  break;
748          case HIGH:
749 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
749 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
750                  break;
751          }
752          d = ambval();
753          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
754          op += strlen(op);
755 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
755 >        op = addarg(op, "-lr 12 -lw .0005");
756          if (vdef(RENDER))
757                  op = addarg(op, vval(RENDER));
758   }
# Line 815 | Line 767 | char   *ro;
767          if (n < 2)
768                  return;
769          if (vdef(OPTFILE)) {
770 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
771 <                        perror(vval(OPTFILE));
772 <                        exit(1);
773 <                }
822 <                if (write(fd, ro+1, n-1) != n-1) {
823 <                        perror(vval(OPTFILE));
824 <                        exit(1);
825 <                }
770 >                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
771 >                        syserr(vval(OPTFILE));
772 >                if (write(fd, ro+1, n-1) != n-1)
773 >                        syserr(vval(OPTFILE));
774                  write(fd, "\n", 1);
775                  close(fd);
776 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
776 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
777          }
778   #ifdef MSDOS
779          else if (n > 50) {
780                  register char   *evp = bmalloc(n+6);
781 <                if (evp == NULL) {
782 <                        perror(progname);
837 <                        exit(1);
838 <                }
781 >                if (evp == NULL)
782 >                        syserr(progname);
783                  strcpy(evp, "ROPT=");
784                  strcat(evp, ro);
785                  if (putenv(evp) != 0) {
# Line 880 | Line 824 | char *
824   specview(vs)                            /* get proper view spec from vs */
825   register char   *vs;
826   {
827 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
828 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
829          static char     viewopts[128];
830          register char   *cp;
831 <        int     xpos, ypos, zpos, viewtype;
832 <        int     exterior;
831 >        int     xpos, ypos, zpos, viewtype, upax;
832 >        register int    i;
833          double  cent[3], dim[3], mult, d;
834  
835          if (vs == NULL || *vs == '-')
836                  return(vs);
837 +        upax = 0;                       /* get the up vector */
838 +        if (vdef(UP)) {
839 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
840 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
841 +                else
842 +                        upax = 1-'X'+vlet(UP);
843 +                if (upax < 1 | upax > 3)
844 +                        badvalue(UP);
845 +                if (vval(UP)[0] == '-')
846 +                        upax = -upax;
847 +        }
848                                          /* check standard view names */
849          xpos = ypos = zpos = 0;
893        viewtype = 0;
850          if (*vs == 'X') {
851                  xpos = 1; vs++;
852          } else if (*vs == 'x') {
# Line 906 | Line 862 | register char  *vs;
862          } else if (*vs == 'z') {
863                  zpos = -1; vs++;
864          }
865 +        viewtype = 'v';
866          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
867                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
868          cp = viewopts;
869 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
869 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
870                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
871                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
872                                  &cent[0], &dim[0], &cent[1], &dim[1],
873 <                                &cent[2], &dim[2]) != 6) {
874 <                        fprintf(stderr, "%s: bad zone specification\n",
875 <                                        progname);
876 <                        exit(1);
873 >                                &cent[2], &dim[2]) != 6)
874 >                        badvalue(ZONE);
875 >                for (i = 0; i < 3; i++) {
876 >                        dim[i] -= cent[i];
877 >                        cent[i] += .5*dim[i];
878                  }
879 <                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 ;
879 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
880                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
881                                  cent[0]+xpos*mult*dim[0],
882                                  cent[1]+ypos*mult*dim[1],
883                                  cent[2]+zpos*mult*dim[2],
884                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
885                  cp += strlen(cp);
886 <                switch (vlet(UP)) {
887 <                case 'Z':
888 <                        if (xpos|ypos) {
889 <                                cp = addarg(cp, "-vu 0 0 1");
890 <                                break;
891 <                        }
892 <                /* 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");
886 >                                        /* redirect up axis if necessary */
887 >                switch (upax) {
888 >                case 3:                 /* plus or minus Z axis */
889 >                case -3:
890 >                case 0:
891 >                        if (!(xpos|ypos))
892 >                                upax = 2;
893                          break;
894 <                default:
895 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
896 <                                        progname, vnam(UP));
897 <                        exit(1);
894 >                case 2:                 /* plus or minus Y axis */
895 >                case -2:
896 >                        if (!(xpos|zpos))
897 >                                upax = 1;
898 >                        break;
899 >                case 1:                 /* plus or minus X axis */
900 >                case -1:
901 >                        if (!(ypos|zpos))
902 >                                upax = 3;
903 >                        break;
904                  }
905 +                cp = addarg(cp, vup[upax+3]);
906                  switch (viewtype) {
907                  case 'v':
908                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 917 | register char  *vs;
917                          cp = addarg(cp, "-vh 180 -vv 180");
918                          break;
919                  }
920 <        } else
921 <                while (*vs && !isspace(*vs))    /* else skip id */
922 <                        vs++;
920 >        } else {
921 >                while (!isspace(*vs))           /* else skip id */
922 >                        if (!*vs++)
923 >                                return(NULL);
924 >                if (upax) {                     /* specify up vector */
925 >                        strcpy(cp, vup[upax+3]);
926 >                        cp += strlen(cp);
927 >                }
928 >        }
929                                          /* append any additional options */
976        while (isspace(*vs)) vs++;
930          strcpy(cp, vs);
931          return(viewopts);
932   }
# Line 1024 | Line 977 | char   *opts;
977          if (rvdevice != NULL)
978                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
979          strcat(combuf, vval(OCTREE));
980 <        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 */
980 >        if (runcom(combuf)) {           /* run it */
981                  fprintf(stderr, "%s: error running rview\n", progname);
982                  exit(1);
983          }
# Line 1041 | Line 988 | rpict(opts)                            /* run rpict and pfilt for each view */
988   char    *opts;
989   {
990          char    combuf[1024];
991 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
992 <        char    pfopts[64];
991 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
992 >        char    pfopts[128];
993          char    vs[32], *vw;
994          int     vn, mult;
995                                          /* get pfilt options */
# Line 1060 | Line 1007 | char   *opts;
1007                  else if (n) {
1008                          if (n == 1) yres = xres;
1009                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1010 <                } else {
1011 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1010 >                } else
1011 >                        badvalue(RESOLUTION);
1012          }
1013          rep[0] = '\0';
1014          if (vdef(REPORT)) {
# Line 1075 | Line 1019 | char   *opts;
1019                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1020                  else if (n == 1)
1021                          sprintf(rep, " -t %d", (int)(minutes*60));
1022 <                else {
1023 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1022 >                else
1023 >                        badvalue(REPORT);
1024          }
1025 +                                        /* check date on ambient file */
1026 +        if (vdef(AMBFILE)) {
1027 +                long    afdate = fdate(vval(AMBFILE));
1028 +                if (afdate >= 0 & octreedate > afdate)
1029 +                        rmfile(vval(AMBFILE));
1030 +        }
1031                                          /* do each view */
1032          vn = 0;
1033          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1101 | Line 1048 | char   *opts;
1048                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1049                                                  rep, vw, opts,
1050                                                  vval(OCTREE), rawfile);
1051 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1051 >                                if (runcom(combuf)) {
1052                                          fprintf(stderr,
1053                          "%s: error in overture for view %s\n\t%s removed\n",
1054                                                  progname, vs, rawfile);
# Line 1117 | Line 1060 | char   *opts;
1060                                          rep, vw, res, opts,
1061                                          vval(OCTREE), rawfile);
1062                  }
1063 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1063 >                if (runcom(combuf)) {           /* run rpict */
1064                          fprintf(stderr, "%s: error rendering view %s\n",
1065                                          progname, vs);
1066                          exit(1);
# Line 1133 | Line 1072 | char   *opts;
1072                  else
1073                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1074                                          rawfile, picfile);
1075 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1075 >                if (runcom(combuf)) {           /* run pfilt */
1076                          fprintf(stderr,
1077                          "%s: error filtering view %s\n\t%s removed\n",
1078                                          progname, vs, picfile);
# Line 1145 | Line 1080 | char   *opts;
1080                          exit(1);
1081                  }
1082                                                  /* remove raw file */
1083 <                if (!silent)
1083 >                rmfile(rawfile);
1084 >        }
1085 > }
1086 >
1087 >
1088 > runcom(cs)                      /* run command */
1089 > char    *cs;
1090 > {
1091 >        if (!silent)            /* echo it */
1092 >                printf("\t%s\n", cs);
1093 >        if (noaction)
1094 >                return(0);
1095 >        fflush(stdout);         /* flush output and pass to shell */
1096 >        return(system(cs));
1097 > }
1098 >
1099 >
1100 > rmfile(fn)                      /* remove a file */
1101 > char    *fn;
1102 > {
1103 >        if (!silent)
1104   #ifdef MSDOS
1105 <                        printf("\tdel %s\n", rawfile);
1105 >                printf("\tdel %s\n", fn);
1106   #else
1107 <                        printf("\trm %s\n", rawfile);
1107 >                printf("\trm -f %s\n", fn);
1108   #endif
1109 <                if (!noaction)
1110 <                        unlink(rawfile);
1111 <        }
1109 >        if (noaction)
1110 >                return(0);
1111 >        return(unlink(fn));
1112 > }
1113 >
1114 >
1115 > badvalue(vc)                    /* report bad variable value and exit */
1116 > int     vc;
1117 > {
1118 >        fprintf(stderr, "%s: bad value for variable '%s'\n",
1119 >                        progname, vnam(vc));
1120 >        exit(1);
1121 > }
1122 >
1123 >
1124 > syserr(s)                       /* report a system error and exit */
1125 > char    *s;
1126 > {
1127 >        perror(s);
1128 >        exit(1);
1129   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines