| 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 */ |
| 65 |
|
if (!strcmp(argv[a], "-a")) |
| 66 |
|
return(doarray(argc, argv, a)); |
| 67 |
|
|
| 68 |
+ |
initotypes(); |
| 69 |
+ |
|
| 70 |
|
for (a = 1; a < argc; a++) { |
| 71 |
|
if (argv[a][0] == '-') |
| 72 |
|
switch (argv[a][1]) { |
| 100 |
|
argv[0], argv[a]); |
| 101 |
|
exit(1); |
| 102 |
|
} |
| 154 |
– |
xac = a; |
| 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]); |
| 203 |
|
|
| 204 |
|
fgetline(buf, sizeof(buf), fin); |
| 205 |
|
if (expand) { |
| 206 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
| 207 |
< |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
| 208 |
< |
progname, fname, buf); |
| 209 |
< |
exit(1); |
| 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 |
|
} |
| 261 |
– |
xform(buf, pin); |
| 262 |
– |
pclose(pin); |
| 219 |
|
} else { |
| 220 |
< |
printf("\n%s | %s -e", buf, xav[0]); |
| 221 |
< |
for (i = 1; i < xac; i++) |
| 222 |
< |
printf(" %s", xav[i]); |
| 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 |
|
} |
| 228 |
|
} |
| 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 |
|
} |