120202Sdist /*
220202Sdist * Copyright (c) 1983 Regents of the University of California.
333682Sbostic * All rights reserved.
433682Sbostic *
5*42809Sbostic * %sccs.include.redist.c%
620202Sdist */
720202Sdist
820202Sdist #ifndef lint
933682Sbostic char copyright[] =
1033682Sbostic "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1133682Sbostic All rights reserved.\n";
1220202Sdist #endif /* not lint */
1320202Sdist
1433682Sbostic #ifndef lint
15*42809Sbostic static char sccsid[] = "@(#)vdmp.c 5.4 (Berkeley) 06/01/90";
1633682Sbostic #endif /* not lint */
1733682Sbostic
1820202Sdist /*
192413Shalbert * reads raster file created by cifplot and dumps it onto the
202413Shalbert * Varian or Versatec plotter.
2112119Sralph * Assumptions:
2212119Sralph * Input is from device 0.
2312119Sralph * plotter is already opened as device 1.
2412119Sralph * error output file is device 2.
252413Shalbert */
262413Shalbert #include <stdio.h>
272413Shalbert #include <sys/vcmd.h>
282413Shalbert
2920202Sdist #define IN 0
3020202Sdist #define OUT 1
3120202Sdist
324006Sfitz #define MAGIC_WORD 0xA5CF4DFA
332413Shalbert
344006Sfitz #define BUFSIZE 1024*128
354006Sfitz #define BLOCK 1024
364006Sfitz
3720202Sdist static char *Sid = "@(#)vdmp.c 5.1\t5/15/85";
382413Shalbert
3912470Sralph int plotmd[] = { VPLOT };
4012470Sralph int prtmd[] = { VPRINT };
412413Shalbert
4212119Sralph int inbuf[BLOCK/sizeof(int)];
4320202Sdist char buf[BUFSIZE];
4412119Sralph int lines;
452413Shalbert
4612470Sralph int varian; /* 0 for versatec, 1 for varian. */
4712470Sralph int BYTES_PER_LINE; /* number of bytes per raster line. */
4812470Sralph int PAGE_LINES; /* number of raster lines per page. */
492413Shalbert
5012119Sralph char *name, *host, *acctfile;
512413Shalbert
main(argc,argv)522413Shalbert main(argc, argv)
5312119Sralph int argc;
5412119Sralph char *argv[];
552413Shalbert {
5612119Sralph register int n;
572413Shalbert
5812119Sralph while (--argc) {
5920202Sdist if (**++argv == '-') {
6012119Sralph switch (argv[0][1]) {
6112470Sralph case 'x':
6212470Sralph BYTES_PER_LINE = atoi(&argv[0][2]) / 8;
6312470Sralph varian = BYTES_PER_LINE == 264;
6412470Sralph break;
6512470Sralph
6612470Sralph case 'y':
6712470Sralph PAGE_LINES = atoi(&argv[0][2]);
6812470Sralph break;
6912470Sralph
7012119Sralph case 'n':
7112119Sralph argc--;
7212119Sralph name = *++argv;
7312119Sralph break;
742413Shalbert
7512119Sralph case 'h':
7612119Sralph argc--;
7712119Sralph host = *++argv;
7812119Sralph }
7912119Sralph } else
8012119Sralph acctfile = *argv;
8112119Sralph }
8212119Sralph
8320202Sdist n = read(IN, inbuf, BLOCK);
8412119Sralph if (inbuf[0] == MAGIC_WORD && n == BLOCK) {
8512119Sralph /* we have a formatted dump file */
8612119Sralph inbuf[(BLOCK/sizeof(int))-1] = 0; /* make sure string terminates */
8720202Sdist ioctl(OUT, VSETSTATE, prtmd);
8820202Sdist write(OUT, &inbuf[4], (strlen(&inbuf[4])+1) & ~1);
8920202Sdist write(OUT, "\n", 2);
9012119Sralph } else /* dump file not formatted */
9120202Sdist lseek(IN, 0L, 0); /* reset in's seek pointer and plot */
9212119Sralph
9312119Sralph n = putplot();
9412119Sralph
9512119Sralph /* page feed */
9620202Sdist ioctl(OUT, VSETSTATE, prtmd);
9720202Sdist if (varian)
9820202Sdist write(OUT, "\f", 2);
9912119Sralph else
10020202Sdist write(OUT, "\n\n\n\n\n", 6);
10112119Sralph account(name, host, acctfile);
10220202Sdist exit(n);
10312119Sralph }
10412119Sralph
putplot()1052413Shalbert putplot()
1062413Shalbert {
10720202Sdist register char *cp;
10820202Sdist register int bytes, n;
1092413Shalbert
11020202Sdist cp = buf;
11120202Sdist bytes = 0;
11220202Sdist ioctl(OUT, VSETSTATE, plotmd);
11320202Sdist while ((n = read(IN, cp, sizeof(buf))) > 0) {
11420202Sdist if (write(OUT, cp, n) != n)
11520202Sdist return(1);
11620202Sdist bytes += n;
11720202Sdist }
11820202Sdist /*
11920202Sdist * Make sure we send complete raster lines.
12020202Sdist */
12120202Sdist if ((n = bytes % BYTES_PER_LINE) > 0) {
12220202Sdist n = BYTES_PER_LINE - n;
12320202Sdist for (cp = &buf[n]; cp > buf; )
12420202Sdist *--cp = 0;
12520202Sdist if (write(OUT, cp, n) != n)
12620202Sdist return(1);
12720202Sdist bytes += n;
12820202Sdist }
12920202Sdist lines += bytes / BYTES_PER_LINE;
13020202Sdist return(0);
13112119Sralph }
13212119Sralph
account(who,from,acctfile)13312119Sralph account(who, from, acctfile)
13412119Sralph char *who, *from, *acctfile;
13512119Sralph {
13612119Sralph register FILE *a;
13712119Sralph
13812119Sralph if (who == NULL || acctfile == NULL)
13912119Sralph return;
14012119Sralph if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
14112119Sralph return;
14212119Sralph /*
14320202Sdist * Varian accounting is done by 8.5 inch pages;
14412119Sralph * Versatec accounting is by the (12 inch) foot.
14512119Sralph */
14620202Sdist fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES);
14712119Sralph if (from != NULL)
14812119Sralph fprintf(a, "%s:", from);
14912119Sralph fprintf(a, "%s\n", who);
15012119Sralph fclose(a);
15112119Sralph }
152