|
|
1.1 root 1: #include <stdio.h>
2: #include "pic.h"
3: #include "y.tab.h"
4:
5: struct obj *linegen(type)
6: {
7: static int prevdx = HT;
8: static int prevdy = 0;
9: static int prevw = HT/10;
10: static int prevh = HT/5;
11: int i, j, some, head, ddtype, ddval, invis;
12: int chop, chop1, chop2, x0, y0, x1, y1;
13: double sin(), cos(), atan2(), theta;
14: int defx, defy;
15: struct obj *p, *ppos;
16: static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */
17: static int ytab[] = { 0, 1, 0, -1 };
18: int ndxy, dx[50], dy[50];
19: coord nx, ny;
20:
21: nx = curx;
22: ny = cury;
23: defx = getvar("linewid");
24: defy = getvar("lineht");
25: prevh = getvar("arrowht");
26: prevw = getvar("arrowwid");
27: dx[0] = dy[0] = ndxy = some = head = invis = 0;
28: chop = chop1 = chop2 = 0;
29: ddtype = ddval = 0;
30: for (i = 0; i < nattr; i++) {
31: switch (attr[i].a_type) {
32: case LJUST: case RJUST: case CENTER: case SPREAD: case FILL: case ABOVE: case BELOW:
33: savetext(attr[i].a_type, attr[i].a_val);
34: break;
35: case HEAD:
36: head += attr[i].a_val;
37: break;
38: case INVIS:
39: invis = INVIS;
40: break;
41: case CHOP:
42: if (chop++ == 0)
43: chop1 = chop2 = attr[i].a_val;
44: else
45: chop2 = attr[i].a_val;
46: break;
47: case DOT:
48: case DASH:
49: ddtype = attr[i].a_type;
50: ddval = attr[i].a_val;
51: if (ddval == 0)
52: ddval = getvar("dashwid");
53: break;
54: case SAME:
55: dx[ndxy] = prevdx;
56: dy[ndxy] = prevdy;
57: some++;
58: break;
59: case LEFT:
60: dx[ndxy] -= (attr[i].a_val==0) ? defx : attr[i].a_val;
61: some++;
62: hvmode = L_DIR;
63: break;
64: case RIGHT:
65: dx[ndxy] += (attr[i].a_val==0) ? defx : attr[i].a_val;
66: some++;
67: hvmode = R_DIR;
68: break;
69: case UP:
70: dy[ndxy] += (attr[i].a_val==0) ? defy : attr[i].a_val;
71: some++;
72: hvmode = U_DIR;
73: break;
74: case DOWN:
75: dy[ndxy] -= (attr[i].a_val==0) ? defy : attr[i].a_val;
76: some++;
77: hvmode = D_DIR;
78: break;
79: case HEIGHT: /* length of arrowhead */
80: prevh = attr[i].a_val;
81: break;
82: case WIDTH: /* width of arrowhead */
83: prevw = attr[i].a_val;
84: break;
85: case TO:
86: if (some) {
87: nx += dx[ndxy];
88: ny += dy[ndxy];
89: ndxy++;
90: dx[ndxy] = dy[ndxy] = some = 0;
91: }
92: ppos = (struct obj *) attr[i].a_val;
93: dx[ndxy] = ppos->o_x - nx;
94: dy[ndxy] = ppos->o_y - ny;
95: some++;
96: break;
97: case BY:
98: ppos = (struct obj *) attr[i].a_val;
99: dx[ndxy] = ppos->o_x;
100: dy[ndxy] = ppos->o_y;
101: some++;
102: break;
103: case THEN: /* turn off any previous accumulation */
104: if (some) {
105: nx += dx[ndxy];
106: ny += dy[ndxy];
107: ndxy++;
108: dx[ndxy] = dy[ndxy] = some = 0;
109: }
110: break;
111: case FROM:
112: case AT:
113: ppos = (struct obj *) attr[i].a_val;
114: nx = curx = ppos->o_x;
115: ny = cury = ppos->o_y;
116: break;
117: }
118: }
119: if (some) {
120: nx += dx[ndxy];
121: ny += dy[ndxy];
122: ndxy++;
123: defx = dx[ndxy-1];
124: defy = dy[ndxy-1];
125: } else {
126: defx *= xtab[hvmode];
127: defy *= ytab[hvmode];
128: dx[ndxy] = defx;
129: dy[ndxy] = defy;
130: ndxy++;
131: nx += defx;
132: ny += defy;
133: }
134: prevdx = defx;
135: prevdy = defy;
136: if (chop) {
137: if (chop == 1 && chop1 == 0) /* just said "chop", so use default */
138: chop1 = chop2 = getvar("circlerad");
139: theta = atan2((float) defy, (float) defx);
140: x0 = chop1 * cos(theta);
141: y0 = chop1 * sin(theta);
142: curx += x0;
143: cury += y0;
144: x1 = chop2 * cos(theta);
145: y1 = chop2 * sin(theta);
146: nx -= x1;
147: ny -= y1;
148: dx[0] -= x0;
149: dy[0] -= y0;
150: dx[ndxy-1] -= x1;
151: dy[ndxy-1] -= y1;
152: if(dbg)printf("chopping %d %d %d %d; cur=%d,%d end=%d,%d\n",
153: x0, y0, x1, y1, curx, cury, nx, ny);
154: }
155: p = makenode(type, 5 + 2 * ndxy);
156: curx = p->o_val[0] = nx;
157: cury = p->o_val[1] = ny;
158: if (head || type == ARROW) {
159: p->o_val[2] = prevw;
160: p->o_val[3] = prevh;
161: if (head == 0)
162: head = HEAD2; /* default arrow head */
163: }
164: p->o_attr = head | invis;
165: p->o_val[4] = ndxy;
166: nx = p->o_x;
167: ny = p->o_y;
168: for (i = 0, j = 5; i < ndxy; i++, j += 2) {
169: p->o_val[j] = dx[i];
170: p->o_val[j+1] = dy[i];
171: extreme(nx += dx[i], ny += dy[i]);
172: }
173: p->o_dotdash = ddtype;
174: p->o_ddval = ddval;
175: if (dbg) {
176: printf("S or L from %d %d to %d %d with %d elements:\n", p->o_x, p->o_y, curx, cury, ndxy);
177: for (i = 0, j = 5; i < ndxy; i++, j += 2)
178: printf("%d %d\n", p->o_val[j], p->o_val[j+1]);
179: }
180: extreme(p->o_x, p->o_y);
181: extreme(curx, cury);
182: return(p);
183: }
184:
185: struct obj *splinegen(type)
186: {
187: linegen(type);
188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.