|
|
1.1 ! root 1: /* ! 2: * vpr -- Versatec printer filter ! 3: */ ! 4: ! 5: #include <stdio.h> ! 6: #include <sgtty.h> ! 7: ! 8: #define LINELN 440 ! 9: #define EJLINE 66 ! 10: #define SETSTATE (('v'<<8)|1) ! 11: ! 12: int anydone; ! 13: char linebuf[LINELN+2]; ! 14: int sppmode[] = {0400, 0, 0}; ! 15: int pltmode[] = {0200, 0, 0}; ! 16: int clrcom[] = {0404, 0, 0}; ! 17: int termcom[] = {0240, 0, 0}; ! 18: int prtmode[] = {0100, 0, 0}; ! 19: int ov; ! 20: char ovbuf[LINELN]; ! 21: FILE *in = {stdin}; ! 22: /* FILE *out; */ ! 23: #define out stdout ! 24: char *ban; ! 25: int npages = 1; ! 26: char chrtab[][16]; ! 27: int lineno; ! 28: ! 29: main(argc, argv) ! 30: char **argv; ! 31: { ! 32: register int i; ! 33: char obuf[BUFSIZ]; ! 34: ! 35: setbuf(stdout, obuf); ! 36: /* vtex comes open on 3 from parent so don't feed paper after each file */ ! 37: close(1); ! 38: dup(3); ! 39: close(3); ! 40: ioctl(1, SETSTATE, prtmode); ! 41: /* ! 42: if ((out = fopen("/dev/vp0", "w")) == NULL) { ! 43: fprintf(stderr, "Can't open printer\n"); ! 44: exit(1); ! 45: } ! 46: */ ! 47: if (argc > 2 && argv[1][0]=='-' && argv[1][1]=='b') { ! 48: argc -= 2; ! 49: banner(ban = argv[2]); ! 50: argv += 2; ! 51: } ! 52: if (argc<=1) ! 53: anydone |= send(); ! 54: else while (argc>1) { ! 55: if ((in = fopen(argv[1], "r")) == NULL) { ! 56: fprintf(stderr, "Can't find %s\n", argv[1]); ! 57: argv++; ! 58: argc--; ! 59: anydone |= 01; ! 60: continue; ! 61: } ! 62: anydone |= send(); ! 63: argc--; ! 64: argv++; ! 65: fclose(in); ! 66: /* ! 67: fprintf(out, "\014"); ! 68: */ ! 69: } ! 70: if (anydone==0) ! 71: exit(1); ! 72: /* ! 73: fprintf(out, "\004"); ! 74: if (ferror(out)) { ! 75: fprintf(out, "Printer IO error\n"); ! 76: exit(1); ! 77: } ! 78: */ ! 79: if (ban && access("/usr/adm/vpacct", 02)>=0 ! 80: && freopen("/usr/adm/vpacct", "a", out) !=NULL) { ! 81: fprintf(out, "%7.2f\t%s\n", npages * (11.0 / 12.0), ban); ! 82: } ! 83: return(0); ! 84: } ! 85: ! 86: send() ! 87: { ! 88: register nskipped; ! 89: ! 90: lineno = 0; ! 91: nskipped = 0; ! 92: while (getline()) { ! 93: /* ! 94: if (lineno==0 && linebuf[0]==0 && nskipped<3) { ! 95: nskipped ++; ! 96: continue; ! 97: } ! 98: if (lineno >= EJLINE) { ! 99: nskipped = 0; ! 100: putline(1); ! 101: lineno = 0; ! 102: } else { ! 103: */ ! 104: putline(0); ! 105: lineno++; ! 106: /* ! 107: } ! 108: */ ! 109: } ! 110: npages = (lineno + EJLINE - 1) / EJLINE; ! 111: return(1); ! 112: } ! 113: ! 114: getline() ! 115: { ! 116: register col, maxcol, c; ! 117: ! 118: ov = 0; ! 119: for (col=0; col<LINELN; col++) { ! 120: linebuf[col] = ' '; ! 121: ovbuf[col] = 0; ! 122: } ! 123: col = 0; ! 124: maxcol = 0; ! 125: for (;;) switch (c = getc(in)) { ! 126: ! 127: case EOF: ! 128: return(0); ! 129: ! 130: default: ! 131: if (c>=' ') { ! 132: if (col < LINELN) { ! 133: if (linebuf[col]=='_') { ! 134: ov++; ! 135: ovbuf[col] = 0377; ! 136: } ! 137: linebuf[col++] = c; ! 138: if (col > maxcol) ! 139: maxcol = col; ! 140: } ! 141: } ! 142: continue; ! 143: ! 144: case '\f': ! 145: lineno = EJLINE; ! 146: continue; ! 147: ! 148: case ' ': ! 149: col++; ! 150: continue; ! 151: ! 152: case '\t': ! 153: col = (col|07) + 1; ! 154: if (col>maxcol) ! 155: maxcol = col; ! 156: continue; ! 157: ! 158: case '\r': ! 159: col = 0; ! 160: continue; ! 161: ! 162: case '_': ! 163: if (col>=LINELN) { ! 164: col++; ! 165: continue; ! 166: } ! 167: if (linebuf[col]!=' ') { ! 168: ovbuf[col] = 0377; ! 169: ov++; ! 170: } else ! 171: linebuf[col] = c; ! 172: col++; ! 173: if (col>maxcol) ! 174: maxcol = col; ! 175: continue; ! 176: ! 177: case '\n': ! 178: if (maxcol>=LINELN) ! 179: maxcol = LINELN; ! 180: linebuf[maxcol] = 0; ! 181: return(1); ! 182: ! 183: case '\b': ! 184: if (col>0) ! 185: col--; ! 186: continue; ! 187: } ! 188: } ! 189: ! 190: putline(ff) ! 191: { ! 192: register char *lp; ! 193: register c, i; ! 194: extern errno; ! 195: ! 196: errno = 0; ! 197: lp = linebuf; ! 198: while (c = *lp++) ! 199: putc(c, out); ! 200: if (ov) { ! 201: putc('\n', out); ! 202: fflush(out); ! 203: ioctl(fileno(out), SETSTATE, &pltmode); ! 204: for (lp=ovbuf; lp < &ovbuf[LINELN]; ) { ! 205: putc(*lp & 0377, out); ! 206: putc(*lp++ & 0377, out); ! 207: } ! 208: fflush(out); ! 209: ioctl(fileno(out), SETSTATE, &prtmode); ! 210: } ! 211: if (ff) { ! 212: putc('\014', out); ! 213: npages++; ! 214: } else if (ov==0) ! 215: putc('\n', out); ! 216: if (ferror(out)) { ! 217: fprintf(stderr, "Printer IO error\n"); ! 218: exit(1); ! 219: } ! 220: } ! 221: ! 222: banner(s) ! 223: char *s; ! 224: { ! 225: long timeb; ! 226: register int i; ! 227: ! 228: time(&timeb); ! 229: fprintf(out, "\n\n%s: %s", s, ctime(&timeb)); ! 230: for (i = 0; i < LINELN; i++) ! 231: putc('_', out); ! 232: putc('\n', out); ! 233: fflush(out); ! 234: /* ! 235: register char *sp; ! 236: int i, j, t; ! 237: ! 238: fprintf(out, "\n\n\n\n\n\n\n\n"); ! 239: for (i=0; i<16; i++) { ! 240: fprintf(out, " "); ! 241: for (sp=s; *sp; sp++) { ! 242: if (*sp<=' '|| *sp >'}') ! 243: continue; ! 244: fprintf(out, " "); ! 245: t = chrtab[*sp - ' '][i]; ! 246: for (j=7; j>=0; j--) ! 247: if ((t>>j) & 01) ! 248: putc('X', out); ! 249: else ! 250: putc(' ', out); ! 251: } ! 252: putc('\n', out); ! 253: } ! 254: fprintf(out, "\n\n\n\n\n\n\n\n"); ! 255: time(&timeb); ! 256: fprintf(out, " "); ! 257: fprintf(out, ctime(&timeb)); ! 258: fprintf(out, "\014"); ! 259: */ ! 260: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.