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