1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: plotout.c,v 1.3 2003/10/27 10:28:59 schorsch Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* Program to send meta-files to plot(3X) drivers |
6 |
* |
7 |
* cc -o plotout plotout.c mfio.o syscalls.o misc.o -lplot |
8 |
* |
9 |
* Plot drivers |
10 |
*/ |
11 |
|
12 |
|
13 |
#ifdef FORTEK |
14 |
#define XCOM "pexpand +vOCIsm -rtpSUR %s" |
15 |
#else |
16 |
#define XCOM "pexpand +vOCIs -rtpSUR %s" |
17 |
#endif |
18 |
|
19 |
|
20 |
#include <fcntl.h> |
21 |
|
22 |
#include "rtprocess.h" |
23 |
#include "meta.h" |
24 |
#include "plot.h" |
25 |
#include "lib4014/lib4014.h" |
26 |
|
27 |
|
28 |
char *progname; |
29 |
|
30 |
static short newpage = TRUE; |
31 |
|
32 |
static int curx = -1, /* current position */ |
33 |
cury = -1; |
34 |
|
35 |
static short curmod = -1; /* current line drawing mode */ |
36 |
|
37 |
static char lmode[4][16] = {"solid", "shortdashed", |
38 |
"dotted", "dotdashed"}; |
39 |
|
40 |
static PRIMITIVE nextp; |
41 |
|
42 |
static void doglobal(PRIMITIVE *g); |
43 |
static void doprim(register PRIMITIVE *p); |
44 |
|
45 |
|
46 |
int |
47 |
main( |
48 |
int argc, |
49 |
char **argv |
50 |
) |
51 |
{ |
52 |
FILE *fp; |
53 |
char comargs[200], command[300]; |
54 |
short condonly = FALSE, conditioned = FALSE; |
55 |
|
56 |
progname = *argv++; |
57 |
argc--; |
58 |
|
59 |
while (argc && **argv == '-') { |
60 |
switch (*(*argv+1)) { |
61 |
case 'c': |
62 |
condonly = TRUE; |
63 |
break; |
64 |
case 'r': |
65 |
conditioned = TRUE; |
66 |
break; |
67 |
default: |
68 |
error(WARNING, "unknown option"); |
69 |
break; |
70 |
} |
71 |
argv++; |
72 |
argc--; |
73 |
} |
74 |
|
75 |
if (conditioned) |
76 |
if (argc) |
77 |
while (argc) { |
78 |
fp = efopen(*argv, "r"); |
79 |
plot(fp); |
80 |
fclose(fp); |
81 |
argv++; |
82 |
argc--; |
83 |
} |
84 |
else |
85 |
plot(stdin); |
86 |
else { |
87 |
comargs[0] = '\0'; |
88 |
while (argc) { |
89 |
strcat(comargs, " "); |
90 |
strcat(comargs, *argv); |
91 |
argv++; |
92 |
argc--; |
93 |
} |
94 |
sprintf(command, XCOM, comargs); |
95 |
if (condonly) |
96 |
return(system(command)); |
97 |
else { |
98 |
if ((fp = popen(command, "r")) == NULL) |
99 |
error(SYSTEM, "cannot execute input filter"); |
100 |
plot(fp); |
101 |
pclose(fp); |
102 |
} |
103 |
} |
104 |
|
105 |
return(0); |
106 |
} |
107 |
|
108 |
|
109 |
|
110 |
void |
111 |
plot( /* plot meta-file */ |
112 |
FILE *infp |
113 |
) |
114 |
{ |
115 |
|
116 |
openpl(); |
117 |
space(0, 0, XYSIZE, XYSIZE); |
118 |
|
119 |
do { |
120 |
readp(&nextp, infp); |
121 |
while (isprim(nextp.com)) { |
122 |
doprim(&nextp); |
123 |
fargs(&nextp); |
124 |
readp(&nextp, infp); |
125 |
} |
126 |
doglobal(&nextp); |
127 |
fargs(&nextp); |
128 |
} while (nextp.com != PEOF); |
129 |
|
130 |
closepl(); |
131 |
|
132 |
} |
133 |
|
134 |
|
135 |
|
136 |
void |
137 |
doglobal( /* execute a global command */ |
138 |
PRIMITIVE *g |
139 |
) |
140 |
{ |
141 |
int tty; |
142 |
char c; |
143 |
|
144 |
switch (g->com) { |
145 |
|
146 |
case PEOF: |
147 |
break; |
148 |
|
149 |
case PDRAW: |
150 |
fflush(stdout); |
151 |
break; |
152 |
|
153 |
case PEOP: |
154 |
newpage = TRUE; |
155 |
if (!isatty(fileno(stdout))) |
156 |
break; |
157 |
/* fall through */ |
158 |
|
159 |
case PPAUS: |
160 |
fflush(stdout); |
161 |
tty = open(TTY, O_RDWR); |
162 |
if (g->args != NULL) { |
163 |
write(tty, g->args, strlen(g->args)); |
164 |
write(tty, " - (hit return to continue)", 27); |
165 |
} else |
166 |
write(tty, "\007", 1); |
167 |
do { |
168 |
c = '\n'; |
169 |
read(tty, &c, 1); |
170 |
} while (c != '\n' && c != '\r'); |
171 |
close(tty); |
172 |
break; |
173 |
|
174 |
default: |
175 |
sprintf(errmsg, "unknown command '%c' in doglobal", g->com); |
176 |
error(WARNING, errmsg); |
177 |
break; |
178 |
} |
179 |
|
180 |
} |
181 |
|
182 |
|
183 |
|
184 |
void |
185 |
doprim( /* plot primitive */ |
186 |
register PRIMITIVE *p |
187 |
) |
188 |
{ |
189 |
|
190 |
if (newpage) { |
191 |
erase(); |
192 |
newpage = FALSE; |
193 |
} |
194 |
|
195 |
switch (p->com) { |
196 |
|
197 |
case PLSEG: |
198 |
plotlseg(p); |
199 |
break; |
200 |
|
201 |
case PMSTR: |
202 |
printstr(p); |
203 |
break; |
204 |
|
205 |
default: |
206 |
sprintf(errmsg, "unknown command '%c' in doprim", p->com); |
207 |
error(WARNING, errmsg); |
208 |
return; |
209 |
} |
210 |
|
211 |
} |
212 |
|
213 |
|
214 |
|
215 |
void |
216 |
printstr( /* output a string */ |
217 |
register PRIMITIVE *p |
218 |
) |
219 |
{ |
220 |
|
221 |
move(p->xy[XMN], p->xy[YMX]); |
222 |
label(p->args); |
223 |
curx = -1; |
224 |
cury = -1; |
225 |
|
226 |
} |
227 |
|
228 |
|
229 |
void |
230 |
plotlseg( /* plot a line segment */ |
231 |
register PRIMITIVE *p |
232 |
) |
233 |
{ |
234 |
static short right = FALSE; |
235 |
int y1, y2; |
236 |
short lm = (p->arg0 >> 4) & 03; |
237 |
|
238 |
if (p->arg0 & 0100) { |
239 |
y1 = p->xy[YMX]; |
240 |
y2 = p->xy[YMN]; |
241 |
} else { |
242 |
y1 = p->xy[YMN]; |
243 |
y2 = p->xy[YMX]; |
244 |
} |
245 |
|
246 |
if (lm != curmod) { |
247 |
linemod(lmode[lm]); |
248 |
curmod = lm; |
249 |
} |
250 |
|
251 |
if (p->xy[XMN] == curx && y1 == cury) { |
252 |
cont(p->xy[XMX], y2); |
253 |
curx = p->xy[XMX]; |
254 |
cury = y2; |
255 |
} else if (p->xy[XMX] == curx && y2 == cury) { |
256 |
cont(p->xy[XMN], y1); |
257 |
curx = p->xy[XMN]; |
258 |
cury = y1; |
259 |
} else if ((right = !right)) { |
260 |
line(p->xy[XMN], y1, p->xy[XMX], y2); |
261 |
curx = p->xy[XMX]; |
262 |
cury = y2; |
263 |
} else { |
264 |
line(p->xy[XMX], y2, p->xy[XMN], y1); |
265 |
curx = p->xy[XMN]; |
266 |
cury = y1; |
267 |
} |
268 |
} |