Commit | Line | Data |
---|---|---|
c936af6c | 1 | #ifndef lint |
984a125c | 2 | static char sccsid[] = "@(#)vpltdmp.c 4.6 (Berkeley) %G%"; |
c936af6c SL |
3 | #endif |
4 | ||
5 | /* | |
6 | * Copyright (C) 1981, Regents of the University of California | |
7 | * All rights reserved | |
a0263b98 RC |
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> | |
a0263b98 RC |
14 | #include <sys/vcmd.h> |
15 | ||
16 | #define IN 0 | |
17 | #define OUT 1 | |
18 | ||
984a125c | 19 | static char *Sid = "@(#)vpltdmp.c 4.6\t%G%"; |
a0263b98 | 20 | |
2d0289ae RC |
21 | int plotmd[] = { VPLOT }; |
22 | int prtmd[] = { VPRINT }; | |
a0263b98 RC |
23 | |
24 | char buf[BUFSIZ]; /* output buffer */ | |
25 | ||
26 | int lines; /* number of raster lines printed */ | |
2d0289ae RC |
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. */ | |
a0263b98 RC |
30 | |
31 | char *name, *host, *acctfile; | |
32 | ||
33 | main(argc, argv) | |
f4944e19 RC |
34 | int argc; |
35 | char *argv[]; | |
a0263b98 | 36 | { |
f4944e19 | 37 | register int n; |
a0263b98 | 38 | |
a0263b98 RC |
39 | while (--argc) { |
40 | if (**++argv == '-') { | |
41 | switch (argv[0][1]) { | |
2d0289ae RC |
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 | ||
a0263b98 RC |
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 | ||
f4944e19 | 64 | n = putplot(); |
a0263b98 RC |
65 | |
66 | ioctl(OUT, VSETSTATE, prtmd); | |
67 | if (varian) | |
dfc1084e | 68 | write(OUT, "\f", 2); |
a0263b98 RC |
69 | else |
70 | write(OUT, "\n\n\n\n\n", 6); | |
71 | account(name, host, *argv); | |
f4944e19 RC |
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); | |
a0263b98 RC |
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 | /* | |
dfc1084e | 113 | * Varian accounting is done by 8.5 inch pages; |
a0263b98 RC |
114 | * Versatec accounting is by the (12 inch) foot. |
115 | */ | |
984a125c | 116 | fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES); |
a0263b98 RC |
117 | if (from != NULL) |
118 | fprintf(a, "%s:", from); | |
119 | fprintf(a, "%s\n", who); | |
120 | fclose(a); | |
121 | } |