|
|
1.1 root 1: #include <stdio.h>
2: #include "pic.h"
3: #include "y.tab.h"
4:
5: setdir(n) /* set direction from n */
6: int n;
7: {
8: switch (n) {
9: case UP: hvmode = U_DIR; break;
10: case DOWN: hvmode = D_DIR; break;
11: case LEFT: hvmode = L_DIR; break;
12: case RIGHT: hvmode = R_DIR; break;
13: }
14: return(hvmode);
15: }
16:
17: coord getcomp(p, t) /* return component of a position */
18: struct obj *p;
19: int t;
20: {
21: switch (t) {
22: case DOTX:
23: return(p->o_x);
24: case DOTY:
25: return(p->o_y);
26: case DOTWID:
27: switch (p->o_type) {
28: case BOX:
29: case BLOCK:
30: return(p->o_val[0]);
31: case CIRCLE:
32: case ELLIPSE:
33: return(2 * p->o_val[0]);
34: case LINE:
35: case ARROW:
36: return(p->o_val[0] - p->o_x);
37: }
38: case DOTHT:
39: switch (p->o_type) {
40: case BOX:
41: case BLOCK:
42: return(p->o_val[1]);
43: case CIRCLE:
44: case ELLIPSE:
45: return(2 * p->o_val[1]);
46: case LINE:
47: case ARROW:
48: return(p->o_val[1] - p->o_y);
49: }
50: case DOTRAD:
51: switch (p->o_type) {
52: case CIRCLE:
53: case ELLIPSE:
54: return(p->o_val[0]);
55: }
56: }
57: }
58:
59: makeattr(type, val) /* add attribute type and val */
60: int type;
61: int val; /* typing probably wrong */
62: {
63: if (type == 0 && val == 0) { /* clear table for next stat */
64: nattr = 0;
65: return;
66: }
67: dprintf("attr %d: %d %d\n", nattr, type, val);
68: attr[nattr].a_type = type;
69: attr[nattr].a_val = val;
70: nattr++;
71: }
72:
73: printexpr(n) /* print expression for debugging */
74: int n;
75: {
76: dprintf("%d\n", n);
77: }
78:
79: printpos(p) /* print position for debugging */
80: struct obj *p;
81: {
82: dprintf("%d, %d\n", p->o_x, p->o_y);
83: }
84:
85: char *tostring(s)
86: register char *s;
87: {
88: register char *p;
89:
90: p = malloc(strlen(s)+1);
91: if (p == NULL) {
92: yyerror("out of space in tostring on %s", s);
93: exit(1);
94: }
95: strcpy(p, s);
96: return(p);
97: }
98:
99: struct obj *makepos(x, y) /* make a position cell */
100: coord x;
101: coord y;
102: {
103: struct obj *p;
104:
105: p = makenode(PLACE, 0);
106: p->o_x = x;
107: p->o_y = y;
108: return(p);
109: }
110:
111: float between; /* stores fraction from lex analyzer */
112: float lastfloat; /* last float seen in lex */
113:
114: struct obj *makebetween(fract, p1, p2) /* make position between p1 and p2 */
115: int fract;
116: struct obj *p1, *p2;
117: {
118: struct obj *p;
119:
120: dprintf("fraction = %.2f\n", between);
121: p = makenode(PLACE, 0);
122: p->o_x = p1->o_x + between * (p2->o_x - p1->o_x) + 0.5;
123: p->o_y = p1->o_y + between * (p2->o_y - p1->o_y) + 0.5;
124: return(p);
125: }
126:
127: struct obj *getpos(p, corner) /* find position of point */
128: struct obj *p;
129: int corner;
130: {
131: coord x, y, x1, y1;
132:
133: dprintf("getpos %o %d\n", p, corner);
134: x = p->o_x;
135: y = p->o_y;
136: x1 = p->o_val[0];
137: y1 = p->o_val[1];
138: switch (p->o_type) {
139: case PLACE:
140: break;
141: case BOX:
142: case BLOCK:
143: switch (corner) {
144: case NORTH: y += y1 / 2; break;
145: case SOUTH: y -= y1 / 2; break;
146: case EAST: x += x1 / 2; break;
147: case WEST: x -= x1 / 2; break;
148: case NE: x += x1 / 2; y += y1 / 2; break;
149: case SW: x -= x1 / 2; y -= y1 / 2; break;
150: case SE: x += x1 / 2; y -= y1 / 2; break;
151: case NW: x -= x1 / 2; y += y1 / 2; break;
152: case START:
153: if (p->o_type == BLOCK)
154: return getpos(objlist[p->o_val[2]], START);
155: case END:
156: if (p->o_type == BLOCK)
157: return getpos(objlist[p->o_val[3]], END);
158: }
159: break;
160: case CIRCLE:
161: case ELLIPSE:
162: switch (corner) {
163: case NORTH: y += y1; break;
164: case SOUTH: y -= y1; break;
165: case EAST: x += x1; break;
166: case WEST: x -= x1; break;
167: case NE: x += 0.707 * x1; y += 0.707 * y1; break;
168: case SE: x += 0.707 * x1; y -= 0.707 * y1; break;
169: case NW: x -= 0.707 * x1; y += 0.707 * y1; break;
170: case SW: x -= 0.707 * x1; y -= 0.707 * y1; break;
171: }
172: break;
173: case LINE:
174: case SPLINE:
175: case ARROW:
176: case MOVE:
177: switch (corner) {
178: case START: break; /* already in place */
179: case END: x = x1; y = y1; break;
180: case CENTER: x = (x+x1)/2; y = (y+y1)/2; break;
181: case NORTH: if (y1 > y) { x = x1; y = y1; } break;
182: case SOUTH: if (y1 < y) { x = x1; y = y1; } break;
183: case EAST: if (x1 > x) { x = x1; y = y1; } break;
184: case WEST: if (x1 < x) { x = x1; y = y1; } break;
185: }
186: break;
187: case ARC:
188: switch (corner) {
189: case START:
190: if (p->o_attr & CW_ARC) {
191: x = p->o_val[2]; y = p->o_val[3];
192: } else {
193: x = x1; y = y1;
194: }
195: break;
196: case END:
197: if (p->o_attr & CW_ARC) {
198: x = x1; y = y1;
199: } else {
200: x = p->o_val[2]; y = p->o_val[3];
201: }
202: break;
203: }
204: break;
205: }
206: dprintf("getpos returns %d %d\n", x, y);
207: return(makepos(x, y));
208: }
209:
210: struct obj *gethere(n) /* make a place for curx,cury */
211: {
212: dprintf("gethere %d %d\n", curx, cury);
213: return(makepos(curx, cury));
214: }
215:
216: struct obj *getlast(n, t) /* find n-th previous occurrence of type t */
217: int n, t;
218: {
219: int i, k;
220: struct obj *p;
221:
222: k = n;
223: for (i = nobj-1; i >= 0; i--) {
224: p = objlist[i];
225: if (p->o_type == BLOCKEND) {
226: i = p->o_val[4];
227: continue;
228: }
229: if (p->o_type != t)
230: continue;
231: if (--k > 0)
232: continue; /* not there yet */
233: dprintf("got a last of x,y= %d,%d\n", p->o_x, p->o_y);
234: return(p);
235: }
236: yyerror("there is no %dth last", n);
237: return(NULL);
238: }
239:
240: struct obj *getfirst(n, t) /* find n-th occurrence of type t */
241: int n, t;
242: {
243: int i, k;
244: struct obj *p;
245:
246: k = n;
247: for (i = 0; i < nobj; i++) {
248: p = objlist[i];
249: if (p->o_type == BLOCK && t != BLOCK) { /* skip whole block */
250: i = p->o_val[5] + 1;
251: continue;
252: }
253: if (p->o_type != t)
254: continue;
255: if (--k > 0)
256: continue; /* not there yet */
257: dprintf("got a first of x,y= %d,%d\n", p->o_x, p->o_y);
258: return(p);
259: }
260: yyerror("there is no %dth ", n);
261: return(NULL);
262: }
263:
264: struct obj *getblock(p, s) /* find variable s in block p */
265: struct obj *p;
266: char *s;
267: {
268: struct symtab *stp;
269:
270: if (p->o_type != BLOCK) {
271: yyerror(".%s is not in that block", s);
272: return(NULL);
273: }
274: for (stp = (struct symtab *) p->o_val[6]; stp != NULL; stp = stp->s_next)
275: if (strcmp(s, stp->s_name) == 0) {
276: dprintf("getblock found x,y= %d,%d\n",
277: stp->s_val->o_x, stp->s_val->o_y);
278: return((struct obj *)stp->s_val);
279: }
280: yyerror("there is no .%s in that []", s);
281: return(NULL);
282: }
283:
284: struct obj *fixpos(p, x, y)
285: struct obj *p;
286: coord x, y;
287: {
288: dprintf("fixpos returns %d %d\n", p->o_x + x, p->o_y + y);
289: return(makepos(p->o_x + x, p->o_y + y));
290: }
291:
292: struct obj *makenode(type, n)
293: int type, n;
294: {
295: struct obj *p;
296:
297: p = (struct obj *) malloc(sizeof(struct obj) + (n-1)*sizeof(coord));
298: if (p == NULL) {
299: yyerror("out of space in makenode\n");
300: exit(1);
301: }
302: p->o_type = type;
303: p->o_count = n;
304: p->o_nobj = nobj;
305: p->o_mode = hvmode;
306: p->o_x = curx;
307: p->o_y = cury;
308: p->o_nt1 = ntext1;
309: p->o_nt2 = ntext;
310: ntext1 = ntext; /* ready for next caller */
311: p->o_attr = p->o_dotdash = p->o_ddval = 0;
312: if (nobj >= MAXOBJ) {
313: yyerror("objlist overflow\n");
314: exit(1);
315: }
316: objlist[nobj++] = p;
317: return(p);
318: }
319:
320: extreme(x, y) /* record max and min x and y values */
321: {
322: if (x > xmax)
323: xmax = x;
324: if (y > ymax)
325: ymax = y;
326: if (x < xmin)
327: xmin = x;
328: if (y < ymin)
329: ymin = y;
330: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.