xref: /csrg-svn/old/vfilters/vpsf/vpsf.c (revision 42812)
120203Sdist /*
220203Sdist  * Copyright (c) 1983 Regents of the University of California.
333682Sbostic  * All rights reserved.
433682Sbostic  *
5*42812Sbostic  * %sccs.include.redist.c%
620203Sdist  */
720203Sdist 
813949Ssam #ifndef lint
933682Sbostic char copyright[] =
1033682Sbostic "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1133682Sbostic  All rights reserved.\n";
1233682Sbostic #endif /* not lint */
1313949Ssam 
1433682Sbostic #ifndef lint
15*42812Sbostic static char sccsid[] = "@(#)vpsf.c	5.4 (Berkeley) 06/01/90";
1633682Sbostic #endif /* not lint */
1733682Sbostic 
1811435Sralph /*
1911435Sralph  * Versatec printer filter
2011435Sralph  * 	make wide listings by placing pages side by side
2111435Sralph  */
2211435Sralph 
2311435Sralph #include <stdio.h>
2411435Sralph #include <sys/vcmd.h>
2511435Sralph 
2611435Sralph #define	LINELN 440
2714667Sralph #define	PAGELN  86
2814667Sralph #define	LMARG   10
2911435Sralph 
3012472Sralph int	pltmode[] = {VPLOT};
3112472Sralph int	prtmode[] = {VPRINT};
3211435Sralph 
3311435Sralph char	screen[PAGELN][LINELN];
3411435Sralph char	ul[PAGELN][LINELN];
3511435Sralph char	anyul[PAGELN];
3614667Sralph int	origin;		/* first column of a page */
3714667Sralph int	origin_ind;	/* origin plus indent */
3814667Sralph int	outline;	/* current line number */
3914667Sralph int	outcol;		/* current column number */
4011435Sralph int	npages;
4114667Sralph int	width = 106;	/* default page width */
4214667Sralph int	length = 86;	/* default page length */
4314667Sralph int	indent = 0;	/* default indent */
4411435Sralph 
4511435Sralph int	literal;
4611435Sralph char	*name;		/* user's login name */
4711435Sralph char	*host;		/* user's machine name */
4811435Sralph char	*acctfile;	/* accounting information file */
4911435Sralph 
main(argc,argv)5014667Sralph main(argc, argv)
5111582Sralph 	int argc;
5211582Sralph 	char *argv[];
5311582Sralph {
5411435Sralph 	register int i;
5511435Sralph 
5611435Sralph 	while (--argc) {
5711435Sralph 		if (*(*++argv) == '-') {
5811435Sralph 			switch (argv[0][1]) {
5911435Sralph 			case 'n':
6011435Sralph 				argc--;
6111435Sralph 				name = *++argv;
6211435Sralph 				break;
6311435Sralph 
6411435Sralph 			case 'h':
6511435Sralph 				argc--;
6611435Sralph 				host = *++argv;
6711435Sralph 				break;
6811435Sralph 
6911435Sralph 			case 'w':
7011435Sralph 				if ((i = atoi(&argv[0][2])) > 0 && i <= LINELN)
7111435Sralph 					width = i;
7211435Sralph 				break;
7311435Sralph 
7411435Sralph 			case 'l':
7511435Sralph 				if ((i = atoi(&argv[0][2])) > 0 && i <= PAGELN)
7611435Sralph 					length = i;
7711435Sralph 				break;
7811435Sralph 
7914667Sralph 			case 'i':
8014667Sralph 				if ((i = atoi(&argv[0][2])) >= 0 &&
8114667Sralph 				    i < LINELN - 1)
8214667Sralph 					indent = i;
8314667Sralph 				break;
8414667Sralph 
8511435Sralph 			case 'c':	/* Print input without throwing away
8611435Sralph 					   control chars and without putting
8711435Sralph 					   in page breaks. */
8811435Sralph 				literal++;
8911435Sralph 				break;
9011435Sralph 			}
9111435Sralph 		} else
9211435Sralph 			acctfile = *argv;
9311435Sralph 	}
9414667Sralph 	indent += literal ? 1 : LMARG;
9514667Sralph 	if (indent >= width)
9614667Sralph 		indent = width - 1;
9711435Sralph 
9811435Sralph 	/*
9911435Sralph 	 * input file is open on file descriptor 0.
10011435Sralph 	 * vp should be open on file descriptor 1.
10111435Sralph 	 * The error log file is open on file descriptor 2.
10211435Sralph 	 */
10311435Sralph 	ioctl(1, VSETSTATE, prtmode);
10411435Sralph 	process();
10511435Sralph 
10611435Sralph 	/*
10711435Sralph 	 * Put out an extra null to ensure versatec will get an even
10811435Sralph 	 * number of good characters.
10911435Sralph 	 */
11011435Sralph 	putchar('\0');
11111435Sralph 
11211435Sralph 	if (ferror(stdout))
11311435Sralph 		exit(1);
11411435Sralph 	if (name && acctfile && access(acctfile, 02) >= 0 &&
11511435Sralph 	    freopen(acctfile, "a", stdout) != NULL) {
11611435Sralph 		if (host)
11711435Sralph 			printf("%7.2f\t%s:%s\n", (float)npages, host, name);
11811435Sralph 		else
11911435Sralph 			printf("%7.2f\t%s\n", (float)npages, name);
12011435Sralph 	}
12111435Sralph 	exit(0);
12211435Sralph }
12311435Sralph 
set_up()12414667Sralph set_up()
12514667Sralph {
12614667Sralph 	clear(screen, sizeof(screen));
12714667Sralph 	origin = 0;
12814667Sralph 	origin_ind = outcol = origin + indent;
12914667Sralph 	outline = 0;
13014667Sralph 	cutmark(origin);
13114667Sralph }
13214667Sralph 
process()13311435Sralph process()
13411435Sralph {
13511435Sralph 	register int c;
13611435Sralph 
13714667Sralph 	set_up();
13811435Sralph 
13911435Sralph 	while ((c = getchar()) != EOF)
14011435Sralph 		switch (c) {
14111435Sralph 		case ' ':
14211435Sralph 			outcol++;
14311435Sralph 			break;
14411435Sralph 
14511435Sralph 		case '\t':
14614667Sralph 			outcol = ((outcol - origin_ind) | 07) + origin_ind + 1;
14711435Sralph 			break;
14811435Sralph 
14911435Sralph 		case '\b':
15014667Sralph 			if (outcol > origin_ind)
15111435Sralph 				outcol--;
15211435Sralph 			break;
15311435Sralph 
15411435Sralph 		case '\r':
15514667Sralph 			outcol = origin_ind;
15611435Sralph 			break;
15711435Sralph 
15811435Sralph 		case '\f':
15911435Sralph 			outline = length;
16011435Sralph 			/* fall into ... */
16111435Sralph 
16211435Sralph 		case '\n':
16311435Sralph 			if (++outline >= length) {
16414667Sralph 				origin += width + 1;
16514667Sralph  				origin_ind += width + 1;
16614667Sralph 				cutmark(origin);
16714667Sralph 				if (origin + width + 1 >= LINELN) {
16811435Sralph 					oflush();
16911435Sralph 					break;
17011435Sralph 				}
17111435Sralph 				outline = 0;
17211435Sralph 			}
17314667Sralph 			outcol = origin_ind;
17411435Sralph 			break;
17511435Sralph 
17611435Sralph 		default:
17711435Sralph 			outchar(c);
17811435Sralph 			break;
17911435Sralph 		}
18011435Sralph 
18114667Sralph 	if (outline || origin) {
18214667Sralph 		cutmark(origin + width + 1);
18311435Sralph 		oflush();
18411435Sralph 	}
18511435Sralph 	printf("\n\n\n\n\n");
18611435Sralph }
18711435Sralph 
outchar(c)18811435Sralph outchar(c)
18911435Sralph 	register int c;
19011435Sralph {
19111435Sralph 	register char *cp;
19211435Sralph 	register int d;
19311435Sralph 
19411435Sralph 	if (!literal && (c < 040 || c >= 0177))
19511435Sralph 		return;
19614667Sralph 	if (outcol >= origin + width + 1) {
19711435Sralph 		outcol++;
19811435Sralph 		return;
19911435Sralph 	}
20011435Sralph 	cp = &screen[outline][outcol];
20111435Sralph 	d = *cp;
20211435Sralph 	if (d != ' ') {
20311435Sralph 		if (d == '_' || c == '_') {
20411435Sralph 			if (c == d) {
20511435Sralph 				outcol++;
20611435Sralph 				return;
20711435Sralph 			}
20811435Sralph 			if (anyul[outline] == 0)
20911435Sralph 				clear(ul[outline], LINELN);
21011435Sralph 			anyul[outline] = 1;
21111435Sralph 			ul[outline][outcol] = 0377;
21211435Sralph 			if (c == '_')
21311435Sralph 				c = d;
21411435Sralph 		}
21511435Sralph 	}
21611435Sralph 	*cp = c;
21711435Sralph 	outcol++;
21811435Sralph }
21911435Sralph 
oflush()22011435Sralph oflush()
22111435Sralph {
22211435Sralph 	register char *cp, *dp;
22311435Sralph 	register int i, j, oc, dc, c;
22411435Sralph 
22511435Sralph 	npages++;
22611435Sralph 	putchar('\n');
22711435Sralph 	for (i = 0; i < length; i++)
22811435Sralph 		putline(i);
22911435Sralph 	for (i = 0; i < LINELN; i++)
23011435Sralph 		putchar('_');
23111435Sralph 	putchar('\n');
23214667Sralph 
23314667Sralph 	set_up();
23411435Sralph }
23511435Sralph 
clear(cp,i)23611435Sralph clear(cp, i)
23711435Sralph 	register char *cp;
23811435Sralph 	register int i;
23911435Sralph {
24011435Sralph 	if (i > 0)
24111435Sralph 		do
24211435Sralph 			*cp++ = ' ';
24311435Sralph 		while (--i);
24411435Sralph }
24511435Sralph 
cutmark(o)24611435Sralph cutmark(o)
24711435Sralph 	register int o;
24811435Sralph {
24911435Sralph 	register int i;
25011435Sralph 
25114667Sralph 	screen[0][o] = '|';
25214667Sralph 	screen[1][o] = '|';
25314667Sralph 	screen[length - 1][o] = '|';
25414667Sralph 	screen[length - 2][o] = '|';
25511435Sralph }
25611435Sralph 
putline(n)25711435Sralph putline(n)
25811435Sralph 	register int n;
25911435Sralph {
26011435Sralph 	register char *cp;
26111435Sralph 	register int j;
26211435Sralph 
26311435Sralph 	fwrite(screen[n], sizeof(char), sizeof(screen[0]), stdout);
26411435Sralph 	if (anyul[n]) {
26511435Sralph 		putchar('\n');
26611435Sralph 		putchar('\0');
26711435Sralph 		fflush(stdout);
26811435Sralph 		ioctl(1, VSETSTATE, pltmode);
26911435Sralph 		cp = ul[n];
27011435Sralph 		j = LINELN;
27111435Sralph 		do {
27211435Sralph 			putchar(*cp & 0377);
27311435Sralph 			putchar(*cp++ & 0377);
27411435Sralph 		} while (--j);
27511435Sralph 		fflush(stdout);
27611435Sralph 		ioctl(1, VSETSTATE, prtmode);
27711435Sralph 	} else
27811435Sralph 		putchar('\n');
27911435Sralph 	if (ferror(stdout))
28011435Sralph 		exit(1);
28111435Sralph }
282