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