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 mt160l mt160l.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o |
8 |
|
|
* |
9 |
|
|
* Mannesman Tally MT160L high-density |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#define MAXALLOC 5000 |
14 |
|
|
|
15 |
|
|
#define DXSIZE 1064 /* x resolution */ |
16 |
|
|
|
17 |
|
|
#define DYSIZE 1024 /* y resolution */ |
18 |
|
|
|
19 |
|
|
#define LINWIDT DXSIZE /* line width */ |
20 |
|
|
|
21 |
|
|
#define LINHITE 16 /* line height */ |
22 |
|
|
|
23 |
|
|
#define NLINES (DYSIZE/LINHITE) /* number of lines */ |
24 |
|
|
|
25 |
|
|
#define CHARWIDTH 8 |
26 |
|
|
|
27 |
|
|
#define PNORM "\033[0y\033[6w" |
28 |
|
|
|
29 |
|
|
#define PINIT "\033[6~\033[7z\033[0y\033[6w" |
30 |
|
|
|
31 |
|
|
#define PUNINIT "\033[6~" |
32 |
|
|
|
33 |
|
|
#define DBLON "\033[=z" |
34 |
|
|
|
35 |
|
|
#define DBLOFF "\033[>z" |
36 |
|
|
|
37 |
|
|
#define OUTHIGH "\033[9~\033%6" |
38 |
|
|
|
39 |
|
|
#define OUTLOW "\033[8~\033%6" |
40 |
|
|
|
41 |
|
|
#define XCOM "pexpand +vOCIsp %s | psort -Y +x" |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
#include "meta.h" |
47 |
|
|
|
48 |
|
|
#include "plot.h" |
49 |
|
|
|
50 |
|
|
#include "span.h" |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
char *progname; |
56 |
|
|
|
57 |
|
|
struct span outspan; |
58 |
|
|
|
59 |
|
|
int dxsize = DXSIZE, dysize = DYSIZE, |
60 |
|
|
linwidt = LINWIDT, linhite = LINHITE, |
61 |
|
|
nrows = (LINHITE-1)/8+1; |
62 |
|
|
|
63 |
|
|
int maxalloc = MAXALLOC; |
64 |
|
|
|
65 |
|
|
int spanmin = 0, spanmax = LINWIDT-1; |
66 |
|
|
|
67 |
|
|
int charwidth = CHARWIDTH; |
68 |
|
|
|
69 |
|
|
static char chrtype[16][9] = { |
70 |
|
|
"\033[1y\033[4y", |
71 |
|
|
"\033[0y\033[0w", |
72 |
|
|
"\033[1y\033[4y", |
73 |
|
|
"\033[0y\033[0w", |
74 |
|
|
"\033[1y\033[5y", |
75 |
|
|
"\033[0y\033[1w", |
76 |
|
|
"\033[1y\033[5y", |
77 |
|
|
"\033[0y\033[1w", |
78 |
|
|
"\033[0y\033[6w", |
79 |
|
|
"\033[0y\033[2w", |
80 |
|
|
"\033[0y\033[6w", |
81 |
|
|
"\033[0y\033[2w", |
82 |
|
|
"\033[0y\033[7w", |
83 |
|
|
"\033[0y\033[3w", |
84 |
|
|
"\033[0y\033[7w", |
85 |
|
|
"\033[0y\033[3w" |
86 |
|
|
}; |
87 |
|
|
|
88 |
|
|
static int lineno = 0; |
89 |
|
|
|
90 |
|
|
static short condonly = FALSE, |
91 |
|
|
conditioned = FALSE; |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
main(argc, argv) |
95 |
|
|
|
96 |
|
|
int argc; |
97 |
|
|
char **argv; |
98 |
|
|
|
99 |
|
|
{ |
100 |
|
|
FILE *fp; |
101 |
|
|
#ifdef UNIX |
102 |
|
|
FILE *popen(); |
103 |
|
|
#endif |
104 |
|
|
char comargs[200], command[300]; |
105 |
|
|
|
106 |
|
|
#ifdef CPM |
107 |
|
|
fixargs("mt160l", &argc, &argv); |
108 |
|
|
#endif |
109 |
|
|
|
110 |
|
|
progname = *argv++; |
111 |
|
|
argc--; |
112 |
|
|
|
113 |
|
|
condonly = FALSE; |
114 |
|
|
#ifdef CPM |
115 |
|
|
conditioned = TRUE; |
116 |
|
|
#else |
117 |
|
|
conditioned = FALSE; |
118 |
|
|
#endif |
119 |
|
|
|
120 |
|
|
while (argc && **argv == '-') { |
121 |
|
|
switch (*(*argv+1)) { |
122 |
|
|
#ifdef UNIX |
123 |
|
|
case 'c': |
124 |
|
|
condonly = TRUE; |
125 |
|
|
break; |
126 |
|
|
case 'r': |
127 |
|
|
conditioned = TRUE; |
128 |
|
|
break; |
129 |
|
|
#endif |
130 |
|
|
default: |
131 |
|
|
error(WARNING, "unknown option"); |
132 |
|
|
break; |
133 |
|
|
} |
134 |
|
|
argv++; |
135 |
|
|
argc--; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
if (conditioned) { |
139 |
|
|
fputs(PINIT, stdout); |
140 |
|
|
if (argc) |
141 |
|
|
while (argc) { |
142 |
|
|
fp = efopen(*argv, "r"); |
143 |
|
|
plot(fp); |
144 |
|
|
fclose(fp); |
145 |
|
|
argv++; |
146 |
|
|
argc--; |
147 |
|
|
} |
148 |
|
|
else |
149 |
|
|
plot(stdin); |
150 |
|
|
if (lineno) |
151 |
|
|
nextpage(); |
152 |
|
|
fputs(PUNINIT, stdout); |
153 |
|
|
} else { |
154 |
|
|
comargs[0] = '\0'; |
155 |
|
|
while (argc) { |
156 |
|
|
strcat(comargs, " "); |
157 |
|
|
strcat(comargs, *argv); |
158 |
|
|
argv++; |
159 |
|
|
argc--; |
160 |
|
|
} |
161 |
|
|
sprintf(command, XCOM, comargs); |
162 |
|
|
#ifdef UNIX |
163 |
|
|
if (condonly) |
164 |
|
|
return(system(command)); |
165 |
|
|
else { |
166 |
|
|
fputs(PINIT, stdout); |
167 |
|
|
if ((fp = popen(command, "r")) == NULL) |
168 |
|
|
error(SYSTEM, "cannot execute input filter"); |
169 |
|
|
plot(fp); |
170 |
|
|
pclose(fp); |
171 |
|
|
if (lineno) |
172 |
|
|
nextpage(); |
173 |
|
|
fputs(PUNINIT, stdout); |
174 |
|
|
} |
175 |
|
|
#endif |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
return(0); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
thispage() /* rewind and initialize current page */ |
188 |
|
|
|
189 |
|
|
{ |
190 |
|
|
|
191 |
|
|
if (lineno) |
192 |
|
|
error(USER, "cannot restart page in thispage"); |
193 |
|
|
|
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
nextpage() /* advance to next page */ |
200 |
|
|
|
201 |
|
|
{ |
202 |
|
|
|
203 |
|
|
fputs("\f\r", stdout); |
204 |
|
|
|
205 |
|
|
lineno = 0; |
206 |
|
|
|
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
contpage() /* continue new plot on current page */ |
213 |
|
|
|
214 |
|
|
{ |
215 |
|
|
|
216 |
|
|
while (lineno++ < NLINES) |
217 |
|
|
putc('\n', stdout); |
218 |
|
|
|
219 |
|
|
lineno = 0; |
220 |
|
|
|
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
printspan() /* output span to printer */ |
226 |
|
|
|
227 |
|
|
{ |
228 |
|
|
register unsigned shiftreg; |
229 |
|
|
unsigned short outc; |
230 |
|
|
register k; |
231 |
|
|
unsigned short offset, mask; |
232 |
|
|
int i,j; |
233 |
|
|
|
234 |
|
|
if (spanmin <= spanmax) |
235 |
|
|
for (offset = 0; offset < 2; offset++) { |
236 |
|
|
|
237 |
|
|
k = spanmin/charwidth; |
238 |
|
|
while (k--) |
239 |
|
|
putc(' ', stdout); |
240 |
|
|
|
241 |
|
|
k = spanmin%charwidth; |
242 |
|
|
if (offset) |
243 |
|
|
fputs(OUTHIGH, stdout); |
244 |
|
|
else |
245 |
|
|
fputs(OUTLOW, stdout); |
246 |
|
|
putc((spanmax-spanmin+k+1)%256, stdout); |
247 |
|
|
putc((spanmax-spanmin+k+1)/256, stdout); |
248 |
|
|
|
249 |
|
|
while (k--) |
250 |
|
|
putc('\0', stdout); |
251 |
|
|
|
252 |
|
|
for (i = spanmin; i <= spanmax; i++) { |
253 |
|
|
outc = '\0'; |
254 |
|
|
for (j = 0; j < 2; j++) { |
255 |
|
|
shiftreg = outspan.cols[j*dxsize + i] >> offset; |
256 |
|
|
if (j) { |
257 |
|
|
shiftreg <<= 4; |
258 |
|
|
mask = 1 << 4; |
259 |
|
|
} else |
260 |
|
|
mask = 1; |
261 |
|
|
for (k = 0; k < 4; k++) { |
262 |
|
|
outc |= shiftreg & (mask << k); |
263 |
|
|
shiftreg >>= 1; |
264 |
|
|
} |
265 |
|
|
} |
266 |
|
|
putc(outc, stdout); |
267 |
|
|
} |
268 |
|
|
putc('\r', stdout); |
269 |
|
|
} |
270 |
|
|
putc('\n', stdout); |
271 |
|
|
lineno++; |
272 |
|
|
|
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
printstr(p) /* output a string to the printer */ |
280 |
|
|
|
281 |
|
|
PRIMITIVE *p; |
282 |
|
|
|
283 |
|
|
{ |
284 |
|
|
int i; |
285 |
|
|
|
286 |
|
|
i = CONV(p->xy[XMN], dxsize)/charwidth; |
287 |
|
|
while (i--) |
288 |
|
|
putc(' ', stdout); |
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 |
|
|
} |