1 |
greg |
1.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id$"; |
3 |
|
|
#endif |
4 |
|
|
/* |
5 |
|
|
* Program to output meta-files to X window system. |
6 |
|
|
* |
7 |
|
|
* cc -o Xmeta Xmeta.c Xplot.o plot.o mfio.o syscalls.o misc.o |
8 |
|
|
* |
9 |
|
|
* 2/26/86 |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#include "meta.h" |
14 |
|
|
|
15 |
|
|
#include "plot.h" |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
#define overlap(p,xmn,ymn,xmx,ymx) (ov((p)->xy[XMN],(p)->xy[XMX],xmn,xmx) \ |
19 |
|
|
&&ov((p)->xy[YMN],(p)->xy[YMX],ymn,ymx)) |
20 |
|
|
|
21 |
|
|
#define ov(mn1,mx1,mn2,mx2) ((mn1)<(mx2)&&(mn2)<(mx1)) |
22 |
|
|
|
23 |
|
|
#define XCOM "pexpand +OCIsv -P %s" |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
char *progname; |
27 |
|
|
|
28 |
|
|
static short newpage = TRUE; |
29 |
|
|
|
30 |
|
|
static PLIST recording; |
31 |
|
|
|
32 |
|
|
int maxalloc = 0; /* no limit */ |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
main(argc, argv) |
37 |
|
|
|
38 |
|
|
int argc; |
39 |
|
|
char **argv; |
40 |
|
|
|
41 |
|
|
{ |
42 |
|
|
FILE *fp; |
43 |
|
|
FILE *popen(); |
44 |
|
|
char *geometry = NULL; |
45 |
|
|
short condonly, conditioned; |
46 |
|
|
char comargs[500], command[600]; |
47 |
|
|
|
48 |
|
|
progname = *argv++; |
49 |
|
|
argc--; |
50 |
|
|
|
51 |
|
|
condonly = FALSE; |
52 |
|
|
conditioned = FALSE; |
53 |
|
|
|
54 |
|
|
for ( ; argc; argv++, argc--) |
55 |
|
|
if (!strcmp(*argv, "-c")) |
56 |
|
|
condonly = TRUE; |
57 |
|
|
else if (!strcmp(*argv, "-r")) |
58 |
|
|
conditioned = TRUE; |
59 |
|
|
else if (**argv == '=') |
60 |
|
|
geometry = *argv; |
61 |
|
|
else |
62 |
|
|
break; |
63 |
|
|
|
64 |
|
|
if (conditioned) { |
65 |
|
|
init(progname, geometry); |
66 |
|
|
if (argc) |
67 |
|
|
while (argc) { |
68 |
|
|
fp = efopen(*argv, "r"); |
69 |
|
|
plot(fp); |
70 |
|
|
fclose(fp); |
71 |
|
|
argv++; |
72 |
|
|
argc--; |
73 |
|
|
} |
74 |
|
|
else |
75 |
|
|
plot(stdin); |
76 |
|
|
} else { |
77 |
|
|
comargs[0] = '\0'; |
78 |
|
|
while (argc) { |
79 |
|
|
strcat(comargs, " "); |
80 |
|
|
strcat(comargs, *argv); |
81 |
|
|
argv++; |
82 |
|
|
argc--; |
83 |
|
|
} |
84 |
|
|
sprintf(command, XCOM, comargs); |
85 |
|
|
if (condonly) |
86 |
|
|
return(system(command)); |
87 |
|
|
else { |
88 |
|
|
init(progname, geometry); |
89 |
|
|
if ((fp = popen(command, "r")) == NULL) |
90 |
|
|
error(SYSTEM, "cannot execute input filter"); |
91 |
|
|
plot(fp); |
92 |
|
|
pclose(fp); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
if (!newpage) |
97 |
|
|
endpage(); |
98 |
|
|
|
99 |
|
|
return(0); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
plot(infp) /* plot meta-file */ |
106 |
|
|
|
107 |
|
|
FILE *infp; |
108 |
|
|
|
109 |
|
|
{ |
110 |
|
|
PRIMITIVE nextp; |
111 |
|
|
|
112 |
|
|
set(SALL, NULL); |
113 |
|
|
do { |
114 |
|
|
readp(&nextp, infp); |
115 |
|
|
while (isprim(nextp.com)) { |
116 |
|
|
doprim(&nextp, 1); |
117 |
|
|
readp(&nextp, infp); |
118 |
|
|
} |
119 |
|
|
doglobal(&nextp, 1); |
120 |
|
|
} while (nextp.com != PEOF); |
121 |
|
|
|
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
replay(xmin, ymin, xmax, ymax) /* play back region */ |
127 |
|
|
int xmin, ymin, xmax, ymax; |
128 |
|
|
{ |
129 |
|
|
register PRIMITIVE *p; |
130 |
|
|
|
131 |
|
|
unset(SALL); |
132 |
|
|
set(SALL, NULL); |
133 |
|
|
for (p = recording.ptop; p != NULL; p = p->pnext) |
134 |
|
|
if (isprim(p->com)) { |
135 |
|
|
if (overlap(p, xmin, ymin, xmax, ymax)) |
136 |
|
|
doprim(p, 0); |
137 |
|
|
} else |
138 |
|
|
doglobal(p, 0); |
139 |
|
|
|
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
save(p) /* record primitive */ |
146 |
|
|
PRIMITIVE *p; |
147 |
|
|
{ |
148 |
|
|
register PRIMITIVE *pnew; |
149 |
|
|
|
150 |
|
|
if ((pnew = palloc()) == NULL) |
151 |
|
|
error(SYSTEM, "out of memory in save"); |
152 |
|
|
mcopy(pnew, p, sizeof(PRIMITIVE)); |
153 |
|
|
add(pnew, &recording); |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
doglobal(g, sf) /* execute a global command */ |
160 |
|
|
|
161 |
|
|
register PRIMITIVE *g; |
162 |
|
|
int sf; |
163 |
|
|
|
164 |
|
|
{ |
165 |
|
|
|
166 |
|
|
switch (g->com) { |
167 |
|
|
|
168 |
|
|
case PEOF: |
169 |
|
|
return; |
170 |
|
|
|
171 |
|
|
case PDRAW: |
172 |
|
|
XFlush(); |
173 |
|
|
break; |
174 |
|
|
|
175 |
|
|
case PEOP: |
176 |
|
|
endpage(); |
177 |
|
|
plfree(&recording); |
178 |
|
|
set(SALL, NULL); |
179 |
|
|
newpage = TRUE; |
180 |
|
|
return; |
181 |
|
|
|
182 |
|
|
case PSET: |
183 |
|
|
set(g->arg0, g->args); |
184 |
|
|
break; |
185 |
|
|
|
186 |
|
|
case PUNSET: |
187 |
|
|
unset(g->arg0); |
188 |
|
|
break; |
189 |
|
|
|
190 |
|
|
case PRESET: |
191 |
|
|
reset(g->arg0); |
192 |
|
|
break; |
193 |
|
|
|
194 |
|
|
default: |
195 |
|
|
sprintf(errmsg, "unknown command '%c' in doglobal", g->com); |
196 |
|
|
error(WARNING, errmsg); |
197 |
|
|
return; |
198 |
|
|
} |
199 |
|
|
if (sf) |
200 |
|
|
save(g); |
201 |
|
|
|
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
doprim(p, sf) /* plot primitive */ |
208 |
|
|
|
209 |
|
|
register PRIMITIVE *p; |
210 |
|
|
int sf; |
211 |
|
|
|
212 |
|
|
{ |
213 |
|
|
|
214 |
|
|
switch (p->com) { |
215 |
|
|
|
216 |
|
|
case PMSTR: |
217 |
|
|
printstr(p); |
218 |
|
|
break; |
219 |
|
|
|
220 |
|
|
case PLSEG: |
221 |
|
|
plotlseg(p); |
222 |
|
|
break; |
223 |
|
|
|
224 |
|
|
case PRFILL: |
225 |
|
|
fillrect(p); |
226 |
|
|
break; |
227 |
|
|
|
228 |
|
|
case PTFILL: |
229 |
|
|
filltri(p); |
230 |
|
|
break; |
231 |
|
|
|
232 |
|
|
case PPFILL: |
233 |
|
|
fillpoly(p); |
234 |
|
|
break; |
235 |
|
|
|
236 |
|
|
default: |
237 |
|
|
sprintf(errmsg, "unknown command '%c' in doprim", p->com); |
238 |
|
|
error(WARNING, errmsg); |
239 |
|
|
return; |
240 |
|
|
} |
241 |
|
|
if (sf) { |
242 |
|
|
save(p); |
243 |
|
|
newpage = FALSE; |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
} |