1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)vdmp.c 5.4 (Berkeley) 06/01/90"; 16 #endif /* not lint */ 17 18 /* 19 * reads raster file created by cifplot and dumps it onto the 20 * Varian or Versatec plotter. 21 * Assumptions: 22 * Input is from device 0. 23 * plotter is already opened as device 1. 24 * error output file is device 2. 25 */ 26 #include <stdio.h> 27 #include <sys/vcmd.h> 28 29 #define IN 0 30 #define OUT 1 31 32 #define MAGIC_WORD 0xA5CF4DFA 33 34 #define BUFSIZE 1024*128 35 #define BLOCK 1024 36 37 static char *Sid = "@(#)vdmp.c 5.1\t5/15/85"; 38 39 int plotmd[] = { VPLOT }; 40 int prtmd[] = { VPRINT }; 41 42 int inbuf[BLOCK/sizeof(int)]; 43 char buf[BUFSIZE]; 44 int lines; 45 46 int varian; /* 0 for versatec, 1 for varian. */ 47 int BYTES_PER_LINE; /* number of bytes per raster line. */ 48 int PAGE_LINES; /* number of raster lines per page. */ 49 50 char *name, *host, *acctfile; 51 52 main(argc, argv) 53 int argc; 54 char *argv[]; 55 { 56 register int n; 57 58 while (--argc) { 59 if (**++argv == '-') { 60 switch (argv[0][1]) { 61 case 'x': 62 BYTES_PER_LINE = atoi(&argv[0][2]) / 8; 63 varian = BYTES_PER_LINE == 264; 64 break; 65 66 case 'y': 67 PAGE_LINES = atoi(&argv[0][2]); 68 break; 69 70 case 'n': 71 argc--; 72 name = *++argv; 73 break; 74 75 case 'h': 76 argc--; 77 host = *++argv; 78 } 79 } else 80 acctfile = *argv; 81 } 82 83 n = read(IN, inbuf, BLOCK); 84 if (inbuf[0] == MAGIC_WORD && n == BLOCK) { 85 /* we have a formatted dump file */ 86 inbuf[(BLOCK/sizeof(int))-1] = 0; /* make sure string terminates */ 87 ioctl(OUT, VSETSTATE, prtmd); 88 write(OUT, &inbuf[4], (strlen(&inbuf[4])+1) & ~1); 89 write(OUT, "\n", 2); 90 } else /* dump file not formatted */ 91 lseek(IN, 0L, 0); /* reset in's seek pointer and plot */ 92 93 n = putplot(); 94 95 /* page feed */ 96 ioctl(OUT, VSETSTATE, prtmd); 97 if (varian) 98 write(OUT, "\f", 2); 99 else 100 write(OUT, "\n\n\n\n\n", 6); 101 account(name, host, acctfile); 102 exit(n); 103 } 104 105 putplot() 106 { 107 register char *cp; 108 register int bytes, n; 109 110 cp = buf; 111 bytes = 0; 112 ioctl(OUT, VSETSTATE, plotmd); 113 while ((n = read(IN, cp, sizeof(buf))) > 0) { 114 if (write(OUT, cp, n) != n) 115 return(1); 116 bytes += n; 117 } 118 /* 119 * Make sure we send complete raster lines. 120 */ 121 if ((n = bytes % BYTES_PER_LINE) > 0) { 122 n = BYTES_PER_LINE - n; 123 for (cp = &buf[n]; cp > buf; ) 124 *--cp = 0; 125 if (write(OUT, cp, n) != n) 126 return(1); 127 bytes += n; 128 } 129 lines += bytes / BYTES_PER_LINE; 130 return(0); 131 } 132 133 account(who, from, acctfile) 134 char *who, *from, *acctfile; 135 { 136 register FILE *a; 137 138 if (who == NULL || acctfile == NULL) 139 return; 140 if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL) 141 return; 142 /* 143 * Varian accounting is done by 8.5 inch pages; 144 * Versatec accounting is by the (12 inch) foot. 145 */ 146 fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES); 147 if (from != NULL) 148 fprintf(a, "%s:", from); 149 fprintf(a, "%s\n", who); 150 fclose(a); 151 } 152