120203Sdist /*
233682Sbostic * Copyright (c) 1981 Regents of the University of California.
333682Sbostic * All rights reserved.
433682Sbostic *
5*42811Sbostic * %sccs.include.redist.c%
620203Sdist */
720203Sdist
813949Ssam #ifndef lint
933682Sbostic char copyright[] =
1033682Sbostic "@(#) Copyright (c) 1981 Regents of the University of California.\n\
1133682Sbostic All rights reserved.\n";
1233682Sbostic #endif /* not lint */
1313949Ssam
1433682Sbostic #ifndef lint
15*42811Sbostic static char sccsid[] = "@(#)vpltdmp.c 5.4 (Berkeley) 06/01/90";
1633682Sbostic #endif /* not lint */
1733682Sbostic
1813949Ssam /*
1911433Sralph * reads raster file created by vplot and dumps it onto the
2011433Sralph * Varian or Versatec plotter.
2111433Sralph * Input comes from file descriptor 0, output is to file descriptor 1.
2211433Sralph */
2311433Sralph #include <stdio.h>
2411433Sralph #include <sys/vcmd.h>
2511433Sralph
2611433Sralph #define IN 0
2711433Sralph #define OUT 1
2811433Sralph
29*42811Sbostic static char *Sid = "@(#)vpltdmp.c 5.4\t06/01/90";
3011433Sralph
3112472Sralph int plotmd[] = { VPLOT };
3212472Sralph int prtmd[] = { VPRINT };
3311433Sralph
3411433Sralph char buf[BUFSIZ]; /* output buffer */
3511433Sralph
3611433Sralph int lines; /* number of raster lines printed */
3712472Sralph int varian; /* 0 for versatec, 1 for varian. */
3812472Sralph int BYTES_PER_LINE; /* number of bytes per raster line. */
3912472Sralph int PAGE_LINES; /* number of raster lines per page. */
4011433Sralph
4111433Sralph char *name, *host, *acctfile;
4211433Sralph
main(argc,argv)4311433Sralph main(argc, argv)
4413273Sralph int argc;
4513273Sralph char *argv[];
4611433Sralph {
4713273Sralph register int n;
4811433Sralph
4911433Sralph while (--argc) {
5011433Sralph if (**++argv == '-') {
5111433Sralph switch (argv[0][1]) {
5212472Sralph case 'x':
5312472Sralph BYTES_PER_LINE = atoi(&argv[0][2]) / 8;
5412472Sralph varian = BYTES_PER_LINE == 264;
5512472Sralph break;
5612472Sralph
5712472Sralph case 'y':
5812472Sralph PAGE_LINES = atoi(&argv[0][2]);
5912472Sralph break;
6012472Sralph
6111433Sralph case 'n':
6211433Sralph argc--;
6311433Sralph name = *++argv;
6411433Sralph break;
6511433Sralph
6611433Sralph case 'h':
6711433Sralph argc--;
6811433Sralph host = *++argv;
6911433Sralph }
7011433Sralph } else
7111433Sralph acctfile = *argv;
7211433Sralph }
7311433Sralph
7413273Sralph n = putplot();
7511433Sralph
7611433Sralph ioctl(OUT, VSETSTATE, prtmd);
7711433Sralph if (varian)
7812123Sralph write(OUT, "\f", 2);
7911433Sralph else
8011433Sralph write(OUT, "\n\n\n\n\n", 6);
8111433Sralph account(name, host, *argv);
8213273Sralph exit(n);
8311433Sralph }
8411433Sralph
putplot()8513273Sralph putplot()
8613273Sralph {
8713273Sralph register char *cp;
8813273Sralph register int bytes, n;
8913273Sralph
9013273Sralph cp = buf;
9113273Sralph bytes = 0;
9213273Sralph ioctl(OUT, VSETSTATE, plotmd);
9313273Sralph while ((n = read(IN, cp, sizeof(buf))) > 0) {
9413273Sralph if (write(OUT, cp, n) != n)
9513273Sralph return(1);
9613273Sralph bytes += n;
9713273Sralph }
9813273Sralph /*
9913273Sralph * Make sure we send complete raster lines.
10013273Sralph */
10113273Sralph if ((n = bytes % BYTES_PER_LINE) > 0) {
10213273Sralph n = BYTES_PER_LINE - n;
10313273Sralph for (cp = &buf[n]; cp > buf; )
10413273Sralph *--cp = 0;
10513273Sralph if (write(OUT, cp, n) != n)
10613273Sralph return(1);
10713273Sralph bytes += n;
10813273Sralph }
10913273Sralph lines += bytes / BYTES_PER_LINE;
11013273Sralph return(0);
11113273Sralph }
11213273Sralph
account(who,from,acctfile)11311433Sralph account(who, from, acctfile)
11411433Sralph char *who, *from, *acctfile;
11511433Sralph {
11611433Sralph register FILE *a;
11711433Sralph
11811433Sralph if (who == NULL || acctfile == NULL)
11911433Sralph return;
12011433Sralph if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
12111433Sralph return;
12211433Sralph /*
12312123Sralph * Varian accounting is done by 8.5 inch pages;
12411433Sralph * Versatec accounting is by the (12 inch) foot.
12511433Sralph */
12616169Sralph fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES);
12711433Sralph if (from != NULL)
12811433Sralph fprintf(a, "%s:", from);
12911433Sralph fprintf(a, "%s\n", who);
13011433Sralph fclose(a);
13111433Sralph }
132