| 1 |
greg |
1.1 |
#ifndef lint
|
| 2 |
schorsch |
1.4 |
static const char RCSid[] = "$Id: mt160.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 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 |
schorsch |
1.4 |
int
|
| 88 |
|
|
main(
|
| 89 |
|
|
int argc,
|
| 90 |
|
|
char **argv
|
| 91 |
|
|
)
|
| 92 |
greg |
1.1 |
{
|
| 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 |
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("\f\r", 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 |
schorsch |
1.4 |
register int i;
|
| 191 |
greg |
1.1 |
|
| 192 |
|
|
if (spanmin <= spanmax) {
|
| 193 |
|
|
|
| 194 |
|
|
i = spanmin/charwidth;
|
| 195 |
|
|
while (i--)
|
| 196 |
|
|
putc(' ', stdout);
|
| 197 |
|
|
|
| 198 |
|
|
i = spanmin%charwidth;
|
| 199 |
|
|
fputs(OUTPUT, stdout);
|
| 200 |
|
|
putc((spanmax-spanmin+i+1)%256, stdout);
|
| 201 |
|
|
putc((spanmax-spanmin+i+1)/256, stdout);
|
| 202 |
|
|
while (i--)
|
| 203 |
|
|
putc('\0', stdout);
|
| 204 |
|
|
|
| 205 |
|
|
for (i = spanmin; i <= spanmax; i++)
|
| 206 |
|
|
putc(outspan.cols[i], stdout);
|
| 207 |
|
|
|
| 208 |
|
|
putc('\r', stdout);
|
| 209 |
|
|
}
|
| 210 |
|
|
|
| 211 |
|
|
putc('\n', stdout);
|
| 212 |
|
|
lineno++;
|
| 213 |
|
|
}
|
| 214 |
|
|
|
| 215 |
|
|
|
| 216 |
schorsch |
1.4 |
void
|
| 217 |
|
|
printstr( /* output a string to the printer */
|
| 218 |
|
|
PRIMITIVE *p
|
| 219 |
|
|
)
|
| 220 |
greg |
1.1 |
{
|
| 221 |
|
|
int i;
|
| 222 |
|
|
|
| 223 |
|
|
i = CONV(p->xy[XMN], dxsize)/charwidth;
|
| 224 |
|
|
while (i--)
|
| 225 |
|
|
putc(' ', stdout);
|
| 226 |
|
|
|
| 227 |
|
|
if (p->arg0 & 0100) /* double strike */
|
| 228 |
|
|
fputs(DBLON, stdout);
|
| 229 |
|
|
else
|
| 230 |
|
|
fputs(DBLOFF, stdout);
|
| 231 |
|
|
|
| 232 |
|
|
fputs(chrtype[(p->arg0 >> 2) & 017], stdout);
|
| 233 |
|
|
fputs(p->args, stdout);
|
| 234 |
|
|
fputs(PNORM, stdout);
|
| 235 |
|
|
putc('\r', stdout);
|
| 236 |
|
|
|
| 237 |
|
|
}
|