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) 5/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: }

Defined functions

account defined in line 126; used 1 times
  • in line 94
main defined in line 45; never used
putplot defined in line 98; used 1 times
  • in line 86

Defined variables

BYTES_PER_LINE defined in line 40; used 5 times
PAGE_LINES defined in line 41; used 2 times
Sid defined in line 30; never used
acctfile defined in line 43; used 7 times
buf defined in line 36; used 4 times
host defined in line 43; used 2 times
inbuf defined in line 35; used 5 times
lines defined in line 37; used 2 times
name defined in line 43; used 2 times
plotmd defined in line 32; used 1 times
prtmd defined in line 33; used 2 times
sccsid defined in line 8; never used
varian defined in line 39; used 2 times

Defined macros

BLOCK defined in line 28; used 4 times
BUFSIZE defined in line 27; used 1 times
  • in line 36
IN defined in line 22; used 3 times
MAGIC_WORD defined in line 25; used 1 times
  • in line 77
OUT defined in line 23; used 9 times
Last modified: 1987-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2697
Valid CSS Valid XHTML 1.0 Strict