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