xref: /csrg-svn/old/vfilters/vpltdmp/vpltdmp.c (revision 12472)
1 /****************************************************************/
2 /*								*/
3 /*								*/
4 /* Copyright (C) 1981, Regents of the University of California	*/
5 /*	All rights reserved					*/
6 /*								*/
7 /****************************************************************/
8 /*  VPLTDMP: version 4.3			updated 05/16/83
9  *
10  *  reads raster file created by vplot and dumps it onto the
11  *  Varian or Versatec plotter.
12  *  Input comes from file descriptor 0, output is to file descriptor 1.
13  */
14 #include <stdio.h>
15 #include <signal.h>
16 #include <sys/vcmd.h>
17 
18 #define IN	0
19 #define OUT	1
20 
21 static	char *Sid = "@(#)vpltdmp.c	4.3\t05/16/83";
22 
23 int	plotmd[] = { VPLOT };
24 int	prtmd[]  = { VPRINT };
25 
26 char	buf[BUFSIZ];		/* output buffer */
27 
28 int	lines;			/* number of raster lines printed */
29 int	varian;			/* 0 for versatec, 1 for varian. */
30 int	BYTES_PER_LINE;		/* number of bytes per raster line. */
31 int	PAGE_LINES;		/* number of raster lines per page. */
32 
33 char	*name, *host, *acctfile;
34 
35 main(argc, argv)
36 char *argv[];
37 {
38 	register int n, bytes;
39 
40 	while (--argc) {
41 		if (**++argv == '-') {
42 			switch (argv[0][1]) {
43 			case 'x':
44 				BYTES_PER_LINE = atoi(&argv[0][2]) / 8;
45 				varian = BYTES_PER_LINE == 264;
46 				break;
47 
48 			case 'y':
49 				PAGE_LINES = atoi(&argv[0][2]);
50 				break;
51 
52 			case 'n':
53 				argc--;
54 				name = *++argv;
55 				break;
56 
57 			case 'h':
58 				argc--;
59 				host = *++argv;
60 			}
61 		} else
62 			acctfile = *argv;
63 	}
64 
65 	ioctl(OUT, VSETSTATE, plotmd);
66 
67 	bytes = 0;
68 	while ((n = read(IN, buf, sizeof(buf))) > 0) {
69 		if (write(OUT, buf, n) != n)
70 			exit(1);
71 		bytes += n;
72 	}
73 	if (bytes & 1) {	/* make sure even number bytes are sent */
74 		write(OUT, "", 1);
75 		bytes++;
76 	}
77 	lines = bytes / BYTES_PER_LINE;
78 
79 	ioctl(OUT, VSETSTATE, prtmd);
80 	if (varian)
81 		write(OUT, "\f", 2);
82 	else
83 		write(OUT, "\n\n\n\n\n", 6);
84 	account(name, host, *argv);
85 	exit(0);
86 }
87 
88 account(who, from, acctfile)
89 	char *who, *from, *acctfile;
90 {
91 	register FILE *a;
92 
93 	if (who == NULL || acctfile == NULL)
94 		return;
95 	if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
96 		return;
97 	/*
98 	 * Varian accounting is done by 8.5 inch pages;
99 	 * Versatec accounting is by the (12 inch) foot.
100 	 */
101 	fprintf(a, "t%6.2f\t", (lines / 200.0) / PAGE_LINES);
102 	if (from != NULL)
103 		fprintf(a, "%s:", from);
104 	fprintf(a, "%s\n", who);
105 	fclose(a);
106 }
107