home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / vpr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  12.1 KB  |  333 lines

  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.  
  11. int    anydone;
  12. char    linebuf[LINELN+2];
  13. int    sppmode[]    = {0400, 0, 0};
  14. int    pltmode[]    = {0200, 0, 0};
  15. int    clrcom[]    = {0404, 0, 0};
  16. int    termcom[]    = {0240, 0, 0};
  17. int    prtmode[]    = {0100, 0, 0};
  18. int    ov;
  19. char    ovbuf[2*LINELN];
  20. FILE    *in    = stdin;
  21. FILE    *out;
  22. char    *ban;
  23. int    npages    = 1;
  24. char    chrtab[][16];
  25. int    lineno;
  26. char    *ctime();
  27.  
  28. main(argc, argv)
  29. char **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.  
  72. send()
  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.  
  97. getline()
  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.  
  175. putline(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.  
  205. banner(s)
  206. char *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.  
  235. char    chrtab[][16] = {
  236. 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */
  237. 0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */
  238. 0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */
  239. 0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */
  240. 0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */
  241. 0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */
  242. 0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */
  243. 0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */
  244. 0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */
  245. 0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */
  246. 0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */
  247. 0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */
  248. 0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */
  249. 0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */
  250. 0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */
  251. 0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */
  252. 0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */
  253. 0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */
  254. 0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */
  255. 0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */
  256. 0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */
  257. 0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */
  258. 0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */
  259. 0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */
  260. 0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */
  261. 0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */
  262. 0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */
  263. 0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */
  264. 0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */
  265. 0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */
  266. 0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */
  267. 0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */
  268. 0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */
  269. 0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */
  270. 0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */
  271. 0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */
  272. 0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */
  273. 0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */
  274. 0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */
  275. 0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */
  276. 0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */
  277. 0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */
  278. 0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */
  279. 0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */
  280. 0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */
  281. 0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */
  282. 0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */
  283. 0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */
  284. 0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */
  285. 0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */
  286. 0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */
  287. 0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */
  288. 0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */
  289. 0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */
  290. 0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */
  291. 0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */
  292. 0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */
  293. 0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */
  294. 0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */
  295. 0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */
  296. 0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */
  297. 0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */
  298. 0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */
  299. 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */
  300. 0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */
  301. 0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */
  302. 0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */
  303. 0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */
  304. 0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */
  305. 0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */
  306. 0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */
  307. 0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */
  308. 0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */
  309. 0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */
  310. 0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */
  311. 0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */
  312. 0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */
  313. 0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */
  314. 0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */
  315. 0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */
  316. 0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */
  317. 0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */
  318. 0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */
  319. 0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */
  320. 0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */
  321. 0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */
  322. 0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */
  323. 0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */
  324. 0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */
  325. 0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */
  326. 0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */
  327. 0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */
  328. 0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */
  329. 0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */
  330. 0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */
  331. 0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */
  332. };
  333.