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