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.6 by greg, Tue Mar 30 13:16:26 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 92 | Line 94 | int    (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94  
95   #define renderopts      (*setqopts[vscale(QUALITY)])
96  
97 +                                /* overture calculation file */
98 + #ifdef NIX
99 + char    overfile[] = "overture.raw";
100 + #else
101 + char    overfile[] = "/dev/null";
102 + #endif
103 +
104   extern long     fdate(), time();
105  
106   long    scenedate;              /* date of latest scene or object file */
# Line 168 | Line 177 | char   *argv[];
177          exit(0);
178   userr:
179          fprintf(stderr,
180 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
180 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
181                          progname);
182          exit(1);
183   }
# Line 193 | Line 202 | load(rfname)                   /* load Radiance simulation file */
202   char    *rfname;
203   {
204          FILE    *fp;
205 <        char    buf[256];
205 >        char    buf[512];
206          register char   *cp;
207  
208          if (rfname == NULL)
209                  fp = stdin;
210 <        else if ((fp = fopen(rfname, "r")) == NULL) {
211 <                perror(rfname);
203 <                exit(1);
204 <        }
210 >        else if ((fp = fopen(rfname, "r")) == NULL)
211 >                syserr(rfname);
212          while (fgetline(buf, sizeof(buf), fp) != NULL) {
213                  for (cp = buf; *cp; cp++) {
214                          switch (*cp) {
# Line 212 | Line 219 | char   *rfname;
219                          case '#':
220                                  *cp = '\0';
221                                  break;
222 +                        default:
223 +                                continue;
224                          }
225                          break;
226                  }
# Line 260 | Line 269 | register char  *ass;
269                  exit(1);
270          }
271                                          /* assign new value */
272 <        cp = vp->value; i = vp->nass;
273 <        while (i--)
274 <                while (*cp++)
275 <                        ;
276 <        i = cp - vp->value;
277 <        vp->value = realloc(vp->value, i+n+1);
278 <        if (vp->value == NULL) {
279 <                perror(progname);
280 <                exit(1);
281 <        }
272 >        if (i = vp->nass) {
273 >                cp = vp->value;
274 >                while (i--)
275 >                        while (*cp++)
276 >                                ;
277 >                i = cp - vp->value;
278 >                vp->value = realloc(vp->value, i+n+1);
279 >        } else
280 >                vp->value = malloc(n+1);
281 >        if (vp->value == NULL)
282 >                syserr(progname);
283          strcpy(vp->value+i, ass);
284          vp->nass++;
285   }
# Line 318 | Line 328 | int    vc;
328          case 'L':
329                  return(LOW);
330          }
331 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
331 >        badvalue(vc);
332   }
333  
334  
# Line 373 | Line 381 | register char  *fnames;
381          while (*fnames) {
382                  while (isspace(*fnames)) fnames++;
383                  cp = thisfile;
384 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
384 >                while (*fnames && !isspace(*fnames))
385 >                        *cp++ = *fnames++;
386                  *cp = '\0';
387 <                if ((thisdate = fdate(thisfile)) < 0) {
388 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
387 >                if ((thisdate = fdate(thisfile)) < 0)
388 >                        syserr(thisfile);
389                  if (thisdate > lastdate)
390                          lastdate = thisdate;
391          }
# Line 392 | Line 399 | checkfiles()                   /* check for existence and modified tim
399          long    objdate;
400  
401          if (!vdef(OCTREE)) {
402 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
403 <                        perror(progname);
397 <                        exit(1);
398 <                }
402 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
403 >                        syserr(progname);
404                  sprintf(cp, "%s.oct", radname);
405                  vval(OCTREE) = cp;
406                  vdef(OCTREE)++;
# Line 429 | Line 434 | double org[3], *sizp;
434          if (osiz <= FTINY) {
435                  oconv();                /* does nothing if done already */
436                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
437 <                if ((fp = popen(buf, "r")) == NULL) {
438 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
437 >                if ((fp = popen(buf, "r")) == NULL)
438 >                        syserr("getinfo");
439                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
440                                  &oorg[2], &osiz) != 4) {
441                          fprintf(stderr,
# Line 458 | Line 461 | setdefaults()                  /* set default values for unassigned v
461                  vval(ZONE) = savqstr(buf);
462                  vdef(ZONE)++;
463          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
464          if (!vdef(INDIRECT)) {
465                  vval(INDIRECT) = "0";
466                  vdef(INDIRECT)++;
# Line 502 | Line 501 | printvals()                    /* print variable values */
501          register int    i, j;
502  
503          for (i = 0; i < NVARS; i++)
504 <                for (j = 0; j < vv[i].nass; j++)
505 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
504 >                for (j = 0; j < vdef(i); j++)
505 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
506          fflush(stdout);
507   }
508  
# Line 516 | Line 515 | oconv()                                /* run oconv if necessary */
515                  return;
516                                          /* build command */
517          oconvopts(ocopts);
518 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
519 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
520 <                        vval(SCENE), vval(OCTREE));
521 <        if (!silent) {                  /* echo it */
522 <                printf("\t%s\n", combuf);
523 <                fflush(stdout);
524 <        }
525 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
518 >        if (vdef(MATERIAL))
519 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
520 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
521 >        else
522 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
523 >                                vval(SCENE), vval(OCTREE));
524 >        
525 >        if (runcom(combuf)) {           /* run it */
526                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
527                                  progname, vval(OCTREE));
528                  unlink(vval(OCTREE));
# Line 560 | Line 557 | register char  *oo;
557   double
558   ambval()                                /* compute ambient value */
559   {
560 <        if (vdef(EXPOSURE))
560 >        if (vdef(EXPOSURE)) {
561                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
562                          return(.5/pow(2.,atof(vval(EXPOSURE))));
563 <                else
563 >                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
564                          return(.5/atof(vval(EXPOSURE)));
565 +                badvalue(EXPOSURE);
566 +        }
567          if (vlet(ZONE) == 'E')
568                  return(10.);
569 <        else
569 >        if (vlet(ZONE) == 'I')
570                  return(.01);
571 +        badvalue(ZONE);
572   }
573  
574  
# Line 579 | Line 579 | register char  *op;
579  
580          *op = '\0';
581          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
582 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
583 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
582 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
583 >                badvalue(ZONE);
584          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
585          getoctcube(org, &d);
586          d *= 3./(siz[0]+siz[1]+siz[2]);
587          switch (vscale(DETAIL)) {
588          case LOW:
589 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
589 >                op = addarg(op, "-ps 16 -dp 16");
590                  sprintf(op, " -ar %d", (int)(4*d));
591                  op += strlen(op);
592                  break;
593          case MEDIUM:
594 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
594 >                op = addarg(op, "-ps 8 -dp 32");
595                  sprintf(op, " -ar %d", (int)(8*d));
596                  op += strlen(op);
597                  break;
598          case HIGH:
599 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
599 >                op = addarg(op, "-ps 4 -dp 64");
600                  sprintf(op, " -ar %d", (int)(16*d));
601                  op += strlen(op);
602                  break;
# Line 610 | Line 604 | register char  *op;
604          op = addarg(op, "-pt .16");
605          if (vbool(PENUMBRAS))
606                  op = addarg(op, "-ds .4");
607 <        op = addarg(op, "-dt .2");
608 <        op = addarg(op, "-dc .25");
609 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
607 >        else
608 >                op = addarg(op, "-ds 0");
609 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
610          if (vdef(AMBFILE)) {
611                  sprintf(op, " -af %s", vval(AMBFILE));
612                  op += strlen(op);
# Line 623 | Line 614 | register char  *op;
614                  overture = 0;
615          switch (vscale(VARIABILITY)) {
616          case LOW:
617 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
617 >                op = addarg(op, "-aa .4 -ad 32");
618                  break;
619          case MEDIUM:
620 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
620 >                op = addarg(op, "-aa .3 -ad 64");
621                  break;
622          case HIGH:
623 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
623 >                op = addarg(op, "-aa .25 -ad 128");
624                  break;
625          }
626          op = addarg(op, "-as 0");
627          d = ambval();
628          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
629          op += strlen(op);
630 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
630 >        op = addarg(op, "-lr 3 -lw .02");
631          if (vdef(RENDER))
632                  op = addarg(op, vval(RENDER));
633   }
# Line 653 | Line 640 | register char  *op;
640  
641          *op = '\0';
642          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
643 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
644 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
643 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
644 >                badvalue(ZONE);
645          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
646          getoctcube(org, &d);
647          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 682 | Line 666 | register char  *op;
666                  break;
667          }
668          op = addarg(op, "-pt .08");
669 <        if (vbool(PENUMBRAS)) {
670 <                op = addarg(op, "-ds .2");
671 <                op = addarg(op, "-dj .35");
688 <        } else
669 >        if (vbool(PENUMBRAS))
670 >                op = addarg(op, "-ds .2 -dj .35");
671 >        else
672                  op = addarg(op, "-ds .3");
673 <        op = addarg(op, "-dt .1");
674 <        op = addarg(op, "-dc .5");
675 <        op = addarg(op, "-dr 1");
676 <        op = addarg(op, "-sj .7");
677 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
673 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
674 >        if (overture = vint(INDIRECT)) {
675 >                sprintf(op, " -ab %d", overture);
676 >                op += strlen(op);
677 >        }
678          if (vdef(AMBFILE)) {
679                  sprintf(op, " -af %s", vval(AMBFILE));
680                  op += strlen(op);
# Line 701 | Line 682 | register char  *op;
682                  overture = 0;
683          switch (vscale(VARIABILITY)) {
684          case LOW:
685 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
685 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
686                  break;
687          case MEDIUM:
688 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
688 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
689                  break;
690          case HIGH:
691 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
691 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
692                  break;
693          }
694          d = ambval();
695          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
696          op += strlen(op);
697 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
697 >        op = addarg(op, "-lr 6 -lw .002");
698          if (vdef(RENDER))
699                  op = addarg(op, vval(RENDER));
700   }
# Line 733 | Line 707 | register char  *op;
707  
708          *op = '\0';
709          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
710 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
711 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
710 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
711 >                badvalue(ZONE);
712          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
713          getoctcube(org, &d);
714          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 733 | register char  *op;
733                  break;
734          }
735          op = addarg(op, "-pt .04");
736 <        if (vbool(PENUMBRAS)) {
737 <                op = addarg(op, "-ds .1");
738 <                op = addarg(op, "-dj .7");
768 <        } else
736 >        if (vbool(PENUMBRAS))
737 >                op = addarg(op, "-ds .1 -dj .7");
738 >        else
739                  op = addarg(op, "-ds .2");
740 <        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");
740 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
741          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
742          op += strlen(op);
743          if (vdef(AMBFILE)) {
# Line 781 | Line 747 | register char  *op;
747                  overture = 0;
748          switch (vscale(VARIABILITY)) {
749          case LOW:
750 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
750 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
751                  break;
752          case MEDIUM:
753 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
753 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
754                  break;
755          case HIGH:
756 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
756 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
757                  break;
758          }
759          d = ambval();
760          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
761          op += strlen(op);
762 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
762 >        op = addarg(op, "-lr 12 -lw .0005");
763          if (vdef(RENDER))
764                  op = addarg(op, vval(RENDER));
765   }
# Line 815 | Line 774 | char   *ro;
774          if (n < 2)
775                  return;
776          if (vdef(OPTFILE)) {
777 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
778 <                        perror(vval(OPTFILE));
779 <                        exit(1);
780 <                }
822 <                if (write(fd, ro+1, n-1) != n-1) {
823 <                        perror(vval(OPTFILE));
824 <                        exit(1);
825 <                }
777 >                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
778 >                        syserr(vval(OPTFILE));
779 >                if (write(fd, ro+1, n-1) != n-1)
780 >                        syserr(vval(OPTFILE));
781                  write(fd, "\n", 1);
782                  close(fd);
783 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
783 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
784          }
785   #ifdef MSDOS
786          else if (n > 50) {
787                  register char   *evp = bmalloc(n+6);
788 <                if (evp == NULL) {
789 <                        perror(progname);
837 <                        exit(1);
838 <                }
788 >                if (evp == NULL)
789 >                        syserr(progname);
790                  strcpy(evp, "ROPT=");
791                  strcat(evp, ro);
792                  if (putenv(evp) != 0) {
# Line 880 | Line 831 | char *
831   specview(vs)                            /* get proper view spec from vs */
832   register char   *vs;
833   {
834 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
835 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
836          static char     viewopts[128];
837          register char   *cp;
838 <        int     xpos, ypos, zpos, viewtype;
839 <        int     exterior;
838 >        int     xpos, ypos, zpos, viewtype, upax;
839 >        register int    i;
840          double  cent[3], dim[3], mult, d;
841  
842          if (vs == NULL || *vs == '-')
843                  return(vs);
844 +        upax = 0;                       /* get the up vector */
845 +        if (vdef(UP)) {
846 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
847 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
848 +                else
849 +                        upax = 1-'X'+vlet(UP);
850 +                if (upax < 1 | upax > 3)
851 +                        badvalue(UP);
852 +                if (vval(UP)[0] == '-')
853 +                        upax = -upax;
854 +        }
855                                          /* check standard view names */
856          xpos = ypos = zpos = 0;
893        viewtype = 0;
857          if (*vs == 'X') {
858                  xpos = 1; vs++;
859          } else if (*vs == 'x') {
# Line 906 | Line 869 | register char  *vs;
869          } else if (*vs == 'z') {
870                  zpos = -1; vs++;
871          }
872 +        viewtype = 'v';
873          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
874                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
875          cp = viewopts;
876 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
876 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
877                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
878                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
879                                  &cent[0], &dim[0], &cent[1], &dim[1],
880 <                                &cent[2], &dim[2]) != 6) {
881 <                        fprintf(stderr, "%s: bad zone specification\n",
882 <                                        progname);
883 <                        exit(1);
880 >                                &cent[2], &dim[2]) != 6)
881 >                        badvalue(ZONE);
882 >                for (i = 0; i < 3; i++) {
883 >                        dim[i] -= cent[i];
884 >                        cent[i] += .5*dim[i];
885                  }
886 <                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 ;
886 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
887                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
888                                  cent[0]+xpos*mult*dim[0],
889                                  cent[1]+ypos*mult*dim[1],
890                                  cent[2]+zpos*mult*dim[2],
891                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
892                  cp += strlen(cp);
893 <                switch (vlet(UP)) {
894 <                case 'Z':
895 <                        if (xpos|ypos) {
896 <                                cp = addarg(cp, "-vu 0 0 1");
897 <                                break;
898 <                        }
899 <                /* 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");
893 >                                        /* redirect up axis if necessary */
894 >                switch (upax) {
895 >                case 3:                 /* plus or minus Z axis */
896 >                case -3:
897 >                case 0:
898 >                        if (!(xpos|ypos))
899 >                                upax = 2;
900                          break;
901 <                default:
902 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
903 <                                        progname, vnam(UP));
904 <                        exit(1);
901 >                case 2:                 /* plus or minus Y axis */
902 >                case -2:
903 >                        if (!(xpos|zpos))
904 >                                upax = 1;
905 >                        break;
906 >                case 1:                 /* plus or minus X axis */
907 >                case -1:
908 >                        if (!(ypos|zpos))
909 >                                upax = 3;
910 >                        break;
911                  }
912 +                cp = addarg(cp, vup[upax+3]);
913                  switch (viewtype) {
914                  case 'v':
915                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 924 | register char  *vs;
924                          cp = addarg(cp, "-vh 180 -vv 180");
925                          break;
926                  }
927 <        } else
928 <                while (*vs && !isspace(*vs))    /* else skip id */
929 <                        vs++;
927 >        } else {
928 >                while (!isspace(*vs))           /* else skip id */
929 >                        if (!*vs++)
930 >                                return(NULL);
931 >                if (upax) {                     /* specify up vector */
932 >                        strcpy(cp, vup[upax+3]);
933 >                        cp += strlen(cp);
934 >                }
935 >        }
936                                          /* append any additional options */
976        while (isspace(*vs)) vs++;
937          strcpy(cp, vs);
938          return(viewopts);
939   }
# Line 1024 | Line 984 | char   *opts;
984          if (rvdevice != NULL)
985                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
986          strcat(combuf, vval(OCTREE));
987 <        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 */
987 >        if (runcom(combuf)) {           /* run it */
988                  fprintf(stderr, "%s: error running rview\n", progname);
989                  exit(1);
990          }
# Line 1041 | Line 995 | rpict(opts)                            /* run rpict and pfilt for each view */
995   char    *opts;
996   {
997          char    combuf[1024];
998 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
999 <        char    pfopts[64];
998 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
999 >        char    pfopts[128];
1000          char    vs[32], *vw;
1001          int     vn, mult;
1002                                          /* get pfilt options */
# Line 1060 | Line 1014 | char   *opts;
1014                  else if (n) {
1015                          if (n == 1) yres = xres;
1016                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1017 <                } else {
1018 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1017 >                } else
1018 >                        badvalue(RESOLUTION);
1019          }
1020          rep[0] = '\0';
1021          if (vdef(REPORT)) {
# Line 1075 | Line 1026 | char   *opts;
1026                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1027                  else if (n == 1)
1028                          sprintf(rep, " -t %d", (int)(minutes*60));
1029 <                else {
1030 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1029 >                else
1030 >                        badvalue(REPORT);
1031          }
1032 +                                        /* check date on ambient file */
1033 +        if (vdef(AMBFILE)) {
1034 +                long    afdate = fdate(vval(AMBFILE));
1035 +                if (afdate >= 0 & octreedate > afdate)
1036 +                        rmfile(vval(AMBFILE));
1037 +        }
1038                                          /* do each view */
1039          vn = 0;
1040          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1100 | Line 1054 | char   *opts;
1054                                  sprintf(combuf,
1055                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1056                                                  rep, vw, opts,
1057 <                                                vval(OCTREE), rawfile);
1058 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1057 >                                                vval(OCTREE), overfile);
1058 >                                if (runcom(combuf)) {
1059                                          fprintf(stderr,
1060 <                        "%s: error in overture for view %s\n\t%s removed\n",
1061 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1060 >                                        "%s: error in overture for view %s\n",
1061 >                                                progname, vs);
1062                                          exit(1);
1063                                  }
1064 + #ifdef NIX
1065 +                                rmfile(overfile);
1066 + #endif
1067                          }
1068                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1069                                          rep, vw, res, opts,
1070                                          vval(OCTREE), rawfile);
1071                  }
1072 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1072 >                if (runcom(combuf)) {           /* run rpict */
1073                          fprintf(stderr, "%s: error rendering view %s\n",
1074                                          progname, vs);
1075                          exit(1);
# Line 1133 | Line 1081 | char   *opts;
1081                  else
1082                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1083                                          rawfile, picfile);
1084 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1084 >                if (runcom(combuf)) {           /* run pfilt */
1085                          fprintf(stderr,
1086                          "%s: error filtering view %s\n\t%s removed\n",
1087                                          progname, vs, picfile);
# Line 1145 | Line 1089 | char   *opts;
1089                          exit(1);
1090                  }
1091                                                  /* remove raw file */
1092 <                if (!silent)
1092 >                rmfile(rawfile);
1093 >        }
1094 > }
1095 >
1096 >
1097 > runcom(cs)                      /* run command */
1098 > char    *cs;
1099 > {
1100 >        if (!silent)            /* echo it */
1101 >                printf("\t%s\n", cs);
1102 >        if (noaction)
1103 >                return(0);
1104 >        fflush(stdout);         /* flush output and pass to shell */
1105 >        return(system(cs));
1106 > }
1107 >
1108 >
1109 > rmfile(fn)                      /* remove a file */
1110 > char    *fn;
1111 > {
1112 >        if (!silent)
1113   #ifdef MSDOS
1114 <                        printf("\tdel %s\n", rawfile);
1114 >                printf("\tdel %s\n", fn);
1115   #else
1116 <                        printf("\trm %s\n", rawfile);
1116 >                printf("\trm -f %s\n", fn);
1117   #endif
1118 <                if (!noaction)
1119 <                        unlink(rawfile);
1120 <        }
1118 >        if (noaction)
1119 >                return(0);
1120 >        return(unlink(fn));
1121 > }
1122 >
1123 >
1124 > badvalue(vc)                    /* report bad variable value and exit */
1125 > int     vc;
1126 > {
1127 >        fprintf(stderr, "%s: bad value for variable '%s'\n",
1128 >                        progname, vnam(vc));
1129 >        exit(1);
1130 > }
1131 >
1132 >
1133 > syserr(s)                       /* report a system error and exit */
1134 > char    *s;
1135 > {
1136 >        perror(s);
1137 >        exit(1);
1138   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines