17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate/*
317c478bdstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bdstevel@tonic-gate * The Regents of the University of California
337c478bdstevel@tonic-gate * All Rights Reserved
347c478bdstevel@tonic-gate *
357c478bdstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bdstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bdstevel@tonic-gate * contributors.
387c478bdstevel@tonic-gate */
397c478bdstevel@tonic-gate
40e5190c1muffin#pragma ident	"%Z%%M%	%I%	%E% SMI"
41e5190c1muffin
427c478bdstevel@tonic-gate/* starting values for typesetting parameters: */
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate#define	PS	10	/* default point size */
457c478bdstevel@tonic-gate#define	FT	1	/* default font position */
467c478bdstevel@tonic-gate#define ULFONT	2	/* default underline font */
477c478bdstevel@tonic-gate#define	BDFONT	3	/* default emboldening font */
487c478bdstevel@tonic-gate#define	BIFONT	4	/* default bold italic font */
497c478bdstevel@tonic-gate#define	LL	(unsigned) 65*INCH/10	/* line length; 39picas=6.5in */
507c478bdstevel@tonic-gate#define	VS	((12*INCH)/72)	/* initial vert space */
517c478bdstevel@tonic-gate
527c478bdstevel@tonic-gate#ifdef	NROFF
537c478bdstevel@tonic-gate#	define	EM	t.Em
547c478bdstevel@tonic-gate#	define	HOR	t.Adj
557c478bdstevel@tonic-gate#	define	VERT	t.Vert
567c478bdstevel@tonic-gate#	define	INCH	240	/* increments per inch */
577c478bdstevel@tonic-gate#	define	SPS	INCH/10	/* space size */
587c478bdstevel@tonic-gate#	define	SS	INCH/10	/* " */
597c478bdstevel@tonic-gate#	define	TRAILER	0
607c478bdstevel@tonic-gate#	define	PO	0 /* page offset */
617c478bdstevel@tonic-gate#	define	ASCII	1
627c478bdstevel@tonic-gate#	define	PTID	1
637c478bdstevel@tonic-gate#	define	LG	0
647c478bdstevel@tonic-gate#	define	DTAB	0	/* set at 8 Ems at init time */
657c478bdstevel@tonic-gate#	define	ICS	2*SPS
667c478bdstevel@tonic-gate#endif
677c478bdstevel@tonic-gate#ifndef NROFF	/* TROFF */
687c478bdstevel@tonic-gate	/* Inch is set by ptinit() when troff started. */
697c478bdstevel@tonic-gate	/* all derived values set then too
707c478bdstevel@tonic-gate	*/
717c478bdstevel@tonic-gate#	define	INCH	Inch	/* troff resolution -- number of goobies/inch  */
727c478bdstevel@tonic-gate#	define	POINT	(INCH/72)	/* goobies per point (1/72 inch) */
737c478bdstevel@tonic-gate#	define	HOR	Hor	/* horizontal resolution in goobies */
747c478bdstevel@tonic-gate#	define	VERT	Vert	/* vertical resolution in goobies */
757c478bdstevel@tonic-gate#	define	SPS	(EM/3)	/* space size  */
767c478bdstevel@tonic-gate#	define	SS	12	/* space size in 36ths of an em */
777c478bdstevel@tonic-gate#	define	PO	(INCH)	/* page offset 1 inch */
787c478bdstevel@tonic-gate/* #	define	EM	(POINT * pts) */
797c478bdstevel@tonic-gate#define	EM	(((long) INCH * pts + 36) / 72)	/* don't lose significance */
807c478bdstevel@tonic-gate#define	EMPTS(pts)	(((long) INCH * (pts) + 36) / 72)
817c478bdstevel@tonic-gate#	define	ASCII	0
827c478bdstevel@tonic-gate#	define	PTID	1
837c478bdstevel@tonic-gate#	define	LG	1
847c478bdstevel@tonic-gate#	define	DTAB	(INCH/2)
857c478bdstevel@tonic-gate#	define	ICS	3*SPS
867c478bdstevel@tonic-gate#endif
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gate/* These "characters" are used to encode various internal functions
897c478bdstevel@tonic-gate * Some make use of the fact that most ascii characters between
907c478bdstevel@tonic-gate * 0 and 040 don't have any graphic or other function.
917c478bdstevel@tonic-gate * The few that do have a purpose (e.g., \n, \b, \t, ...
927c478bdstevel@tonic-gate * are avoided by the ad hoc choices here.
937c478bdstevel@tonic-gate * See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012
947c478bdstevel@tonic-gate */
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gate#define	LEADER	001
977c478bdstevel@tonic-gate#define	IMP	004	/* impossible char; glues things together */
987c478bdstevel@tonic-gate#define	TAB	011
997c478bdstevel@tonic-gate#define	RPT	014	/* next character is to be repeated many times */
1007c478bdstevel@tonic-gate#define	CHARHT	015	/* size field sets character height */
1017c478bdstevel@tonic-gate#define	SLANT	016	/* size field sets amount of slant */
1027c478bdstevel@tonic-gate#define	DRAWFCN	017	/* next several chars describe arb drawing fcn */
1037c478bdstevel@tonic-gate			/* line: 'l' dx dy char */
1047c478bdstevel@tonic-gate			/* circle: 'c' r */
1057c478bdstevel@tonic-gate			/* ellipse: 'e' rx ry */
1067c478bdstevel@tonic-gate			/* arc: 'a' dx dy r */
1077c478bdstevel@tonic-gate			/* wiggly line '~' x y x y ... */
1087c478bdstevel@tonic-gate#define	DRAWLINE	'l'
1097c478bdstevel@tonic-gate#define	DRAWCIRCLE	'c'	/* circle */
1107c478bdstevel@tonic-gate#define	DRAWELLIPSE	'e'
1117c478bdstevel@tonic-gate#define	DRAWARC		'a'	/* arbitrary arc */
1127c478bdstevel@tonic-gate#define	DRAWSPLINE	'~'	/* quadratic B spline */
1137c478bdstevel@tonic-gate
1147c478bdstevel@tonic-gate#define	LEFT	020	/* \{ */
1157c478bdstevel@tonic-gate#define	RIGHT	021	/* \} */
1167c478bdstevel@tonic-gate#define	FILLER	022	/* \& and similar purposes */
1177c478bdstevel@tonic-gate#define	XON	023	/* \X'...' starts here */
1187c478bdstevel@tonic-gate#define	OHC	024	/* optional hyphenation character \% */
1197c478bdstevel@tonic-gate#define	CONT	025	/* \c character */
1207c478bdstevel@tonic-gate#define	PRESC	026	/* printable escape */
1217c478bdstevel@tonic-gate#define	UNPAD	027	/* unpaddable blank */
1227c478bdstevel@tonic-gate#define	XPAR	030	/* transparent mode indicator */
1237c478bdstevel@tonic-gate#define	FLSS	031
1247c478bdstevel@tonic-gate#define	WORDSP	032	/* paddable word space */
1257c478bdstevel@tonic-gate#define	ESC	033
1267c478bdstevel@tonic-gate#define	XOFF	034	/* \X'...' ends here */
1277c478bdstevel@tonic-gate
1287c478bdstevel@tonic-gate#define	iscontrol(n)	(n==035 || n==036)	/* used to test the next two */
1297c478bdstevel@tonic-gate#define	HX	035	/* next character is value of \x'...' */
1307c478bdstevel@tonic-gate#define	FONTPOS	036	/* position of font \f(XX encoded in top */
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate#define	HYPHEN	c_hyphen
1337c478bdstevel@tonic-gate#define	EMDASH	c_emdash	/* \(em */
1347c478bdstevel@tonic-gate#define	RULE	c_rule		/* \(ru */
1357c478bdstevel@tonic-gate#define	MINUS	c_minus		/* minus sign on current font */
1367c478bdstevel@tonic-gate#define	LIG_FI	c_fi		/* \(ff */
1377c478bdstevel@tonic-gate#define	LIG_FL	c_fl		/* \(fl */
1387c478bdstevel@tonic-gate#define	LIG_FF	c_ff		/* \(ff */
1397c478bdstevel@tonic-gate#define	LIG_FFI	c_ffi		/* \(Fi */
1407c478bdstevel@tonic-gate#define	LIG_FFL	c_ffl		/* \(Fl */
1417c478bdstevel@tonic-gate#define	ACUTE	c_acute		/* acute accent \(aa */
1427c478bdstevel@tonic-gate#define	GRAVE	c_grave		/* grave accent \(ga */
1437c478bdstevel@tonic-gate#define	UNDERLINE c_under	/* \(ul */
1447c478bdstevel@tonic-gate#define	ROOTEN	c_rooten	/* root en \(rn */
1457c478bdstevel@tonic-gate#define	BOXRULE	c_boxrule	/* box rule \(br */
1467c478bdstevel@tonic-gate#define	LEFTHAND c_lefthand	/* left hand for word overflow */
1477c478bdstevel@tonic-gate#define	DAGGER	c_dagger	/* dagger for footnotes */
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gate/* array sizes, and similar limits: */
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gate#define	NFONT	10	/* maximum number of fonts (including specials) */
1527c478bdstevel@tonic-gate#define	EXTRAFONT 500	/* extra space for swapping a font */
1537c478bdstevel@tonic-gate#define	NN	400	/* number registers */
1547c478bdstevel@tonic-gate#define	NNAMES	15	 /* predefined reg names */
1557c478bdstevel@tonic-gate#define	NIF	15	/* if-else nesting */
1567c478bdstevel@tonic-gate#define	NS	128	/* name buffer */
1577c478bdstevel@tonic-gate#define	NTM	256	/* tm buffer */
1587c478bdstevel@tonic-gate#define	NEV	3	/* environments */
1597c478bdstevel@tonic-gate#define	EVLSZ	10	/* size of ev stack */
1607c478bdstevel@tonic-gate#define	DSIZE	512	/* disk sector size in chars */
1617c478bdstevel@tonic-gate
1627c478bdstevel@tonic-gate#define	NM	500	/* requests + macros */
1637c478bdstevel@tonic-gate#define	DELTA	1024	/* delta core bytes */
1647c478bdstevel@tonic-gate#define	NHYP	10	/* max hyphens per word */
1657c478bdstevel@tonic-gate#define	NHEX	128	/* byte size of exception word list */
1667c478bdstevel@tonic-gate#define	NTAB	40	/* tab stops */
1677c478bdstevel@tonic-gate#define	NSO	5	/* "so" depth */
1687c478bdstevel@tonic-gate#define	NMF	5	/* number of -m flags */
1697c478bdstevel@tonic-gate#define	WDSIZE	540	/* word buffer size */
1707c478bdstevel@tonic-gate#define	LNSIZE	680	/* line buffer size */
1717c478bdstevel@tonic-gate#define	NDI	5	/* number of diversions */
1727c478bdstevel@tonic-gate#define	NCHARS	512	/* maximum size of troff character set */
1737c478bdstevel@tonic-gate#define	NTRTAB	NCHARS	/* number of items in trtab[] */
1747c478bdstevel@tonic-gate#define	NWIDCACHE NCHARS	/* number of items in widcache */
1757c478bdstevel@tonic-gate#define	NTRAP	20	/* number of traps */
1767c478bdstevel@tonic-gate#define	NPN	20	/* numbers in "-o" */
1777c478bdstevel@tonic-gate#define	FBUFSZ	256	/* field buf size words */
1787c478bdstevel@tonic-gate#define	OBUFSZ	4096	/* bytes */
1797c478bdstevel@tonic-gate#define	IBUFSZ	4096	/* bytes */
1807c478bdstevel@tonic-gate#define	NC	1024	/* cbuf size words */
1817c478bdstevel@tonic-gate#define	NOV	10	/* number of overstrike chars */
1827c478bdstevel@tonic-gate#define	NPP	10	/* pads per field */
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gate/*
1857c478bdstevel@tonic-gate	Internal character representation:
1867c478bdstevel@tonic-gate	Internally, every character is carried around as
1877c478bdstevel@tonic-gate	a 32 bit cookie, called a "tchar" (typedef long).
1887c478bdstevel@tonic-gate	Bits are numbered 31..0 from left to right.
1897c478bdstevel@tonic-gate	If bit 15 is 1, the character is motion, with
1907c478bdstevel@tonic-gate		if bit 16 it's vertical motion
1917c478bdstevel@tonic-gate		if bit 17 it's negative motion
1927c478bdstevel@tonic-gate	If bit 15 is 0, the character is a real character.
1937c478bdstevel@tonic-gate		if bit 31	zero motion
1947c478bdstevel@tonic-gate		bits 30..24	size
1957c478bdstevel@tonic-gate		bits 23..16	font
1967c478bdstevel@tonic-gateifndef EUC
1977c478bdstevel@tonic-gate		bit 8		absolute char number in 7..0
1987c478bdstevel@tonic-gate	This implies at most 256-32 characters in a single font,
1997c478bdstevel@tonic-gate	which is going to be a problem somewhere
2007c478bdstevel@tonic-gateelse
2017c478bdstevel@tonic-gate		bits 14,13	identifier for the colunm of print of character.
2027c478bdstevel@tonic-gate		bits 12,11	multibyte position identifier
2037c478bdstevel@tonic-gate	Currently, this applies only to nroff.
2047c478bdstevel@tonic-gateendif EUC
2057c478bdstevel@tonic-gate*/
2067c478bdstevel@tonic-gate
2077c478bdstevel@tonic-gate/* in the following, "L" should really be a tchar, but ... */
2087c478bdstevel@tonic-gate
2097c478bdstevel@tonic-gate#define	MOT	(01L<<15)	/* motion character indicator */
2107c478bdstevel@tonic-gate#define	MOTV	(07L<<15)	/* clear for motion part */
2117c478bdstevel@tonic-gate#define	VMOT	(01L<<16)	/* vert motion bit */
2127c478bdstevel@tonic-gate#define	NMOT	(01L<<17)	/* negative motion indicator*/
2137c478bdstevel@tonic-gate#define	MAXMOT	32767	/* bad way to write this!!! */
2147c478bdstevel@tonic-gate#define	ismot(n)	((n) & MOT)
2157c478bdstevel@tonic-gate#define	isvmot(n)	((n) & VMOT)	/* must have tested MOT previously */
2167c478bdstevel@tonic-gate#define	isnmot(n)	((n) & NMOT)	/* ditto */
2177c478bdstevel@tonic-gate#define	absmot(n)	(unsigned)(0177777 & (n) & ~MOT)	/* (short) is cheap mask */
2187c478bdstevel@tonic-gate
2197c478bdstevel@tonic-gate#define	ZBIT	0x80000000 	/*  (01L << 31) */	/* zero width char */
2207c478bdstevel@tonic-gate#define	iszbit(n)	((n) & ZBIT)
2217c478bdstevel@tonic-gate#define	ABSCHAR		0400	/* absolute char number in this font */
2227c478bdstevel@tonic-gate
2237c478bdstevel@tonic-gate#define	SMASK		(0177L << 24)
2247c478bdstevel@tonic-gate#define	FMASK		(0377L << 16)
2257c478bdstevel@tonic-gate#define	SFMASK		(SMASK|FMASK)	/* size and font in a tchar */
2267c478bdstevel@tonic-gate#define	sbits(n)	(unsigned)(((n) >> 24) & 0177)
2277c478bdstevel@tonic-gate#define	fbits(n)	(((n) >> 16) & 0377)
2287c478bdstevel@tonic-gate#define	sfbits(n)	(unsigned)(0177777 & (((n) & SFMASK) >> 16))
2297c478bdstevel@tonic-gate#define	cbits(n)	(unsigned)(0177777 & (n))	/* isolate bottom 16 bits  */
2307c478bdstevel@tonic-gate#define	absbits(n)	(cbits(n) & ~ABSCHAR)
2317c478bdstevel@tonic-gate
2327c478bdstevel@tonic-gate#define	setsbits(n,s)	n = (n & ~SMASK) | (tchar)(s) << 24
2337c478bdstevel@tonic-gate#define	setfbits(n,f)	n = (n & ~FMASK) | (tchar)(f) << 16
2347c478bdstevel@tonic-gate#define	setsfbits(n,sf)	n = (n & ~SFMASK) | (tchar)(sf) << 16
2357c478bdstevel@tonic-gate#define	setcbits(n,c)	n = (n & ~077777L | (c))	/* set character bits */
2367c478bdstevel@tonic-gate
2377c478bdstevel@tonic-gate#define	BYTEMASK	0377
2387c478bdstevel@tonic-gate#define	BYTE	8
2397c478bdstevel@tonic-gate
2407c478bdstevel@tonic-gate#define	ischar(n)	(((n) & ~BYTEMASK) == 0)
2417c478bdstevel@tonic-gate
2427c478bdstevel@tonic-gate#ifdef EUC
2437c478bdstevel@tonic-gate#ifdef NROFF
2447c478bdstevel@tonic-gate#define CSMASK	0x6000	/* colunm of print identifier */
2457c478bdstevel@tonic-gate#define MBMASK	0x1c00	/* bits identifying position in a multibyte char */
2467c478bdstevel@tonic-gate#define MBMASK1	0x1800
2477c478bdstevel@tonic-gate#define FIRSTOFMB	0x1000
2487c478bdstevel@tonic-gate#define MIDDLEOFMB	0x0800
2497c478bdstevel@tonic-gate#define LASTOFMB	0x0400
2507c478bdstevel@tonic-gate#define BYTE_CHR	0x0000
2517c478bdstevel@tonic-gate#define	cs(n)	(((n) & CSMASK) >> 13)	/* colum of print of character */
2527c478bdstevel@tonic-gate#define	setcsbits(n,c)	n = ((n & ~CSMASK) | ((c) << 13))
2537c478bdstevel@tonic-gate#define CHMASK	(BYTEMASK | CSMASK | MBMASK)
2547c478bdstevel@tonic-gate#define ZWDELIM1	ZBIT | FIRSTOFMB | ' '	/* non-ASCII word delimiter 1 */
2557c478bdstevel@tonic-gate#define ZWDELIM2	ZBIT | MIDDLEOFMB | ' '	/* non-ASCII word delimiter 2 */
2567c478bdstevel@tonic-gate#define ZWDELIM(c)	((c) == 0) ? ' ' : ((c) == 1) ? ZWDELIM1 : ZWDELIM2
2577c478bdstevel@tonic-gate#endif /* NROFF */
2587c478bdstevel@tonic-gate#endif /* EUC */
2597c478bdstevel@tonic-gate
2607c478bdstevel@tonic-gate#define	ZONE	5	/* 5 hrs for EST */
2617c478bdstevel@tonic-gate#define	TABMASK	 037777
2627c478bdstevel@tonic-gate#define	RTAB	(unsigned) 0100000
2637c478bdstevel@tonic-gate#define	CTAB	040000
2647c478bdstevel@tonic-gate
2657c478bdstevel@tonic-gate#define	TABBIT	02		/* bits in gchtab */
2667c478bdstevel@tonic-gate#define	LDRBIT	04
2677c478bdstevel@tonic-gate#define	FCBIT	010
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate#define	PAIR(A,B)	(A|(B<<BYTE))
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gate#ifndef EUC
2727c478bdstevel@tonic-gate#define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
2737c478bdstevel@tonic-gate#else
2747c478bdstevel@tonic-gate#ifndef NROFF
2757c478bdstevel@tonic-gate#define	oput(c)	if ((*obufp++ = (c)), obufp >= &obuf[OBUFSZ]) flusho(); else
2767c478bdstevel@tonic-gate#endif /* NROFF */
2777c478bdstevel@tonic-gate#define	oput(c)	if ((*obufp++ = cbits(c) & BYTEMASK), obufp >= &obuf[OBUFSZ]) flusho(); else
2787c478bdstevel@tonic-gate#endif /* EUC */
2797c478bdstevel@tonic-gate
2807c478bdstevel@tonic-gate/*
2817c478bdstevel@tonic-gate * "temp file" parameters.  macros and strings
2827c478bdstevel@tonic-gate * are stored in an array of linked blocks,
2837c478bdstevel@tonic-gate * which may be in memory and an array called
2847c478bdstevel@tonic-gate * corebuf[], if INCORE is set during
2857c478bdstevel@tonic-gate * compilation, or otherwise in a file called trtmp$$.
2867c478bdstevel@tonic-gate
2877c478bdstevel@tonic-gate * The numerology is delicate if filep is 16 bits:
2887c478bdstevel@tonic-gate	#define BLK 128
2897c478bdstevel@tonic-gate	#define NBLIST 512
2907c478bdstevel@tonic-gate * i.e., the product is 16 bits long.
2917c478bdstevel@tonic-gate
2927c478bdstevel@tonic-gate * If filep is an unsigned long (and if your
2937c478bdstevel@tonic-gate * compiler will let you say that) then NBLIST
2947c478bdstevel@tonic-gate * can be a lot bigger.  Of course that makes
2957c478bdstevel@tonic-gate * the file or core image a lot bigger too,
2967c478bdstevel@tonic-gate * and means you don't detect missing diversion
2977c478bdstevel@tonic-gate * terminations as quickly... .
2987c478bdstevel@tonic-gate * It also means that you may have trouble running
2997c478bdstevel@tonic-gate * on non-swapping systems, since the core image
3007c478bdstevel@tonic-gate * will be over 1Mb.
3017c478bdstevel@tonic-gate
3027c478bdstevel@tonic-gate * BLK must be a power of 2
3037c478bdstevel@tonic-gate */
3047c478bdstevel@tonic-gate
3057c478bdstevel@tonic-gatetypedef unsigned int filep;	/* this is good for 32 bit machines */
3067c478bdstevel@tonic-gate
3077c478bdstevel@tonic-gate#define	BLK	128	/* alloc block in tchars */
3087c478bdstevel@tonic-gate
3097c478bdstevel@tonic-gate#ifdef SMALLER
3107c478bdstevel@tonic-gate#	define	NBLIST	512
3117c478bdstevel@tonic-gate#else
3127c478bdstevel@tonic-gate#	define	NBLIST	1024	/* allocation list.  smallish machines use 512 */
3137c478bdstevel@tonic-gate				/* machines with paging can use 2048 */
3147c478bdstevel@tonic-gate#endif
3157c478bdstevel@tonic-gate
3167c478bdstevel@tonic-gate/* Other things are stored in the temp file or corebuf:
3177c478bdstevel@tonic-gate *	a single block for .rd input, at offset RD_OFFSET
3187c478bdstevel@tonic-gate *	NEV copies of the environment block, at offset ENV_OFFSET
3197c478bdstevel@tonic-gate
3207c478bdstevel@tonic-gate * The existing implementation assumes very strongly that
3217c478bdstevel@tonic-gate * these are respectively NBLIST*BLK and 0.
3227c478bdstevel@tonic-gate
3237c478bdstevel@tonic-gate */
3247c478bdstevel@tonic-gate
3257c478bdstevel@tonic-gate#define	RD_OFFSET	(NBLIST * BLK)
3267c478bdstevel@tonic-gate#define ENV_OFFSET	0
3277c478bdstevel@tonic-gate#define	ENV_BLK		((NEV * sizeof(env) / sizeof(tchar) + BLK-1) / BLK)
3287c478bdstevel@tonic-gate				/* rounded up to even BLK */
3297c478bdstevel@tonic-gate
3307c478bdstevel@tonic-gatetypedef	long	tchar;
3317c478bdstevel@tonic-gate
3327c478bdstevel@tonic-gateextern	tchar	getch(), getch0();
3337c478bdstevel@tonic-gateextern	tchar	rbf(), rbf0();
3347c478bdstevel@tonic-gateextern	tchar	mot(), hmot(), vmot();
3357c478bdstevel@tonic-gateextern	tchar	makem(), sethl();
3367c478bdstevel@tonic-gateextern	tchar	popi();
3377c478bdstevel@tonic-gateextern	tchar	getlg();
3387c478bdstevel@tonic-gateextern	tchar	xlss();
3397c478bdstevel@tonic-gateextern	tchar	setfield();
3407c478bdstevel@tonic-gateextern	tchar	setz();
3417c478bdstevel@tonic-gateextern	tchar	setch();
3427c478bdstevel@tonic-gateextern	tchar	setht(), setslant();
3437c478bdstevel@tonic-gate
3447c478bdstevel@tonic-gate#define	atoi(i)		((int) atoi0(i))
3457c478bdstevel@tonic-gateextern	long	atoi0();
3467c478bdstevel@tonic-gate
3477c478bdstevel@tonic-gateextern	int	Inch, Hor, Vert, Unitwidth;
3487c478bdstevel@tonic-gate
3497c478bdstevel@tonic-gate/* these characters are used as various signals or values
3507c478bdstevel@tonic-gate * in miscellaneous places.
3517c478bdstevel@tonic-gate * values are set in specnames in t10.c
3527c478bdstevel@tonic-gate */
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gateextern int	c_hyphen;
3557c478bdstevel@tonic-gateextern int	c_emdash;
3567c478bdstevel@tonic-gateextern int	c_rule;
3577c478bdstevel@tonic-gateextern int	c_minus;
3587c478bdstevel@tonic-gateextern int	c_fi;
3597c478bdstevel@tonic-gateextern int	c_fl;
3607c478bdstevel@tonic-gateextern int	c_ff;
3617c478bdstevel@tonic-gateextern int	c_ffi;
3627c478bdstevel@tonic-gateextern int	c_ffl;
3637c478bdstevel@tonic-gateextern int	c_acute;
3647c478bdstevel@tonic-gateextern int	c_grave;
3657c478bdstevel@tonic-gateextern int	c_under;
3667c478bdstevel@tonic-gateextern int	c_rooten;
3677c478bdstevel@tonic-gateextern int	c_boxrule;
3687c478bdstevel@tonic-gateextern int	c_lefthand;
3697c478bdstevel@tonic-gateextern int	c_dagger;
3707c478bdstevel@tonic-gate
3717c478bdstevel@tonic-gate/*
3727c478bdstevel@tonic-gate * <widec.h> includes <stdio.h> which defines
3737c478bdstevel@tonic-gate * stderr. So undef it if it is already defined.
3747c478bdstevel@tonic-gate */
3757c478bdstevel@tonic-gate#ifdef stderr
3767c478bdstevel@tonic-gate#	undef stderr
3777c478bdstevel@tonic-gate#endif
3787c478bdstevel@tonic-gateextern int	stderr;	/* this is NOT the stdio value! */
3797c478bdstevel@tonic-gate
3807c478bdstevel@tonic-gate#ifdef	DEBUG
3817c478bdstevel@tonic-gateextern	int	debug;	/*debug flag*/
3827c478bdstevel@tonic-gate#define	DB_MAC	01	/*print out macro calls*/
3837c478bdstevel@tonic-gate#define	DB_ALLC	02	/*print out message from alloc()*/
3847c478bdstevel@tonic-gate#define	DB_GETC	04	/*print out message from getch()*/
3857c478bdstevel@tonic-gate#define	DB_LOOP	010	/*print out message before "Eileen's loop" fix*/
386e5190c1muffin#endif	/* DEBUG */
3877c478bdstevel@tonic-gate
388e5190c1muffinstruct	d {	/* diversion */
3897c478bdstevel@tonic-gate	filep	op;
3907c478bdstevel@tonic-gate	int	dnl;
3917c478bdstevel@tonic-gate	int	dimac;
3927c478bdstevel@tonic-gate	int	ditrap;
3937c478bdstevel@tonic-gate	int	ditf;
3947c478bdstevel@tonic-gate	int	alss;
3957c478bdstevel@tonic-gate	int	blss;
3967c478bdstevel@tonic-gate	int	nls;
3977c478bdstevel@tonic-gate	int	mkline;
3987c478bdstevel@tonic-gate	int	maxl;
3997c478bdstevel@tonic-gate	int	hnl;
4007c478bdstevel@tonic-gate	int	curd;
4017c478bdstevel@tonic-gate};
4027c478bdstevel@tonic-gate
403e5190c1muffinstruct	s {	/* stack frame */
4047c478bdstevel@tonic-gate	int	nargs;
4057c478bdstevel@tonic-gate	struct s *pframe;
4067c478bdstevel@tonic-gate	filep	pip;
4077c478bdstevel@tonic-gate	int	pnchar;
4087c478bdstevel@tonic-gate	tchar	prchar;
4097c478bdstevel@tonic-gate	int	ppendt;
4107c478bdstevel@tonic-gate	tchar	pch;
4117c478bdstevel@tonic-gate	tchar	*lastpbp;
4127c478bdstevel@tonic-gate	int	mname;
4137c478bdstevel@tonic-gate};
4147c478bdstevel@tonic-gate
4157c478bdstevel@tonic-gateextern struct contab {
4167c478bdstevel@tonic-gate	unsigned short	rq;
4177c478bdstevel@tonic-gate	struct	contab *link;
4187c478bdstevel@tonic-gate	int	(*f)();
4197c478bdstevel@tonic-gate	unsigned mx;
4207c478bdstevel@tonic-gate} contab[NM];
4217c478bdstevel@tonic-gate
4227c478bdstevel@tonic-gateextern struct numtab {
4237c478bdstevel@tonic-gate	short	r;		/* name */
4247c478bdstevel@tonic-gate	short	fmt;
4257c478bdstevel@tonic-gate	short	inc;
4267c478bdstevel@tonic-gate	int	val;
4277c478bdstevel@tonic-gate	struct	numtab *link;
4287c478bdstevel@tonic-gate} numtab[NN];
4297c478bdstevel@tonic-gate
4307c478bdstevel@tonic-gate#define	PN	0
4317c478bdstevel@tonic-gate#define	NL	1
4327c478bdstevel@tonic-gate#define	YR	2
4337c478bdstevel@tonic-gate#define	HP	3
4347c478bdstevel@tonic-gate#define	CT	4
4357c478bdstevel@tonic-gate#define	DN	5
4367c478bdstevel@tonic-gate#define	MO	6
4377c478bdstevel@tonic-gate#define	DY	7
4387c478bdstevel@tonic-gate#define	DW	8
4397c478bdstevel@tonic-gate#define	LN	9
4407c478bdstevel@tonic-gate#define	DL	10
4417c478bdstevel@tonic-gate#define	ST	11
4427c478bdstevel@tonic-gate#define	SB	12
4437c478bdstevel@tonic-gate#define	CD	13
4447c478bdstevel@tonic-gate#define	PID	14
4457c478bdstevel@tonic-gate
4467c478bdstevel@tonic-gate/* the infamous environment block */
4477c478bdstevel@tonic-gate
4487c478bdstevel@tonic-gate#define	ics	env._ics
4497c478bdstevel@tonic-gate#define	sps	env._sps
4507c478bdstevel@tonic-gate#define	spacesz	env._spacesz
4517c478bdstevel@tonic-gate#define	lss	env._lss
4527c478bdstevel@tonic-gate#define	lss1	env._lss1
4537c478bdstevel@tonic-gate#define	ll	env._ll
4547c478bdstevel@tonic-gate#define	ll1	env._ll1
4557c478bdstevel@tonic-gate#define	lt	env._lt
4567c478bdstevel@tonic-gate#define	lt1	env._lt1
4577c478bdstevel@tonic-gate#define	ic	env._ic
4587c478bdstevel@tonic-gate#define	icf	env._icf
4597c478bdstevel@tonic-gate#define	chbits	env._chbits
4607c478bdstevel@tonic-gate#define	spbits	env._spbits
4617c478bdstevel@tonic-gate#define	nmbits	env._nmbits
4627c478bdstevel@tonic-gate#define	apts	env._apts
4637c478bdstevel@tonic-gate#define	apts1	env._apts1
4647c478bdstevel@tonic-gate#define	pts	env._pts
4657c478bdstevel@tonic-gate#define	pts1	env._pts1
4667c478bdstevel@tonic-gate#define	font	env._font
4677c478bdstevel@tonic-gate#define	font1	env._font1
4687c478bdstevel@tonic-gate#define	ls	env._ls
4697c478bdstevel@tonic-gate#define	ls1	env._ls1
4707c478bdstevel@tonic-gate#define	ad	env._ad
4717c478bdstevel@tonic-gate#define	nms	env._nms
4727c478bdstevel@tonic-gate#define	ndf	env._ndf
4737c478bdstevel@tonic-gate#define	fi	env._fi
4747c478bdstevel@tonic-gate#define	cc	env._cc
4757c478bdstevel@tonic-gate#define	c2	env._c2
4767c478bdstevel@tonic-gate#define	ohc	env._ohc
4777c478bdstevel@tonic-gate#define	tdelim	env._tdelim
4787c478bdstevel@tonic-gate#define	hyf	env._hyf
4797c478bdstevel@tonic-gate#define	hyoff	env._hyoff
4807c478bdstevel@tonic-gate#define	un1	env._un1
4817c478bdstevel@tonic-gate#define	tabc	env._tabc
4827c478bdstevel@tonic-gate#define	dotc	env._dotc
4837c478bdstevel@tonic-gate#define	adsp	env._adsp
4847c478bdstevel@tonic-gate#define	adrem	env._adrem
4857c478bdstevel@tonic-gate#define	lastl	env._lastl
4867c478bdstevel@tonic-gate#define	nel	env._nel
4877c478bdstevel@tonic-gate#define	admod	env._admod
4887c478bdstevel@tonic-gate#define	wordp	env._wordp
4897c478bdstevel@tonic-gate#define	spflg	env._spflg
4907c478bdstevel@tonic-gate#define	linep	env._linep
4917c478bdstevel@tonic-gate#define	wdend	env._wdend
4927c478bdstevel@tonic-gate#define	wdstart	env._wdstart
4937c478bdstevel@tonic-gate#define	wne	env._wne
4947c478bdstevel@tonic-gate#define	ne	env._ne
4957c478bdstevel@tonic-gate#define	nc	env._nc
4967c478bdstevel@tonic-gate#define	nb	env._nb
4977c478bdstevel@tonic-gate#define	lnmod	env._lnmod
4987c478bdstevel@tonic-gate#define	nwd	env._nwd
4997c478bdstevel@tonic-gate#define	nn	env._nn
5007c478bdstevel@tonic-gate#define	ni	env._ni
5017c478bdstevel@tonic-gate#define	ul	env._ul
5027c478bdstevel@tonic-gate#define	cu	env._cu
5037c478bdstevel@tonic-gate#define	ce	env._ce
5047c478bdstevel@tonic-gate#define	in	env._in
5057c478bdstevel@tonic-gate#define	in1	env._in1
5067c478bdstevel@tonic-gate#define	un	env._un
5077c478bdstevel@tonic-gate#define	wch	env._wch
5087c478bdstevel@tonic-gate#define	pendt	env._pendt
5097c478bdstevel@tonic-gate#define	pendw	env._pendw
5107c478bdstevel@tonic-gate#define	pendnf	env._pendnf
5117c478bdstevel@tonic-gate#define	spread	env._spread
5127c478bdstevel@tonic-gate#define	it	env._it
5137c478bdstevel@tonic-gate#define	itmac	env._itmac
5147c478bdstevel@tonic-gate#define	lnsize	env._lnsize
5157c478bdstevel@tonic-gate#define	hyptr	env._hyptr
5167c478bdstevel@tonic-gate#define	tabtab	env._tabtab
5177c478bdstevel@tonic-gate#define	line	env._line
5187c478bdstevel@tonic-gate#define	word	env._word
5197c478bdstevel@tonic-gate
5207c478bdstevel@tonic-gateextern struct env {
5217c478bdstevel@tonic-gate	int	_ics;
5227c478bdstevel@tonic-gate	int	_sps;
5237c478bdstevel@tonic-gate	int	_spacesz;
5247c478bdstevel@tonic-gate	int	_lss;
5257c478bdstevel@tonic-gate	int	_lss1;
5267c478bdstevel@tonic-gate	int	_ll;
5277c478bdstevel@tonic-gate	int	_ll1;
5287c478bdstevel@tonic-gate	int	_lt;
5297c478bdstevel@tonic-gate	int	_lt1;
5307c478bdstevel@tonic-gate	tchar	_ic;
5317c478bdstevel@tonic-gate	int	_icf;
5327c478bdstevel@tonic-gate	tchar	_chbits;
5337c478bdstevel@tonic-gate	tchar	_spbits;
5347c478bdstevel@tonic-gate	tchar	_nmbits;
5357c478bdstevel@tonic-gate	int	_apts;
5367c478bdstevel@tonic-gate	int	_apts1;
5377c478bdstevel@tonic-gate	int	_pts;
5387c478bdstevel@tonic-gate	int	_pts1;
5397c478bdstevel@tonic-gate	int	_font;
5407c478bdstevel@tonic-gate	int	_font1;
5417c478bdstevel@tonic-gate	int	_ls;
5427c478bdstevel@tonic-gate	int	_ls1;
5437c478bdstevel@tonic-gate	int	_ad;
5447c478bdstevel@tonic-gate	int	_nms;
5457c478bdstevel@tonic-gate	int	_ndf;
5467c478bdstevel@tonic-gate	int	_fi;
5477c478bdstevel@tonic-gate	int	_cc;
5487c478bdstevel@tonic-gate	int	_c2;
5497c478bdstevel@tonic-gate	int	_ohc;
5507c478bdstevel@tonic-gate	int	_tdelim;
5517c478bdstevel@tonic-gate	int	_hyf;
5527c478bdstevel@tonic-gate	int	_hyoff;
5537c478bdstevel@tonic-gate	int	_un1;
5547c478bdstevel@tonic-gate	int	_tabc;
5557c478bdstevel@tonic-gate	int	_dotc;
5567c478bdstevel@tonic-gate	int	_adsp;
5577c478bdstevel@tonic-gate	int	_adrem;
5587c478bdstevel@tonic-gate	int	_lastl;
5597c478bdstevel@tonic-gate	int	_nel;
5607c478bdstevel@tonic-gate	int	_admod;
5617c478bdstevel@tonic-gate	tchar	*_wordp;
5627c478bdstevel@tonic-gate	int	_spflg;
5637c478bdstevel@tonic-gate	tchar	*_linep;
5647c478bdstevel@tonic-gate	tchar	*_wdend;
5657c478bdstevel@tonic-gate	tchar	*_wdstart;
5667c478bdstevel@tonic-gate	int	_wne;
5677c478bdstevel@tonic-gate	int	_ne;
5687c478bdstevel@tonic-gate	int	_nc;
5697c478bdstevel@tonic-gate	int	_nb;
5707c478bdstevel@tonic-gate	int	_lnmod;
5717c478bdstevel@tonic-gate	int	_nwd;
5727c478bdstevel@tonic-gate	int	_nn;
5737c478bdstevel@tonic-gate	int	_ni;
5747c478bdstevel@tonic-gate	int	_ul;
5757c478bdstevel@tonic-gate	int	_cu;
5767c478bdstevel@tonic-gate	int	_ce;
5777c478bdstevel@tonic-gate	int	_in;
5787c478bdstevel@tonic-gate	int	_in1;
5797c478bdstevel@tonic-gate	int	_un;
5807c478bdstevel@tonic-gate	int	_wch;
5817c478bdstevel@tonic-gate	int	_pendt;
5827c478bdstevel@tonic-gate	tchar	*_pendw;
5837c478bdstevel@tonic-gate	int	_pendnf;
5847c478bdstevel@tonic-gate	int	_spread;
5857c478bdstevel@tonic-gate	int	_it;
5867c478bdstevel@tonic-gate	int	_itmac;
5877c478bdstevel@tonic-gate	int	_lnsize;
5887c478bdstevel@tonic-gate	tchar	*_hyptr[NHYP];
5897c478bdstevel@tonic-gate	int	_tabtab[NTAB];
5907c478bdstevel@tonic-gate	tchar	_line[LNSIZE];
5917c478bdstevel@tonic-gate	tchar	_word[WDSIZE];
5927c478bdstevel@tonic-gate} env;
593