initial port of plan9 troff to linux
[troff.git] / pic / movegen.c
blob5ff44d46b01dcca94e57d5a0f90faa83b78b043d
1 #include <stdio.h>
2 #include "pic.h"
3 #include "y.tab.h"
5 obj *movegen(void)
7 static double prevdx, prevdy;
8 int i, some;
9 double defx, defy, dx, dy;
10 obj *p;
11 obj *ppos;
12 static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */
13 static int ytab[] = { 0, 1, 0, -1 };
14 Attr *ap;
16 defx = getfval("movewid");
17 defy = getfval("moveht");
18 dx = dy = some = 0;
19 for (i = 0; i < nattr; i++) {
20 ap = &attr[i];
21 switch (ap->a_type) {
22 case TEXTATTR:
23 savetext(ap->a_sub, ap->a_val.p);
24 break;
25 case SAME:
26 dx = prevdx;
27 dy = prevdy;
28 some++;
29 break;
30 case LEFT:
31 dx -= (ap->a_sub==DEFAULT) ? defx : ap->a_val.f;
32 some++;
33 hvmode = L_DIR;
34 break;
35 case RIGHT:
36 dx += (ap->a_sub==DEFAULT) ? defx : ap->a_val.f;
37 some++;
38 hvmode = R_DIR;
39 break;
40 case UP:
41 dy += (ap->a_sub==DEFAULT) ? defy : ap->a_val.f;
42 some++;
43 hvmode = U_DIR;
44 break;
45 case DOWN:
46 dy -= (ap->a_sub==DEFAULT) ? defy : ap->a_val.f;
47 some++;
48 hvmode = D_DIR;
49 break;
50 case TO:
51 ppos = ap->a_val.o;
52 dx = ppos->o_x - curx;
53 dy = ppos->o_y - cury;
54 some++;
55 break;
56 case BY:
57 ppos = ap->a_val.o;
58 dx = ppos->o_x;
59 dy = ppos->o_y;
60 some++;
61 break;
62 case FROM:
63 case AT:
64 ppos = ap->a_val.o;
65 curx = ppos->o_x;
66 cury = ppos->o_y;
67 break;
70 if (some) {
71 defx = dx;
72 defy = dy;
73 } else {
74 defx *= xtab[hvmode];
75 defy *= ytab[hvmode];
77 prevdx = defx;
78 prevdy = defy;
79 extreme(curx, cury);
80 curx += defx;
81 cury += defy;
82 extreme(curx, cury);
83 p = makenode(MOVE, 0);
84 dprintf("M %g %g\n", curx, cury);
85 return(p);