1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: mx80.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 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 |
FILE *popen(); |
78 |
char comargs[200], command[300]; |
79 |
|
80 |
progname = *argv++; |
81 |
argc--; |
82 |
|
83 |
condonly = FALSE; |
84 |
conditioned = FALSE; |
85 |
|
86 |
while (argc && **argv == '-') { |
87 |
switch (*(*argv+1)) { |
88 |
case 'c': |
89 |
condonly = TRUE; |
90 |
break; |
91 |
case 'r': |
92 |
conditioned = TRUE; |
93 |
break; |
94 |
default: |
95 |
error(WARNING, "unknown option"); |
96 |
break; |
97 |
} |
98 |
argv++; |
99 |
argc--; |
100 |
} |
101 |
|
102 |
if (conditioned) { |
103 |
fputs(PINIT, stdout); |
104 |
if (argc) |
105 |
while (argc) { |
106 |
fp = efopen(*argv, "r"); |
107 |
plot(fp); |
108 |
fclose(fp); |
109 |
argv++; |
110 |
argc--; |
111 |
} |
112 |
else |
113 |
plot(stdin); |
114 |
fputs(PUNINIT, stdout); |
115 |
} else { |
116 |
comargs[0] = '\0'; |
117 |
while (argc) { |
118 |
strcat(comargs, " "); |
119 |
strcat(comargs, *argv); |
120 |
argv++; |
121 |
argc--; |
122 |
} |
123 |
sprintf(command, XCOM, comargs); |
124 |
if (condonly) |
125 |
return(system(command)); |
126 |
else { |
127 |
fputs(PINIT, stdout); |
128 |
if ((fp = popen(command, "r")) == NULL) |
129 |
error(SYSTEM, "cannot execute input filter"); |
130 |
plot(fp); |
131 |
pclose(fp); |
132 |
fputs(PUNINIT, stdout); |
133 |
} |
134 |
} |
135 |
|
136 |
return(0); |
137 |
} |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
thispage() /* rewind and initialize current page */ |
146 |
|
147 |
{ |
148 |
|
149 |
if (lineno) |
150 |
error(USER, "cannot restart page in thispage"); |
151 |
|
152 |
} |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
nextpage() /* advance to next page */ |
158 |
|
159 |
{ |
160 |
|
161 |
fputs("\f\r", stdout); |
162 |
|
163 |
lineno = 0; |
164 |
|
165 |
} |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
contpage() /* continue new plot on current page */ |
171 |
|
172 |
{ |
173 |
|
174 |
while (lineno++ < NLINES) |
175 |
putc('\n', stdout); |
176 |
|
177 |
lineno = 0; |
178 |
|
179 |
} |
180 |
|
181 |
|
182 |
|
183 |
printspan() /* output span to printer */ |
184 |
|
185 |
{ |
186 |
register int k; |
187 |
|
188 |
if (spanmin <= spanmax) { |
189 |
|
190 |
k = spanmin/charwidth; |
191 |
while (k--) |
192 |
putc(' ', stdout); |
193 |
|
194 |
k = spanmin%charwidth; |
195 |
fputs(OUTPUT, stdout); |
196 |
putc((spanmax-spanmin+k+1)%256, stdout); |
197 |
putc((spanmax-spanmin+k+1)/256, stdout); |
198 |
while (k--) |
199 |
putc('\0', stdout); |
200 |
|
201 |
for (k = spanmin; k <= spanmax; k++) |
202 |
putc(outspan.cols[k], stdout); |
203 |
|
204 |
putc('\r', stdout); |
205 |
} |
206 |
putc('\n', stdout); |
207 |
lineno++; |
208 |
|
209 |
} |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
printstr(p) /* output a string to the printer */ |
216 |
|
217 |
PRIMITIVE *p; |
218 |
|
219 |
{ |
220 |
int i; |
221 |
|
222 |
i = CONV(p->xy[XMN], dxsize)/charwidth; |
223 |
while (i--) |
224 |
putc(' ', stdout); |
225 |
|
226 |
fputs(p->args, stdout); |
227 |
fputs(PNORM, stdout); |
228 |
putc('\r', stdout); |
229 |
|
230 |
} |