Annotation of 42BSD/old/vpr/vpf.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.