1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* qmsf.c - output filter for qms printers
*
* Copyright 1985 Massachusetts Institute of Technology
* Author: CJL@OZ
*
*
*/
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include "util.h"
#include "fonts.h"
/* \122 = 'R'. The MOBY_RESET string is constructed this way so
* this source text can be printed out on a QMS printer without resetting
* the printer. */
#define MOBY_RESET "\122eSeTrEsEtReSeT"
#define QUIC_ON "\r^PY^-\r"
#define QUIC_OFF "\r^-^PN^-\r"
#define DEFAULT_FONT "^IS%05.5d^-"
#define DELETE_FONTS "^DFEA^G^-"
#define CLEAR_OVERLAYS "^DOC^Z^-"
#define SYNTAX "^ISYNTAX%1.1d%1.1d%1.1d%1.1d%1.1d^-"
#define PORTRAIT "^IOP^-"
#define V_MARGINS "^IMV%05.5d%05.5d^-"
#define H_MARGINS "^IMH%05.5d%05.5d^-"
#define TRAY "^IF%1.1d%1.1d%1.1d%1.1d^-"
#define CHAR_SP "^IC%04.4d^-"
#define LINE_SP "^IL%04.4d^-"
extern char *rindex();
char *programname;
long charvec[4];
int devwidth,texwidth;
int ready = 0;
int length = 66;
int width = 94;
int charpos,charcol,onfirstpage;
int qms2400 = 0;
init_qms()
{
int i;
char *s = PXLDIR;
/* Reset the printer.
* We can assume nothing about the current state of the printer.
* So first set the printer to a known state.
*/
printf(MOBY_RESET); /* MOBY reset */
printf(QUIC_ON); /* Turn on QUIC */
/* printf(DELETE_FONTS); */ /* Delete all downloaded fonts */
printf(CLEAR_OVERLAYS); /* Clear all overlays */
printf(MOBY_RESET); /* MOBY reset again */
printf(QUIC_ON); /* Turn on QUIC */
printf(SYNTAX,0,0,0,0,0); /* Ensure default SYNTAX */
printf(PORTRAIT); /* Portrait page orientation */
printf(V_MARGINS,250,11000); /* Vertical margins */
printf(H_MARGINS,890,8500); /* Horizontal margins */
printf(CHAR_SP,0); /* Turn off char spacing */
printf(LINE_SP,620); /* Vertical spacing */
printf(DEFAULT_FONT,10); /* Select the font I like */
printf(SYNTAX,0,0,0,1,0); /* Ensure default SYNTAX */
if (qms2400)
printf(TRAY,0,0,0,1); /* Take first page from tray 2 */
f_init(stdout,programname,&s,1,10,157876,1000,0);
for (i = ' ';i < 0377;i++) charvec[i / 32] |= (1 << (i % 32));
f_define_font(1,0,"","amtt10",1095,717619,0);
i = 1;
f_newpage(&i,charvec,1);
f_use_font(1,&i);
onfirstpage = ready = 1;
charpos = charcol = 0;
};
dev_print_log()
{
}
term_qms()
{
if (ready) {
dochar('\f');
ready = 0;
}
printf(QUIC_OFF);
fflush(stdout);
};
main(argc, argv)
int argc;
char *argv[];
{
register int ch;
int i;
programname = argv[0];
if (!access("qms2400",0)) qms2400 = -1;
for (i = 0; i < argc; i++) {
if (argv[i][0] = '-') switch (argv[i][1]) {
case 'w':
sscanf(argv[i]+2,"%d",&width);
break;
case 'l':
sscanf(argv[i]+2,"%d",&length);
break;
}
}
while (!ferror(stdin) && (ch = getchar()) != EOF) switch (ch) {
case '\031':
/*
* lpd needs to use a different filter to
* print data so stop what we are doing and
* wait for lpd to restart us.
*/
if ((ch = getchar()) == '\1') {
term_qms();
kill(getpid(), SIGSTOP);
break;
} else {
ungetc(ch, stdin);
ch = '\031';
}
default:
dochar(ch);
}
term_qms();
exit(0);
}
dochar (ch)
int ch;
{
int i;
if (ch < ' ')
switch (ch) {
case '\b':
if (!ready) break;
if (charpos) {
charpos--;
printf("^TR-%04.4d",devwidth);
}
break;
case '\t':
if (!ready) init_qms();
for (i = 8 - charpos%8; i > 0; i--) dochar(' ');
break;
case '\n':
if (!ready) init_qms();
if (++charcol >= length) dochar('\f');
else {
putchar('\r');
putchar('\n');
charpos = 0;
}
break;
case '\r':
if (!ready) break;
if (charpos != 0) {
charpos = 0;
putchar('\r');
}
break;
case '\f':
if (!ready || ((charpos == 0) && (charcol == 0))) break;
charpos = 0;
charcol = 0;
putchar('\f');
i = 1;
f_newpage(&i,charvec,1);
f_use_font(1,&i);
fflush(stdout);
if (qms2400 && onfirstpage) {
printf(TRAY,2,0,0,0); /* Take rest of paper from tray 1 */
}
onfirstpage = 0;
break;
default:
if (!ready) init_qms();
dochar('^'); dochar('\b'); dochar('|');
dochar(ch+'A'-001);
break;
} else {
if (!ready) init_qms();
if (++charpos > width) {
putchar('!');
dochar('\n');
dochar(ch);
} else {
f_use_char(ch,&texwidth,&devwidth);
switch (ch) {
case ' ':
printf("^TR%04.4d",devwidth);
break;
case '^':
putchar(ch);
default:
putchar(ch);
}
}
}
}
|