1 #ifndef lint 2 static char sccsid[] = "@(#)vpltdmp.c 4.5 (Berkeley) 07/16/83"; 3 #endif 4 5 /* 6 * Copyright (C) 1981, Regents of the University of California 7 * All rights reserved 8 * 9 * reads raster file created by vplot and dumps it onto the 10 * Varian or Versatec plotter. 11 * Input comes from file descriptor 0, output is to file descriptor 1. 12 */ 13 #include <stdio.h> 14 #include <sys/vcmd.h> 15 16 #define IN 0 17 #define OUT 1 18 19 static char *Sid = "@(#)vpltdmp.c 4.5\t07/16/83"; 20 21 int plotmd[] = { VPLOT }; 22 int prtmd[] = { VPRINT }; 23 24 char buf[BUFSIZ]; /* output buffer */ 25 26 int lines; /* number of raster lines printed */ 27 int varian; /* 0 for versatec, 1 for varian. */ 28 int BYTES_PER_LINE; /* number of bytes per raster line. */ 29 int PAGE_LINES; /* number of raster lines per page. */ 30 31 char *name, *host, *acctfile; 32 33 main(argc, argv) 34 int argc; 35 char *argv[]; 36 { 37 register int n; 38 39 while (--argc) { 40 if (**++argv == '-') { 41 switch (argv[0][1]) { 42 case 'x': 43 BYTES_PER_LINE = atoi(&argv[0][2]) / 8; 44 varian = BYTES_PER_LINE == 264; 45 break; 46 47 case 'y': 48 PAGE_LINES = atoi(&argv[0][2]); 49 break; 50 51 case 'n': 52 argc--; 53 name = *++argv; 54 break; 55 56 case 'h': 57 argc--; 58 host = *++argv; 59 } 60 } else 61 acctfile = *argv; 62 } 63 64 n = putplot(); 65 66 ioctl(OUT, VSETSTATE, prtmd); 67 if (varian) 68 write(OUT, "\f", 2); 69 else 70 write(OUT, "\n\n\n\n\n", 6); 71 account(name, host, *argv); 72 exit(n); 73 } 74 75 putplot() 76 { 77 register char *cp; 78 register int bytes, n; 79 80 cp = buf; 81 bytes = 0; 82 ioctl(OUT, VSETSTATE, plotmd); 83 while ((n = read(IN, cp, sizeof(buf))) > 0) { 84 if (write(OUT, cp, n) != n) 85 return(1); 86 bytes += n; 87 } 88 /* 89 * Make sure we send complete raster lines. 90 */ 91 if ((n = bytes % BYTES_PER_LINE) > 0) { 92 n = BYTES_PER_LINE - n; 93 for (cp = &buf[n]; cp > buf; ) 94 *--cp = 0; 95 if (write(OUT, cp, n) != n) 96 return(1); 97 bytes += n; 98 } 99 lines += bytes / BYTES_PER_LINE; 100 return(0); 101 } 102 103 account(who, from, acctfile) 104 char *who, *from, *acctfile; 105 { 106 register FILE *a; 107 108 if (who == NULL || acctfile == NULL) 109 return; 110 if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL) 111 return; 112 /* 113 * Varian accounting is done by 8.5 inch pages; 114 * Versatec accounting is by the (12 inch) foot. 115 */ 116 fprintf(a, "t%6.2f\t", (lines / 200.0) / PAGE_LINES); 117 if (from != NULL) 118 fprintf(a, "%s:", from); 119 fprintf(a, "%s\n", who); 120 fclose(a); 121 } 122