16 |
|
|
17 |
|
#include <ctype.h> |
18 |
|
|
19 |
+ |
#include "otypes.h" |
20 |
|
|
20 |
– |
typedef struct { |
21 |
– |
char *funame; /* function name */ |
22 |
– |
int (*funp)(); /* pointer to function */ |
23 |
– |
} FUN; |
24 |
– |
|
21 |
|
int xac; /* global xform argument count */ |
22 |
|
char **xav; /* global xform argument pointer */ |
23 |
|
int xfa; /* start of xf arguments */ |
30 |
|
|
31 |
|
char *idprefix = NULL; /* prefix for object identifiers */ |
32 |
|
|
33 |
< |
extern int o_source(); |
38 |
< |
extern int o_sphere(); |
39 |
< |
extern int o_face(); |
40 |
< |
extern int o_cone(); |
41 |
< |
extern int o_cylinder(); |
42 |
< |
extern int o_ring(); |
43 |
< |
extern int m_glow(); |
44 |
< |
extern int m_spot(); |
45 |
< |
extern int m_dielectric(); |
46 |
< |
extern int m_interface(); |
47 |
< |
extern int text(); |
48 |
< |
extern int alias(); |
49 |
< |
extern int passargs(); |
50 |
< |
extern int addxform(); |
33 |
> |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
34 |
|
|
35 |
< |
FUN ofun[] = { |
53 |
< |
{ "source", o_source }, |
54 |
< |
{ "sphere", o_sphere }, |
55 |
< |
{ "bubble", o_sphere }, |
56 |
< |
{ "polygon", o_face }, |
57 |
< |
{ "cone", o_cone }, |
58 |
< |
{ "cup", o_cone }, |
59 |
< |
{ "cylinder", o_cylinder }, |
60 |
< |
{ "tube", o_cylinder }, |
61 |
< |
{ "ring", o_ring }, |
62 |
< |
{ "instance", addxform }, |
63 |
< |
{ "alias", alias }, |
64 |
< |
{ "antimatter", passargs }, |
65 |
< |
{ "glow", m_glow }, |
66 |
< |
{ "spotlight", m_spot }, |
67 |
< |
{ "dielectric", m_dielectric }, |
68 |
< |
{ "interface", m_interface }, |
69 |
< |
{ "colortext", text }, |
70 |
< |
{ "brighttext", text }, |
71 |
< |
{ "texfunc", addxform }, |
72 |
< |
{ "texdata", addxform }, |
73 |
< |
{ "colorfunc", addxform }, |
74 |
< |
{ "brightfunc", addxform }, |
75 |
< |
{ "colorpict", addxform }, |
76 |
< |
{ "colordata", addxform }, |
77 |
< |
{ "brightdata", addxform }, |
78 |
< |
{ "mixfunc", addxform }, |
79 |
< |
{ "mixdata", addxform }, |
80 |
< |
{ "mixtext", text }, |
81 |
< |
{ "light", passargs }, |
82 |
< |
{ "illum", passargs }, |
83 |
< |
{ "plastic", passargs }, |
84 |
< |
{ "metal", passargs }, |
85 |
< |
{ "trans", passargs }, |
86 |
< |
{ "glass", passargs }, |
87 |
< |
{ 0 } /* terminator */ |
88 |
< |
}; |
35 |
> |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
36 |
|
|
37 |
< |
#define issurface(t) ((t)<=9) |
37 |
> |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
38 |
|
|
39 |
|
typedef struct { |
40 |
|
short nsargs; /* # of string arguments */ |
60 |
|
FILE *fopen(); |
61 |
|
FILE *fp; |
62 |
|
int a; |
63 |
+ |
/* check for array */ |
64 |
+ |
for (a = 1; a < argc; a++) |
65 |
+ |
if (!strcmp(argv[a], "-a")) |
66 |
+ |
return(doarray(argc, argv, a)); |
67 |
|
|
68 |
< |
xav = argv; |
68 |
> |
initotypes(); |
69 |
|
|
70 |
|
for (a = 1; a < argc; a++) { |
71 |
|
if (argv[a][0] == '-') |
72 |
|
switch (argv[a][1]) { |
73 |
|
case 'n': |
74 |
+ |
if (argv[a][2] || a+1 >= argc) |
75 |
+ |
break; |
76 |
|
idprefix = argv[++a]; |
77 |
|
continue; |
78 |
|
case 'e': |
79 |
+ |
if (argv[a][2]) |
80 |
+ |
break; |
81 |
|
expand = 1; |
82 |
|
continue; |
83 |
|
} |
84 |
|
break; |
85 |
|
} |
86 |
|
|
87 |
+ |
xav = argv; |
88 |
|
xfa = a; |
89 |
|
|
90 |
|
totscale = 1.0; |
95 |
|
if (reverse = totscale < 0.0) |
96 |
|
totscale = -totscale; |
97 |
|
|
98 |
< |
xac = a; |
98 |
> |
if (a < argc && argv[a][0] == '-') { |
99 |
> |
fprintf(stderr, "%s: command line error at '%s'\n", |
100 |
> |
argv[0], argv[a]); |
101 |
> |
exit(1); |
102 |
> |
} |
103 |
|
|
104 |
< |
putchar('#'); /* simple header */ |
104 |
> |
xac = a; |
105 |
> |
/* simple header */ |
106 |
> |
putchar('#'); |
107 |
|
for (a = 0; a < xac; a++) |
108 |
|
printf(" %s", xav[a]); |
109 |
|
putchar('\n'); |
110 |
< |
|
111 |
< |
if (a == argc) |
110 |
> |
/* transform input */ |
111 |
> |
if (xac == argc) |
112 |
|
xform("standard input", stdin); |
113 |
|
else |
114 |
< |
for ( ; a < argc; a++) { |
114 |
> |
for (a = xac; a < argc; a++) { |
115 |
|
if ((fp = fopen(argv[a], "r")) == NULL) { |
116 |
|
fprintf(stderr, "%s: cannot open \"%s\"\n", |
117 |
|
progname, argv[a]); |
121 |
|
fclose(fp); |
122 |
|
} |
123 |
|
|
124 |
< |
exit(0); |
124 |
> |
return(0); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
+ |
doarray(ac, av, ai) /* make array */ |
129 |
+ |
char **av; |
130 |
+ |
int ac, ai; |
131 |
+ |
{ |
132 |
+ |
char *newav[256], **avp; |
133 |
+ |
char newid[128], repts[32]; |
134 |
+ |
char *oldid = NULL; |
135 |
+ |
int i, err; |
136 |
+ |
|
137 |
+ |
avp = newav+2; |
138 |
+ |
avp[0] = av[0]; |
139 |
+ |
for (i = 1; i < ac; i++) |
140 |
+ |
if (!strcmp(av[i-1], "-n")) { |
141 |
+ |
oldid = av[i]; |
142 |
+ |
avp[i] = newid; |
143 |
+ |
} else |
144 |
+ |
avp[i] = av[i]; |
145 |
+ |
avp[ai] = "-i"; |
146 |
+ |
avp[ai+1] = repts; |
147 |
+ |
avp[i] = NULL; |
148 |
+ |
if (oldid == NULL) { |
149 |
+ |
newav[0] = av[0]; |
150 |
+ |
newav[1] = "-n"; |
151 |
+ |
newav[2] = newid; |
152 |
+ |
avp = newav; |
153 |
+ |
ac += 2; |
154 |
+ |
} |
155 |
+ |
err = 0; |
156 |
+ |
for (i = 0; i < atoi(av[ai+1]); i++) { |
157 |
+ |
if (oldid == NULL) |
158 |
+ |
sprintf(newid, "a%d", i); |
159 |
+ |
else |
160 |
+ |
sprintf(newid, "%s.%d", oldid, i); |
161 |
+ |
sprintf(repts, "%d", i); |
162 |
+ |
err |= main(ac, avp); |
163 |
+ |
} |
164 |
+ |
return(err); |
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
|
168 |
|
xform(name, fin) /* transform stream by totxform */ |
169 |
|
char *name; |
170 |
|
register FILE *fin; |
183 |
|
} while (c != '\n'); |
184 |
|
} else if (c == '!') { /* command */ |
185 |
|
ungetc(c, fin); |
186 |
< |
if (expand) |
185 |
< |
xfcomm(name, fin); |
186 |
< |
else { |
187 |
< |
putchar('\n'); |
188 |
< |
while ((c = getc(fin)) != EOF && c != '\n') |
189 |
< |
putchar(c); |
190 |
< |
printf(" |"); |
191 |
< |
for (c = 0; c < xac; c++) |
192 |
< |
printf(" %s", xav[c]); |
193 |
< |
putchar('\n'); |
194 |
< |
} |
186 |
> |
xfcomm(name, fin); |
187 |
|
} else { /* object */ |
188 |
|
ungetc(c, fin); |
189 |
|
xfobject(name, fin); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
< |
xfcomm(fname, fin) /* expand a command */ |
195 |
> |
xfcomm(fname, fin) /* transform a command */ |
196 |
|
FILE *fin; |
197 |
|
{ |
198 |
|
FILE *popen(); |
199 |
< |
char *fgets(); |
199 |
> |
char *fgetline(); |
200 |
|
FILE *pin; |
201 |
|
char buf[512]; |
202 |
+ |
int i; |
203 |
|
|
204 |
< |
fgets(buf, sizeof(buf), fin); |
205 |
< |
if (buf[strlen(buf)-1] == '\n') |
206 |
< |
buf[strlen(buf)-1] = '\0'; |
207 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
208 |
< |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
209 |
< |
progname, fname, buf); |
210 |
< |
exit(1); |
204 |
> |
fgetline(buf, sizeof(buf), fin); |
205 |
> |
if (expand) { |
206 |
> |
if (xac > 2) { |
207 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
208 |
> |
fprintf(stderr, |
209 |
> |
"%s: (%s): cannot execute \"%s\"\n", |
210 |
> |
progname, fname, buf); |
211 |
> |
exit(1); |
212 |
> |
} |
213 |
> |
xform(buf, pin); |
214 |
> |
pclose(pin); |
215 |
> |
} else { |
216 |
> |
fflush(stdout); |
217 |
> |
system(buf+1); |
218 |
> |
} |
219 |
> |
} else { |
220 |
> |
printf("\n%s", buf); |
221 |
> |
if (xac > 1) { |
222 |
> |
printf(" | %s -e", xav[0]); |
223 |
> |
for (i = 1; i < xac; i++) |
224 |
> |
printf(" %s", xav[i]); |
225 |
> |
} |
226 |
> |
putchar('\n'); |
227 |
|
} |
219 |
– |
xform(buf, pin); |
220 |
– |
pclose(pin); |
228 |
|
} |
229 |
|
|
230 |
|
|
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
< |
passargs(fin) /* pass on arguments unchanged */ |
261 |
> |
o_default(fin) /* pass on arguments unchanged */ |
262 |
|
FILE *fin; |
263 |
|
{ |
264 |
|
register int i; |
322 |
|
{ |
323 |
|
register int i; |
324 |
|
|
325 |
< |
for (i = 0; ofun[i].funame != NULL; i++) |
325 |
> |
for (i = 0; i < NUMTYPES; i++) |
326 |
|
if (!strcmp(ofun[i].funame, ofname)) |
327 |
|
return(i); |
328 |
|
|
682 |
|
if (fa->nfargs) |
683 |
|
free(fa->farg); |
684 |
|
free(fa); |
685 |
+ |
} |
686 |
+ |
|
687 |
+ |
|
688 |
+ |
initotypes() /* initialize ofun[] array */ |
689 |
+ |
{ |
690 |
+ |
extern int o_source(); |
691 |
+ |
extern int o_sphere(); |
692 |
+ |
extern int o_face(); |
693 |
+ |
extern int o_cone(); |
694 |
+ |
extern int o_cylinder(); |
695 |
+ |
extern int o_ring(); |
696 |
+ |
extern int m_glow(); |
697 |
+ |
extern int m_spot(); |
698 |
+ |
extern int m_dielectric(); |
699 |
+ |
extern int m_interface(); |
700 |
+ |
extern int text(); |
701 |
+ |
extern int alias(); |
702 |
+ |
extern int passargs(); |
703 |
+ |
extern int addxform(); |
704 |
+ |
register int i; |
705 |
+ |
|
706 |
+ |
if (ofun[OBJ_SOURCE].funp == o_source) |
707 |
+ |
return; /* done already */ |
708 |
+ |
/* alias is additional */ |
709 |
+ |
ofun[ALIAS].funame = ALIASID; |
710 |
+ |
ofun[ALIAS].flags = 0; |
711 |
+ |
/* functions get new transform */ |
712 |
+ |
for (i = 0; i < NUMTYPES; i++) |
713 |
+ |
if (hasfunc(i)) |
714 |
+ |
ofun[i].funp = addxform; |
715 |
+ |
/* special cases */ |
716 |
+ |
ofun[OBJ_SOURCE].funp = o_source; |
717 |
+ |
ofun[OBJ_SPHERE].funp = |
718 |
+ |
ofun[OBJ_BUBBLE].funp = o_sphere; |
719 |
+ |
ofun[OBJ_FACE].funp = o_face; |
720 |
+ |
ofun[OBJ_CONE].funp = |
721 |
+ |
ofun[OBJ_CUP].funp = o_cone; |
722 |
+ |
ofun[OBJ_CYLINDER].funp = |
723 |
+ |
ofun[OBJ_TUBE].funp = o_cylinder; |
724 |
+ |
ofun[OBJ_RING].funp = o_ring; |
725 |
+ |
ofun[OBJ_INSTANCE].funp = addxform; |
726 |
+ |
ofun[MAT_GLOW].funp = m_glow; |
727 |
+ |
ofun[MAT_SPOT].funp = m_spot; |
728 |
+ |
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
729 |
+ |
ofun[MAT_INTERFACE].funp = m_interface; |
730 |
+ |
ofun[PAT_CTEXT].funp = |
731 |
+ |
ofun[PAT_BTEXT].funp = |
732 |
+ |
ofun[MIX_TEXT].funp = text; |
733 |
+ |
ofun[ALIAS].funp = alias; |
734 |
|
} |