xref: /original-bsd/old/vfilters/vpltdmp/vpltdmp.c (revision 79cf7955)
1 /*
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 the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 char copyright[] =
20 "@(#) Copyright (c) 1981 Regents of the University of California.\n\
21  All rights reserved.\n";
22 #endif /* not lint */
23 
24 #ifndef lint
25 static char sccsid[] = "@(#)vpltdmp.c	5.3 (Berkeley) 06/30/88";
26 #endif /* not lint */
27 
28 /*
29  *  reads raster file created by vplot and dumps it onto the
30  *  Varian or Versatec plotter.
31  *  Input comes from file descriptor 0, output is to file descriptor 1.
32  */
33 #include <stdio.h>
34 #include <sys/vcmd.h>
35 
36 #define IN	0
37 #define OUT	1
38 
39 static	char *Sid = "@(#)vpltdmp.c	5.3\t06/30/88";
40 
41 int	plotmd[] = { VPLOT };
42 int	prtmd[]  = { VPRINT };
43 
44 char	buf[BUFSIZ];		/* output buffer */
45 
46 int	lines;			/* number of raster lines printed */
47 int	varian;			/* 0 for versatec, 1 for varian. */
48 int	BYTES_PER_LINE;		/* number of bytes per raster line. */
49 int	PAGE_LINES;		/* number of raster lines per page. */
50 
51 char	*name, *host, *acctfile;
52 
53 main(argc, argv)
54 	int argc;
55 	char *argv[];
56 {
57 	register int n;
58 
59 	while (--argc) {
60 		if (**++argv == '-') {
61 			switch (argv[0][1]) {
62 			case 'x':
63 				BYTES_PER_LINE = atoi(&argv[0][2]) / 8;
64 				varian = BYTES_PER_LINE == 264;
65 				break;
66 
67 			case 'y':
68 				PAGE_LINES = atoi(&argv[0][2]);
69 				break;
70 
71 			case 'n':
72 				argc--;
73 				name = *++argv;
74 				break;
75 
76 			case 'h':
77 				argc--;
78 				host = *++argv;
79 			}
80 		} else
81 			acctfile = *argv;
82 	}
83 
84 	n = putplot();
85 
86 	ioctl(OUT, VSETSTATE, prtmd);
87 	if (varian)
88 		write(OUT, "\f", 2);
89 	else
90 		write(OUT, "\n\n\n\n\n", 6);
91 	account(name, host, *argv);
92 	exit(n);
93 }
94 
95 putplot()
96 {
97 	register char *cp;
98 	register int bytes, n;
99 
100 	cp = buf;
101 	bytes = 0;
102 	ioctl(OUT, VSETSTATE, plotmd);
103 	while ((n = read(IN, cp, sizeof(buf))) > 0) {
104 		if (write(OUT, cp, n) != n)
105 			return(1);
106 		bytes += n;
107 	}
108 	/*
109 	 * Make sure we send complete raster lines.
110 	 */
111 	if ((n = bytes % BYTES_PER_LINE) > 0) {
112 		n = BYTES_PER_LINE - n;
113 		for (cp = &buf[n]; cp > buf; )
114 			*--cp = 0;
115 		if (write(OUT, cp, n) != n)
116 			return(1);
117 		bytes += n;
118 	}
119 	lines += bytes / BYTES_PER_LINE;
120 	return(0);
121 }
122 
123 account(who, from, acctfile)
124 	char *who, *from, *acctfile;
125 {
126 	register FILE *a;
127 
128 	if (who == NULL || acctfile == NULL)
129 		return;
130 	if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
131 		return;
132 	/*
133 	 * Varian accounting is done by 8.5 inch pages;
134 	 * Versatec accounting is by the (12 inch) foot.
135 	 */
136 	fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES);
137 	if (from != NULL)
138 		fprintf(a, "%s:", from);
139 	fprintf(a, "%s\n", who);
140 	fclose(a);
141 }
142