6 |
|
*/ |
7 |
|
|
8 |
|
|
9 |
+ |
#include <stdio.h> |
10 |
+ |
#include <string.h> |
11 |
|
#include <fcntl.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
|
#include "meta.h" |
12 |
– |
|
15 |
|
#include "plot.h" |
14 |
– |
|
16 |
|
#include "span.h" |
17 |
|
|
18 |
|
|
23 |
|
|
24 |
|
static PRIMITIVE nextp; |
25 |
|
|
26 |
+ |
static void initplot(void); |
27 |
+ |
static void plotspan(FILE *infp); |
28 |
+ |
static void doglobal(PRIMITIVE *g); |
29 |
+ |
static void doprim(PRIMITIVE *p); |
30 |
+ |
static void outputspan(void); |
31 |
+ |
static void tfill(PRIMITIVE *p); |
32 |
+ |
static void fill(int attrib, int xmin, int ymin, int xmax, int ymax); |
33 |
+ |
static void paintline(int x, int y, int run, int rise, int hrad, int vrad, |
34 |
+ |
int lpat, long run2, long rise2, int n); |
35 |
+ |
static void nextspan(void); |
36 |
|
|
37 |
|
|
38 |
< |
plot(infp) /* plot meta-file */ |
39 |
< |
|
40 |
< |
FILE *infp; |
41 |
< |
|
38 |
> |
void |
39 |
> |
plot( /* plot meta-file */ |
40 |
> |
FILE *infp |
41 |
> |
) |
42 |
|
{ |
43 |
|
|
44 |
|
do { |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
< |
|
57 |
< |
|
47 |
< |
|
48 |
< |
initplot() /* initialize this plot */ |
49 |
< |
|
56 |
> |
void |
57 |
> |
initplot(void) /* initialize this plot */ |
58 |
|
{ |
51 |
– |
|
59 |
|
thispage(); |
60 |
|
outspan.xleft = 0; |
61 |
< |
outspan.xright = dxsize - 1; |
62 |
< |
outspan.ytop = dysize + linhite - 1; |
63 |
< |
outspan.ybot = dysize; |
61 |
> |
outspan.xright = dxsiz - 1; |
62 |
> |
outspan.ytop = dysiz + linhite - 1; |
63 |
> |
outspan.ybot = dysiz; |
64 |
|
|
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
< |
|
70 |
< |
|
71 |
< |
doglobal(g) /* execute a global command */ |
72 |
< |
|
66 |
< |
PRIMITIVE *g; |
67 |
< |
|
69 |
> |
void |
70 |
> |
doglobal( /* execute a global command */ |
71 |
> |
PRIMITIVE *g |
72 |
> |
) |
73 |
|
{ |
74 |
|
char c; |
75 |
|
int tty; |
92 |
|
error(USER, "illegal continue direction in doglobal"); |
93 |
|
break; |
94 |
|
|
95 |
< |
case PPAUSE: |
95 |
> |
case PPAUS: |
96 |
|
fflush(stdout); |
97 |
|
tty = open(TTY, O_RDWR); |
98 |
|
if (g->args != NULL) { |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
< |
|
133 |
< |
|
134 |
< |
plotspan(infp) /* plot next span */ |
135 |
< |
|
131 |
< |
FILE *infp; |
132 |
< |
|
132 |
> |
void |
133 |
> |
plotspan( /* plot next span */ |
134 |
> |
FILE *infp |
135 |
> |
) |
136 |
|
{ |
137 |
|
PLIST lastinq; |
138 |
|
register PRIMITIVE *p; |
148 |
|
pfree(p); |
149 |
|
} |
150 |
|
/* plot from file */ |
151 |
< |
while (isprim(nextp.com) && CONV(nextp.xy[YMX],dysize) >= outspan.ybot) { |
151 |
> |
while (isprim(nextp.com) && CONV(nextp.xy[YMX],dysiz) >= outspan.ybot) { |
152 |
|
doprim(&nextp); |
153 |
|
fargs(&nextp); |
154 |
|
readp(&nextp, infp); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
< |
|
163 |
< |
|
161 |
< |
|
162 |
< |
nextspan() /* prepare next span */ |
163 |
< |
|
162 |
> |
void |
163 |
> |
nextspan(void) /* prepare next span */ |
164 |
|
{ |
165 |
|
register int i; |
166 |
|
register char *colp, *tcolp; |
167 |
|
|
168 |
|
if (spanmin <= spanmax) { /* clear span */ |
169 |
|
|
170 |
< |
i = nrows*dxsize; |
170 |
> |
i = nrows*dxsiz; |
171 |
|
colp = outspan.cols; |
172 |
|
tcolp = outspan.tcols; |
173 |
|
while (i--) |
176 |
|
|
177 |
|
outspan.ytop -= linhite; /* advance to next */ |
178 |
|
outspan.ybot -= linhite; |
179 |
< |
spanmin = dxsize; |
179 |
> |
spanmin = dxsiz; |
180 |
|
spanmax = 0; |
181 |
|
|
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
< |
|
186 |
< |
outputspan() /* output span to printer */ |
185 |
> |
void |
186 |
> |
outputspan(void) /* output span to printer */ |
187 |
|
{ |
188 |
|
register int i; |
189 |
|
register char *colp, *tcolp; |
190 |
|
|
191 |
|
if (spanmin <= spanmax) { /* overlay spans */ |
192 |
|
|
193 |
< |
i = nrows*dxsize; |
193 |
> |
i = nrows*dxsiz; |
194 |
|
colp = outspan.cols; |
195 |
|
tcolp = outspan.tcols; |
196 |
|
while (i--) |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
|
204 |
< |
doprim(p) /* plot primitive */ |
205 |
< |
|
206 |
< |
register PRIMITIVE *p; |
207 |
< |
|
203 |
> |
void |
204 |
> |
doprim( /* plot primitive */ |
205 |
> |
register PRIMITIVE *p |
206 |
> |
) |
207 |
|
{ |
208 |
|
register PRIMITIVE *newp; |
209 |
|
|
215 |
|
|
216 |
|
case PRFILL: |
217 |
|
fill((p->arg0&0103) | (pati[(p->arg0>>2)&03]<<2), |
218 |
< |
CONV(p->xy[XMN],dxsize),CONV(p->xy[YMN],dysize), |
219 |
< |
CONV(p->xy[XMX],dxsize)+(p->arg0&0100?-1:0), |
220 |
< |
CONV(p->xy[YMX],dysize)+(p->arg0&0100?-1:0)); |
218 |
> |
CONV(p->xy[XMN],dxsiz),CONV(p->xy[YMN],dysiz), |
219 |
> |
CONV(p->xy[XMX],dxsiz)+(p->arg0&0100?-1:0), |
220 |
> |
CONV(p->xy[YMX],dysiz)+(p->arg0&0100?-1:0)); |
221 |
|
break; |
222 |
|
|
223 |
|
case PTFILL: |
234 |
|
return; |
235 |
|
} |
236 |
|
|
237 |
< |
if (CONV(p->xy[YMN],dysize) < outspan.ybot) { /* save for next time */ |
237 |
> |
if (CONV(p->xy[YMN],dysiz) < outspan.ybot) { /* save for next time */ |
238 |
|
if ((newp = palloc()) == NULL) |
239 |
|
error(SYSTEM, "memory limit exceeded in doprim"); |
240 |
|
mcopy((char *)newp, (char *)p, sizeof(PRIMITIVE)); |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
< |
|
250 |
< |
|
251 |
< |
plotlseg(p) /* plot a line segment */ |
252 |
< |
|
254 |
< |
register PRIMITIVE *p; |
255 |
< |
|
249 |
> |
void |
250 |
> |
plotlseg( /* plot a line segment */ |
251 |
> |
register PRIMITIVE *p |
252 |
> |
) |
253 |
|
{ |
254 |
|
register int ti; |
255 |
|
long run2 = 0L, rise2 = 0L; |
263 |
|
|
264 |
|
ti = (p->arg0 >> 2) & 03; /* compute line radius */ |
265 |
|
ti = WIDTH(ti) / 2; |
266 |
< |
hrad = CONV(ti, dxsize); |
267 |
< |
vrad = CONV(ti, dysize); |
266 |
> |
hrad = CONV(ti, dxsiz); |
267 |
> |
vrad = CONV(ti, dysiz); |
268 |
|
if (hrad < minwidth) |
269 |
|
hrad = minwidth; |
270 |
|
if (vrad < minwidth) |
271 |
|
vrad = minwidth; |
272 |
|
|
273 |
< |
x = CONV(p->xy[XMX], dxsize); /* start at top */ |
274 |
< |
y = CONV(p->xy[YMX], dysize); |
275 |
< |
run = CONV(p->xy[XMN], dxsize) - x; |
276 |
< |
rise = CONV(p->xy[YMN], dysize) - y; |
273 |
> |
x = CONV(p->xy[XMX], dxsiz); /* start at top */ |
274 |
> |
y = CONV(p->xy[YMX], dysiz); |
275 |
> |
run = CONV(p->xy[XMN], dxsiz) - x; |
276 |
> |
rise = CONV(p->xy[YMN], dysiz) - y; |
277 |
|
|
278 |
|
if (p->arg0 & 0100) /* slope < 0; reverse x */ |
279 |
|
x -= (run = -run); |
307 |
|
* This routine paints a line with calls to fill(). The line can |
308 |
|
* start and end at arbitrary points on a longer line segment. |
309 |
|
*/ |
310 |
< |
|
311 |
< |
paintline(x, y, run, rise, hrad, vrad, lpat, run2, rise2, n) |
312 |
< |
|
313 |
< |
register int x, y; |
314 |
< |
int run, rise; |
315 |
< |
int hrad, vrad; |
316 |
< |
int lpat; |
317 |
< |
long run2, rise2; |
318 |
< |
int n; |
319 |
< |
|
310 |
> |
void |
311 |
> |
paintline( |
312 |
> |
register int x, |
313 |
> |
register int y, |
314 |
> |
int run, |
315 |
> |
int rise, |
316 |
> |
int hrad, |
317 |
> |
int vrad, |
318 |
> |
int lpat, |
319 |
> |
long run2, |
320 |
> |
long rise2, |
321 |
> |
int n |
322 |
> |
) |
323 |
|
{ |
324 |
|
int xstep, ystep; |
325 |
|
|
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
< |
|
368 |
< |
tfill(p) /* fill a triangle */ |
369 |
< |
register PRIMITIVE *p; |
367 |
> |
void |
368 |
> |
tfill( /* fill a triangle */ |
369 |
> |
register PRIMITIVE *p |
370 |
> |
) |
371 |
|
{ |
372 |
|
register int x, txmin, txmax; |
373 |
|
int xmn, ymn, tpat; |
374 |
|
long xsz, ysz; |
375 |
|
|
376 |
< |
xmn = CONV(p->xy[XMN], dxsize); |
377 |
< |
xsz = CONV(p->xy[XMX], dxsize) - xmn; |
378 |
< |
ymn = CONV(p->xy[YMN], dysize); |
379 |
< |
ysz = CONV(p->xy[YMX], dysize) - ymn; |
376 |
> |
xmn = CONV(p->xy[XMN], dxsiz); |
377 |
> |
xsz = CONV(p->xy[XMX], dxsiz) - xmn; |
378 |
> |
ymn = CONV(p->xy[YMN], dysiz); |
379 |
> |
ysz = CONV(p->xy[YMX], dysiz) - ymn; |
380 |
|
if (xsz <= 0 || ysz <= 0) |
381 |
|
return; |
382 |
|
txmin = (outspan.ybot - ymn)*xsz/ysz; |
411 |
|
|
412 |
|
|
413 |
|
|
414 |
< |
|
415 |
< |
fill(attrib, xmin, ymin, xmax, ymax) /* fill rectangle with attribute */ |
416 |
< |
|
417 |
< |
int attrib; |
418 |
< |
int xmin, ymin, xmax, ymax; |
419 |
< |
|
414 |
> |
void |
415 |
> |
fill( /* fill rectangle with attribute */ |
416 |
> |
int attrib, |
417 |
> |
int xmin, |
418 |
> |
int ymin, |
419 |
> |
int xmax, |
420 |
> |
int ymax |
421 |
> |
) |
422 |
|
{ |
423 |
|
int filpat; |
424 |
|
int rpos; |
449 |
|
[((outspan.ybot>>3)+rpos)%(PATSIZE>>3)]; |
450 |
|
|
451 |
|
if (attrib & 0100) { |
452 |
< |
colp = &outspan.tcols[rpos*dxsize + xmin]; |
452 |
> |
colp = &outspan.tcols[rpos*dxsiz + xmin]; |
453 |
|
for (i = xmin; i <= xmax; i++) |
454 |
|
*colp++ ^= filpat & pattr[i%PATSIZE]; |
455 |
|
} else { |
456 |
< |
colp = &outspan.cols[rpos*dxsize + xmin]; |
456 |
> |
colp = &outspan.cols[rpos*dxsiz + xmin]; |
457 |
|
for (i = xmin; i <= xmax; i++) |
458 |
|
*colp++ |= filpat & pattr[i%PATSIZE]; |
459 |
|
} |