| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
schorsch |
1.3 |
static const char RCSid[] = "$Id: mt160.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 mt160 mt160.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o |
| 8 |
|
|
* |
| 9 |
|
|
* Mannesman Tally MT160 high-speed |
| 10 |
|
|
*/ |
| 11 |
|
|
|
| 12 |
|
|
|
| 13 |
|
|
#define MAXALLOC 5000 |
| 14 |
|
|
|
| 15 |
|
|
#define DXSIZE 532 /* x resolution */ |
| 16 |
|
|
|
| 17 |
|
|
#define DYSIZE 512 /* 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 to plot */ |
| 24 |
|
|
|
| 25 |
|
|
#define CHARWIDTH 4 |
| 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 OUTPUT "\033%5" |
| 38 |
|
|
|
| 39 |
|
|
#define XCOM "pexpand +vOCIsp %s | psort -Y +x" |
| 40 |
|
|
|
| 41 |
|
|
|
| 42 |
schorsch |
1.3 |
#include "rtprocess.h" |
| 43 |
greg |
1.1 |
#include "meta.h" |
| 44 |
|
|
#include "plot.h" |
| 45 |
|
|
#include "span.h" |
| 46 |
|
|
|
| 47 |
|
|
|
| 48 |
|
|
char *progname; |
| 49 |
|
|
|
| 50 |
|
|
struct span outspan; |
| 51 |
|
|
|
| 52 |
|
|
int dxsize = DXSIZE, dysize = DYSIZE, |
| 53 |
|
|
linwidt = LINWIDT, linhite = LINHITE, |
| 54 |
|
|
nrows = (LINHITE-1)/8+1; |
| 55 |
|
|
|
| 56 |
|
|
int maxalloc = MAXALLOC; |
| 57 |
|
|
|
| 58 |
|
|
int spanmin = 0, spanmax = LINWIDT-1; |
| 59 |
|
|
|
| 60 |
|
|
int charwidth = CHARWIDTH; |
| 61 |
|
|
|
| 62 |
|
|
static char chrtype[16][5] = { |
| 63 |
|
|
"\033[4w", |
| 64 |
|
|
"\033[0w", |
| 65 |
|
|
"\033[4w", |
| 66 |
|
|
"\033[0w", |
| 67 |
|
|
"\033[5w", |
| 68 |
|
|
"\033[1w", |
| 69 |
|
|
"\033[5w", |
| 70 |
|
|
"\033[1w", |
| 71 |
|
|
"\033[6w", |
| 72 |
|
|
"\033[2w", |
| 73 |
|
|
"\033[6w", |
| 74 |
|
|
"\033[2w", |
| 75 |
|
|
"\033[7w", |
| 76 |
|
|
"\033[3w", |
| 77 |
|
|
"\033[7w", |
| 78 |
|
|
"\033[3w" |
| 79 |
|
|
}; |
| 80 |
|
|
|
| 81 |
|
|
static int lineno = 0; |
| 82 |
|
|
|
| 83 |
|
|
static short condonly = FALSE, |
| 84 |
|
|
conditioned = FALSE; |
| 85 |
|
|
|
| 86 |
|
|
|
| 87 |
|
|
main(argc, argv) |
| 88 |
|
|
|
| 89 |
|
|
int argc; |
| 90 |
|
|
char **argv; |
| 91 |
|
|
|
| 92 |
|
|
{ |
| 93 |
|
|
FILE *fp; |
| 94 |
|
|
char comargs[200], command[300]; |
| 95 |
|
|
|
| 96 |
|
|
progname = *argv++; |
| 97 |
|
|
argc--; |
| 98 |
|
|
|
| 99 |
|
|
condonly = FALSE; |
| 100 |
|
|
conditioned = FALSE; |
| 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 |
|
|
|
| 161 |
|
|
|
| 162 |
|
|
|
| 163 |
|
|
|
| 164 |
|
|
thispage() /* rewind and initialize current page */ |
| 165 |
|
|
|
| 166 |
|
|
{ |
| 167 |
|
|
|
| 168 |
|
|
if (lineno) |
| 169 |
|
|
error(USER, "cannot restart page in thispage"); |
| 170 |
|
|
|
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
|
| 174 |
|
|
|
| 175 |
|
|
|
| 176 |
|
|
nextpage() /* advance to next page */ |
| 177 |
|
|
|
| 178 |
|
|
{ |
| 179 |
|
|
|
| 180 |
|
|
fputs("\f\r", stdout); |
| 181 |
|
|
|
| 182 |
|
|
lineno = 0; |
| 183 |
|
|
|
| 184 |
|
|
} |
| 185 |
|
|
|
| 186 |
|
|
|
| 187 |
|
|
|
| 188 |
|
|
contpage() /* continue new plot on current page */ |
| 189 |
|
|
|
| 190 |
|
|
{ |
| 191 |
|
|
|
| 192 |
|
|
while (lineno++ < NLINES) |
| 193 |
|
|
putc('\n', stdout); |
| 194 |
|
|
|
| 195 |
|
|
lineno = 0; |
| 196 |
|
|
|
| 197 |
|
|
} |
| 198 |
|
|
|
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
|
|
printspan() /* output span to printer */ |
| 202 |
|
|
|
| 203 |
|
|
{ |
| 204 |
|
|
register i; |
| 205 |
|
|
|
| 206 |
|
|
if (spanmin <= spanmax) { |
| 207 |
|
|
|
| 208 |
|
|
i = spanmin/charwidth; |
| 209 |
|
|
while (i--) |
| 210 |
|
|
putc(' ', stdout); |
| 211 |
|
|
|
| 212 |
|
|
i = spanmin%charwidth; |
| 213 |
|
|
fputs(OUTPUT, stdout); |
| 214 |
|
|
putc((spanmax-spanmin+i+1)%256, stdout); |
| 215 |
|
|
putc((spanmax-spanmin+i+1)/256, stdout); |
| 216 |
|
|
while (i--) |
| 217 |
|
|
putc('\0', stdout); |
| 218 |
|
|
|
| 219 |
|
|
for (i = spanmin; i <= spanmax; i++) |
| 220 |
|
|
putc(outspan.cols[i], stdout); |
| 221 |
|
|
|
| 222 |
|
|
putc('\r', stdout); |
| 223 |
|
|
} |
| 224 |
|
|
|
| 225 |
|
|
putc('\n', stdout); |
| 226 |
|
|
lineno++; |
| 227 |
|
|
|
| 228 |
|
|
} |
| 229 |
|
|
|
| 230 |
|
|
|
| 231 |
|
|
|
| 232 |
|
|
|
| 233 |
|
|
|
| 234 |
|
|
|
| 235 |
|
|
|
| 236 |
|
|
printstr(p) /* output a string to the printer */ |
| 237 |
|
|
|
| 238 |
|
|
PRIMITIVE *p; |
| 239 |
|
|
|
| 240 |
|
|
{ |
| 241 |
|
|
int i; |
| 242 |
|
|
|
| 243 |
|
|
i = CONV(p->xy[XMN], dxsize)/charwidth; |
| 244 |
|
|
while (i--) |
| 245 |
|
|
putc(' ', stdout); |
| 246 |
|
|
|
| 247 |
|
|
if (p->arg0 & 0100) /* double strike */ |
| 248 |
|
|
fputs(DBLON, stdout); |
| 249 |
|
|
else |
| 250 |
|
|
fputs(DBLOFF, stdout); |
| 251 |
|
|
|
| 252 |
|
|
fputs(chrtype[(p->arg0 >> 2) & 017], stdout); |
| 253 |
|
|
fputs(p->args, stdout); |
| 254 |
|
|
fputs(PNORM, stdout); |
| 255 |
|
|
putc('\r', stdout); |
| 256 |
|
|
|
| 257 |
|
|
} |