xref: /onnv-gate/usr/src/cmd/troff/troff.d/ta.c (revision 217:758a5315b0d7)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate  * The Regents of the University of California
330Sstevel@tonic-gate  * All Rights Reserved
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate  * contributors.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
40*217Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*217Smuffin 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  *	drive hp2621 terminal
440Sstevel@tonic-gate  *	just to see stuff quickly. like troff -a
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate output language from troff:
490Sstevel@tonic-gate all numbers are character strings
500Sstevel@tonic-gate 
510Sstevel@tonic-gate sn	size in points
520Sstevel@tonic-gate fn	font as number from 1-n
530Sstevel@tonic-gate cx	ascii character x
540Sstevel@tonic-gate Cxyz	funny char xyz. terminated by white space
550Sstevel@tonic-gate Hn	go to absolute horizontal position n
560Sstevel@tonic-gate Vn	go to absolute vertical position n (down is positive)
570Sstevel@tonic-gate hn	go n units horizontally (relative)
580Sstevel@tonic-gate vn	ditto vertically
590Sstevel@tonic-gate nnc	move right nn (exactly 2 digits!), then print c
600Sstevel@tonic-gate 		(this wart is an optimization that shrinks output file size
610Sstevel@tonic-gate 		 about 35% and run-time about 15% while preserving ascii-ness)
620Sstevel@tonic-gate w	paddable word space - no action needed
630Sstevel@tonic-gate nb a	end of line (information only -- no action needed)
640Sstevel@tonic-gate 	b = space before line, a = after
650Sstevel@tonic-gate pn	begin page n
660Sstevel@tonic-gate #...\n	comment
670Sstevel@tonic-gate Dt ...\n	draw operation 't':
680Sstevel@tonic-gate 	Dl x y		line from here by x,y
690Sstevel@tonic-gate 	Dc d		circle of diameter d with left side here
700Sstevel@tonic-gate 	De x y		ellipse of axes x,y with left side here
710Sstevel@tonic-gate 	Da x y u v	arc counter-clockwise from here to u,v from center
720Sstevel@tonic-gate 				with center x,y from here
730Sstevel@tonic-gate 	D~ x y x y ...	wiggly line by x,y then x,y ...
740Sstevel@tonic-gate x ...\n	device control functions:
750Sstevel@tonic-gate 	x i	init
760Sstevel@tonic-gate 	x T s	name of device is s
770Sstevel@tonic-gate 	x r n h v	resolution is n/inch
780Sstevel@tonic-gate 		h = min horizontal motion, v = min vert
790Sstevel@tonic-gate 	x p	pause (can restart)
800Sstevel@tonic-gate 	x s	stop -- done for ever
810Sstevel@tonic-gate 	x t	generate trailer
820Sstevel@tonic-gate 	x f n s	font position n contains font s
830Sstevel@tonic-gate 	x H n	set character height to n
840Sstevel@tonic-gate 	x S n	set character slant to n
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	Subcommands like "i" are often spelled out like "init".
870Sstevel@tonic-gate */
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #include	<stdio.h>
900Sstevel@tonic-gate #include	<signal.h>
910Sstevel@tonic-gate #include	<ctype.h>
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #include "dev.h"
940Sstevel@tonic-gate #define	NFONT	10
950Sstevel@tonic-gate 
960Sstevel@tonic-gate int	output	= 0;	/* do we do output at all? */
970Sstevel@tonic-gate int	nolist	= 0;	/* output page list if > 0 */
980Sstevel@tonic-gate int	olist[20];	/* pairs of page numbers */
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate int	erase	= 1;
1010Sstevel@tonic-gate float	aspect	= 1.5;	/* default aspect ratio */
1020Sstevel@tonic-gate int	wflag	= 0;	/* wait, looping, for new input if on */
1030Sstevel@tonic-gate void	(*sigint)();
1040Sstevel@tonic-gate void	(*sigquit)();
1050Sstevel@tonic-gate void	done();
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate struct dev dev;
1080Sstevel@tonic-gate struct font *fontbase[NFONT];
1090Sstevel@tonic-gate short	psizes[]	={ 11, 16, 22, 36, 0};	/* approx sizes available */
1100Sstevel@tonic-gate short	*pstab		= psizes;
1110Sstevel@tonic-gate int	nsizes	= 1;
1120Sstevel@tonic-gate int	nfonts;
1130Sstevel@tonic-gate int	smnt;	/* index of first special font */
1140Sstevel@tonic-gate int	nchtab;
1150Sstevel@tonic-gate char	*chname;
1160Sstevel@tonic-gate short	*chtab;
1170Sstevel@tonic-gate char	*fitab[NFONT];
1180Sstevel@tonic-gate char	*widthtab[NFONT];	/* widtab would be a better name */
1190Sstevel@tonic-gate char	*codetab[NFONT];	/* device codes */
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate #define	FATAL	1
1220Sstevel@tonic-gate #define	BMASK	0377
1230Sstevel@tonic-gate int	dbg	= 0;
1240Sstevel@tonic-gate int	res	= 972;		/* input assumed computed according to this resolution */
1250Sstevel@tonic-gate 				/* initial value to avoid 0 divide */
1260Sstevel@tonic-gate FILE	*tf	= stdout;	/* output file */
1270Sstevel@tonic-gate char	*fontdir	= "/usr/lib/font";
1280Sstevel@tonic-gate extern char devname[];
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate FILE *fp = stdin;	/* input file pointer */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate int	nowait = 0;	/* 0 => wait at bottom of each page */
1330Sstevel@tonic-gate 
134*217Smuffin int
main(int argc,char ** argv)135*217Smuffin main(int argc, char **argv)
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate 	char buf[BUFSIZ];
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	setbuf(stdout, buf);
1400Sstevel@tonic-gate 	while (argc > 1 && argv[1][0] == '-') {
1410Sstevel@tonic-gate 		switch (argv[1][1]) {
1420Sstevel@tonic-gate 		case 'a':
1430Sstevel@tonic-gate 			aspect = atof(&argv[1][2]);
1440Sstevel@tonic-gate 			break;
1450Sstevel@tonic-gate 		case 'e':
1460Sstevel@tonic-gate 			erase = 0;
1470Sstevel@tonic-gate 			break;
1480Sstevel@tonic-gate 		case 'o':
1490Sstevel@tonic-gate 			outlist(&argv[1][2]);
1500Sstevel@tonic-gate 			break;
1510Sstevel@tonic-gate 		case 'd':
1520Sstevel@tonic-gate 			dbg = atoi(&argv[1][2]);
1530Sstevel@tonic-gate 			if (dbg == 0) dbg = 1;
1540Sstevel@tonic-gate 			break;
1550Sstevel@tonic-gate 		case 'w':	/* no wait at bottom of page */
1560Sstevel@tonic-gate 			nowait = 1;
1570Sstevel@tonic-gate 			break;
1580Sstevel@tonic-gate 		}
1590Sstevel@tonic-gate 		argc--;
1600Sstevel@tonic-gate 		argv++;
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	if (argc <= 1)
1640Sstevel@tonic-gate 		conv(stdin);
1650Sstevel@tonic-gate 	else
1660Sstevel@tonic-gate 		while (--argc > 0) {
1670Sstevel@tonic-gate 			if (strcmp(*++argv, "-") == 0)
1680Sstevel@tonic-gate 				fp = stdin;
1690Sstevel@tonic-gate 			else if ((fp = fopen(*argv, "r")) == NULL)
1700Sstevel@tonic-gate 				error(FATAL, "can't open %s", *argv);
1710Sstevel@tonic-gate 			conv(fp);
1720Sstevel@tonic-gate 			fclose(fp);
1730Sstevel@tonic-gate 		}
1740Sstevel@tonic-gate 	done();
175*217Smuffin 
176*217Smuffin 	return (0);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate 
179*217Smuffin int
outlist(s)1800Sstevel@tonic-gate outlist(s)	/* process list of page numbers to be printed */
1810Sstevel@tonic-gate char *s;
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	int n1, n2, i;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	nolist = 0;
1860Sstevel@tonic-gate 	while (*s) {
1870Sstevel@tonic-gate 		n1 = 0;
1880Sstevel@tonic-gate 		if (isdigit((unsigned char)*s))
1890Sstevel@tonic-gate 			do
1900Sstevel@tonic-gate 				n1 = 10 * n1 + *s++ - '0';
1910Sstevel@tonic-gate 			while (isdigit((unsigned char)*s));
1920Sstevel@tonic-gate 		else
1930Sstevel@tonic-gate 			n1 = -9999;
1940Sstevel@tonic-gate 		n2 = n1;
1950Sstevel@tonic-gate 		if (*s == '-') {
1960Sstevel@tonic-gate 			s++;
1970Sstevel@tonic-gate 			n2 = 0;
1980Sstevel@tonic-gate 			if (isdigit((unsigned char)*s))
1990Sstevel@tonic-gate 				do
2000Sstevel@tonic-gate 					n2 = 10 * n2 + *s++ - '0';
2010Sstevel@tonic-gate 				while (isdigit((unsigned char)*s));
2020Sstevel@tonic-gate 			else
2030Sstevel@tonic-gate 				n2 = 9999;
2040Sstevel@tonic-gate 		}
2050Sstevel@tonic-gate 		olist[nolist++] = n1;
2060Sstevel@tonic-gate 		olist[nolist++] = n2;
2070Sstevel@tonic-gate 		if (*s != '\0')
2080Sstevel@tonic-gate 			s++;
2090Sstevel@tonic-gate 	}
2100Sstevel@tonic-gate 	olist[nolist] = 0;
2110Sstevel@tonic-gate 	if (dbg)
2120Sstevel@tonic-gate 		for (i=0; i<nolist; i += 2)
2130Sstevel@tonic-gate 			printf("%3d %3d\n", olist[i], olist[i+1]);
214*217Smuffin 
215*217Smuffin 	return (0);
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate 
218*217Smuffin int
in_olist(n)2190Sstevel@tonic-gate in_olist(n)	/* is n in olist? */
2200Sstevel@tonic-gate int n;
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate 	int i;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	if (nolist == 0)
2250Sstevel@tonic-gate 		return(1);	/* everything is included */
2260Sstevel@tonic-gate 	for (i = 0; i < nolist; i += 2)
2270Sstevel@tonic-gate 		if (n >= olist[i] && n <= olist[i+1])
2280Sstevel@tonic-gate 			return(1);
2290Sstevel@tonic-gate 	return(0);
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate 
232*217Smuffin int
conv(fp)2330Sstevel@tonic-gate conv(fp)
234*217Smuffin FILE *fp;
2350Sstevel@tonic-gate {
236*217Smuffin 	int c, k;
2370Sstevel@tonic-gate 	int m, n, i, n1, m1;
2380Sstevel@tonic-gate 	char str[100], buf[300];
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	while ((c = getc(fp)) != EOF) {
2410Sstevel@tonic-gate 		switch (c) {
2420Sstevel@tonic-gate 		case '\n':	/* when input is text */
2430Sstevel@tonic-gate 		case ' ':
2440Sstevel@tonic-gate 		case 0:		/* occasional noise creeps in */
2450Sstevel@tonic-gate 			break;
2460Sstevel@tonic-gate 		case '{':	/* push down current environment */
2470Sstevel@tonic-gate 			t_push();
2480Sstevel@tonic-gate 			break;
2490Sstevel@tonic-gate 		case '}':
2500Sstevel@tonic-gate 			t_pop();
2510Sstevel@tonic-gate 			break;
2520Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
2530Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
2540Sstevel@tonic-gate 			/* two motion digits plus a character */
2550Sstevel@tonic-gate 			hmot((c-'0')*10 + getc(fp)-'0');
2560Sstevel@tonic-gate 			put1(getc(fp));
2570Sstevel@tonic-gate 			break;
2580Sstevel@tonic-gate 		case 'c':	/* single ascii character */
2590Sstevel@tonic-gate 			put1(getc(fp));
2600Sstevel@tonic-gate 			break;
2610Sstevel@tonic-gate 		case 'C':
2620Sstevel@tonic-gate 			fscanf(fp, "%s", str);
2630Sstevel@tonic-gate 			put1s(str);
2640Sstevel@tonic-gate 			break;
2650Sstevel@tonic-gate 		case 't':	/* straight text */
2660Sstevel@tonic-gate 			fgets(buf, sizeof(buf), fp);
2670Sstevel@tonic-gate 			t_text(buf);
2680Sstevel@tonic-gate 			break;
2690Sstevel@tonic-gate 		case 'D':	/* draw function */
2700Sstevel@tonic-gate 			fgets(buf, sizeof(buf), fp);
2710Sstevel@tonic-gate 			switch (buf[0]) {
2720Sstevel@tonic-gate 			case 'l':	/* draw a line */
2730Sstevel@tonic-gate 				sscanf(buf+1, "%d %d", &n, &m);
2740Sstevel@tonic-gate 				drawline(n, m, ".");
2750Sstevel@tonic-gate 				break;
2760Sstevel@tonic-gate 			case 'c':	/* circle */
2770Sstevel@tonic-gate 				sscanf(buf+1, "%d", &n);
2780Sstevel@tonic-gate 				drawcirc(n);
2790Sstevel@tonic-gate 				break;
2800Sstevel@tonic-gate 			case 'e':	/* ellipse */
2810Sstevel@tonic-gate 				sscanf(buf+1, "%d %d", &m, &n);
2820Sstevel@tonic-gate 				drawellip(m, n);
2830Sstevel@tonic-gate 				break;
2840Sstevel@tonic-gate 			case 'a':	/* arc */
2850Sstevel@tonic-gate 				sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1);
2860Sstevel@tonic-gate 				drawarc(n, m, n1, m1);
2870Sstevel@tonic-gate 				break;
2880Sstevel@tonic-gate 			case '~':	/* wiggly line */
2890Sstevel@tonic-gate 				drawwig(buf+1);
2900Sstevel@tonic-gate 				break;
2910Sstevel@tonic-gate 			default:
2920Sstevel@tonic-gate 				error(FATAL, "unknown drawing function %s\n", buf);
2930Sstevel@tonic-gate 				break;
2940Sstevel@tonic-gate 			}
2950Sstevel@tonic-gate 			break;
2960Sstevel@tonic-gate 		case 's':
2970Sstevel@tonic-gate 			fscanf(fp, "%d", &n);	/* ignore fractional sizes */
2980Sstevel@tonic-gate 			setsize(t_size(n));
2990Sstevel@tonic-gate 			break;
3000Sstevel@tonic-gate 		case 'f':
3010Sstevel@tonic-gate 			fscanf(fp, "%s", str);
3020Sstevel@tonic-gate 			setfont(t_font(str));
3030Sstevel@tonic-gate 			break;
3040Sstevel@tonic-gate 		case 'H':	/* absolute horizontal motion */
3050Sstevel@tonic-gate 			/* fscanf(fp, "%d", &n); */
3060Sstevel@tonic-gate 			while ((c = getc(fp)) == ' ')
3070Sstevel@tonic-gate 				;
3080Sstevel@tonic-gate 			k = 0;
3090Sstevel@tonic-gate 			do {
3100Sstevel@tonic-gate 				k = 10 * k + c - '0';
3110Sstevel@tonic-gate 			} while (isdigit(c = getc(fp)));
3120Sstevel@tonic-gate 			ungetc(c, fp);
3130Sstevel@tonic-gate 			hgoto(k);
3140Sstevel@tonic-gate 			break;
3150Sstevel@tonic-gate 		case 'h':	/* relative horizontal motion */
3160Sstevel@tonic-gate 			/* fscanf(fp, "%d", &n); */
3170Sstevel@tonic-gate 			while ((c = getc(fp)) == ' ')
3180Sstevel@tonic-gate 				;
3190Sstevel@tonic-gate 			k = 0;
3200Sstevel@tonic-gate 			do {
3210Sstevel@tonic-gate 				k = 10 * k + c - '0';
3220Sstevel@tonic-gate 			} while (isdigit(c = getc(fp)));
3230Sstevel@tonic-gate 			ungetc(c, fp);
3240Sstevel@tonic-gate 			hmot(k);
3250Sstevel@tonic-gate 			break;
3260Sstevel@tonic-gate 		case 'w':	/* word space */
3270Sstevel@tonic-gate 			putc(' ', stdout);
3280Sstevel@tonic-gate 			break;
3290Sstevel@tonic-gate 		case 'V':
3300Sstevel@tonic-gate 			fscanf(fp, "%d", &n);
3310Sstevel@tonic-gate 			vgoto(n);
3320Sstevel@tonic-gate 			break;
3330Sstevel@tonic-gate 		case 'v':
3340Sstevel@tonic-gate 			fscanf(fp, "%d", &n);
3350Sstevel@tonic-gate 			vmot(n);
3360Sstevel@tonic-gate 			break;
3370Sstevel@tonic-gate 		case 'p':	/* new page */
3380Sstevel@tonic-gate 			fscanf(fp, "%d", &n);
3390Sstevel@tonic-gate 			t_page(n);
3400Sstevel@tonic-gate 			break;
3410Sstevel@tonic-gate 		case 'n':	/* end of line */
3420Sstevel@tonic-gate 			while (getc(fp) != '\n')
3430Sstevel@tonic-gate 				;
3440Sstevel@tonic-gate 			t_newline();
3450Sstevel@tonic-gate 			break;
3460Sstevel@tonic-gate 		case '#':	/* comment */
3470Sstevel@tonic-gate 			while (getc(fp) != '\n')
3480Sstevel@tonic-gate 				;
3490Sstevel@tonic-gate 			break;
3500Sstevel@tonic-gate 		case 'x':	/* device control */
3510Sstevel@tonic-gate 			devcntrl(fp);
3520Sstevel@tonic-gate 			break;
3530Sstevel@tonic-gate 		default:
3540Sstevel@tonic-gate 			error(!FATAL, "unknown input character %o %c\n", c, c);
3550Sstevel@tonic-gate 			done();
3560Sstevel@tonic-gate 		}
3570Sstevel@tonic-gate 	}
358*217Smuffin 
359*217Smuffin 	return (0);
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate 
362*217Smuffin int
devcntrl(fp)3630Sstevel@tonic-gate devcntrl(fp)	/* interpret device control functions */
3640Sstevel@tonic-gate FILE *fp;
3650Sstevel@tonic-gate {
3660Sstevel@tonic-gate 	char str[20];
3670Sstevel@tonic-gate 	int c, n;
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 	fscanf(fp, "%s", str);
3700Sstevel@tonic-gate 	switch (str[0]) {	/* crude for now */
3710Sstevel@tonic-gate 	case 'i':	/* initialize */
3720Sstevel@tonic-gate 		fileinit();
3730Sstevel@tonic-gate 		t_init(0);
3740Sstevel@tonic-gate 		break;
3750Sstevel@tonic-gate 	case 'T':	/* device name */
3760Sstevel@tonic-gate 		fscanf(fp, "%s", devname);
3770Sstevel@tonic-gate 		break;
3780Sstevel@tonic-gate 	case 't':	/* trailer */
3790Sstevel@tonic-gate 		t_trailer();
3800Sstevel@tonic-gate 		break;
3810Sstevel@tonic-gate 	case 'p':	/* pause -- can restart */
3820Sstevel@tonic-gate 		t_reset('p');
3830Sstevel@tonic-gate 		break;
3840Sstevel@tonic-gate 	case 's':	/* stop */
3850Sstevel@tonic-gate 		t_reset('s');
3860Sstevel@tonic-gate 		break;
3870Sstevel@tonic-gate 	case 'r':	/* resolution assumed when prepared */
3880Sstevel@tonic-gate 		fscanf(fp, "%d", &res);
3890Sstevel@tonic-gate 		break;
3900Sstevel@tonic-gate 	case 'f':	/* font used */
3910Sstevel@tonic-gate 		fscanf(fp, "%d %s", &n, str);
3920Sstevel@tonic-gate 		loadfont(n, str);
3930Sstevel@tonic-gate 		break;
3940Sstevel@tonic-gate 	}
3950Sstevel@tonic-gate 	while (getc(fp) != '\n')	/* skip rest of input line */
3960Sstevel@tonic-gate 		;
397*217Smuffin 
398*217Smuffin 	return (0);
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate 
401*217Smuffin int
fileinit()4020Sstevel@tonic-gate fileinit()	/* read in font and code files, etc. */
4030Sstevel@tonic-gate {
404*217Smuffin 	return (0);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate 
407*217Smuffin int
fontprint(i)4080Sstevel@tonic-gate fontprint(i)	/* debugging print of font i (0,...) */
4090Sstevel@tonic-gate {
410*217Smuffin 	return (0);
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate 
413*217Smuffin int
loadcode(n,nw)4140Sstevel@tonic-gate loadcode(n, nw)	/* load codetab on position n (0...); #chars is nw */
4150Sstevel@tonic-gate int n, nw;
4160Sstevel@tonic-gate {
417*217Smuffin 	return (0);
4180Sstevel@tonic-gate }
4190Sstevel@tonic-gate 
420*217Smuffin int
loadfont(n,s)4210Sstevel@tonic-gate loadfont(n, s)	/* load font info for font s on position n (1...) */
4220Sstevel@tonic-gate int n;
4230Sstevel@tonic-gate char *s;
4240Sstevel@tonic-gate {
425*217Smuffin 	return (0);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate 
428*217Smuffin int
error(f,s,a1,a2,a3,a4,a5,a6,a7)4290Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7)
4300Sstevel@tonic-gate char *s;
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate 	fprintf(stderr, "ta: ");
4330Sstevel@tonic-gate 	fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
4340Sstevel@tonic-gate 	fprintf(stderr, "\n");
4350Sstevel@tonic-gate 	if (f)
4360Sstevel@tonic-gate 		exit(1);
437*217Smuffin 
438*217Smuffin 	return (0);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate /*
4430Sstevel@tonic-gate 	Here beginneth all the stuff that really depends
4440Sstevel@tonic-gate 	on the 202 (we hope).
4450Sstevel@tonic-gate */
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate char	devname[20]	= "hp2621";
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate #define	ESC	033
4510Sstevel@tonic-gate #define	HOME	'H'
4520Sstevel@tonic-gate #define	CLEAR	'J'
4530Sstevel@tonic-gate #define	FF	014
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate int	size	= 1;
4560Sstevel@tonic-gate int	font	= 1;		/* current font */
4570Sstevel@tonic-gate int	hpos;		/* horizontal position where we are supposed to be next (left = 0) */
4580Sstevel@tonic-gate int	vpos;		/* current vertical position (down positive) */
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate int	horig;		/* h origin of current block; hpos rel to this */
4610Sstevel@tonic-gate int	vorig;		/* v origin of current block; vpos rel to this */
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate int	DX	= 10;	/* step size in x for drawing */
4640Sstevel@tonic-gate int	DY	= 10;	/* step size in y for drawing */
4650Sstevel@tonic-gate int	drawdot	= '.';	/* draw with this character */
4660Sstevel@tonic-gate int	drawsize = 1;	/* shrink by this factor when drawing */
4670Sstevel@tonic-gate 
468*217Smuffin int
t_init(reinit)4690Sstevel@tonic-gate t_init(reinit)	/* initialize device */
4700Sstevel@tonic-gate int reinit;
4710Sstevel@tonic-gate {
4720Sstevel@tonic-gate 	int i, j;
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 	fflush(stdout);
4750Sstevel@tonic-gate 	hpos = vpos = 0;
476*217Smuffin 
477*217Smuffin 	return (0);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate #define	MAXSTATE	5
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate struct state {
4830Sstevel@tonic-gate 	int	ssize;
4840Sstevel@tonic-gate 	int	sfont;
4850Sstevel@tonic-gate 	int	shpos;
4860Sstevel@tonic-gate 	int	svpos;
4870Sstevel@tonic-gate 	int	shorig;
4880Sstevel@tonic-gate 	int	svorig;
4890Sstevel@tonic-gate };
4900Sstevel@tonic-gate struct	state	state[MAXSTATE];
4910Sstevel@tonic-gate struct	state	*statep = state;
4920Sstevel@tonic-gate 
493*217Smuffin int
t_push()4940Sstevel@tonic-gate t_push()	/* begin a new block */
4950Sstevel@tonic-gate {
4960Sstevel@tonic-gate 	hflush();
4970Sstevel@tonic-gate 	statep->ssize = size;
4980Sstevel@tonic-gate 	statep->sfont = font;
4990Sstevel@tonic-gate 	statep->shorig = horig;
5000Sstevel@tonic-gate 	statep->svorig = vorig;
5010Sstevel@tonic-gate 	statep->shpos = hpos;
5020Sstevel@tonic-gate 	statep->svpos = vpos;
5030Sstevel@tonic-gate 	horig = hpos;
5040Sstevel@tonic-gate 	vorig = vpos;
5050Sstevel@tonic-gate 	hpos = vpos = 0;
5060Sstevel@tonic-gate 	if (statep++ >= state+MAXSTATE)
5070Sstevel@tonic-gate 		error(FATAL, "{ nested too deep");
5080Sstevel@tonic-gate 	hpos = vpos = 0;
509*217Smuffin 
510*217Smuffin 	return (0);
5110Sstevel@tonic-gate }
5120Sstevel@tonic-gate 
513*217Smuffin int
t_pop()5140Sstevel@tonic-gate t_pop()	/* pop to previous state */
5150Sstevel@tonic-gate {
5160Sstevel@tonic-gate 	if (--statep < state)
5170Sstevel@tonic-gate 		error(FATAL, "extra }");
5180Sstevel@tonic-gate 	size = statep->ssize;
5190Sstevel@tonic-gate 	font = statep->sfont;
5200Sstevel@tonic-gate 	hpos = statep->shpos;
5210Sstevel@tonic-gate 	vpos = statep->svpos;
5220Sstevel@tonic-gate 	horig = statep->shorig;
5230Sstevel@tonic-gate 	vorig = statep->svorig;
524*217Smuffin 
525*217Smuffin 	return (0);
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate int	np;	/* number of pages seen */
5290Sstevel@tonic-gate int	npmax;	/* high-water mark of np */
5300Sstevel@tonic-gate int	pgnum[40];	/* their actual numbers */
5310Sstevel@tonic-gate long	pgadr[40];	/* their seek addresses */
5320Sstevel@tonic-gate 
533*217Smuffin int
t_page(n)5340Sstevel@tonic-gate t_page(n)	/* do whatever new page functions */
5350Sstevel@tonic-gate {
5360Sstevel@tonic-gate 	long ftell();
5370Sstevel@tonic-gate 	int c, m, i;
5380Sstevel@tonic-gate 	char buf[100], *bp;
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate 	pgnum[np++] = n;
5410Sstevel@tonic-gate 	pgadr[np] = ftell(fp);
5420Sstevel@tonic-gate 	if (np > npmax)
5430Sstevel@tonic-gate 		npmax = np;
5440Sstevel@tonic-gate 	if (output == 0) {
5450Sstevel@tonic-gate 		output = in_olist(n);
5460Sstevel@tonic-gate 		t_init(1);
547*217Smuffin 		return (0);
5480Sstevel@tonic-gate 	}
5490Sstevel@tonic-gate 	/* have just printed something, and seen p<n> for next one */
5500Sstevel@tonic-gate 	putpage();
5510Sstevel@tonic-gate 	fflush(stdout);
5520Sstevel@tonic-gate 	if (nowait)
553*217Smuffin 		return (0);
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate   next:
5560Sstevel@tonic-gate 	for (bp = buf; (*bp = readch()); )
5570Sstevel@tonic-gate 		if (*bp++ == '\n')
5580Sstevel@tonic-gate 			break;
5590Sstevel@tonic-gate 	*bp = 0;
5600Sstevel@tonic-gate 	switch (buf[0]) {
5610Sstevel@tonic-gate 	case 0:
5620Sstevel@tonic-gate 		done();
5630Sstevel@tonic-gate 		break;
5640Sstevel@tonic-gate 	case '\n':
5650Sstevel@tonic-gate 		output = in_olist(n);
5660Sstevel@tonic-gate 		t_init(1);
567*217Smuffin 		return (0);
5680Sstevel@tonic-gate 	case '!':
5690Sstevel@tonic-gate 		callunix(&buf[1]);
5700Sstevel@tonic-gate 		fputs("!\n", stderr);
5710Sstevel@tonic-gate 		break;
5720Sstevel@tonic-gate 	case 'e':
5730Sstevel@tonic-gate 		erase = 1 - erase;
5740Sstevel@tonic-gate 		break;
5750Sstevel@tonic-gate 	case 'w':
5760Sstevel@tonic-gate 		wflag = 1 - wflag;
5770Sstevel@tonic-gate 		break;
5780Sstevel@tonic-gate 	case 'a':
5790Sstevel@tonic-gate 		aspect = atof(&buf[1]);
5800Sstevel@tonic-gate 		break;
5810Sstevel@tonic-gate 	case '-':
5820Sstevel@tonic-gate 	case 'p':
5830Sstevel@tonic-gate 		m = atoi(&buf[1]) + 1;
5840Sstevel@tonic-gate 		if (fp == stdin) {
5850Sstevel@tonic-gate 			fputs("you can't; it's not a file\n", stderr);
5860Sstevel@tonic-gate 			break;
5870Sstevel@tonic-gate 		}
5880Sstevel@tonic-gate 		if (np - m <= 0) {
5890Sstevel@tonic-gate 			fputs("too far back\n", stderr);
5900Sstevel@tonic-gate 			break;
5910Sstevel@tonic-gate 		}
5920Sstevel@tonic-gate 		np -= m;
5930Sstevel@tonic-gate 		fseek(fp, pgadr[np], 0);
5940Sstevel@tonic-gate 		output = 1;
5950Sstevel@tonic-gate 		t_init(1);
596*217Smuffin 		return (0);
5970Sstevel@tonic-gate 	case '0': case '1': case '2': case '3': case '4':
5980Sstevel@tonic-gate 	case '5': case '6': case '7': case '8': case '9':
5990Sstevel@tonic-gate 		m = atoi(&buf[0]);
6000Sstevel@tonic-gate 		for (i = 0; i < npmax; i++)
6010Sstevel@tonic-gate 			if (m == pgnum[i])
6020Sstevel@tonic-gate 				break;
6030Sstevel@tonic-gate 		if (i >= npmax || fp == stdin) {
6040Sstevel@tonic-gate 			fputs("you can't\n", stderr);
6050Sstevel@tonic-gate 			break;
6060Sstevel@tonic-gate 		}
6070Sstevel@tonic-gate 		np = i + 1;
6080Sstevel@tonic-gate 		fseek(fp, pgadr[np], 0);
6090Sstevel@tonic-gate 		output = 1;
6100Sstevel@tonic-gate 		t_init(1);
611*217Smuffin 		return (0);
6120Sstevel@tonic-gate 	case 'o':
6130Sstevel@tonic-gate 		outlist(&buf[1]);
6140Sstevel@tonic-gate 		output = 0;
6150Sstevel@tonic-gate 		t_init(1);
616*217Smuffin 		return (0);
6170Sstevel@tonic-gate 	case '?':
6180Sstevel@tonic-gate 		fputs("!cmd	unix cmd\n", stderr);
6190Sstevel@tonic-gate 		fputs("p	print this page again\n", stderr);
6200Sstevel@tonic-gate 		fputs("-n	go back n pages\n", stderr);
6210Sstevel@tonic-gate 		fputs("n	print page n (previously printed)\n", stderr);
6220Sstevel@tonic-gate 		fputs("o...	set the -o output list to ...\n", stderr);
6230Sstevel@tonic-gate 		fputs("en	n=0 -> don't erase; n=1 -> erase\n", stderr);
6240Sstevel@tonic-gate 		fputs("an	sets aspect ratio to n\n", stderr);
6250Sstevel@tonic-gate 		break;
6260Sstevel@tonic-gate 	default:
6270Sstevel@tonic-gate 		fputs("?\n", stderr);
6280Sstevel@tonic-gate 		break;
6290Sstevel@tonic-gate 	}
6300Sstevel@tonic-gate 	goto next;
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate 
633*217Smuffin int
putpage()6340Sstevel@tonic-gate putpage()
6350Sstevel@tonic-gate {
6360Sstevel@tonic-gate 	int i, j, k;
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate 	fflush(stdout);
639*217Smuffin 
640*217Smuffin 	return (0);
6410Sstevel@tonic-gate }
6420Sstevel@tonic-gate 
643*217Smuffin int
t_newline()6440Sstevel@tonic-gate t_newline()	/* do whatever for the end of a line */
6450Sstevel@tonic-gate {
6460Sstevel@tonic-gate 	printf("\n");
6470Sstevel@tonic-gate 	hpos = 0;
648*217Smuffin 
649*217Smuffin 	return (0);
6500Sstevel@tonic-gate }
6510Sstevel@tonic-gate 
652*217Smuffin int
t_size(n)6530Sstevel@tonic-gate t_size(n)	/* convert integer to internal size number*/
6540Sstevel@tonic-gate int n;
6550Sstevel@tonic-gate {
656*217Smuffin 	return (0);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate 
659*217Smuffin int
t_font(s)6600Sstevel@tonic-gate t_font(s)	/* convert string to internal font number */
6610Sstevel@tonic-gate char *s;
6620Sstevel@tonic-gate {
663*217Smuffin 	return (0);
6640Sstevel@tonic-gate }
6650Sstevel@tonic-gate 
666*217Smuffin int
t_text(s)6670Sstevel@tonic-gate t_text(s)	/* print string s as text */
6680Sstevel@tonic-gate char *s;
6690Sstevel@tonic-gate {
6700Sstevel@tonic-gate 	int c, w=0;
6710Sstevel@tonic-gate 	char str[100];
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	if (!output)
674*217Smuffin 		return (0);
6750Sstevel@tonic-gate 	while ((c = *s++) != '\n') {
6760Sstevel@tonic-gate 		if (c == '\\') {
6770Sstevel@tonic-gate 			switch (c = *s++) {
6780Sstevel@tonic-gate 			case '\\':
6790Sstevel@tonic-gate 			case 'e':
6800Sstevel@tonic-gate 				put1('\\');
6810Sstevel@tonic-gate 				break;
6820Sstevel@tonic-gate 			case '(':
6830Sstevel@tonic-gate 				str[0] = *s++;
6840Sstevel@tonic-gate 				str[1] = *s++;
6850Sstevel@tonic-gate 				str[2] = '\0';
6860Sstevel@tonic-gate 				put1s(str);
6870Sstevel@tonic-gate 				break;
6880Sstevel@tonic-gate 			}
6890Sstevel@tonic-gate 		} else {
6900Sstevel@tonic-gate 			put1(c);
6910Sstevel@tonic-gate 		}
6920Sstevel@tonic-gate 		hmot(w);
6930Sstevel@tonic-gate 	}
694*217Smuffin 
695*217Smuffin 	return (0);
6960Sstevel@tonic-gate }
6970Sstevel@tonic-gate 
698*217Smuffin int
t_reset(c)6990Sstevel@tonic-gate t_reset(c)
7000Sstevel@tonic-gate {
7010Sstevel@tonic-gate 	int n;
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 	output = 1;
7040Sstevel@tonic-gate 	fflush(stdout);
7050Sstevel@tonic-gate 	if (c == 's')
7060Sstevel@tonic-gate 		t_page(9999);
707*217Smuffin 
708*217Smuffin 	return (0);
7090Sstevel@tonic-gate }
7100Sstevel@tonic-gate 
711*217Smuffin int
t_trailer()7120Sstevel@tonic-gate t_trailer()
7130Sstevel@tonic-gate {
714*217Smuffin 	return (0);
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate 
717*217Smuffin int
hgoto(n)7180Sstevel@tonic-gate hgoto(n)
7190Sstevel@tonic-gate {
7200Sstevel@tonic-gate 	hpos = n;	/* this is where we want to be */
7210Sstevel@tonic-gate 			/* before printing a character, */
7220Sstevel@tonic-gate 			/* have to make sure it's true */
723*217Smuffin 
724*217Smuffin 	return (0);
7250Sstevel@tonic-gate }
7260Sstevel@tonic-gate 
727*217Smuffin int
hmot(n)7280Sstevel@tonic-gate hmot(n)	/* generate n units of horizontal motion */
7290Sstevel@tonic-gate int n;
7300Sstevel@tonic-gate {
7310Sstevel@tonic-gate 	hgoto(hpos + n);
732*217Smuffin 
733*217Smuffin 	return (0);
7340Sstevel@tonic-gate }
7350Sstevel@tonic-gate 
736*217Smuffin int
hflush()7370Sstevel@tonic-gate hflush()	/* actual horizontal output occurs here */
7380Sstevel@tonic-gate {
739*217Smuffin 	return (0);
7400Sstevel@tonic-gate }
7410Sstevel@tonic-gate 
742*217Smuffin int
vgoto(n)7430Sstevel@tonic-gate vgoto(n)
7440Sstevel@tonic-gate {
7450Sstevel@tonic-gate 	vpos = n;
746*217Smuffin 
747*217Smuffin 	return (0);
7480Sstevel@tonic-gate }
7490Sstevel@tonic-gate 
750*217Smuffin int
vmot(n)7510Sstevel@tonic-gate vmot(n)	/* generate n units of vertical motion */
7520Sstevel@tonic-gate int n;
7530Sstevel@tonic-gate {
7540Sstevel@tonic-gate 	vgoto(vpos + n);	/* ignores rounding */
755*217Smuffin 
756*217Smuffin 	return (0);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate 
759*217Smuffin int
put1s(s)7600Sstevel@tonic-gate put1s(s)	/* s is a funny char name */
7610Sstevel@tonic-gate char *s;
7620Sstevel@tonic-gate {
7630Sstevel@tonic-gate 	int i;
7640Sstevel@tonic-gate 	char *p;
7650Sstevel@tonic-gate 	extern char *spectab[];
7660Sstevel@tonic-gate 	static char prev[10] = "";
7670Sstevel@tonic-gate 	static int previ;
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate 	if (!output)
770*217Smuffin 		return (0);
7710Sstevel@tonic-gate 	if (strcmp(s, prev) != 0) {
7720Sstevel@tonic-gate 		previ = -1;
7730Sstevel@tonic-gate 		for (i = 0; spectab[i] != 0; i += 2)
7740Sstevel@tonic-gate 			if (strcmp(spectab[i], s) == 0) {
7750Sstevel@tonic-gate 				strcpy(prev, s);
7760Sstevel@tonic-gate 				previ = i;
7770Sstevel@tonic-gate 				break;
7780Sstevel@tonic-gate 			}
7790Sstevel@tonic-gate 	}
7800Sstevel@tonic-gate 	if (previ >= 0) {
7810Sstevel@tonic-gate 		for (p = spectab[previ+1]; *p; p++)
7820Sstevel@tonic-gate 			putc(*p, stdout);
7830Sstevel@tonic-gate 	} else
7840Sstevel@tonic-gate 		prev[0] = 0;
785*217Smuffin 
786*217Smuffin 	return (0);
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate 
789*217Smuffin int
put1(c)7900Sstevel@tonic-gate put1(c)	/* output char c */
7910Sstevel@tonic-gate int c;
7920Sstevel@tonic-gate {
7930Sstevel@tonic-gate 	if (!output)
794*217Smuffin 		return (0);
7950Sstevel@tonic-gate 	putc(c, stdout);
796*217Smuffin 
797*217Smuffin 	return (0);
7980Sstevel@tonic-gate }
7990Sstevel@tonic-gate 
800*217Smuffin int
setsize(n)8010Sstevel@tonic-gate setsize(n)	/* set point size to n (internal) */
8020Sstevel@tonic-gate int n;
8030Sstevel@tonic-gate {
804*217Smuffin 	return (0);
8050Sstevel@tonic-gate }
8060Sstevel@tonic-gate 
807*217Smuffin int
t_fp(n,s)8080Sstevel@tonic-gate t_fp(n, s)	/* font position n now contains font s */
8090Sstevel@tonic-gate int n;
8100Sstevel@tonic-gate char *s;
8110Sstevel@tonic-gate {
812*217Smuffin 	return (0);
8130Sstevel@tonic-gate }
8140Sstevel@tonic-gate 
815*217Smuffin int
setfont(n)8160Sstevel@tonic-gate setfont(n)	/* set font to n */
8170Sstevel@tonic-gate int n;
8180Sstevel@tonic-gate {
819*217Smuffin 	return (0);
8200Sstevel@tonic-gate }
8210Sstevel@tonic-gate 
done()8220Sstevel@tonic-gate void done()
8230Sstevel@tonic-gate {
8240Sstevel@tonic-gate 	output = 1;
8250Sstevel@tonic-gate 	putpage();
8260Sstevel@tonic-gate 	fflush(stdout);
8270Sstevel@tonic-gate 	exit(0);
8280Sstevel@tonic-gate }
8290Sstevel@tonic-gate 
830*217Smuffin int
callunix(line)8310Sstevel@tonic-gate callunix(line)
8320Sstevel@tonic-gate char line[];
8330Sstevel@tonic-gate {
8340Sstevel@tonic-gate 	int rc, status, unixpid;
8350Sstevel@tonic-gate 	if( (unixpid=fork())==0 ) {
8360Sstevel@tonic-gate 		signal(SIGINT,sigint); signal(SIGQUIT,sigquit);
8370Sstevel@tonic-gate 		close(0); dup(2);
8380Sstevel@tonic-gate 		execl("/bin/sh", "-sh", "-c", line, 0);
8390Sstevel@tonic-gate 		exit(255);
8400Sstevel@tonic-gate 	}
8410Sstevel@tonic-gate 	else if(unixpid == -1)
842*217Smuffin 		return (0);
8430Sstevel@tonic-gate 	else{	signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
8440Sstevel@tonic-gate 		while( (rc = wait(&status)) != unixpid && rc != -1 ) ;
8450Sstevel@tonic-gate 		signal(SIGINT,(void(*)())done); signal(SIGQUIT,(void(*)())sigquit);
8460Sstevel@tonic-gate 	}
847*217Smuffin 
848*217Smuffin 	return (0);
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate 
851*217Smuffin int
readch()8520Sstevel@tonic-gate readch(){
8530Sstevel@tonic-gate 	char c;
8540Sstevel@tonic-gate 	if (read(2,&c,1)<1) c=0;
8550Sstevel@tonic-gate 	return(c);
8560Sstevel@tonic-gate }
8570Sstevel@tonic-gate 
8580Sstevel@tonic-gate char *spectab[] ={
8590Sstevel@tonic-gate 	"em", "-",
8600Sstevel@tonic-gate 	"hy", "-",
8610Sstevel@tonic-gate 	"en", "-",
8620Sstevel@tonic-gate 	"ru", "_",
8630Sstevel@tonic-gate 	"l.", ".",
8640Sstevel@tonic-gate 	"br", "|",
8650Sstevel@tonic-gate 	"vr", "|",
8660Sstevel@tonic-gate 	"fm", "'",
8670Sstevel@tonic-gate 	"or", "|",
8680Sstevel@tonic-gate 	0, 0,
8690Sstevel@tonic-gate };
870