1 |
greg |
1.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id$"; |
3 |
|
|
#endif |
4 |
|
|
/* |
5 |
|
|
* Program to print meta-files on a dot-matrix printer |
6 |
|
|
* |
7 |
|
|
* cc -o image image.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o |
8 |
|
|
* |
9 |
|
|
* Apple Imagewriter |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#define MAXALLOC 5000 |
14 |
|
|
|
15 |
|
|
#define DXSIZE 576 /* x resolution */ |
16 |
|
|
|
17 |
|
|
#define DYSIZE 576 /* y resolution */ |
18 |
|
|
|
19 |
|
|
#define LINWIDT DXSIZE /* line width */ |
20 |
|
|
|
21 |
|
|
#define LINHITE 8 /* line height */ |
22 |
|
|
|
23 |
|
|
#define NLINES (DYSIZE/LINHITE) |
24 |
|
|
|
25 |
|
|
#define CHARWIDTH 8 |
26 |
|
|
|
27 |
|
|
#define PNORM "\033n\017\033\"" |
28 |
|
|
|
29 |
|
|
#define PCLEAR "\033c" |
30 |
|
|
|
31 |
|
|
#define PINIT "\033>\033n\033T16" |
32 |
|
|
|
33 |
|
|
#define LFNORM "\033f" |
34 |
|
|
|
35 |
|
|
#define LFREV "\033r" |
36 |
|
|
|
37 |
|
|
#define DBLON "\033!" |
38 |
|
|
|
39 |
|
|
#define DBLOFF "" |
40 |
|
|
|
41 |
|
|
#define PTAB "\033F" |
42 |
|
|
|
43 |
|
|
#define OUTPUT "\033g" |
44 |
|
|
|
45 |
|
|
#define XCOM "pexpand +vtOCIps %s | psort -Y +x" |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
#include "meta.h" |
51 |
|
|
|
52 |
|
|
#include "plot.h" |
53 |
|
|
|
54 |
|
|
#include "span.h" |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
char *progname; |
60 |
|
|
|
61 |
|
|
struct span outspan; |
62 |
|
|
|
63 |
|
|
int dxsize = DXSIZE, dysize = DYSIZE, |
64 |
|
|
linwidt = LINWIDT, linhite = LINHITE, |
65 |
|
|
nrows = (LINHITE-1)/8+1; |
66 |
|
|
|
67 |
|
|
int maxalloc = MAXALLOC; |
68 |
|
|
|
69 |
|
|
int spanmin = 0, spanmax = LINWIDT-1; |
70 |
|
|
|
71 |
|
|
int charwidth = CHARWIDTH; |
72 |
|
|
|
73 |
|
|
static char chrtype[16][5] = { |
74 |
|
|
"\033N", |
75 |
|
|
"\033N\016", |
76 |
|
|
"\033N", |
77 |
|
|
"\033N\016", |
78 |
|
|
"\033E", |
79 |
|
|
"\033E\016", |
80 |
|
|
"\033E", |
81 |
|
|
"\033E\016", |
82 |
|
|
"\033q", |
83 |
|
|
"\033q\016", |
84 |
|
|
"\033q", |
85 |
|
|
"\033q\016", |
86 |
|
|
"\033Q", |
87 |
|
|
"\033Q\016", |
88 |
|
|
"\033Q", |
89 |
|
|
"\033Q\016" |
90 |
|
|
}; |
91 |
|
|
|
92 |
|
|
static int lineno = 0; |
93 |
|
|
|
94 |
|
|
static short condonly = FALSE, |
95 |
|
|
conditioned = FALSE; |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
main(argc, argv) |
99 |
|
|
|
100 |
|
|
int argc; |
101 |
|
|
char **argv; |
102 |
|
|
|
103 |
|
|
{ |
104 |
|
|
FILE *fp; |
105 |
|
|
#ifdef UNIX |
106 |
|
|
FILE *popen(); |
107 |
|
|
#endif |
108 |
|
|
char comargs[200], command[300]; |
109 |
|
|
|
110 |
|
|
#ifdef CPM |
111 |
|
|
fixargs("imagew", &argc, &argv); |
112 |
|
|
#endif |
113 |
|
|
|
114 |
|
|
progname = *argv++; |
115 |
|
|
argc--; |
116 |
|
|
|
117 |
|
|
condonly = FALSE; |
118 |
|
|
#ifdef UNIX |
119 |
|
|
conditioned = FALSE; |
120 |
|
|
#else |
121 |
|
|
conditioned = TRUE; |
122 |
|
|
#endif |
123 |
|
|
|
124 |
|
|
while (argc && **argv == '-') { |
125 |
|
|
switch (*(*argv+1)) { |
126 |
|
|
#ifdef UNIX |
127 |
|
|
case 'c': |
128 |
|
|
condonly = TRUE; |
129 |
|
|
break; |
130 |
|
|
case 'r': |
131 |
|
|
conditioned = TRUE; |
132 |
|
|
break; |
133 |
|
|
#endif |
134 |
|
|
default: |
135 |
|
|
error(WARNING, "unknown option"); |
136 |
|
|
break; |
137 |
|
|
} |
138 |
|
|
argv++; |
139 |
|
|
argc--; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
if (conditioned) { |
143 |
|
|
pinit(); |
144 |
|
|
if (argc) |
145 |
|
|
while (argc) { |
146 |
|
|
fp = efopen(*argv, "r"); |
147 |
|
|
plot(fp); |
148 |
|
|
fclose(fp); |
149 |
|
|
argv++; |
150 |
|
|
argc--; |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
plot(stdin); |
154 |
|
|
if (lineno > 0) |
155 |
|
|
nextpage(); |
156 |
|
|
puninit(); |
157 |
|
|
} else { |
158 |
|
|
comargs[0] = '\0'; |
159 |
|
|
while (argc) { |
160 |
|
|
strcat(comargs, " "); |
161 |
|
|
strcat(comargs, *argv); |
162 |
|
|
argv++; |
163 |
|
|
argc--; |
164 |
|
|
} |
165 |
|
|
sprintf(command, XCOM, comargs); |
166 |
|
|
#ifdef UNIX |
167 |
|
|
if (condonly) |
168 |
|
|
return(system(command)); |
169 |
|
|
else { |
170 |
|
|
pinit(); |
171 |
|
|
if ((fp = popen(command, "r")) == NULL) |
172 |
|
|
error(SYSTEM, "cannot execute input filter"); |
173 |
|
|
plot(fp); |
174 |
|
|
pclose(fp); |
175 |
|
|
if (lineno > 0) |
176 |
|
|
nextpage(); |
177 |
|
|
puninit(); |
178 |
|
|
} |
179 |
|
|
#endif |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
return(0); |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
thispage() /* rewind and initialize current page */ |
191 |
|
|
|
192 |
|
|
{ |
193 |
|
|
|
194 |
|
|
if (lineno != 0) { |
195 |
|
|
fputs(LFREV, stdout); |
196 |
|
|
while (lineno) { |
197 |
|
|
putc('\n', stdout); |
198 |
|
|
lineno--; |
199 |
|
|
} |
200 |
|
|
fputs(LFNORM, stdout); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
nextpage() /* advance to next page */ |
209 |
|
|
|
210 |
|
|
{ |
211 |
|
|
|
212 |
|
|
fputs("\f\r", stdout); |
213 |
|
|
|
214 |
|
|
lineno = 0; |
215 |
|
|
|
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
contpage() /* continue on this page */ |
221 |
|
|
|
222 |
|
|
{ |
223 |
|
|
|
224 |
|
|
while (lineno++ < NLINES) |
225 |
|
|
putc('\n', stdout); |
226 |
|
|
|
227 |
|
|
lineno = 0; |
228 |
|
|
|
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
printspan() /* output span to printer */ |
234 |
|
|
|
235 |
|
|
{ |
236 |
|
|
register int i; |
237 |
|
|
|
238 |
|
|
if (spanmin <= spanmax) { |
239 |
|
|
|
240 |
|
|
fprintf(stdout, "%s%4d", PTAB, spanmin); |
241 |
|
|
fprintf(stdout, "%s%3d", OUTPUT, (spanmax-spanmin)/8 + 1); |
242 |
|
|
|
243 |
|
|
for (i = spanmin; i <= spanmax; i++) |
244 |
|
|
putc(flipbyte(outspan.cols[i]), stdout); |
245 |
|
|
|
246 |
|
|
i = 7 - (spanmax-spanmin)%8; |
247 |
|
|
while (i--) |
248 |
|
|
putc('\0', stdout); |
249 |
|
|
|
250 |
|
|
putc('\r', stdout); |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
putc('\n', stdout); |
254 |
|
|
lineno++; |
255 |
|
|
|
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
int |
262 |
|
|
flipbyte(b) /* flip an 8-bit byte end-to-end */ |
263 |
|
|
|
264 |
|
|
register int b; |
265 |
|
|
|
266 |
|
|
{ |
267 |
|
|
register int i, a = 0; |
268 |
|
|
|
269 |
|
|
if (b) |
270 |
|
|
for (i = 0; i < 8; i++) { |
271 |
|
|
a <<= 1; |
272 |
|
|
a |= b & 01; |
273 |
|
|
b >>= 1; |
274 |
|
|
} |
275 |
|
|
|
276 |
|
|
return(a); |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
printstr(p) /* output a string to the printer */ |
283 |
|
|
|
284 |
|
|
PRIMITIVE *p; |
285 |
|
|
|
286 |
|
|
{ |
287 |
|
|
|
288 |
|
|
fprintf(stdout, "%s%4d", PTAB, CONV(p->xy[XMN], dxsize)); |
289 |
|
|
|
290 |
|
|
if (p->arg0 & 0100) /* double strike */ |
291 |
|
|
fputs(DBLON, stdout); |
292 |
|
|
else |
293 |
|
|
fputs(DBLOFF, stdout); |
294 |
|
|
|
295 |
|
|
fputs(chrtype[(p->arg0 >> 2) & 017], stdout); |
296 |
|
|
fputs(p->args, stdout); |
297 |
|
|
fputs(PNORM, stdout); |
298 |
|
|
putc('\r', stdout); |
299 |
|
|
|
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
pinit() /* initialize printer for output */ |
305 |
|
|
{ |
306 |
|
|
pclear(); |
307 |
|
|
/* get eighth bit */ |
308 |
|
|
fputs("\033Z", stdout); |
309 |
|
|
putc('\0', stdout); |
310 |
|
|
putc(' ', stdout); |
311 |
|
|
fputs(PINIT, stdout); |
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
|
315 |
|
|
puninit() /* uninitialize printer */ |
316 |
|
|
{ |
317 |
|
|
pclear(); |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
|
321 |
|
|
pclear() /* clear printer and sleep */ |
322 |
|
|
|
323 |
|
|
{ |
324 |
|
|
register int i, j; |
325 |
|
|
|
326 |
|
|
fputs(PCLEAR, stdout); |
327 |
|
|
fflush(stdout); |
328 |
|
|
for (i = 0; i < 1000; i++) |
329 |
|
|
for (j = 0; j < 500; j++) |
330 |
|
|
; |
331 |
|
|
|
332 |
|
|
} |