1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: mt160l.c,v 1.1 2003/02/22 02:07:26 greg Exp $"; |
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 |
FILE *popen(); |
102 |
char comargs[200], command[300]; |
103 |
|
104 |
progname = *argv++; |
105 |
argc--; |
106 |
|
107 |
condonly = FALSE; |
108 |
conditioned = FALSE; |
109 |
|
110 |
while (argc && **argv == '-') { |
111 |
switch (*(*argv+1)) { |
112 |
case 'c': |
113 |
condonly = TRUE; |
114 |
break; |
115 |
case 'r': |
116 |
conditioned = TRUE; |
117 |
break; |
118 |
default: |
119 |
error(WARNING, "unknown option"); |
120 |
break; |
121 |
} |
122 |
argv++; |
123 |
argc--; |
124 |
} |
125 |
|
126 |
if (conditioned) { |
127 |
fputs(PINIT, stdout); |
128 |
if (argc) |
129 |
while (argc) { |
130 |
fp = efopen(*argv, "r"); |
131 |
plot(fp); |
132 |
fclose(fp); |
133 |
argv++; |
134 |
argc--; |
135 |
} |
136 |
else |
137 |
plot(stdin); |
138 |
if (lineno) |
139 |
nextpage(); |
140 |
fputs(PUNINIT, stdout); |
141 |
} else { |
142 |
comargs[0] = '\0'; |
143 |
while (argc) { |
144 |
strcat(comargs, " "); |
145 |
strcat(comargs, *argv); |
146 |
argv++; |
147 |
argc--; |
148 |
} |
149 |
sprintf(command, XCOM, comargs); |
150 |
if (condonly) |
151 |
return(system(command)); |
152 |
else { |
153 |
fputs(PINIT, stdout); |
154 |
if ((fp = popen(command, "r")) == NULL) |
155 |
error(SYSTEM, "cannot execute input filter"); |
156 |
plot(fp); |
157 |
pclose(fp); |
158 |
if (lineno) |
159 |
nextpage(); |
160 |
fputs(PUNINIT, stdout); |
161 |
} |
162 |
} |
163 |
|
164 |
return(0); |
165 |
} |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
thispage() /* rewind and initialize current page */ |
174 |
|
175 |
{ |
176 |
|
177 |
if (lineno) |
178 |
error(USER, "cannot restart page in thispage"); |
179 |
|
180 |
} |
181 |
|
182 |
|
183 |
|
184 |
|
185 |
nextpage() /* advance to next page */ |
186 |
|
187 |
{ |
188 |
|
189 |
fputs("\f\r", stdout); |
190 |
|
191 |
lineno = 0; |
192 |
|
193 |
} |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
contpage() /* continue new plot on current page */ |
199 |
|
200 |
{ |
201 |
|
202 |
while (lineno++ < NLINES) |
203 |
putc('\n', stdout); |
204 |
|
205 |
lineno = 0; |
206 |
|
207 |
} |
208 |
|
209 |
|
210 |
|
211 |
printspan() /* output span to printer */ |
212 |
|
213 |
{ |
214 |
register unsigned shiftreg; |
215 |
unsigned short outc; |
216 |
register k; |
217 |
unsigned short offset, mask; |
218 |
int i,j; |
219 |
|
220 |
if (spanmin <= spanmax) |
221 |
for (offset = 0; offset < 2; offset++) { |
222 |
|
223 |
k = spanmin/charwidth; |
224 |
while (k--) |
225 |
putc(' ', stdout); |
226 |
|
227 |
k = spanmin%charwidth; |
228 |
if (offset) |
229 |
fputs(OUTHIGH, stdout); |
230 |
else |
231 |
fputs(OUTLOW, stdout); |
232 |
putc((spanmax-spanmin+k+1)%256, stdout); |
233 |
putc((spanmax-spanmin+k+1)/256, stdout); |
234 |
|
235 |
while (k--) |
236 |
putc('\0', stdout); |
237 |
|
238 |
for (i = spanmin; i <= spanmax; i++) { |
239 |
outc = '\0'; |
240 |
for (j = 0; j < 2; j++) { |
241 |
shiftreg = outspan.cols[j*dxsize + i] >> offset; |
242 |
if (j) { |
243 |
shiftreg <<= 4; |
244 |
mask = 1 << 4; |
245 |
} else |
246 |
mask = 1; |
247 |
for (k = 0; k < 4; k++) { |
248 |
outc |= shiftreg & (mask << k); |
249 |
shiftreg >>= 1; |
250 |
} |
251 |
} |
252 |
putc(outc, stdout); |
253 |
} |
254 |
putc('\r', stdout); |
255 |
} |
256 |
putc('\n', stdout); |
257 |
lineno++; |
258 |
|
259 |
} |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
printstr(p) /* output a string to the printer */ |
266 |
|
267 |
PRIMITIVE *p; |
268 |
|
269 |
{ |
270 |
int i; |
271 |
|
272 |
i = CONV(p->xy[XMN], dxsize)/charwidth; |
273 |
while (i--) |
274 |
putc(' ', stdout); |
275 |
|
276 |
if (p->arg0 & 0100) /* double strike */ |
277 |
fputs(DBLON, stdout); |
278 |
else |
279 |
fputs(DBLOFF, stdout); |
280 |
|
281 |
fputs(chrtype[(p->arg0 >> 2) & 017], stdout); |
282 |
fputs(p->args, stdout); |
283 |
fputs(PNORM, stdout); |
284 |
putc('\r', stdout); |
285 |
|
286 |
} |