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 mx80 mx80.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o |
8 |
|
|
* |
9 |
|
|
* Epson MX-80 printer |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#define MAXALLOC 5000 |
14 |
|
|
|
15 |
|
|
#define DXSIZE 480 /* x resolution */ |
16 |
|
|
|
17 |
|
|
#define DYSIZE 616 /* y resolution */ |
18 |
|
|
|
19 |
|
|
#define LINWIDT DXSIZE /* line width */ |
20 |
|
|
|
21 |
|
|
#define LINHITE 8 /* line height */ |
22 |
|
|
|
23 |
|
|
#define NLINES (DYSIZE/LINHITE) /* number of lines */ |
24 |
|
|
|
25 |
|
|
#define CHARWIDTH 6 |
26 |
|
|
|
27 |
|
|
#define PNORM "" |
28 |
|
|
|
29 |
|
|
#define PINIT "\033@\033#\0331\033U1" |
30 |
|
|
|
31 |
|
|
#define PUNINIT "\033@\033=" |
32 |
|
|
|
33 |
|
|
#define OUTPUT "\033K" |
34 |
|
|
|
35 |
|
|
#define XCOM "pexpand +vOCIsp %s | psort -Y +x" |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
#include "meta.h" |
42 |
|
|
|
43 |
|
|
#include "plot.h" |
44 |
|
|
|
45 |
|
|
#include "span.h" |
46 |
|
|
|
47 |
|
|
|
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 int lineno = 0; |
65 |
|
|
|
66 |
|
|
static short condonly = FALSE, |
67 |
|
|
conditioned = FALSE; |
68 |
|
|
|
69 |
|
|
|
70 |
|
|
main(argc, argv) |
71 |
|
|
|
72 |
|
|
int argc; |
73 |
|
|
char **argv; |
74 |
|
|
|
75 |
|
|
{ |
76 |
|
|
FILE *fp; |
77 |
|
|
#ifdef UNIX |
78 |
|
|
FILE *popen(); |
79 |
|
|
#endif |
80 |
|
|
char comargs[200], command[300]; |
81 |
|
|
|
82 |
|
|
#ifdef CPM |
83 |
|
|
fixargs("mx80", &argc, &argv); |
84 |
|
|
#endif |
85 |
|
|
|
86 |
|
|
progname = *argv++; |
87 |
|
|
argc--; |
88 |
|
|
|
89 |
|
|
condonly = FALSE; |
90 |
|
|
#ifdef CPM |
91 |
|
|
conditioned = TRUE; |
92 |
|
|
#else |
93 |
|
|
conditioned = FALSE; |
94 |
|
|
#endif |
95 |
|
|
|
96 |
|
|
while (argc && **argv == '-') { |
97 |
|
|
switch (*(*argv+1)) { |
98 |
|
|
#ifdef UNIX |
99 |
|
|
case 'c': |
100 |
|
|
condonly = TRUE; |
101 |
|
|
break; |
102 |
|
|
case 'r': |
103 |
|
|
conditioned = TRUE; |
104 |
|
|
break; |
105 |
|
|
#endif |
106 |
|
|
default: |
107 |
|
|
error(WARNING, "unknown option"); |
108 |
|
|
break; |
109 |
|
|
} |
110 |
|
|
argv++; |
111 |
|
|
argc--; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
if (conditioned) { |
115 |
|
|
fputs(PINIT, stdout); |
116 |
|
|
if (argc) |
117 |
|
|
while (argc) { |
118 |
|
|
fp = efopen(*argv, "r"); |
119 |
|
|
plot(fp); |
120 |
|
|
fclose(fp); |
121 |
|
|
argv++; |
122 |
|
|
argc--; |
123 |
|
|
} |
124 |
|
|
else |
125 |
|
|
plot(stdin); |
126 |
|
|
fputs(PUNINIT, stdout); |
127 |
|
|
} else { |
128 |
|
|
comargs[0] = '\0'; |
129 |
|
|
while (argc) { |
130 |
|
|
strcat(comargs, " "); |
131 |
|
|
strcat(comargs, *argv); |
132 |
|
|
argv++; |
133 |
|
|
argc--; |
134 |
|
|
} |
135 |
|
|
sprintf(command, XCOM, comargs); |
136 |
|
|
#ifdef UNIX |
137 |
|
|
if (condonly) |
138 |
|
|
return(system(command)); |
139 |
|
|
else { |
140 |
|
|
fputs(PINIT, stdout); |
141 |
|
|
if ((fp = popen(command, "r")) == NULL) |
142 |
|
|
error(SYSTEM, "cannot execute input filter"); |
143 |
|
|
plot(fp); |
144 |
|
|
pclose(fp); |
145 |
|
|
fputs(PUNINIT, stdout); |
146 |
|
|
} |
147 |
|
|
#endif |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
return(0); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
thispage() /* rewind and initialize current page */ |
160 |
|
|
|
161 |
|
|
{ |
162 |
|
|
|
163 |
|
|
if (lineno) |
164 |
|
|
error(USER, "cannot restart page in thispage"); |
165 |
|
|
|
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
nextpage() /* advance to next page */ |
172 |
|
|
|
173 |
|
|
{ |
174 |
|
|
|
175 |
|
|
fputs("\f\r", stdout); |
176 |
|
|
|
177 |
|
|
lineno = 0; |
178 |
|
|
|
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
contpage() /* continue new plot on current page */ |
185 |
|
|
|
186 |
|
|
{ |
187 |
|
|
|
188 |
|
|
while (lineno++ < NLINES) |
189 |
|
|
putc('\n', stdout); |
190 |
|
|
|
191 |
|
|
lineno = 0; |
192 |
|
|
|
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
printspan() /* output span to printer */ |
198 |
|
|
|
199 |
|
|
{ |
200 |
|
|
register int k; |
201 |
|
|
|
202 |
|
|
if (spanmin <= spanmax) { |
203 |
|
|
|
204 |
|
|
k = spanmin/charwidth; |
205 |
|
|
while (k--) |
206 |
|
|
putc(' ', stdout); |
207 |
|
|
|
208 |
|
|
k = spanmin%charwidth; |
209 |
|
|
fputs(OUTPUT, stdout); |
210 |
|
|
putc((spanmax-spanmin+k+1)%256, stdout); |
211 |
|
|
putc((spanmax-spanmin+k+1)/256, stdout); |
212 |
|
|
while (k--) |
213 |
|
|
putc('\0', stdout); |
214 |
|
|
|
215 |
|
|
for (k = spanmin; k <= spanmax; k++) |
216 |
|
|
putc(outspan.cols[k], stdout); |
217 |
|
|
|
218 |
|
|
putc('\r', stdout); |
219 |
|
|
} |
220 |
|
|
putc('\n', stdout); |
221 |
|
|
lineno++; |
222 |
|
|
|
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
printstr(p) /* output a string to the printer */ |
230 |
|
|
|
231 |
|
|
PRIMITIVE *p; |
232 |
|
|
|
233 |
|
|
{ |
234 |
|
|
int i; |
235 |
|
|
|
236 |
|
|
i = CONV(p->xy[XMN], dxsize)/charwidth; |
237 |
|
|
while (i--) |
238 |
|
|
putc(' ', stdout); |
239 |
|
|
|
240 |
|
|
fputs(p->args, stdout); |
241 |
|
|
fputs(PNORM, stdout); |
242 |
|
|
putc('\r', stdout); |
243 |
|
|
|
244 |
|
|
} |