--- ray/src/util/rad.c 1996/02/14 16:34:05 2.52 +++ ray/src/util/rad.c 1998/01/23 17:17:32 2.55 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include "standard.h" +#include "view.h" #include "paths.h" #include "vars.h" #include @@ -23,7 +24,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define RENDER 5 /* rendering options */ #define OCONV 6 /* oconv options */ #define PFILT 7 /* pfilt options */ -#define VIEW 8 /* view(s) for picture(s) */ +#define VIEWS 8 /* view(s) for picture(s) */ #define ZONE 9 /* simulation zone */ #define QUALITY 10 /* desired rendering quality */ #define OCTREE 11 /* octree file name */ @@ -155,7 +156,11 @@ char *argv[]; loadvars(rifname); /* get any additional assignments */ for (i++; i < argc; i++) - setvariable(argv[i]); + if (setvariable(argv[i], matchvar) < 0) { + fprintf(stderr, "%s: unknown variable: %s\n", + progname, argv[i]); + quit(1); + } /* check assignments */ checkvalues(); /* check files and dates */ @@ -176,12 +181,12 @@ char *argv[]; rview(ropts, popts); else rpict(ropts, popts); - exit(0); + quit(0); userr: fprintf(stderr, "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", progname); - exit(1); + quit(1); } @@ -276,7 +281,7 @@ checkfiles() /* check for existence and modified tim if (!octreedate & !scenedate & !illumdate) { fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); - exit(1); + quit(1); } matdate = checklast(vval(MATERIAL)); } @@ -306,7 +311,7 @@ double org[3], *sizp; fprintf(stderr, "%s: error reading bounding box from getbbox\n", progname); - exit(1); + quit(1); } for (i = 0; i < 3; i++) if (max[i] - min[i] > osiz) @@ -324,7 +329,7 @@ double org[3], *sizp; fprintf(stderr, "%s: error reading bounding cube from getinfo\n", progname); - exit(1); + quit(1); } pclose(fp); } @@ -360,9 +365,9 @@ setdefaults() /* set default values for unassigned v vval(PICTURE) = radname; vdef(PICTURE)++; } - if (!vdef(VIEW)) { - vval(VIEW) = "X"; - vdef(VIEW)++; + if (!vdef(VIEWS)) { + vval(VIEWS) = "X"; + vdef(VIEWS)++; } if (!vdef(DETAIL)) { vval(DETAIL) = "M"; @@ -402,7 +407,7 @@ oconv() /* run oconv and mkillum if necessary */ "%s: error generating octree\n\t%s removed\n", progname, vval(OCTREE)); unlink(vval(OCTREE)); - exit(1); + quit(1); } } octreedate = time((time_t *)NULL); @@ -433,7 +438,7 @@ oconv() /* run oconv and mkillum if necessary */ "%s: error generating octree\n\t%s removed\n", progname, oct0name); unlink(oct0name); - exit(1); + quit(1); } } oct0date = time((time_t *)NULL); @@ -453,7 +458,7 @@ oconv() /* run oconv and mkillum if necessary */ fprintf(stderr, "%s: error running mkillum\n", progname); unlink(illumtmp); - exit(1); + quit(1); } /* make octree1 (frozen) */ if (octreedate) @@ -471,7 +476,7 @@ oconv() /* run oconv and mkillum if necessary */ progname, oct1name); unlink(oct1name); unlink(illumtmp); - exit(1); + quit(1); } rmfile(illumtmp); } @@ -612,10 +617,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .4 -ad 64"); + op = addarg(op, "-aa .4 -ad 64"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .3 -ad 128"); + op = addarg(op, "-aa .3 -ad 128"); break; case HIGH: op = addarg(op, "-aa .25 -ad 256"); @@ -691,10 +696,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .25 -ad 196 -as 0"); + op = addarg(op, "-aa .25 -ad 196 -as 0"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .2 -ad 400 -as 64"); + op = addarg(op, "-aa .2 -ad 400 -as 64"); break; case HIGH: op = addarg(op, "-aa .15 -ad 768 -as 196"); @@ -767,10 +772,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .15 -ad 256 -as 0"); + op = addarg(op, "-aa .15 -ad 256 -as 0"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .125 -ad 512 -as 256"); + op = addarg(op, "-aa .125 -ad 512 -as 256"); break; case HIGH: op = addarg(op, "-aa .08 -ad 1024 -as 512"); @@ -995,14 +1000,14 @@ char *vn; /* returned view name */ } /* view number? */ if (isint(viewselect)) - return(specview(nvalue(VIEW, atoi(viewselect)-1))); + return(specview(nvalue(VIEWS, atoi(viewselect)-1))); /* check list */ - while ((mv = nvalue(VIEW, n++)) != NULL) + while ((mv = nvalue(VIEWS, n++)) != NULL) if (matchword(viewselect, mv)) return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - mv = nvalue(VIEW, n); /* use view n */ + mv = nvalue(VIEWS, n); /* use view n */ if (vn != NULL & mv != NULL) { register char *mv2 = mv; if (*mv2 != '-') @@ -1017,56 +1022,28 @@ char *vn; /* returned view name */ printview(vopts) /* print out selected view */ register char *vopts; { - extern char *atos(), *getenv(); - char buf[256]; - FILE *fp; + extern char *strstr(), *atos(), *getenv(); + VIEW vwr; + char buf[128]; register char *cp; - +again: if (vopts == NULL) return(-1); - fputs("VIEW=", stdout); - do { - if (matchword(vopts, "-vf")) { /* expand view file */ - vopts = sskip(vopts); - if (!*atos(buf, sizeof(buf), vopts)) - return(-1); - if ((fp = fopen(buf, "r")) == NULL) - return(-1); - for (buf[sizeof(buf)-2] = '\n'; - fgets(buf, sizeof(buf), fp) != NULL && - buf[0] != '\n'; - buf[sizeof(buf)-2] = '\n') { - if (buf[sizeof(buf)-2] != '\n') { - ungetc(buf[sizeof(buf)-2], fp); - buf[sizeof(buf)-2] = '\0'; - } - if (matchword(buf, "VIEW=") || - matchword(buf, "rview")) { - for (cp = sskip(buf); *cp && *cp != '\n'; cp++) - putchar(*cp); - } - } - fclose(fp); - vopts = sskip(vopts); - } else { - while (isspace(*vopts)) - vopts++; - putchar(' '); #ifdef MSDOS - if (*vopts == '$') { /* expand env. var. */ - if (!*atos(buf, sizeof(buf), vopts+1)) - return(-1); - if ((cp = getenv(buf)) == NULL) - return(-1); - fputs(cp, stdout); - vopts = sskip(vopts); - } else + if (vopts[0] == '$') { + vopts = getenv(vopts+1); + goto again; + } #endif - while (*vopts && !isspace(*vopts)) - putchar(*vopts++); - } - } while (*vopts++); - putchar('\n'); + copystruct(&vwr, &stdview); + cp = vopts; /* get -vf files first */ + while ((cp = strstr(cp, "-vf ")) != NULL && + *atos(buf, sizeof(buf), cp += 4)) + viewfile(buf, &vwr, NULL); + sscanview(&vwr, vopts); /* get the rest */ + fputs(VIEWSTR, stdout); + fprintview(&vwr, stdout); /* print full spec. */ + fputc('\n', stdout); return(0); } @@ -1089,7 +1066,7 @@ char *opts, *po; strcat(combuf, oct1name); if (runcom(combuf)) { /* run it */ fprintf(stderr, "%s: error running rview\n", progname); - exit(1); + quit(1); } } @@ -1186,7 +1163,7 @@ char *opts, *po; fprintf(stderr, "%s: error in overture for view %s\n", progname, vs); - exit(1); + quit(1); } #ifdef NIX rmfile(overfile); @@ -1199,7 +1176,7 @@ char *opts, *po; if (runcom(combuf)) { /* run rpict */ fprintf(stderr, "%s: error rendering view %s\n", progname, vs); - exit(1); + quit(1); } if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ @@ -1214,7 +1191,7 @@ char *opts, *po; "%s: error filtering view %s\n\t%s removed\n", progname, vs, picfile); unlink(picfile); - exit(1); + quit(1); } } /* remove/rename raw file */ @@ -1297,7 +1274,7 @@ char *vname, *value; sprintf(evp, "%s=%s", vname, value); if (putenv(evp) != 0) { fprintf(stderr, "%s: out of environment space\n", progname); - exit(1); + quit(1); } if (!silent) printf("set %s\n", evp); @@ -1310,7 +1287,7 @@ int vc; { fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); - exit(1); + quit(1); } @@ -1318,5 +1295,12 @@ syserr(s) /* report a system error and exit */ char *s; { perror(s); - exit(1); + quit(1); +} + + +quit(ec) /* exit program */ +int ec; +{ + exit(ec); }