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