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 |
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 |
|
} |
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) { |
266 |
|
; |
267 |
|
i = cp - vp->value; |
268 |
|
vp->value = realloc(vp->value, i+n+1); |
269 |
< |
if (vp->value == NULL) { |
270 |
< |
perror(progname); |
271 |
< |
exit(1); |
272 |
< |
} |
269 |
> |
if (vp->value == NULL) |
270 |
> |
syserr(progname); |
271 |
|
strcpy(vp->value+i, ass); |
272 |
|
vp->nass++; |
273 |
|
} |
316 |
|
case 'L': |
317 |
|
return(LOW); |
318 |
|
} |
319 |
< |
fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n", |
322 |
< |
progname, vnam(vc), vval(vc)); |
323 |
< |
exit(1); |
319 |
> |
badvalue(vc); |
320 |
|
} |
321 |
|
|
322 |
|
|
371 |
|
cp = thisfile; |
372 |
|
while (*fnames && !isspace(*fnames)) *cp++ = *fnames++; |
373 |
|
*cp = '\0'; |
374 |
< |
if ((thisdate = fdate(thisfile)) < 0) { |
375 |
< |
perror(thisfile); |
380 |
< |
exit(1); |
381 |
< |
} |
374 |
> |
if ((thisdate = fdate(thisfile)) < 0) |
375 |
> |
syserr(thisfile); |
376 |
|
if (thisdate > lastdate) |
377 |
|
lastdate = thisdate; |
378 |
|
} |
386 |
|
long objdate; |
387 |
|
|
388 |
|
if (!vdef(OCTREE)) { |
389 |
< |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) { |
390 |
< |
perror(progname); |
397 |
< |
exit(1); |
398 |
< |
} |
389 |
> |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) |
390 |
> |
syserr(progname); |
391 |
|
sprintf(cp, "%s.oct", radname); |
392 |
|
vval(OCTREE) = cp; |
393 |
|
vdef(OCTREE)++; |
421 |
|
if (osiz <= FTINY) { |
422 |
|
oconv(); /* does nothing if done already */ |
423 |
|
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
424 |
< |
if ((fp = popen(buf, "r")) == NULL) { |
425 |
< |
perror("getinfo"); |
434 |
< |
exit(1); |
435 |
< |
} |
424 |
> |
if ((fp = popen(buf, "r")) == NULL) |
425 |
> |
syserr("getinfo"); |
426 |
|
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
427 |
|
&oorg[2], &osiz) != 4) { |
428 |
|
fprintf(stderr, |
448 |
|
vval(ZONE) = savqstr(buf); |
449 |
|
vdef(ZONE)++; |
450 |
|
} |
461 |
– |
if (!vdef(UP)) { |
462 |
– |
vval(UP) = "Z"; |
463 |
– |
vdef(UP)++; |
464 |
– |
} |
451 |
|
if (!vdef(INDIRECT)) { |
452 |
|
vval(INDIRECT) = "0"; |
453 |
|
vdef(INDIRECT)++; |
546 |
|
double |
547 |
|
ambval() /* compute ambient value */ |
548 |
|
{ |
549 |
< |
if (vdef(EXPOSURE)) |
549 |
> |
if (vdef(EXPOSURE)) { |
550 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
551 |
|
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
552 |
< |
else |
552 |
> |
if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') |
553 |
|
return(.5/atof(vval(EXPOSURE))); |
554 |
+ |
badvalue(EXPOSURE); |
555 |
+ |
} |
556 |
|
if (vlet(ZONE) == 'E') |
557 |
|
return(10.); |
558 |
< |
else |
558 |
> |
if (vlet(ZONE) == 'I') |
559 |
|
return(.01); |
560 |
+ |
badvalue(ZONE); |
561 |
|
} |
562 |
|
|
563 |
|
|
568 |
|
|
569 |
|
*op = '\0'; |
570 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
571 |
< |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) { |
572 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
584 |
< |
progname, vnam(ZONE)); |
585 |
< |
exit(1); |
586 |
< |
} |
571 |
> |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
572 |
> |
badvalue(ZONE); |
573 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
574 |
|
getoctcube(org, &d); |
575 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
639 |
|
|
640 |
|
*op = '\0'; |
641 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
642 |
< |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) { |
643 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
658 |
< |
progname, vnam(ZONE)); |
659 |
< |
exit(1); |
660 |
< |
} |
642 |
> |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
643 |
> |
badvalue(ZONE); |
644 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
645 |
|
getoctcube(org, &d); |
646 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
716 |
|
|
717 |
|
*op = '\0'; |
718 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
719 |
< |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) { |
720 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
738 |
< |
progname, vnam(ZONE)); |
739 |
< |
exit(1); |
740 |
< |
} |
719 |
> |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
720 |
> |
badvalue(ZONE); |
721 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
722 |
|
getoctcube(org, &d); |
723 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
795 |
|
if (n < 2) |
796 |
|
return; |
797 |
|
if (vdef(OPTFILE)) { |
798 |
< |
if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
799 |
< |
perror(vval(OPTFILE)); |
800 |
< |
exit(1); |
801 |
< |
} |
822 |
< |
if (write(fd, ro+1, n-1) != n-1) { |
823 |
< |
perror(vval(OPTFILE)); |
824 |
< |
exit(1); |
825 |
< |
} |
798 |
> |
if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
799 |
> |
syserr(vval(OPTFILE)); |
800 |
> |
if (write(fd, ro+1, n-1) != n-1) |
801 |
> |
syserr(vval(OPTFILE)); |
802 |
|
write(fd, "\n", 1); |
803 |
|
close(fd); |
804 |
|
ro[0] = ' '; |
808 |
|
#ifdef MSDOS |
809 |
|
else if (n > 50) { |
810 |
|
register char *evp = bmalloc(n+6); |
811 |
< |
if (evp == NULL) { |
812 |
< |
perror(progname); |
837 |
< |
exit(1); |
838 |
< |
} |
811 |
> |
if (evp == NULL) |
812 |
> |
syserr(progname); |
813 |
|
strcpy(evp, "ROPT="); |
814 |
|
strcat(evp, ro); |
815 |
|
if (putenv(evp) != 0) { |
854 |
|
specview(vs) /* get proper view spec from vs */ |
855 |
|
register char *vs; |
856 |
|
{ |
857 |
+ |
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
858 |
+ |
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
859 |
|
static char viewopts[128]; |
860 |
|
register char *cp; |
861 |
< |
int xpos, ypos, zpos, viewtype; |
862 |
< |
int exterior; |
861 |
> |
int xpos, ypos, zpos, viewtype, upax; |
862 |
> |
register int i; |
863 |
|
double cent[3], dim[3], mult, d; |
864 |
|
|
865 |
|
if (vs == NULL || *vs == '-') |
866 |
|
return(vs); |
867 |
+ |
upax = 0; /* get the up vector */ |
868 |
+ |
if (vdef(UP)) { |
869 |
+ |
if (vval(UP)[0] == '-' || vval(UP)[0] == '+') |
870 |
+ |
upax = 1-'X'+UPPER(vval(UP)[1]); |
871 |
+ |
else |
872 |
+ |
upax = 1-'X'+vlet(UP); |
873 |
+ |
if (upax < 1 | upax > 3) |
874 |
+ |
badvalue(UP); |
875 |
+ |
if (vval(UP)[0] == '-') |
876 |
+ |
upax = -upax; |
877 |
+ |
} |
878 |
|
/* check standard view names */ |
879 |
|
xpos = ypos = zpos = 0; |
893 |
– |
viewtype = 0; |
880 |
|
if (*vs == 'X') { |
881 |
|
xpos = 1; vs++; |
882 |
|
} else if (*vs == 'x') { |
892 |
|
} else if (*vs == 'z') { |
893 |
|
zpos = -1; vs++; |
894 |
|
} |
895 |
+ |
viewtype = 'v'; |
896 |
|
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') |
897 |
|
viewtype = *vs++; |
911 |
– |
else if (!*vs || isspace(*vs)) |
912 |
– |
viewtype = 'v'; |
898 |
|
cp = viewopts; |
899 |
< |
if (viewtype && (xpos|ypos|zpos)) { /* got standard view */ |
899 |
> |
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
900 |
|
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
901 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
902 |
|
¢[0], &dim[0], ¢[1], &dim[1], |
903 |
< |
¢[2], &dim[2]) != 6) { |
904 |
< |
fprintf(stderr, "%s: bad zone specification\n", |
905 |
< |
progname); |
906 |
< |
exit(1); |
903 |
> |
¢[2], &dim[2]) != 6) |
904 |
> |
badvalue(ZONE); |
905 |
> |
for (i = 0; i < 3; i++) { |
906 |
> |
dim[i] -= cent[i]; |
907 |
> |
cent[i] += .5*dim[i]; |
908 |
|
} |
909 |
< |
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 ; |
909 |
> |
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
910 |
|
sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", |
911 |
|
cent[0]+xpos*mult*dim[0], |
912 |
|
cent[1]+ypos*mult*dim[1], |
913 |
|
cent[2]+zpos*mult*dim[2], |
914 |
|
-xpos*dim[0], -ypos*dim[1], -zpos*dim[2]); |
915 |
|
cp += strlen(cp); |
916 |
< |
switch (vlet(UP)) { |
917 |
< |
case 'Z': |
918 |
< |
if (xpos|ypos) { |
919 |
< |
cp = addarg(cp, "-vu 0 0 1"); |
920 |
< |
break; |
921 |
< |
} |
922 |
< |
/* 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"); |
916 |
> |
/* redirect up axis if necessary */ |
917 |
> |
switch (upax) { |
918 |
> |
case 3: /* plus or minus Z axis */ |
919 |
> |
case -3: |
920 |
> |
case 0: |
921 |
> |
if (!(xpos|ypos)) |
922 |
> |
upax = 2; |
923 |
|
break; |
924 |
< |
default: |
925 |
< |
fprintf(stderr, "%s: illegal value for variable '%s'\n", |
926 |
< |
progname, vnam(UP)); |
927 |
< |
exit(1); |
924 |
> |
case 2: /* plus or minus Y axis */ |
925 |
> |
case -2: |
926 |
> |
if (!(xpos|zpos)) |
927 |
> |
upax = 1; |
928 |
> |
break; |
929 |
> |
case 1: /* plus or minus X axis */ |
930 |
> |
case -1: |
931 |
> |
if (!(ypos|zpos)) |
932 |
> |
upax = 3; |
933 |
> |
break; |
934 |
|
} |
935 |
+ |
cp = addarg(cp, vup[upax+3]); |
936 |
|
switch (viewtype) { |
937 |
|
case 'v': |
938 |
|
cp = addarg(cp, "-vh 45 -vv 45"); |
947 |
|
cp = addarg(cp, "-vh 180 -vv 180"); |
948 |
|
break; |
949 |
|
} |
950 |
< |
} else |
950 |
> |
} else { |
951 |
|
while (*vs && !isspace(*vs)) /* else skip id */ |
952 |
|
vs++; |
953 |
+ |
if (upax) { /* specify up vector */ |
954 |
+ |
strcpy(cp, vup[upax+3]); |
955 |
+ |
cp += strlen(cp); |
956 |
+ |
} |
957 |
+ |
} |
958 |
|
/* append any additional options */ |
976 |
– |
while (isspace(*vs)) vs++; |
959 |
|
strcpy(cp, vs); |
960 |
|
return(viewopts); |
961 |
|
} |
1023 |
|
char *opts; |
1024 |
|
{ |
1025 |
|
char combuf[1024]; |
1026 |
< |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32]; |
1027 |
< |
char pfopts[64]; |
1026 |
> |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; |
1027 |
> |
char pfopts[128]; |
1028 |
|
char vs[32], *vw; |
1029 |
|
int vn, mult; |
1030 |
|
/* get pfilt options */ |
1042 |
|
else if (n) { |
1043 |
|
if (n == 1) yres = xres; |
1044 |
|
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1045 |
< |
} else { |
1046 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1065 |
< |
progname, vnam(RESOLUTION)); |
1066 |
< |
exit(1); |
1067 |
< |
} |
1045 |
> |
} else |
1046 |
> |
badvalue(RESOLUTION); |
1047 |
|
} |
1048 |
|
rep[0] = '\0'; |
1049 |
|
if (vdef(REPORT)) { |
1054 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1055 |
|
else if (n == 1) |
1056 |
|
sprintf(rep, " -t %d", (int)(minutes*60)); |
1057 |
< |
else { |
1058 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1059 |
< |
progname, vnam(REPORT)); |
1060 |
< |
exit(1); |
1057 |
> |
else |
1058 |
> |
badvalue(REPORT); |
1059 |
> |
} |
1060 |
> |
/* check date on ambient file */ |
1061 |
> |
if (vdef(AMBFILE)) { |
1062 |
> |
long afdate = fdate(vval(AMBFILE)); |
1063 |
> |
if (afdate >= 0 & octreedate > afdate) { |
1064 |
> |
if (!silent) |
1065 |
> |
#ifdef MSDOS |
1066 |
> |
printf("\tdel %s\n", vval(AMBFILE)); |
1067 |
> |
#else |
1068 |
> |
printf("\trm %s\n", vval(AMBFILE)); |
1069 |
> |
#endif |
1070 |
> |
if (!noaction) |
1071 |
> |
unlink(vval(AMBFILE)); |
1072 |
|
} |
1073 |
|
} |
1074 |
|
/* do each view */ |
1144 |
|
if (!noaction) |
1145 |
|
unlink(rawfile); |
1146 |
|
} |
1147 |
+ |
} |
1148 |
+ |
|
1149 |
+ |
|
1150 |
+ |
badvalue(vc) /* report bad variable value and exit */ |
1151 |
+ |
int vc; |
1152 |
+ |
{ |
1153 |
+ |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1154 |
+ |
progname, vnam(vc)); |
1155 |
+ |
exit(1); |
1156 |
+ |
} |
1157 |
+ |
|
1158 |
+ |
|
1159 |
+ |
syserr(s) /* report a system error and exit */ |
1160 |
+ |
char *s; |
1161 |
+ |
{ |
1162 |
+ |
perror(s); |
1163 |
+ |
exit(1); |
1164 |
|
} |