|
|
1.1 root 1: #include "idfilt.h"
2:
3: FILE *infile;
4: char *filename;
5: int lineno = 0;
6:
7: float maxx, maxy;
8: float minx, miny;
9: float width = 4.0;
10: float height;
11: float colwid = 6.0;
12:
13: boolean maxxset, maxyset;
14: boolean minxset, minyset;
15: boolean widset, heightset, colset;
16: boolean boundset;
17:
18: boolean veryfirst = TRUE;
19:
20: boolean wantquality = FALSE;
21: boolean banzai = FALSE;
22:
23: main (argc, argv)
24: int argc;
25: char *argv[];
26: {
27: while (argc > 1 && argv[1][0] == '-') {
28: switch (argv[1][1]) {
29: case 'q':
30: wantquality = TRUE;
31: break;
32: case 'b':
33: banzai = TRUE;
34: break;
35: default:
36: fprintf (stderr, "ideal filter: unknown flag %c\n", argv[1][1]);
37: break;
38: }
39: argc--;
40: argv++;
41: }
42: if (argc < 2) {
43: infile = stdin;
44: lineno = 0;
45: interpret (infile);
46: } else {
47: while (argc-- > 1) {
48: if (!(infile = fopen (*++argv, "r"))) {
49: fprintf (stderr, "ideal filter: can't open %s\n", *argv);
50: exit (1);
51: }
52: filename = *argv;
53: lineno = 0;
54: interpret (infile);
55: fclose (infile);
56: }
57: }
58: exit (0);
59: }
60:
61: interpret (infile)
62: register FILE *infile;
63: {
64: char buf[250];
65:
66: int numitems;
67: char cmd[10];
68: int i[10];
69: float f[30];
70: char *string;
71:
72:
73: while (fgets (buf, sizeof buf, infile)) {
74: lineno++;
75: idjusttext (buf);
76: if (buf[0] == '.') {
77: if (buf[1] == 'I') {
78: switch (buf[2]) {
79: case 'S':
80: numitems = sscanf (buf, "%s %d %d %d %d %d %d",
81: cmd, &i[0], &i[1], &i[2], &i[3], &i[4], &i[5]
82: );
83: idstart (numitems, i);
84: maxxset = minxset = FALSE;
85: maxyset = minyset = FALSE;
86: colset = boundset = widset = heightset = FALSE;
87: break;
88: case 'E':
89: idendE ();
90: break;
91: case 'F':
92: idendF ();
93: break;
94: default:
95: break;
96: }
97: } else if (buf[1] == '.' && buf[2] == '.') {
98: sscanf (buf, "%s", cmd);
99: if (!boundset) {
100: if (strcmp (cmd, "...maxx") == 0) {
101: sscanf (buf, "%s %f",
102: cmd, &f[0]
103: );
104: idmaxx (f[0]);
105: } else if (strcmp (cmd, "...maxy") == 0) {
106: sscanf (buf, "%s %f",
107: cmd, &f[0]
108: );
109: idmaxy (f[0]);
110: } else if (strcmp (cmd, "...minx") == 0) {
111: sscanf (buf, "%s %f",
112: cmd, &f[0]
113: );
114: idminx (f[0]);
115: } else if (strcmp (cmd, "...miny") == 0) {
116: sscanf (buf, "%s %f",
117: cmd, &f[0]
118: );
119: idminy (f[0]);
120: } else if (strcmp (cmd, "...width") == 0) {
121: sscanf (buf, "%s %f",
122: cmd, &f[0]
123: );
124: idwidth (f[0]);
125: } else if (strcmp (cmd, "...height") == 0) {
126: sscanf (buf, "%s %f",
127: cmd, &f[0]
128: );
129: idheight (f[0]);
130: } else if (strcmp (cmd, "...colwid") == 0) {
131: sscanf (buf, "%s %f",
132: cmd, &f[0]
133: );
134: idcolwid (f[0]);
135: } else if (strcmp (cmd, "...obbox") == 0) {
136: if (!veryfirst) {
137: maxxset = maxyset = TRUE;
138: minxset = minyset = TRUE;
139: boundset = TRUE;
140: }
141: } else if (strcmp (cmd, "...noerase") == 0) {
142: idnoerase ();
143: } else if (strcmp (cmd, "...yeserase") == 0) {
144: idyeserase ();
145: } else {
146: idendbound ();
147: veryfirst = FALSE;
148: }
149: }
150: if (boundset) {
151: if (strcmp (cmd, "...line") == 0) {
152: sscanf (buf, "%s %f %f %f %f",
153: cmd, &f[0], &f[1], &f[2], &f[3]
154: );
155: idline (f[0], f[1], f[2], f[3]);
156: } else if (strcmp (cmd, "...circle") == 0) {
157: sscanf (buf, "%s %f %f %f",
158: cmd, &f[0], &f[1], &f[2]
159: );
160: idcircle (f[0], f[1], f[2]);
161: } else if (strcmp (cmd, "...arc") == 0) {
162: sscanf (buf, "%s %f %f %f %f %f %f %f %f %f",
163: cmd, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], &f[8]
164: );
165: idarc (f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8]);
166: } else if (strcmp (cmd, "...left") == 0) {
167: sscanf (buf, "%s %f %f",
168: cmd, &f[0], &f[1]
169: );
170: buf[strlen(buf)-1] = '\0';
171: string = buf;
172: while (*string != '\'')
173: string ++;
174: idleft (f[0], f[1], string);
175: } else if (strcmp (cmd, "...center") == 0) {
176: sscanf (buf, "%s %f %f",
177: cmd, &f[0], &f[1]
178: );
179: buf[strlen(buf)-1] = '\0';
180: string = buf;
181: while (*string != '\'')
182: string ++;
183: idcenter (f[0], f[1], string);
184: } else if (strcmp (cmd, "...right") == 0) {
185: sscanf (buf, "%s %f %f",
186: cmd, &f[0], &f[1]
187: );
188: buf[strlen(buf)-1] = '\0';
189: string = buf;
190: while (*string != '\'')
191: string ++;
192: idright (f[0], f[1], string);
193: } else if (strcmp (cmd, "...spline") == 0) {
194: sscanf (buf, "%s %f %f",
195: cmd, &f[0], &f[1]
196: );
197: idspline (f[0], f[1]);
198: } else if (strcmp (cmd, "...knot") == 0) {
199: sscanf (buf, "%s %f %f",
200: cmd, &f[0], &f[1]
201: );
202: idknot (f[0], f[1]);
203: } else if (strcmp (cmd, "...endspline") == 0) {
204: idendspline ();
205: }
206: }
207: }
208: }
209: }
210: }
211:
212: void idmaxx (x)
213: float x;
214: {
215: if (!maxxset) {
216: maxx = x;
217: maxxset = TRUE;
218: }
219: }
220:
221: void idmaxy (y)
222: float y;
223: {
224: if (!maxyset) {
225: maxy = y;
226: maxyset = TRUE;
227: }
228: }
229:
230: void idminx (x)
231: float x;
232: {
233: if (!minxset) {
234: minx = x;
235: minxset = TRUE;
236: }
237: }
238:
239: void idminy (y)
240: float y;
241: {
242: if (!minyset) {
243: miny = y;
244: minyset = TRUE;
245: }
246: }
247:
248: void idwidth (wid)
249: float wid;
250: {
251: if (!widset) {
252: width = wid;
253: widset = TRUE;
254: }
255: }
256:
257: void idheight (ht)
258: float ht;
259: {
260: if (!heightset) {
261: height = ht;
262: heightset = TRUE;
263: }
264: }
265:
266: void idcolwid (wid)
267: float wid;
268: {
269: if (!colset) {
270: colwid = wid;
271: colset = TRUE;
272: }
273: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.