8 setdir(int n) /* set direction (hvmode) from LEFT, RIGHT, etc. */
11 case UP: hvmode = U_DIR; break;
12 case DOWN: hvmode = D_DIR; break;
13 case LEFT: hvmode = L_DIR; break;
14 case RIGHT: hvmode = R_DIR; break;
20 curdir(void) /* convert current dir (hvmode) to RIGHT, LEFT, etc. */
23 case R_DIR: return RIGHT;
24 case L_DIR: return LEFT;
25 case U_DIR: return UP;
26 case D_DIR: return DOWN;
28 ERROR "can't happen curdir" FATAL;
33 getcomp(obj *p, int t) /* return component of a position */
48 return 2 * p->o_val[0];
51 return p->o_val[0] - p->o_x;
63 return 2 * p->o_val[1];
66 return p->o_val[1] - p->o_y;
77 ERROR "you asked for a weird dimension or position" WARNING;
87 exprlist[nexpr++] = f;
95 sprintf(buf, fmt, exprlist[0], exprlist[1], exprlist[2], exprlist[3], exprlist[4]);
102 makefattr(int type, int sub, double f) /* double attr */
106 makeattr(type, sub, val);
110 makeoattr(int type, obj *o) /* obj* attr */
114 makeattr(type, 0, val);
118 makeiattr(int type, int i) /* int attr */
122 makeattr(type, 0, val);
126 maketattr(int sub, char *p) /* text attribute: takes two */
130 makeattr(TEXTATTR, sub, val);
134 addtattr(int sub) /* add text attrib to existing item */
136 attr[nattr-1].a_sub |= sub;
140 makevattr(char *p) /* varname attribute */
144 makeattr(VARNAME, 0, val);
148 makeattr(int type, int sub, YYSTYPE val) /* add attribute type and val */
150 if (type == 0 && val.i == 0) { /* clear table for next stat */
154 if (nattr >= nattrlist)
155 attr = (Attr *) grow((char *)attr, "attr", nattrlist += 100, sizeof(Attr));
156 dprintf("attr %d: %d %d %d\n", nattr, type, sub, val.i);
157 attr[nattr].a_type = type;
158 attr[nattr].a_sub = sub;
159 attr[nattr].a_val = val;
164 printexpr(double f) /* print expression for debugging */
170 printpos(obj *p) /* print position for debugging */
172 printf("%g, %g\n", p->o_x, p->o_y);
180 p = malloc(strlen(s)+1);
182 ERROR "out of space in tostring on %s", s FATAL;
188 makepos(double x, double y) /* make a position cell */
192 p = makenode(PLACE, 0);
199 makebetween(double f, obj *p1, obj* p2) /* make position between p1 and p2 */
203 dprintf("fraction = %.2f\n", f);
204 p = makenode(PLACE, 0);
205 p->o_x = p1->o_x + f * (p2->o_x - p1->o_x);
206 p->o_y = p1->o_y + f * (p2->o_y - p1->o_y);
211 getpos(obj *p, int corner) /* find position of point */
215 whatpos(p, corner, &x, &y);
216 return makepos(x, y);
220 whatpos(obj *p, int corner, double *px, double *py) /* what is the position (no side effect) */
224 dprintf("whatpos %p %d %d\n", p, p->o_type, corner);
229 if (p->o_type != PLACE) {
240 case NORTH: y += y1 / 2; break;
241 case SOUTH: y -= y1 / 2; break;
242 case EAST: x += x1 / 2; break;
243 case WEST: x -= x1 / 2; break;
244 case NE: x += x1 / 2; y += y1 / 2; break;
245 case SW: x -= x1 / 2; y -= y1 / 2; break;
246 case SE: x += x1 / 2; y -= y1 / 2; break;
247 case NW: x -= x1 / 2; y += y1 / 2; break;
249 if (p->o_type == BLOCK)
250 return whatpos(objlist[(int)p->o_val[2]], START, px, py);
252 if (p->o_type == BLOCK)
253 return whatpos(objlist[(int)p->o_val[3]], END, px, py);
259 if (p->o_attr & CW_ARC) {
260 x = p->o_val[2]; y = p->o_val[3];
266 if (p->o_attr & CW_ARC) {
269 x = p->o_val[2]; y = p->o_val[3];
273 if (corner == START || corner == END)
275 x1 = y1 = sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y));
280 case NORTH: y += y1; break;
281 case SOUTH: y -= y1; break;
282 case EAST: x += x1; break;
283 case WEST: x -= x1; break;
284 case NE: x += 0.707 * x1; y += 0.707 * y1; break;
285 case SE: x += 0.707 * x1; y -= 0.707 * y1; break;
286 case NW: x -= 0.707 * x1; y += 0.707 * y1; break;
287 case SW: x -= 0.707 * x1; y -= 0.707 * y1; break;
294 case START: break; /* already in place */
295 case END: x = x1; y = y1; break;
296 default: /* change! */
297 case CENTER: x = (x+x1)/2; y = (y+y1)/2; break;
298 case NORTH: if (y1 > y) { x = x1; y = y1; } break;
299 case SOUTH: if (y1 < y) { x = x1; y = y1; } break;
300 case EAST: if (x1 > x) { x = x1; y = y1; } break;
301 case WEST: if (x1 < x) { x = x1; y = y1; } break;
305 /* really ought to be same as line... */
308 dprintf("whatpos returns %g %g\n", x, y);
315 gethere(void) /* make a place for curx,cury */
317 dprintf("gethere %g %g\n", curx, cury);
318 return(makepos(curx, cury));
322 getlast(int n, int t) /* find n-th previous occurrence of type t */
328 for (i = nobj-1; i >= 0; i--) {
330 if (p->o_type == BLOCKEND) {
337 continue; /* not there yet */
338 dprintf("got a last of x,y= %g,%g\n", p->o_x, p->o_y);
341 ERROR "there is no %dth last", n WARNING;
346 getfirst(int n, int t) /* find n-th occurrence of type t */
352 for (i = 0; i < nobj; i++) {
354 if (p->o_type == BLOCK && t != BLOCK) { /* skip whole block */
361 continue; /* not there yet */
362 dprintf("got a first of x,y= %g,%g\n", p->o_x, p->o_y);
365 ERROR "there is no %dth ", n WARNING;
370 getblkvar(obj *p, char *s) /* find variable s2 in block p */
379 getblock(obj *p, char *s) /* find variable s in block p */
388 getblk(obj *p, char *s) /* find union type for s in p */
393 if (p->o_type != BLOCK) {
394 ERROR ".%s is not in that block", s WARNING;
397 for (stp = p->o_symtab; stp != NULL; stp = stp->s_next)
398 if (strcmp(s, stp->s_name) == 0) {
399 dprintf("getblk %s found x,y= %g,%g\n",
400 s, (stp->s_val.o)->o_x, (stp->s_val.o)->o_y);
403 ERROR "there is no .%s in that []", s WARNING;
408 fixpos(obj *p, double x, double y)
410 dprintf("fixpos returns %g %g\n", p->o_x + x, p->o_y + y);
411 return makepos(p->o_x + x, p->o_y + y);
415 addpos(obj *p, obj *q)
417 dprintf("addpos returns %g %g\n", p->o_x+q->o_x, p->o_y+q->o_y);
418 return makepos(p->o_x+q->o_x, p->o_y+q->o_y);
422 subpos(obj *p, obj *q)
424 dprintf("subpos returns %g %g\n", p->o_x-q->o_x, p->o_y-q->o_y);
425 return makepos(p->o_x-q->o_x, p->o_y-q->o_y);
429 makenode(int type, int n)
433 p = (obj *) calloc(1, sizeof(obj) + (n-1)*sizeof(ofloat));
435 ERROR "out of space in makenode" FATAL;
444 ntext1 = ntext; /* ready for next caller */
445 if (nobj >= nobjlist)
446 objlist = (obj **) grow((char *) objlist, "objlist",
447 nobjlist *= 2, sizeof(obj *));
453 extreme(double x, double y) /* record max and min x and y values */