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