1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
14 |
|
|
15 |
|
#include "standard.h" |
16 |
|
|
17 |
+ |
#include "paths.h" |
18 |
+ |
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
|
#include "object.h" |
45 |
|
|
46 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
47 |
|
|
48 |
+ |
int nrept = 1; /* number of array repetitions */ |
49 |
+ |
|
50 |
|
extern char *malloc(), *fgetword(); |
51 |
|
|
52 |
+ |
char *mainfn[MAXPATH]; /* main file name */ |
53 |
+ |
FILE *mainfp = NULL; /* main file pointer */ |
54 |
+ |
|
55 |
|
#define progname (xav[0]) |
56 |
|
|
57 |
|
|
59 |
|
int argc; |
60 |
|
char *argv[]; |
61 |
|
{ |
62 |
< |
FILE *fopen(); |
56 |
< |
FILE *fp; |
62 |
> |
char *fname; |
63 |
|
int a; |
64 |
|
/* check for array */ |
65 |
|
for (a = 1; a < argc; a++) |
118 |
|
printf(" %s", xav[a]); |
119 |
|
putchar('\n'); |
120 |
|
/* transform input */ |
121 |
< |
if (xac == argc) |
122 |
< |
xform("standard input", stdin); |
123 |
< |
else |
121 |
> |
if (xac == argc) { |
122 |
> |
openmain(NULL); |
123 |
> |
xform(mainfn, mainfp); |
124 |
> |
} else |
125 |
|
for (a = xac; a < argc; a++) { |
126 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
127 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
126 |
> |
openmain(argv[a]); |
127 |
> |
xform(mainfn, mainfp); |
128 |
|
} |
129 |
|
|
130 |
|
return(0); |
138 |
|
char *newav[256], **avp; |
139 |
|
char newid[128], repts[32]; |
140 |
|
char *oldid = NULL; |
141 |
< |
int i, err; |
141 |
> |
int n, i, err; |
142 |
|
|
143 |
|
avp = newav+2; |
144 |
|
avp[0] = av[0]; |
158 |
|
avp = newav; |
159 |
|
ac += 2; |
160 |
|
} |
161 |
+ |
nrept *= n = atoi(av[ai+1]); |
162 |
|
err = 0; |
163 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
163 |
> |
for (i = 0; i < n; i++) { |
164 |
|
if (oldid == NULL) |
165 |
|
sprintf(newid, "a%d", i); |
166 |
|
else |
176 |
|
char *name; |
177 |
|
register FILE *fin; |
178 |
|
{ |
179 |
+ |
int nobjs = 0; |
180 |
|
register int c; |
181 |
|
|
182 |
|
while ((c = getc(fin)) != EOF) { |
192 |
|
} else if (c == '!') { /* command */ |
193 |
|
ungetc(c, fin); |
194 |
|
xfcomm(name, fin); |
195 |
+ |
nobjs++; |
196 |
|
} else { /* object */ |
197 |
|
ungetc(c, fin); |
198 |
|
xfobject(name, fin); |
199 |
+ |
nobjs++; |
200 |
|
} |
201 |
|
} |
202 |
+ |
if (nobjs == 0) |
203 |
+ |
fprintf(stderr, "%s: (%s): warning - empty file\n", |
204 |
+ |
progname, name); |
205 |
|
} |
206 |
|
|
207 |
|
|
209 |
|
char *fname; |
210 |
|
FILE *fin; |
211 |
|
{ |
212 |
< |
FILE *popen(); |
213 |
< |
char *fgetline(); |
212 |
> |
extern FILE *popen(); |
213 |
> |
extern char *fgetline(); |
214 |
|
FILE *pin; |
215 |
|
char buf[512]; |
216 |
|
int i; |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
+ |
m_mist(fin) /* transform arguments for mist */ |
411 |
+ |
FILE *fin; |
412 |
+ |
{ |
413 |
+ |
FUNARGS fa; |
414 |
+ |
int i; |
415 |
+ |
|
416 |
+ |
if (readfargs(&fa, fin) != 1) |
417 |
+ |
return(-1); |
418 |
+ |
if (fa.nfargs > 5) |
419 |
+ |
return(-1); |
420 |
+ |
printf("%d", fa.nsargs); |
421 |
+ |
if (idprefix == NULL) |
422 |
+ |
for (i = 0; i < fa.nsargs; i++) |
423 |
+ |
printf(" %s", fa.sarg[i]); |
424 |
+ |
else |
425 |
+ |
for (i = 0; i < fa.nsargs; i++) { |
426 |
+ |
char sname[256], *sp; |
427 |
+ |
register char *cp1, *cp2 = sname; |
428 |
+ |
/* add idprefix */ |
429 |
+ |
for (sp = fa.sarg[i]; *sp; sp = cp1) { |
430 |
+ |
for (cp1 = idprefix; *cp1; ) |
431 |
+ |
*cp2++ = *cp1++; |
432 |
+ |
*cp2++ = '.'; |
433 |
+ |
for (cp1 = sp; *cp1 && |
434 |
+ |
(*cp2++ = *cp1++) != '>'; ) |
435 |
+ |
; |
436 |
+ |
} |
437 |
+ |
*cp2 = '\0'; |
438 |
+ |
printf(" %s", sname); |
439 |
+ |
} |
440 |
+ |
printf("\n0\n%d", fa.nfargs); |
441 |
+ |
if (fa.nfargs > 2) |
442 |
+ |
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
443 |
+ |
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
444 |
+ |
if (fa.nfargs > 3) |
445 |
+ |
printf(" %12.6g", fa.farg[3]); |
446 |
+ |
if (fa.nfargs > 4) |
447 |
+ |
printf(" %12.6g", fa.farg[4]); |
448 |
+ |
printf("\n"); |
449 |
+ |
freefargs(&fa); |
450 |
+ |
return(0); |
451 |
+ |
} |
452 |
+ |
|
453 |
+ |
|
454 |
|
m_dielectric(fin) /* transform arguments for dielectric */ |
455 |
|
FILE *fin; |
456 |
|
{ |
461 |
|
if (fa.nsargs != 0 || fa.nfargs != 5) |
462 |
|
return(-1); |
463 |
|
printf("0\n0\n5"); |
464 |
< |
printf(" %18.12g %18.12g %18.12g", |
464 |
> |
printf(" %12.6g %12.6g %12.6g", |
465 |
|
pow(fa.farg[0], 1.0/tot.sca), |
466 |
|
pow(fa.farg[1], 1.0/tot.sca), |
467 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
468 |
< |
printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]); |
468 |
> |
printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
469 |
|
freefargs(&fa); |
470 |
|
return(0); |
471 |
|
} |
481 |
|
if (fa.nsargs != 0 || fa.nfargs != 8) |
482 |
|
return(-1); |
483 |
|
printf("0\n0\n8\n"); |
484 |
< |
printf("%18.12g %18.12g %18.12g", |
484 |
> |
printf("%12.6g %12.6g %12.6g", |
485 |
|
pow(fa.farg[0], 1.0/tot.sca), |
486 |
|
pow(fa.farg[1], 1.0/tot.sca), |
487 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
488 |
< |
printf(" %18.12g\n", fa.farg[3]); |
489 |
< |
printf("%18.12g %18.12g %18.12g", |
488 |
> |
printf(" %12.6g\n", fa.farg[3]); |
489 |
> |
printf("%12.6g %12.6g %12.6g", |
490 |
|
pow(fa.farg[4], 1.0/tot.sca), |
491 |
|
pow(fa.farg[5], 1.0/tot.sca), |
492 |
|
pow(fa.farg[6], 1.0/tot.sca)); |
493 |
< |
printf(" %18.12g\n", fa.farg[7]); |
493 |
> |
printf(" %12.6g\n", fa.farg[7]); |
494 |
|
freefargs(&fa); |
495 |
|
return(0); |
496 |
|
} |
689 |
|
|
690 |
|
initotypes() /* initialize ofun[] array */ |
691 |
|
{ |
639 |
– |
extern int o_source(); |
640 |
– |
extern int o_sphere(); |
641 |
– |
extern int o_face(); |
642 |
– |
extern int o_cone(); |
643 |
– |
extern int o_cylinder(); |
644 |
– |
extern int o_ring(); |
645 |
– |
extern int m_glow(); |
646 |
– |
extern int m_spot(); |
647 |
– |
extern int m_dielectric(); |
648 |
– |
extern int m_interface(); |
649 |
– |
extern int text(); |
650 |
– |
extern int alias(); |
651 |
– |
extern int passargs(); |
652 |
– |
extern int addxform(); |
692 |
|
register int i; |
693 |
|
|
694 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
715 |
|
ofun[MAT_SPOT].funp = m_spot; |
716 |
|
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
717 |
|
ofun[MAT_INTERFACE].funp = m_interface; |
718 |
+ |
ofun[MAT_MIST].funp = m_mist; |
719 |
|
ofun[PAT_CTEXT].funp = |
720 |
|
ofun[PAT_BTEXT].funp = |
721 |
|
ofun[MIX_TEXT].funp = text; |
722 |
|
ofun[ALIAS].funp = alias; |
723 |
|
/* surface inverses */ |
724 |
+ |
tinvers[OBJ_FACE] = OBJ_FACE; |
725 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
726 |
|
tinvers[OBJ_CONE] = OBJ_CUP; |
727 |
|
tinvers[OBJ_CUP] = OBJ_CONE; |
732 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
733 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
734 |
|
} |
735 |
+ |
|
736 |
+ |
|
737 |
+ |
#ifdef OLDXFORM |
738 |
+ |
openmain(fname) |
739 |
+ |
char *fname; |
740 |
+ |
{ |
741 |
+ |
if (fname == NULL) { |
742 |
+ |
strcpy(mainfn, "standard input"); |
743 |
+ |
mainfp = stdin; |
744 |
+ |
return; |
745 |
+ |
} |
746 |
+ |
if (mainfp != NULL) { |
747 |
+ |
if (!strcmp(fname, mainfn)) { |
748 |
+ |
rewind(mainfp); |
749 |
+ |
return; |
750 |
+ |
} |
751 |
+ |
fclose(mainfp); |
752 |
+ |
} |
753 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
754 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
755 |
+ |
progname, fname); |
756 |
+ |
exit(1); |
757 |
+ |
} |
758 |
+ |
strcpy(mainfn, fname); |
759 |
+ |
} |
760 |
+ |
#else |
761 |
+ |
openmain(fname) /* open fname for input, changing to its directory */ |
762 |
+ |
char *fname; |
763 |
+ |
{ |
764 |
+ |
extern FILE *tmpfile(); |
765 |
+ |
extern char *getlibpath(), *getpath(); |
766 |
+ |
static char origdir[MAXPATH]; |
767 |
+ |
static char curdir[MAXPATH]; |
768 |
+ |
char newdir[MAXPATH], *cp; |
769 |
+ |
|
770 |
+ |
if (fname == NULL) { /* standard input */ |
771 |
+ |
if (mainfp == NULL) { |
772 |
+ |
register int c; |
773 |
+ |
strcpy(mainfn, "standard input"); |
774 |
+ |
if (nrept <= 1) { |
775 |
+ |
mainfp = stdin; |
776 |
+ |
return; /* just read once */ |
777 |
+ |
} |
778 |
+ |
/* else copy */ |
779 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
780 |
+ |
fprintf(stderr, |
781 |
+ |
"%s: cannot create temporary file\n", |
782 |
+ |
progname); |
783 |
+ |
exit(1); |
784 |
+ |
} |
785 |
+ |
while ((c = getc(stdin)) != EOF) |
786 |
+ |
putc(c, mainfp); |
787 |
+ |
fclose(stdin); |
788 |
+ |
} |
789 |
+ |
rewind(mainfp); /* rewind copy */ |
790 |
+ |
return; |
791 |
+ |
} |
792 |
+ |
/* get full path */ |
793 |
+ |
if ((cp = getpath(fname, getlibpath(), R_OK)) == NULL) { |
794 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
795 |
+ |
progname, fname); |
796 |
+ |
exit(1); |
797 |
+ |
} |
798 |
+ |
if (cp[0] == '.' && ISDIRSEP(cp[1])) /* remove leading ./ */ |
799 |
+ |
cp += 2; |
800 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
801 |
+ |
getwd(origdir); |
802 |
+ |
strcpy(curdir, origdir); |
803 |
+ |
} else if (!strcmp(cp, mainfn)) { /* just need to rewind? */ |
804 |
+ |
rewind(mainfp); |
805 |
+ |
return; |
806 |
+ |
} else /* else close old stream */ |
807 |
+ |
fclose(mainfp); |
808 |
+ |
/* record path name */ |
809 |
+ |
strcpy(mainfn, cp); |
810 |
+ |
if (expand) { /* get directory component */ |
811 |
+ |
if (ISDIRSEP(cp[0])) |
812 |
+ |
strcpy(newdir, cp); |
813 |
+ |
else |
814 |
+ |
sprintf(newdir, "%s%c%s", origdir, DIRSEP, cp); |
815 |
+ |
for (cp = newdir+strlen(newdir); !ISDIRSEP(cp[-1]); cp--) |
816 |
+ |
; |
817 |
+ |
*cp = '\0'; |
818 |
+ |
if (strcmp(newdir, curdir)) { /* change to new directory? */ |
819 |
+ |
if (chdir(newdir) < 0) { |
820 |
+ |
fprintf(stderr, |
821 |
+ |
"%s: cannot change directory to \"%s\"\n", |
822 |
+ |
progname, newdir); |
823 |
+ |
exit(1); |
824 |
+ |
} |
825 |
+ |
strcpy(curdir, newdir); |
826 |
+ |
} |
827 |
+ |
/* get final path component */ |
828 |
+ |
for (cp = fname+strlen(fname); |
829 |
+ |
cp > fname && !ISDIRSEP(cp[-1]); cp--) |
830 |
+ |
; |
831 |
+ |
} |
832 |
+ |
/* open the file */ |
833 |
+ |
if ((mainfp = fopen(cp, "r")) == NULL) { |
834 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
835 |
+ |
progname, mainfn); |
836 |
+ |
exit(1); |
837 |
+ |
} |
838 |
+ |
} |
839 |
+ |
#endif |