xref: /csrg-svn/old/vfilters/vpltdmp/vpltdmp.c (revision 33682)
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 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.
11  */
12 
13 #ifndef lint
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) 03/08/88";
21 #endif /* not lint */
22 
23 /*
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>
29 #include <sys/vcmd.h>
30 
31 #define IN	0
32 #define OUT	1
33 
34 static	char *Sid = "@(#)vpltdmp.c	5.2\t03/08/88";
35 
36 int	plotmd[] = { VPLOT };
37 int	prtmd[]  = { VPRINT };
38 
39 char	buf[BUFSIZ];		/* output buffer */
40 
41 int	lines;			/* number of raster lines printed */
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. */
45 
46 char	*name, *host, *acctfile;
47 
48 main(argc, argv)
49 	int argc;
50 	char *argv[];
51 {
52 	register int n;
53 
54 	while (--argc) {
55 		if (**++argv == '-') {
56 			switch (argv[0][1]) {
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 
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 
79 	n = putplot();
80 
81 	ioctl(OUT, VSETSTATE, prtmd);
82 	if (varian)
83 		write(OUT, "\f", 2);
84 	else
85 		write(OUT, "\n\n\n\n\n", 6);
86 	account(name, host, *argv);
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);
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 	/*
128 	 * Varian accounting is done by 8.5 inch pages;
129 	 * Versatec accounting is by the (12 inch) foot.
130 	 */
131 	fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES);
132 	if (from != NULL)
133 		fprintf(a, "%s:", from);
134 	fprintf(a, "%s\n", who);
135 	fclose(a);
136 }
137