xref: /onnv-gate/usr/src/cmd/troff/nroff.d/n10.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 n10.c
440Sstevel@tonic-gate 
450Sstevel@tonic-gate Device interfaces
460Sstevel@tonic-gate */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #include <limits.h>
490Sstevel@tonic-gate #include <ctype.h>
500Sstevel@tonic-gate #include <sys/types.h>
510Sstevel@tonic-gate #include <sys/stat.h>
520Sstevel@tonic-gate #ifdef EUC
530Sstevel@tonic-gate #ifdef NROFF
540Sstevel@tonic-gate #include <stdlib.h>
550Sstevel@tonic-gate #endif /* NROFF */
560Sstevel@tonic-gate #endif /* EUC */
570Sstevel@tonic-gate #include "tdef.h"
580Sstevel@tonic-gate #include "ext.h"
590Sstevel@tonic-gate #include "tw.h"
600Sstevel@tonic-gate 
610Sstevel@tonic-gate struct t t;	/* terminal characteristics */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate int	dtab;
640Sstevel@tonic-gate int	plotmode;
650Sstevel@tonic-gate int	esct;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate char	xchname[4 * (NROFFCHARS-_SPECCHAR_ST)];	/* hy, em, etc. */
680Sstevel@tonic-gate short	xchtab[NROFFCHARS-_SPECCHAR_ST];		/* indexes into chname[] */
690Sstevel@tonic-gate char	*codestr;
700Sstevel@tonic-gate char	*chname = xchname;
710Sstevel@tonic-gate short	*chtab = xchtab;
720Sstevel@tonic-gate int	nchtab = 0;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 
750Sstevel@tonic-gate int	Inch;
760Sstevel@tonic-gate int	Hor;
770Sstevel@tonic-gate int	Vert;
780Sstevel@tonic-gate int	nfonts	= 4;	/* R, I, B, S */
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /* these characters are used as various signals or values
810Sstevel@tonic-gate  * in miscellaneous places.
820Sstevel@tonic-gate  * values are set in specnames in t10.c
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate int	c_hyphen;
860Sstevel@tonic-gate int	c_emdash;
870Sstevel@tonic-gate int	c_rule;
880Sstevel@tonic-gate int	c_minus;
890Sstevel@tonic-gate int	c_fi;
900Sstevel@tonic-gate int	c_fl;
910Sstevel@tonic-gate int	c_ff;
920Sstevel@tonic-gate int	c_ffi;
930Sstevel@tonic-gate int	c_ffl;
940Sstevel@tonic-gate int	c_acute;
950Sstevel@tonic-gate int	c_grave;
960Sstevel@tonic-gate int	c_under;
970Sstevel@tonic-gate int	c_rooten;
980Sstevel@tonic-gate int	c_boxrule;
990Sstevel@tonic-gate int	c_lefthand;
1000Sstevel@tonic-gate int	c_dagger;
1010Sstevel@tonic-gate int	c_isalnum;
1020Sstevel@tonic-gate 
103*217Smuffin int
ptinit()1040Sstevel@tonic-gate ptinit()
1050Sstevel@tonic-gate {
106*217Smuffin 	int i, j;
107*217Smuffin 	char *p, *cp, *q;
1080Sstevel@tonic-gate 	int nread, fd;
1090Sstevel@tonic-gate 	extern char *skipstr(), *getstr(), *getint();
1100Sstevel@tonic-gate 	extern char *setbrk();
1110Sstevel@tonic-gate 	struct stat stbuf;
1120Sstevel@tonic-gate 	char check[50];
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	strcat(termtab, devname);
1150Sstevel@tonic-gate 	if ((fd = open(termtab, 0)) < 0) {
1160Sstevel@tonic-gate 		errprint(gettext("cannot open %s"), termtab);
1170Sstevel@tonic-gate 		exit(-1);
1180Sstevel@tonic-gate 	}
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	fstat(fd, &stbuf);
1210Sstevel@tonic-gate 	codestr = setbrk((int) stbuf.st_size);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	nread = read(fd, codestr, (int) stbuf.st_size);
1240Sstevel@tonic-gate 	close(fd);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	p = codestr;
1270Sstevel@tonic-gate 	p = skipstr(p);		/* skip over type, could check */
1280Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.bset);
1290Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.breset);
1300Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Hor);
1310Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Vert);
1320Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Newline);
1330Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Char);
1340Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Em);
1350Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Halfline);
1360Sstevel@tonic-gate 	p = skipstr(p); p = getint(p, &t.Adj);
1370Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.twinit = p);
1380Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.twrest = p);
1390Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.twnl = p);
1400Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.hlr = p);
1410Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.hlf = p);
1420Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.flr = p);
1430Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.bdon = p);
1440Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.bdoff = p);
1450Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.iton = p);
1460Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.itoff = p);
1470Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.ploton = p);
1480Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.plotoff = p);
1490Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.up = p);
1500Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.down = p);
1510Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.right = p);
1520Sstevel@tonic-gate 	p = skipstr(p); p = getstr(p, t.left = p);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	getstr(p, check);
1550Sstevel@tonic-gate 	if (strcmp(check, "charset") != 0) {
1560Sstevel@tonic-gate 		errprint(gettext("device table apparently curdled"));
1570Sstevel@tonic-gate 		exit(1);
1580Sstevel@tonic-gate 	}
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	for (i = 0; i < _SPECCHAR_ST; i++)
1610Sstevel@tonic-gate 		t.width[i] = 1;	/* default widths */
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	i = 0;
1640Sstevel@tonic-gate /* this ought to be a pointer array and in place in codestr */
1650Sstevel@tonic-gate 	cp = chname + 1;	/* bug if starts at 0, in setch */
1660Sstevel@tonic-gate 	while (p < codestr + nread) {
1670Sstevel@tonic-gate 		while (*p == ' ' || *p == '\t' || *p == '\n')
1680Sstevel@tonic-gate 			p++;
1690Sstevel@tonic-gate 		if (i + _SPECCHAR_ST >= NROFFCHARS) {
1700Sstevel@tonic-gate 			errprint(gettext("too many names in charset for %s"),
1710Sstevel@tonic-gate 					 termtab);
1720Sstevel@tonic-gate 			exit(1);
1730Sstevel@tonic-gate 		}
1740Sstevel@tonic-gate 		chtab[i] = cp - chname;	/* index, not pointer */
1750Sstevel@tonic-gate 		*cp++ = *p++;	/* 2-char names */
1760Sstevel@tonic-gate 		*cp++ = *p++;
1770Sstevel@tonic-gate 		*cp++ = '\0';
1780Sstevel@tonic-gate 		while (*p == ' ' || *p == '\t')
1790Sstevel@tonic-gate 			p++;
1800Sstevel@tonic-gate 		t.width[i+_SPECCHAR_ST] = *p++ - '0';
1810Sstevel@tonic-gate 		while (*p == ' ' || *p == '\t')
1820Sstevel@tonic-gate 			p++;
1830Sstevel@tonic-gate 		t.codetab[i] = p;
1840Sstevel@tonic-gate 		p = getstr(p, p);	/* compress string */
1850Sstevel@tonic-gate 		p++;
1860Sstevel@tonic-gate 		i++;
1870Sstevel@tonic-gate 		nchtab++;
1880Sstevel@tonic-gate 	}
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	sps = EM;
1910Sstevel@tonic-gate 	ics = EM * 2;
1920Sstevel@tonic-gate 	dtab = 8 * t.Em;
1930Sstevel@tonic-gate 	for (i = 0; i < 16; i++)
1940Sstevel@tonic-gate 		tabtab[i] = dtab * (i + 1);
1950Sstevel@tonic-gate 	pl = 11 * INCH;
1960Sstevel@tonic-gate 	po = PO;
1970Sstevel@tonic-gate 	spacesz = SS;
1980Sstevel@tonic-gate 	lss = lss1 = VS;
1990Sstevel@tonic-gate 	ll = ll1 = lt = lt1 = LL;
2000Sstevel@tonic-gate 	smnt = nfonts = 5;	/* R I B BI S */
2010Sstevel@tonic-gate 	specnames();	/* install names like "hyphen", etc. */
2020Sstevel@tonic-gate 	if (eqflg)
2030Sstevel@tonic-gate 		t.Adj = t.Hor;
204*217Smuffin 
205*217Smuffin 	return (0);
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
skipstr(s)2080Sstevel@tonic-gate char *skipstr(s)	/* skip over leading space plus string */
2090Sstevel@tonic-gate 	char *s;
2100Sstevel@tonic-gate {
2110Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
2120Sstevel@tonic-gate 		s++;
2130Sstevel@tonic-gate 	while (*s != ' ' && *s != '\t' && *s != '\n')
2140Sstevel@tonic-gate 		if (*s++ == '\\')
2150Sstevel@tonic-gate 			s++;
2160Sstevel@tonic-gate 	return s;
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate 
getstr(s,t)2190Sstevel@tonic-gate char *getstr(s, t)	/* find next string in s, copy to t */
2200Sstevel@tonic-gate 	char *s, *t;
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate 	int quote = 0;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
2250Sstevel@tonic-gate 		s++;
2260Sstevel@tonic-gate 	if (*s == '"') {
2270Sstevel@tonic-gate 		s++;
2280Sstevel@tonic-gate 		quote = 1;
2290Sstevel@tonic-gate 	}
2300Sstevel@tonic-gate 	for (;;) {
2310Sstevel@tonic-gate 		if (quote && *s == '"') {
2320Sstevel@tonic-gate 			s++;
2330Sstevel@tonic-gate 			break;
2340Sstevel@tonic-gate 		}
2350Sstevel@tonic-gate 		if (!quote && (*s == ' ' || *s == '\t' || *s == '\n'))
2360Sstevel@tonic-gate 			break;
2370Sstevel@tonic-gate 		if (*s != '\\')
2380Sstevel@tonic-gate 			*t++ = *s++;
2390Sstevel@tonic-gate 		else {
2400Sstevel@tonic-gate 			s++;	/* skip \\ */
2410Sstevel@tonic-gate 			if (isdigit((unsigned char)s[0]) &&
2420Sstevel@tonic-gate 			    isdigit((unsigned char)s[1]) &&
2430Sstevel@tonic-gate 			    isdigit((unsigned char)s[2])) {
2440Sstevel@tonic-gate 				*t++ = (s[0]-'0')<<6 | (s[1]-'0')<<3 | s[2]-'0';
2450Sstevel@tonic-gate 				s += 2;
2460Sstevel@tonic-gate 			} else if (isdigit((unsigned char)s[0])) {
2470Sstevel@tonic-gate 				*t++ = *s - '0';
2480Sstevel@tonic-gate 			} else if (*s == 'b') {
2490Sstevel@tonic-gate 				*t++ = '\b';
2500Sstevel@tonic-gate 			} else if (*s == 'n') {
2510Sstevel@tonic-gate 				*t++ = '\n';
2520Sstevel@tonic-gate 			} else if (*s == 'r') {
2530Sstevel@tonic-gate 				*t++ = '\r';
2540Sstevel@tonic-gate 			} else if (*s == 't') {
2550Sstevel@tonic-gate 				*t++ = '\t';
2560Sstevel@tonic-gate 			} else {
2570Sstevel@tonic-gate 				*t++ = *s;
2580Sstevel@tonic-gate 			}
2590Sstevel@tonic-gate 			s++;
2600Sstevel@tonic-gate 		}
2610Sstevel@tonic-gate 	}
2620Sstevel@tonic-gate 	*t = '\0';
2630Sstevel@tonic-gate 	return s;
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate 
getint(s,pn)2660Sstevel@tonic-gate char *getint(s, pn)	/* find integer at s */
2670Sstevel@tonic-gate 	char *s;
2680Sstevel@tonic-gate 	int *pn;
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate 	int base;
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	while (*s == ' ' || *s == '\t' || *s == '\n')
2730Sstevel@tonic-gate 		s++;
2740Sstevel@tonic-gate 	base = (*s == '0') ? 8 : 10;
2750Sstevel@tonic-gate 	*pn = 0;
2760Sstevel@tonic-gate 	while (isdigit((unsigned char)*s))
2770Sstevel@tonic-gate 		*pn = base * *pn + *s++ - '0';
2780Sstevel@tonic-gate 	return s;
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate 
281*217Smuffin int
specnames()2820Sstevel@tonic-gate specnames()
2830Sstevel@tonic-gate {
2840Sstevel@tonic-gate 	static struct {
2850Sstevel@tonic-gate 		int	*n;
2860Sstevel@tonic-gate 		char	*v;
2870Sstevel@tonic-gate 	} spnames[] = {
2880Sstevel@tonic-gate 		&c_hyphen, "hy",
2890Sstevel@tonic-gate 		&c_emdash, "em",
2900Sstevel@tonic-gate 		&c_rule, "ru",
2910Sstevel@tonic-gate 		&c_minus, "\\-",
2920Sstevel@tonic-gate 		&c_fi, "fi",
2930Sstevel@tonic-gate 		&c_fl, "fl",
2940Sstevel@tonic-gate 		&c_ff, "ff",
2950Sstevel@tonic-gate 		&c_ffi, "Fi",
2960Sstevel@tonic-gate 		&c_ffl, "Fl",
2970Sstevel@tonic-gate 		&c_acute, "aa",
2980Sstevel@tonic-gate 		&c_grave, "ga",
2990Sstevel@tonic-gate 		&c_under, "ul",
3000Sstevel@tonic-gate 		&c_rooten, "rn",
3010Sstevel@tonic-gate 		&c_boxrule, "br",
3020Sstevel@tonic-gate 		&c_lefthand, "lh",
3030Sstevel@tonic-gate 		&c_isalnum, "__",
3040Sstevel@tonic-gate 		0, 0
3050Sstevel@tonic-gate 	};
3060Sstevel@tonic-gate 	int	i;
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	for (i = 0; spnames[i].n; i++)
3090Sstevel@tonic-gate 		*spnames[i].n = findch(spnames[i].v);
3100Sstevel@tonic-gate 	if (c_isalnum == 0)
3110Sstevel@tonic-gate 		c_isalnum = NROFFCHARS;
312*217Smuffin 
313*217Smuffin 	return (0);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 
317*217Smuffin int
findch(s)3180Sstevel@tonic-gate findch(s)	/* find char s in chname */
319*217Smuffin char	*s;
3200Sstevel@tonic-gate {
321*217Smuffin 	int	i;
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 	for (i = 0; chtab[i] != 0; i++)
3240Sstevel@tonic-gate 		if (strcmp(s, &chname[chtab[i]]) == 0)
3250Sstevel@tonic-gate 			return(i + _SPECCHAR_ST);
3260Sstevel@tonic-gate 	return(0);
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate 
329*217Smuffin int
twdone()3300Sstevel@tonic-gate twdone()
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate 	int waitf;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	obufp = obuf;
3350Sstevel@tonic-gate 	if (t.twrest)		/* has ptinit() been done yet? */
3360Sstevel@tonic-gate 		oputs(t.twrest);
3370Sstevel@tonic-gate 	flusho();
3380Sstevel@tonic-gate 	if (pipeflg) {
3390Sstevel@tonic-gate 		close(ptid);
3400Sstevel@tonic-gate 		wait(&waitf);
3410Sstevel@tonic-gate 	}
3420Sstevel@tonic-gate 	restore_tty();
343*217Smuffin 
344*217Smuffin 	return (0);
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 
348*217Smuffin int
ptout(i)3490Sstevel@tonic-gate ptout(i)
3500Sstevel@tonic-gate 	tchar i;
3510Sstevel@tonic-gate {
3520Sstevel@tonic-gate 	*olinep++ = i;
3530Sstevel@tonic-gate 	if (olinep >= &oline[LNSIZE])
3540Sstevel@tonic-gate 		olinep--;
3550Sstevel@tonic-gate 	if (cbits(i) != '\n')
356*217Smuffin 		return (0);
3570Sstevel@tonic-gate 	olinep--;
3580Sstevel@tonic-gate 	lead += dip->blss + lss - t.Newline;
3590Sstevel@tonic-gate 	dip->blss = 0;
3600Sstevel@tonic-gate 	esct = esc = 0;
3610Sstevel@tonic-gate 	if (olinep > oline) {
3620Sstevel@tonic-gate 		move();
3630Sstevel@tonic-gate 		ptout1();
3640Sstevel@tonic-gate 		oputs(t.twnl);
3650Sstevel@tonic-gate 	} else {
3660Sstevel@tonic-gate 		lead += t.Newline;
3670Sstevel@tonic-gate 		move();
3680Sstevel@tonic-gate 	}
3690Sstevel@tonic-gate 	lead += dip->alss;
3700Sstevel@tonic-gate 	dip->alss = 0;
3710Sstevel@tonic-gate 	olinep = oline;
372*217Smuffin 
373*217Smuffin 	return (0);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 
377*217Smuffin int
ptout1()3780Sstevel@tonic-gate ptout1()
3790Sstevel@tonic-gate {
380*217Smuffin 	int	k;
381*217Smuffin 	char	*codep;
3820Sstevel@tonic-gate #ifdef EUC
3830Sstevel@tonic-gate #ifdef NROFF
384*217Smuffin 	int cnt;
385*217Smuffin 	tchar *qq;
3860Sstevel@tonic-gate #endif /* NROFF */
3870Sstevel@tonic-gate #endif /* EUC */
3880Sstevel@tonic-gate 	extern char	*plot();
3890Sstevel@tonic-gate 	int	w, j, phyw;
3900Sstevel@tonic-gate #ifdef EUC
3910Sstevel@tonic-gate #ifdef NROFF
3920Sstevel@tonic-gate 	int jj;
3930Sstevel@tonic-gate #endif /* NROFF */
3940Sstevel@tonic-gate #endif /* EUC */
3950Sstevel@tonic-gate 	tchar * q, i;
3960Sstevel@tonic-gate 	static int oxfont = FT;	/* start off in roman */
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	for (q = oline; q < olinep; q++) {
3990Sstevel@tonic-gate 		i = *q;
4000Sstevel@tonic-gate 		if (ismot(i)) {
4010Sstevel@tonic-gate 			j = absmot(i);
4020Sstevel@tonic-gate 			if (isnmot(i))
4030Sstevel@tonic-gate 				j = -j;
4040Sstevel@tonic-gate 			if (isvmot(i))
4050Sstevel@tonic-gate 				lead += j;
4060Sstevel@tonic-gate 			else
4070Sstevel@tonic-gate 				esc += j;
4080Sstevel@tonic-gate 			continue;
4090Sstevel@tonic-gate 		}
4100Sstevel@tonic-gate 		if ((k = cbits(i)) <= 040) {
4110Sstevel@tonic-gate 			switch (k) {
4120Sstevel@tonic-gate 			case ' ': /*space*/
4130Sstevel@tonic-gate 				esc += t.Char;
4140Sstevel@tonic-gate 				break;
4150Sstevel@tonic-gate 			case '\033':
4160Sstevel@tonic-gate 			case '\007':
4170Sstevel@tonic-gate 			case '\016':
4180Sstevel@tonic-gate 			case '\017':
4190Sstevel@tonic-gate 				oput(k);
4200Sstevel@tonic-gate 				break;
4210Sstevel@tonic-gate 			}
4220Sstevel@tonic-gate 			continue;
4230Sstevel@tonic-gate 		}
4240Sstevel@tonic-gate #ifdef EUC
4250Sstevel@tonic-gate #ifdef NROFF
4260Sstevel@tonic-gate 		if (multi_locale && ((k & MBMASK) || (k & CSMASK))) {
4270Sstevel@tonic-gate 			cnt = 0;
4280Sstevel@tonic-gate 			while ((*q & MBMASK1) && (cnt + 1 < (int)MB_CUR_MAX)) {
4290Sstevel@tonic-gate 				cnt++;
4300Sstevel@tonic-gate 				q++;
4310Sstevel@tonic-gate 			}
4320Sstevel@tonic-gate 			if ((cnt && !(*q & CSMASK)) || (*q & MBMASK1)) {
4330Sstevel@tonic-gate 				q -= cnt;
4340Sstevel@tonic-gate 				cnt = 0;
4350Sstevel@tonic-gate 				*q &= ~0xfe00;
4360Sstevel@tonic-gate 			}
4370Sstevel@tonic-gate 			k = cbits(i = *q);
4380Sstevel@tonic-gate 			phyw = w = t.Char * csi_width[cs(i)];
4390Sstevel@tonic-gate 		} else {
4400Sstevel@tonic-gate #endif /* NROFF */
4410Sstevel@tonic-gate #endif /* EUC */
4420Sstevel@tonic-gate 		phyw = w = t.Char * t.width[k];
4430Sstevel@tonic-gate 		if (iszbit(i))
4440Sstevel@tonic-gate 			w = 0;
4450Sstevel@tonic-gate #ifdef EUC
4460Sstevel@tonic-gate #ifdef NROFF
4470Sstevel@tonic-gate 		}
4480Sstevel@tonic-gate #endif /* NROFF */
4490Sstevel@tonic-gate #endif /* EUC */
4500Sstevel@tonic-gate 		if (esc || lead)
4510Sstevel@tonic-gate 			move();
4520Sstevel@tonic-gate 		esct += w;
4530Sstevel@tonic-gate #ifndef EUC
4540Sstevel@tonic-gate 		xfont = fbits(i);
4550Sstevel@tonic-gate #else
4560Sstevel@tonic-gate #ifndef NROFF
4570Sstevel@tonic-gate 		xfont = fbits(i);
4580Sstevel@tonic-gate #else
4590Sstevel@tonic-gate #endif /* NROFF */
4600Sstevel@tonic-gate 		xfont = (fbits(*q) % NFONT);	/* for invalid code */
4610Sstevel@tonic-gate #endif /* EUC */
4620Sstevel@tonic-gate 		if (xfont != oxfont) {
4630Sstevel@tonic-gate 			if (oxfont == ulfont || oxfont == BIFONT)
4640Sstevel@tonic-gate 				oputs(t.itoff);
4650Sstevel@tonic-gate 			if (bdtab[oxfont])
4660Sstevel@tonic-gate 				oputs(t.bdoff);
4670Sstevel@tonic-gate 			if (xfont == ulfont || xfont == BIFONT)
4680Sstevel@tonic-gate 				oputs(t.iton);
4690Sstevel@tonic-gate 			if (bdtab[xfont])
4700Sstevel@tonic-gate 				oputs(t.bdon);
4710Sstevel@tonic-gate 			oxfont = xfont;
4720Sstevel@tonic-gate 		}
4730Sstevel@tonic-gate 		if ((xfont == ulfont || xfont == BIFONT) && !(*t.iton & 0377)) {
4740Sstevel@tonic-gate 			for (j = w / t.Char; j > 0; j--)
4750Sstevel@tonic-gate 				oput('_');
4760Sstevel@tonic-gate 			for (j = w / t.Char; j > 0; j--)
4770Sstevel@tonic-gate 				oput('\b');
4780Sstevel@tonic-gate 		}
4790Sstevel@tonic-gate 		if ((j = bdtab[xfont]) && !(*t.bdon & 0377))
4800Sstevel@tonic-gate 			j++;
4810Sstevel@tonic-gate 		else
4820Sstevel@tonic-gate 			j = 1;	/* number of overstrikes for bold */
4830Sstevel@tonic-gate 		if (k < 128) {	/* ordinary ascii */
4840Sstevel@tonic-gate 			oput(k);
4850Sstevel@tonic-gate 			while (--j > 0) {
4860Sstevel@tonic-gate 				oput('\b');
4870Sstevel@tonic-gate 				oput(k);
4880Sstevel@tonic-gate 			}
4890Sstevel@tonic-gate #ifdef EUC
4900Sstevel@tonic-gate #ifdef NROFF
4910Sstevel@tonic-gate 		} else if (multi_locale && (k & CSMASK)) {
4920Sstevel@tonic-gate 			for (qq = q - cnt; qq <= q;)
4930Sstevel@tonic-gate 				oput(cbits(*qq++));
4940Sstevel@tonic-gate 			while (--j > 0) {
4950Sstevel@tonic-gate 				for (jj = cnt + 1; jj > 0; jj--)
4960Sstevel@tonic-gate 					oput('\b');
4970Sstevel@tonic-gate 				for (qq = q - cnt; qq <= q;)
4980Sstevel@tonic-gate 					oput(cbits(*qq++));
4990Sstevel@tonic-gate 			}
5000Sstevel@tonic-gate 		} else if (k < 256) {
5010Sstevel@tonic-gate 			/*
5020Sstevel@tonic-gate 			 * Invalid character for C locale or
5030Sstevel@tonic-gate 			 * non-printable 8-bit single byte
5040Sstevel@tonic-gate 			 * character such as <no-break-sp>
5050Sstevel@tonic-gate 			 * in ISO-8859-1
5060Sstevel@tonic-gate 			 */
5070Sstevel@tonic-gate 			oput(k);
5080Sstevel@tonic-gate 			while (--j > 0) {
5090Sstevel@tonic-gate 				oput('\b');
5100Sstevel@tonic-gate 				oput(k);
5110Sstevel@tonic-gate 			}
5120Sstevel@tonic-gate #endif /* NROFF */
5130Sstevel@tonic-gate #endif /* EUC */
5140Sstevel@tonic-gate 		} else if (k >= nchtab + _SPECCHAR_ST) {
5150Sstevel@tonic-gate 			oput(k - nchtab - _SPECCHAR_ST);
5160Sstevel@tonic-gate 		} else {
5170Sstevel@tonic-gate 			int oj = j;
5180Sstevel@tonic-gate 			codep = t.codetab[k-_SPECCHAR_ST];
5190Sstevel@tonic-gate 			while (*codep != 0) {
5200Sstevel@tonic-gate 				if (*codep & 0200) {
5210Sstevel@tonic-gate 					codep = plot(codep);
5220Sstevel@tonic-gate 					oput(' ');
5230Sstevel@tonic-gate 				} else {
5240Sstevel@tonic-gate 					if (*codep == '%')	/* escape */
5250Sstevel@tonic-gate 						codep++;
5260Sstevel@tonic-gate 					oput(*codep);
5270Sstevel@tonic-gate 					if (*codep == '\033')
5280Sstevel@tonic-gate 						oput(*++codep);
5290Sstevel@tonic-gate 					else if (*codep != '\b')
5300Sstevel@tonic-gate 						for (j = oj; --j > 0; ) {
5310Sstevel@tonic-gate 							oput('\b');
5320Sstevel@tonic-gate 							oput(*codep);
5330Sstevel@tonic-gate 						}
5340Sstevel@tonic-gate 					codep++;
5350Sstevel@tonic-gate 				}
5360Sstevel@tonic-gate 			}
5370Sstevel@tonic-gate 		}
5380Sstevel@tonic-gate 		if (!w)
5390Sstevel@tonic-gate 			for (j = phyw / t.Char; j > 0; j--)
5400Sstevel@tonic-gate 				oput('\b');
5410Sstevel@tonic-gate 	}
542*217Smuffin 
543*217Smuffin 	return (0);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 
plot(x)5470Sstevel@tonic-gate char	*plot(x)
5480Sstevel@tonic-gate char	*x;
5490Sstevel@tonic-gate {
550*217Smuffin 	int	i;
551*217Smuffin 	char	*j, *k;
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 	oputs(t.ploton);
5540Sstevel@tonic-gate 	k = x;
5550Sstevel@tonic-gate 	if ((*k & 0377) == 0200)
5560Sstevel@tonic-gate 		k++;
5570Sstevel@tonic-gate 	for (; *k; k++) {
5580Sstevel@tonic-gate 		if (*k == '%') {	/* quote char within plot mode */
5590Sstevel@tonic-gate 			oput(*++k);
5600Sstevel@tonic-gate 		} else if (*k & 0200) {
5610Sstevel@tonic-gate 			if (*k & 0100) {
5620Sstevel@tonic-gate 				if (*k & 040)
5630Sstevel@tonic-gate 					j = t.up;
5640Sstevel@tonic-gate 				else
5650Sstevel@tonic-gate 					j = t.down;
5660Sstevel@tonic-gate 			} else {
5670Sstevel@tonic-gate 				if (*k & 040)
5680Sstevel@tonic-gate 					j = t.left;
5690Sstevel@tonic-gate 				else
5700Sstevel@tonic-gate 					j = t.right;
5710Sstevel@tonic-gate 			}
5720Sstevel@tonic-gate 			if ((i = *k & 037) == 0) {	/* 2nd 0200 turns it off */
5730Sstevel@tonic-gate 				++k;
5740Sstevel@tonic-gate 				break;
5750Sstevel@tonic-gate 			}
5760Sstevel@tonic-gate 			while (i--)
5770Sstevel@tonic-gate 				oputs(j);
5780Sstevel@tonic-gate 		} else
5790Sstevel@tonic-gate 			oput(*k);
5800Sstevel@tonic-gate 	}
5810Sstevel@tonic-gate 	oputs(t.plotoff);
5820Sstevel@tonic-gate 	return(k);
5830Sstevel@tonic-gate }
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate 
586*217Smuffin int
move()5870Sstevel@tonic-gate move()
5880Sstevel@tonic-gate {
589*217Smuffin 	int	k;
590*217Smuffin 	char	*i, *j;
5910Sstevel@tonic-gate 	char	*p, *q;
5920Sstevel@tonic-gate 	int	iesct, dt;
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate 	iesct = esct;
5950Sstevel@tonic-gate 	if (esct += esc)
5960Sstevel@tonic-gate 		i = "\0";
5970Sstevel@tonic-gate 	else
5980Sstevel@tonic-gate 		i = "\n\0";
5990Sstevel@tonic-gate 	j = t.hlf;
6000Sstevel@tonic-gate 	p = t.right;
6010Sstevel@tonic-gate 	q = t.down;
6020Sstevel@tonic-gate 	if (lead) {
6030Sstevel@tonic-gate 		if (lead < 0) {
6040Sstevel@tonic-gate 			lead = -lead;
6050Sstevel@tonic-gate 			i = t.flr;
6060Sstevel@tonic-gate 			/*	if(!esct)i = t.flr; else i = "\0";*/
6070Sstevel@tonic-gate 			j = t.hlr;
6080Sstevel@tonic-gate 			q = t.up;
6090Sstevel@tonic-gate 		}
6100Sstevel@tonic-gate 		if (*i & 0377) {
6110Sstevel@tonic-gate 			k = lead / t.Newline;
6120Sstevel@tonic-gate 			lead = lead % t.Newline;
6130Sstevel@tonic-gate 			while (k--)
6140Sstevel@tonic-gate 				oputs(i);
6150Sstevel@tonic-gate 		}
6160Sstevel@tonic-gate 		if (*j & 0377) {
6170Sstevel@tonic-gate 			k = lead / t.Halfline;
6180Sstevel@tonic-gate 			lead = lead % t.Halfline;
6190Sstevel@tonic-gate 			while (k--)
6200Sstevel@tonic-gate 				oputs(j);
6210Sstevel@tonic-gate 		} else { /* no half-line forward, not at line begining */
6220Sstevel@tonic-gate 			k = lead / t.Newline;
6230Sstevel@tonic-gate 			lead = lead % t.Newline;
6240Sstevel@tonic-gate 			if (k > 0)
6250Sstevel@tonic-gate 				esc = esct;
6260Sstevel@tonic-gate 			i = "\n";
6270Sstevel@tonic-gate 			while (k--)
6280Sstevel@tonic-gate 				oputs(i);
6290Sstevel@tonic-gate 		}
6300Sstevel@tonic-gate 	}
6310Sstevel@tonic-gate 	if (esc) {
6320Sstevel@tonic-gate 		if (esc < 0) {
6330Sstevel@tonic-gate 			esc = -esc;
6340Sstevel@tonic-gate 			j = "\b";
6350Sstevel@tonic-gate 			p = t.left;
6360Sstevel@tonic-gate 		} else {
6370Sstevel@tonic-gate 			j = " ";
6380Sstevel@tonic-gate 			if (hflg)
6390Sstevel@tonic-gate 				while ((dt = dtab - (iesct % dtab)) <= esc) {
6400Sstevel@tonic-gate 					if (dt % t.Em)
6410Sstevel@tonic-gate 						break;
6420Sstevel@tonic-gate 					oput(TAB);
6430Sstevel@tonic-gate 					esc -= dt;
6440Sstevel@tonic-gate 					iesct += dt;
6450Sstevel@tonic-gate 				}
6460Sstevel@tonic-gate 		}
6470Sstevel@tonic-gate 		k = esc / t.Em;
6480Sstevel@tonic-gate 		esc = esc % t.Em;
6490Sstevel@tonic-gate 		while (k--)
6500Sstevel@tonic-gate 			oputs(j);
6510Sstevel@tonic-gate 	}
6520Sstevel@tonic-gate 	if ((*t.ploton & 0377) && (esc || lead)) {
6530Sstevel@tonic-gate 		oputs(t.ploton);
6540Sstevel@tonic-gate 		esc /= t.Hor;
6550Sstevel@tonic-gate 		lead /= t.Vert;
6560Sstevel@tonic-gate 		while (esc--)
6570Sstevel@tonic-gate 			oputs(p);
6580Sstevel@tonic-gate 		while (lead--)
6590Sstevel@tonic-gate 			oputs(q);
6600Sstevel@tonic-gate 		oputs(t.plotoff);
6610Sstevel@tonic-gate 	}
6620Sstevel@tonic-gate 	esc = lead = 0;
663*217Smuffin 
664*217Smuffin 	return (0);
6650Sstevel@tonic-gate }
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate 
668*217Smuffin int
ptlead()6690Sstevel@tonic-gate ptlead()
6700Sstevel@tonic-gate {
6710Sstevel@tonic-gate 	move();
672*217Smuffin 
673*217Smuffin 	return (0);
6740Sstevel@tonic-gate }
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 
677*217Smuffin int
dostop()6780Sstevel@tonic-gate dostop()
6790Sstevel@tonic-gate {
6800Sstevel@tonic-gate 	char	junk;
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate 	flusho();
6830Sstevel@tonic-gate 	read(2, &junk, 1);
684*217Smuffin 
685*217Smuffin 	return (0);
686*217Smuffin }
687*217Smuffin 
688*217Smuffin int
newpage()689*217Smuffin newpage()
690*217Smuffin {
691*217Smuffin 	return (0);
6920Sstevel@tonic-gate }
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 
695*217Smuffin int
pttrailer()696*217Smuffin pttrailer()
697*217Smuffin {
698*217Smuffin 	return (0);
699*217Smuffin }
700