1 /* VDMP: version 4.5 updated 04/29/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.1\t4/29/83"; 19 20 int plotmd[] = { VPLOT, 0, 0 }; 21 int prtmd[] = { VPRINT, 0, 0 }; 22 23 int inbuf[BLOCK/sizeof(int)]; 24 char vpbuf[BUFSIZE]; 25 int lines; 26 27 int varian = 1; /* use varian by default */ 28 int BytesPerLine = 264; /* Number of bytes per raster line */ 29 30 char *name, *host, *acctfile; 31 32 main(argc, argv) 33 int argc; 34 char *argv[]; 35 { 36 register int n; 37 38 if (argv[0][strlen(argv[0]-1)] == 'W') { 39 varian = 0; 40 BytesPerLine = 880; 41 } 42 43 while (--argc) { 44 if (*(*++argv) == '-') { 45 switch (argv[0][1]) { 46 case 'n': 47 argc--; 48 name = *++argv; 49 break; 50 51 case 'h': 52 argc--; 53 host = *++argv; 54 } 55 } else 56 acctfile = *argv; 57 } 58 59 n = read(0, inbuf, BLOCK); 60 if (inbuf[0] == MAGIC_WORD && n == BLOCK) { 61 /* we have a formatted dump file */ 62 inbuf[(BLOCK/sizeof(int))-1] = 0; /* make sure string terminates */ 63 ioctl(1, VSETSTATE, prtmd); 64 write(1, &inbuf[4], (strlen(&inbuf[4])+1) & ~1); 65 write(1, "\n", 2); 66 } else /* dump file not formatted */ 67 lseek(0, 0L, 0); /* reset in's seek pointer and plot */ 68 69 n = putplot(); 70 71 /* page feed */ 72 ioctl(1, VSETSTATE, prtmd); 73 if (varian) 74 write(1, "\f", 2); 75 else 76 write(1, "\n\n\n\n\n", 6); 77 account(name, host, acctfile); 78 exit(n != 0); 79 } 80 81 putplot() 82 { 83 register char *buf; 84 register int i, n; 85 86 n = 0; 87 buf = vpbuf; 88 ioctl(1, VSETSTATE, plotmd); 89 while ((i = read(0, buf, BUFSIZE)) > 0) 90 if (write(1, buf, i) != i) { 91 i = -1; 92 break; 93 } else 94 n += BUFSIZE; 95 lines += n / BytesPerLine; 96 return(i); 97 } 98 99 account(who, from, acctfile) 100 char *who, *from, *acctfile; 101 { 102 register FILE *a; 103 104 if (who == NULL || acctfile == NULL) 105 return; 106 if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL) 107 return; 108 /* 109 * Varian accounting is done by 11 inch pages; 110 * Versatec accounting is by the (12 inch) foot. 111 */ 112 fprintf(a, "t%6.2f\t", (lines / 200.0) / (varian ? 11.0 : 12.0)); 113 if (from != NULL) 114 fprintf(a, "%s:", from); 115 fprintf(a, "%s\n", who); 116 fclose(a); 117 } 118