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: }

Defined functions

banner defined in line 228; used 1 times
  • in line 66
getline defined in line 120; used 1 times
  • in line 97
main defined in line 31; never used
putline defined in line 195; used 2 times
send defined in line 91; used 2 times

Defined variables

EJLINE defined in line 15; used 5 times
LINELN defined in line 14; used 8 times
ban defined in line 24; used 4 times
chrtab defined in line 28; used 1 times
linebuf defined in line 16; used 8 times
lineno defined in line 29; used 7 times
literal defined in line 26; used 4 times
npages defined in line 27; used 3 times
ov defined in line 19; used 5 times
ovbuf defined in line 20; used 5 times
pltmode defined in line 17; used 1 times
prtmode defined in line 18; used 2 times
wide defined in line 25; used 6 times

Defined macros

VAEJLINE defined in line 11; used 1 times
  • in line 15
VALINELN defined in line 9; used 1 times
  • in line 14
VPEJLINE defined in line 12; used 1 times
  • in line 61
VPLINELN defined in line 10; used 3 times
out defined in line 23; used 33 times
Last modified: 1982-08-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1506
Valid CSS Valid XHTML 1.0 Strict