1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
1.4 |
static const char RCSid[] = "$Id: okimate.c,v 1.3 2003/10/27 10:28:59 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Program to print meta-files on a dot-matrix printer |
6 |
|
|
* |
7 |
|
|
* cc -o okimate okimate.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o |
8 |
|
|
* |
9 |
|
|
* Okimate 20 printer (version for black ribbon) |
10 |
|
|
*/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#define MAXALLOC 5000 |
14 |
|
|
|
15 |
|
|
#define DXSIZE 960 /* x resolution */ |
16 |
|
|
|
17 |
|
|
#define DYSIZE 1152 /* y resolution */ |
18 |
|
|
|
19 |
|
|
#define LINWIDT DXSIZE /* line width */ |
20 |
|
|
|
21 |
|
|
#define LINHITE 24 /* line height */ |
22 |
|
|
|
23 |
|
|
#define NLINES (DYSIZE/LINHITE) /* number of lines */ |
24 |
|
|
|
25 |
|
|
#define CHARWIDTH 12 |
26 |
|
|
|
27 |
|
|
#define PNORM "\024\022\033%H" |
28 |
|
|
|
29 |
|
|
#define PINIT "\033O\033T\033I\002\033%H\033T\022\033A\014\0332" |
30 |
|
|
|
31 |
|
|
#define PUNINIT "" |
32 |
|
|
|
33 |
|
|
#define DBLON "\033%G" |
34 |
|
|
|
35 |
|
|
#define GRPH "\033%O" |
36 |
|
|
|
37 |
|
|
#define XCOM "pexpand +vOCIsp %s | psort -Y +x" |
38 |
|
|
|
39 |
|
|
|
40 |
schorsch |
1.3 |
#include "rtprocess.h" |
41 |
greg |
1.1 |
#include "meta.h" |
42 |
|
|
#include "plot.h" |
43 |
|
|
#include "span.h" |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
char *progname; |
47 |
|
|
|
48 |
|
|
struct span outspan; |
49 |
|
|
|
50 |
|
|
int dxsize = DXSIZE, dysize = DYSIZE, |
51 |
|
|
linwidt = LINWIDT, linhite = LINHITE, |
52 |
|
|
nrows = (LINHITE-1)/8+1; |
53 |
|
|
|
54 |
|
|
int maxalloc = MAXALLOC; |
55 |
|
|
|
56 |
|
|
int spanmin = 0, spanmax = LINWIDT-1; |
57 |
|
|
|
58 |
|
|
int charwidth = CHARWIDTH; |
59 |
|
|
|
60 |
|
|
static char chrtype[16][4] = { |
61 |
|
|
"", |
62 |
|
|
"\016", |
63 |
|
|
"", |
64 |
|
|
"\016", |
65 |
|
|
"\033:", |
66 |
|
|
"\033:\016", |
67 |
|
|
"\033:", |
68 |
|
|
"\033:\016", |
69 |
|
|
"\017", |
70 |
|
|
"\017\016", |
71 |
|
|
"\017", |
72 |
|
|
"\017\016", |
73 |
|
|
"\017", |
74 |
|
|
"", |
75 |
|
|
"\017", |
76 |
|
|
"" |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
|
static int lineno = 0; |
80 |
|
|
|
81 |
|
|
static short condonly = FALSE, |
82 |
|
|
conditioned = FALSE; |
83 |
|
|
|
84 |
|
|
|
85 |
schorsch |
1.4 |
int |
86 |
|
|
main( |
87 |
|
|
int argc, |
88 |
|
|
char **argv |
89 |
|
|
) |
90 |
greg |
1.1 |
{ |
91 |
|
|
FILE *fp; |
92 |
|
|
char comargs[200], command[300]; |
93 |
|
|
|
94 |
|
|
progname = *argv++; |
95 |
|
|
argc--; |
96 |
|
|
|
97 |
|
|
condonly = FALSE; |
98 |
|
|
conditioned = FALSE; |
99 |
|
|
|
100 |
|
|
minwidth = 1; /* so lines aren't invisible */ |
101 |
|
|
|
102 |
|
|
while (argc && **argv == '-') { |
103 |
|
|
switch (*(*argv+1)) { |
104 |
|
|
case 'c': |
105 |
|
|
condonly = TRUE; |
106 |
|
|
break; |
107 |
|
|
case 'r': |
108 |
|
|
conditioned = TRUE; |
109 |
|
|
break; |
110 |
|
|
default: |
111 |
|
|
error(WARNING, "unknown option"); |
112 |
|
|
break; |
113 |
|
|
} |
114 |
|
|
argv++; |
115 |
|
|
argc--; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
if (conditioned) { |
119 |
|
|
fputs(PINIT, stdout); |
120 |
|
|
if (argc) |
121 |
|
|
while (argc) { |
122 |
|
|
fp = efopen(*argv, "r"); |
123 |
|
|
plot(fp); |
124 |
|
|
fclose(fp); |
125 |
|
|
argv++; |
126 |
|
|
argc--; |
127 |
|
|
} |
128 |
|
|
else |
129 |
|
|
plot(stdin); |
130 |
|
|
if (lineno) |
131 |
|
|
nextpage(); |
132 |
|
|
fputs(PUNINIT, stdout); |
133 |
|
|
} else { |
134 |
|
|
comargs[0] = '\0'; |
135 |
|
|
while (argc) { |
136 |
|
|
strcat(comargs, " "); |
137 |
|
|
strcat(comargs, *argv); |
138 |
|
|
argv++; |
139 |
|
|
argc--; |
140 |
|
|
} |
141 |
|
|
sprintf(command, XCOM, comargs); |
142 |
|
|
if (condonly) |
143 |
|
|
return(system(command)); |
144 |
|
|
else { |
145 |
|
|
fputs(PINIT, stdout); |
146 |
|
|
if ((fp = popen(command, "r")) == NULL) |
147 |
|
|
error(SYSTEM, "cannot execute input filter"); |
148 |
|
|
plot(fp); |
149 |
|
|
pclose(fp); |
150 |
|
|
if (lineno) |
151 |
|
|
nextpage(); |
152 |
|
|
fputs(PUNINIT, stdout); |
153 |
|
|
} |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
return(0); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
|
160 |
schorsch |
1.4 |
void |
161 |
|
|
thispage(void) /* rewind and initialize current page */ |
162 |
greg |
1.1 |
{ |
163 |
|
|
if (lineno) |
164 |
|
|
error(USER, "cannot restart page in thispage"); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
|
168 |
schorsch |
1.4 |
void |
169 |
|
|
nextpage(void) /* advance to next page */ |
170 |
greg |
1.1 |
{ |
171 |
|
|
fputs("\r\f", stdout); |
172 |
|
|
|
173 |
|
|
lineno = 0; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|
177 |
schorsch |
1.4 |
void |
178 |
|
|
contpage(void) /* continue new plot on current page */ |
179 |
greg |
1.1 |
{ |
180 |
|
|
while (lineno++ < NLINES) |
181 |
|
|
putc('\n', stdout); |
182 |
|
|
|
183 |
|
|
lineno = 0; |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
schorsch |
1.4 |
void |
188 |
|
|
printspan(void) /* output span to printer */ |
189 |
greg |
1.1 |
{ |
190 |
|
|
register int i,j; |
191 |
|
|
|
192 |
|
|
if (spanmin <= spanmax) { |
193 |
|
|
j = spanmin/charwidth; |
194 |
|
|
while (j--) |
195 |
|
|
putc(' ', stdout); |
196 |
|
|
|
197 |
|
|
fputs(GRPH, stdout); |
198 |
|
|
j = spanmin%charwidth; |
199 |
|
|
putc((spanmax-spanmin+j+1)%256, stdout); |
200 |
|
|
putc((spanmax-spanmin+j+1)/256, stdout); |
201 |
|
|
|
202 |
|
|
j *= 3; |
203 |
|
|
while (j--) |
204 |
|
|
putc('\0', stdout); |
205 |
|
|
|
206 |
|
|
for (i = spanmin; i <= spanmax; i++) |
207 |
|
|
for (j = 2; j >= 0; j--) |
208 |
|
|
putc(outspan.cols[j*dxsize + i], stdout); |
209 |
|
|
} |
210 |
|
|
fputs("\r\n", stdout); |
211 |
|
|
lineno++; |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
|
215 |
schorsch |
1.4 |
void |
216 |
|
|
printstr( /* output a string to the printer */ |
217 |
|
|
PRIMITIVE *p |
218 |
|
|
) |
219 |
greg |
1.1 |
{ |
220 |
|
|
int i; |
221 |
|
|
|
222 |
|
|
i = CONV(p->xy[XMN], dxsize)/charwidth; |
223 |
|
|
while (i--) |
224 |
|
|
putc(' ', stdout); |
225 |
|
|
|
226 |
|
|
if (p->arg0 & 0100) /* double strike */ |
227 |
|
|
fputs(DBLON, stdout); |
228 |
|
|
|
229 |
|
|
fputs(chrtype[(p->arg0 >> 2) & 017], stdout); |
230 |
|
|
fputs(p->args, stdout); |
231 |
|
|
fputs(PNORM, stdout); |
232 |
|
|
putc('\r', stdout); |
233 |
|
|
|
234 |
|
|
} |