Bell 32V release
[unix-history] / usr / src / cmd / vpr.c
CommitLineData
3a0850a9
TL
1/*
2 * vpr -- Versatek printer filter
3 */
4
5#include <stdio.h>
6
7#define LINELN 132
8#define EJLINE 63
9#define SETSTATE (('v'<<8)+1)
10
11int anydone;
12char linebuf[LINELN+2];
13int sppmode[] = {0400, 0, 0};
14int pltmode[] = {0200, 0, 0};
15int clrcom[] = {0404, 0, 0};
16int termcom[] = {0240, 0, 0};
17int prtmode[] = {0100, 0, 0};
18int ov;
19char ovbuf[2*LINELN];
20FILE *in = stdin;
21FILE *out;
22char *ban;
23int npages = 1;
24char chrtab[][16];
25int lineno;
26char *ctime();
27
28main(argc, argv)
29char **argv;
30{
31
32 if ((out = fopen("/dev/vp0", "w")) == NULL) {
33 fprintf(stderr, "Can't open printer\n");
34 exit(1);
35 }
36 if (argc > 2 && argv[1][0]=='-' && argv[1][1]=='b') {
37 argc -= 2;
38 banner(ban = argv[2]);
39 argv += 2;
40 }
41 if (argc<=1)
42 anydone |= send();
43 else while (argc>1) {
44 if ((in = fopen(argv[1], "r")) == NULL) {
45 fprintf(stderr, "Can't find %s\n", argv[1]);
46 argv++;
47 argc--;
48 anydone |= 01;
49 continue;
50 }
51 anydone |= send();
52 argc--;
53 argv++;
54 fclose(in);
55 fprintf(out, "\014");
56 }
57 if (anydone==0)
58 exit(1);
59 fprintf(out, "\004");
60 if (ferror(out)) {
61 fprintf(out, "Printer IO error\n");
62 exit(1);
63 }
64 fclose(out);
65 if (ban && access("/usr/adm/vpacct", 02)>=0
66 && (out = fopen("/usr/adm/vpacct", "a"))!=NULL) {
67 fprintf(out, "%4d %s\n", npages, ban);
68 }
69 return(0);
70}
71
72send()
73{
74 register nskipped;
75
76 lineno = 0;
77 nskipped = 0;
78 while (getline()) {
79 if (lineno==0 && linebuf[0]==0 && nskipped<3) {
80 nskipped ++;
81 continue;
82 }
83 if (lineno >= EJLINE) {
84 nskipped = 0;
85 putline(1);
86 lineno = 0;
87 } else {
88 putline(0);
89 lineno++;
90 }
91 }
92 if (lineno>0)
93 npages++;
94 return(1);
95}
96
97getline()
98{
99 register col, maxcol, c;
100
101 ov = 0;
102 for (col=0; col<LINELN; col++) {
103 linebuf[col] = ' ';
104 ovbuf[2*col] = ovbuf[2*col+1] = 0;
105 }
106 col = 8;
107 maxcol = 0;
108 for (;;) switch (c = getc(in)) {
109
110 case EOF:
111 return(0);
112
113 default:
114 if (c>=' ') {
115 if (col < LINELN) {
116 if (linebuf[col]=='_') {
117 ov++;
118 ovbuf[2*col] = 0377;
119 ovbuf[2*col+1] = 0377;
120 }
121 linebuf[col++] = c;
122 if (col > maxcol)
123 maxcol = col;
124 }
125 }
126 continue;
127
128 case '\f':
129 lineno = EJLINE;
130 continue;
131 case ' ':
132 col++;
133 continue;
134
135
136 case '\t':
137 col = (col|07) + 1;
138 if (col>maxcol)
139 maxcol = col;
140 continue;
141
142 case '\r':
143 col = 0;
144 continue;
145
146 case '_':
147 if (col>=LINELN) {
148 col++;
149 continue;
150 }
151 if (linebuf[col]!=' ') {
152 ovbuf[2*col] = 0377;
153 ovbuf[2*col+1] = 0377;
154 ov++;
155 } else
156 linebuf[col] = c;
157 col++;
158 if (col>maxcol)
159 maxcol = col;
160 continue;
161
162 case '\n':
163 if (maxcol>=LINELN)
164 maxcol = LINELN;
165 linebuf[maxcol] = 0;
166 return(1);
167
168 case '\b':
169 if (col>0)
170 col--;
171 continue;
172 }
173}
174
175putline(ff)
176{
177 register char *lp;
178 register c;
179 extern errno;
180
181 errno = 0;
182 lp = linebuf;
183 while (c = *lp++)
184 putc(c, out);
185 if (ov) {
186 putc('\n', out);
187 fflush(out);
188 ioctl(fileno(out), SETSTATE, pltmode);
189 for (lp=ovbuf; lp < &ovbuf[2*LINELN]; )
190 putc(*lp++, out);
191 fflush(out);
192 ioctl(fileno(out), SETSTATE, prtmode);
193 }
194 if (ff) {
195 putc('\014', out);
196 npages++;
197 } else if (ov==0)
198 putc('\n', out);
199 if (ferror(out)) {
200 printf("Printer IO error\n");
201 exit(1);
202 }
203}
204
205banner(s)
206char *s;
207{
208 long timeb;
209 register char *sp;
210 int i, j, t;
211
212 fprintf(out, "\n\n\n\n\n\n\n\n");
213 for (i=0; i<16; i++) {
214 fprintf(out, " ");
215 for (sp=s; *sp; sp++) {
216 if (*sp<=' '|| *sp >'}')
217 continue;
218 fprintf(out, " ");
219 t = chrtab[*sp - ' '][i];
220 for (j=7; j>=0; j--)
221 if ((t>>j) & 01)
222 putc('X', out);
223 else
224 putc(' ', out);
225 }
226 putc('\n', out);
227 }
228 fprintf(out, "\n\n\n\n\n\n\n\n");
229 time(&timeb);
230 fprintf(out, " ");
231 fprintf(out, ctime(&timeb));
232 fprintf(out, "\014");
233}
234
235char chrtab[][16] = {
2360000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */
2370010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */
2380024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */
2390000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */
2400000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */
2410000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */
2420000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */
2430004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */
2440000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */
2450000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */
2460000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */
2470000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */
2480000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */
2490000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */
2500000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */
2510000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */
2520000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */
2530000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */
2540000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */
2550000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */
2560000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */
2570000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */
2580000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */
2590000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */
2600000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */
2610000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */
2620000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */
2630000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */
2640002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */
2650000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */
2660100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */
2670000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */
2680000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */
2690000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */
2700000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */
2710000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */
2720000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */
2730000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */
2740000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */
2750000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */
2760000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */
2770000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */
2780000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */
2790000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */
2800000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */
2810000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */
2820000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */
2830000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */
2840000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */
2850000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */
2860000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */
2870000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */
2880000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */
2890000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */
2900000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */
2910000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */
2920000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */
2930000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */
2940000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */
2950000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */
2960000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */
2970000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */
2980010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */
2990000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */
3000040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */
3010000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */
3020000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */
3030000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */
3040002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */
3050000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */
3060000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */
3070000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */
3080000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */
3090000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */
3100000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */
3110000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */
3120000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */
3130000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */
3140000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */
3150000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */
3160000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */
3170000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */
3180000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */
3190000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */
3200000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */
3210000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */
3220000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */
3230000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */
3240000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */
3250000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */
3260000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */
3270000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */
3280000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */
3290000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */
3300020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */
3310000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */
332};