10 |
|
*/ |
11 |
|
|
12 |
|
#include "rtprocess.h" |
13 |
+ |
#include "string.h" |
14 |
|
#include "meta.h" |
15 |
|
#include "plot.h" |
16 |
|
|
31 |
|
|
32 |
|
int maxalloc = 0; /* no limit */ |
33 |
|
|
34 |
+ |
extern void pXFlush(void); |
35 |
|
|
36 |
|
|
35 |
– |
main(argc, argv) |
36 |
– |
|
37 |
– |
int argc; |
38 |
– |
char **argv; |
39 |
– |
|
40 |
– |
{ |
41 |
– |
FILE *fp; |
42 |
– |
char *geometry = NULL; |
43 |
– |
short condonly, conditioned; |
44 |
– |
char comargs[500], command[600]; |
45 |
– |
|
46 |
– |
progname = *argv++; |
47 |
– |
argc--; |
48 |
– |
|
49 |
– |
condonly = FALSE; |
50 |
– |
conditioned = FALSE; |
51 |
– |
|
52 |
– |
for ( ; argc; argv++, argc--) |
53 |
– |
if (!strcmp(*argv, "-c")) |
54 |
– |
condonly = TRUE; |
55 |
– |
else if (!strcmp(*argv, "-r")) |
56 |
– |
conditioned = TRUE; |
57 |
– |
else if (**argv == '=') |
58 |
– |
geometry = *argv; |
59 |
– |
else |
60 |
– |
break; |
61 |
– |
|
62 |
– |
if (conditioned) { |
63 |
– |
init(progname, geometry); |
64 |
– |
if (argc) |
65 |
– |
while (argc) { |
66 |
– |
fp = efopen(*argv, "r"); |
67 |
– |
plot(fp); |
68 |
– |
fclose(fp); |
69 |
– |
argv++; |
70 |
– |
argc--; |
71 |
– |
} |
72 |
– |
else |
73 |
– |
plot(stdin); |
74 |
– |
} else { |
75 |
– |
comargs[0] = '\0'; |
76 |
– |
while (argc) { |
77 |
– |
strcat(comargs, " "); |
78 |
– |
strcat(comargs, *argv); |
79 |
– |
argv++; |
80 |
– |
argc--; |
81 |
– |
} |
82 |
– |
sprintf(command, XCOM, comargs); |
83 |
– |
if (condonly) |
84 |
– |
return(system(command)); |
85 |
– |
else { |
86 |
– |
init(progname, geometry); |
87 |
– |
if ((fp = popen(command, "r")) == NULL) |
88 |
– |
error(SYSTEM, "cannot execute input filter"); |
89 |
– |
plot(fp); |
90 |
– |
pclose(fp); |
91 |
– |
} |
92 |
– |
} |
93 |
– |
|
94 |
– |
if (!newpage) |
95 |
– |
endpage(); |
96 |
– |
|
97 |
– |
return(0); |
98 |
– |
} |
99 |
– |
|
100 |
– |
|
101 |
– |
|
102 |
– |
|
37 |
|
void |
104 |
– |
plot(infp) /* plot meta-file */ |
105 |
– |
|
106 |
– |
FILE *infp; |
107 |
– |
|
108 |
– |
{ |
109 |
– |
PRIMITIVE nextp; |
110 |
– |
|
111 |
– |
set(SALL, NULL); |
112 |
– |
do { |
113 |
– |
readp(&nextp, infp); |
114 |
– |
while (isprim(nextp.com)) { |
115 |
– |
doprim(&nextp, 1); |
116 |
– |
readp(&nextp, infp); |
117 |
– |
} |
118 |
– |
doglobal(&nextp, 1); |
119 |
– |
} while (nextp.com != PEOF); |
120 |
– |
|
121 |
– |
} |
122 |
– |
|
123 |
– |
|
124 |
– |
|
125 |
– |
replay(xmin, ymin, xmax, ymax) /* play back region */ |
126 |
– |
int xmin, ymin, xmax, ymax; |
127 |
– |
{ |
128 |
– |
register PRIMITIVE *p; |
129 |
– |
|
130 |
– |
unset(SALL); |
131 |
– |
set(SALL, NULL); |
132 |
– |
for (p = recording.ptop; p != NULL; p = p->pnext) |
133 |
– |
if (isprim(p->com)) { |
134 |
– |
if (overlap(p, xmin, ymin, xmax, ymax)) |
135 |
– |
doprim(p, 0); |
136 |
– |
} else |
137 |
– |
doglobal(p, 0); |
138 |
– |
|
139 |
– |
} |
140 |
– |
|
141 |
– |
|
142 |
– |
|
143 |
– |
|
38 |
|
save(p) /* record primitive */ |
39 |
|
PRIMITIVE *p; |
40 |
|
{ |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
< |
|
157 |
< |
|
50 |
> |
void |
51 |
|
doglobal(g, sf) /* execute a global command */ |
159 |
– |
|
52 |
|
register PRIMITIVE *g; |
53 |
|
int sf; |
162 |
– |
|
54 |
|
{ |
55 |
|
|
56 |
|
switch (g->com) { |
59 |
|
return; |
60 |
|
|
61 |
|
case PDRAW: |
62 |
< |
XFlush(); |
62 |
> |
pXFlush(); |
63 |
|
break; |
64 |
|
|
65 |
|
case PEOP: |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
< |
|
205 |
< |
|
95 |
> |
void |
96 |
|
doprim(p, sf) /* plot primitive */ |
207 |
– |
|
97 |
|
register PRIMITIVE *p; |
98 |
|
int sf; |
210 |
– |
|
99 |
|
{ |
100 |
|
|
101 |
|
switch (p->com) { |
131 |
|
} |
132 |
|
|
133 |
|
} |
134 |
+ |
|
135 |
+ |
|
136 |
+ |
void |
137 |
+ |
plot(infp) /* plot meta-file */ |
138 |
+ |
FILE *infp; |
139 |
+ |
{ |
140 |
+ |
PRIMITIVE nextp; |
141 |
+ |
|
142 |
+ |
set(SALL, NULL); |
143 |
+ |
do { |
144 |
+ |
readp(&nextp, infp); |
145 |
+ |
while (isprim(nextp.com)) { |
146 |
+ |
doprim(&nextp, 1); |
147 |
+ |
readp(&nextp, infp); |
148 |
+ |
} |
149 |
+ |
doglobal(&nextp, 1); |
150 |
+ |
} while (nextp.com != PEOF); |
151 |
+ |
|
152 |
+ |
} |
153 |
+ |
|
154 |
+ |
|
155 |
+ |
void |
156 |
+ |
replay(xmin, ymin, xmax, ymax) /* play back region */ |
157 |
+ |
int xmin, ymin, xmax, ymax; |
158 |
+ |
{ |
159 |
+ |
register PRIMITIVE *p; |
160 |
+ |
|
161 |
+ |
unset(SALL); |
162 |
+ |
set(SALL, NULL); |
163 |
+ |
for (p = recording.ptop; p != NULL; p = p->pnext) |
164 |
+ |
if (isprim(p->com)) { |
165 |
+ |
if (overlap(p, xmin, ymin, xmax, ymax)) |
166 |
+ |
doprim(p, 0); |
167 |
+ |
} else |
168 |
+ |
doglobal(p, 0); |
169 |
+ |
|
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
|
173 |
+ |
int |
174 |
+ |
main(argc, argv) |
175 |
+ |
int argc; |
176 |
+ |
char **argv; |
177 |
+ |
{ |
178 |
+ |
FILE *fp; |
179 |
+ |
char *geometry = NULL; |
180 |
+ |
short condonly, conditioned; |
181 |
+ |
char comargs[500], command[600]; |
182 |
+ |
|
183 |
+ |
progname = *argv++; |
184 |
+ |
argc--; |
185 |
+ |
|
186 |
+ |
condonly = FALSE; |
187 |
+ |
conditioned = FALSE; |
188 |
+ |
|
189 |
+ |
for ( ; argc; argv++, argc--) |
190 |
+ |
if (!strcmp(*argv, "-c")) |
191 |
+ |
condonly = TRUE; |
192 |
+ |
else if (!strcmp(*argv, "-r")) |
193 |
+ |
conditioned = TRUE; |
194 |
+ |
else if (**argv == '=') |
195 |
+ |
geometry = *argv; |
196 |
+ |
else |
197 |
+ |
break; |
198 |
+ |
|
199 |
+ |
if (conditioned) { |
200 |
+ |
init(progname, geometry); |
201 |
+ |
if (argc) |
202 |
+ |
while (argc) { |
203 |
+ |
fp = efopen(*argv, "r"); |
204 |
+ |
plot(fp); |
205 |
+ |
fclose(fp); |
206 |
+ |
argv++; |
207 |
+ |
argc--; |
208 |
+ |
} |
209 |
+ |
else |
210 |
+ |
plot(stdin); |
211 |
+ |
} else { |
212 |
+ |
comargs[0] = '\0'; |
213 |
+ |
while (argc) { |
214 |
+ |
strcat(comargs, " "); |
215 |
+ |
strcat(comargs, *argv); |
216 |
+ |
argv++; |
217 |
+ |
argc--; |
218 |
+ |
} |
219 |
+ |
sprintf(command, XCOM, comargs); |
220 |
+ |
if (condonly) |
221 |
+ |
return(system(command)); |
222 |
+ |
else { |
223 |
+ |
init(progname, geometry); |
224 |
+ |
if ((fp = popen(command, "r")) == NULL) |
225 |
+ |
error(SYSTEM, "cannot execute input filter"); |
226 |
+ |
plot(fp); |
227 |
+ |
pclose(fp); |
228 |
+ |
} |
229 |
+ |
} |
230 |
+ |
|
231 |
+ |
if (!newpage) |
232 |
+ |
endpage(); |
233 |
+ |
|
234 |
+ |
return(0); |
235 |
+ |
} |