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