xref: /titanic_53/usr/src/cmd/troff/n7.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
35*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
36*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
39*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
40*7c478bd9Sstevel@tonic-gate  * contributors.
41*7c478bd9Sstevel@tonic-gate  */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #ifdef EUC
44*7c478bd9Sstevel@tonic-gate #ifdef NROFF
45*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
46*7c478bd9Sstevel@tonic-gate #include <widec.h>
47*7c478bd9Sstevel@tonic-gate #include <limits.h>
48*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
49*7c478bd9Sstevel@tonic-gate #endif /* EUC */
50*7c478bd9Sstevel@tonic-gate #include "tdef.h"
51*7c478bd9Sstevel@tonic-gate #ifdef NROFF
52*7c478bd9Sstevel@tonic-gate #include "tw.h"
53*7c478bd9Sstevel@tonic-gate #endif
54*7c478bd9Sstevel@tonic-gate #ifdef NROFF
55*7c478bd9Sstevel@tonic-gate #define GETCH gettch
56*7c478bd9Sstevel@tonic-gate tchar	gettch();
57*7c478bd9Sstevel@tonic-gate #endif
58*7c478bd9Sstevel@tonic-gate #ifndef NROFF
59*7c478bd9Sstevel@tonic-gate #define GETCH getch
60*7c478bd9Sstevel@tonic-gate #endif
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  * troff7.c
64*7c478bd9Sstevel@tonic-gate  *
65*7c478bd9Sstevel@tonic-gate  * text
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #include <ctype.h>
69*7c478bd9Sstevel@tonic-gate #ifdef EUC
70*7c478bd9Sstevel@tonic-gate #ifdef NROFF
71*7c478bd9Sstevel@tonic-gate #include <wctype.h>
72*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
73*7c478bd9Sstevel@tonic-gate #endif /* EUC */
74*7c478bd9Sstevel@tonic-gate #include "ext.h"
75*7c478bd9Sstevel@tonic-gate #ifdef EUC
76*7c478bd9Sstevel@tonic-gate #ifdef NROFF
77*7c478bd9Sstevel@tonic-gate char	mbbuf2[MB_LEN_MAX + 1];
78*7c478bd9Sstevel@tonic-gate char	*mbbuf2p = mbbuf2;
79*7c478bd9Sstevel@tonic-gate tchar	mtbuf[MB_LEN_MAX + 1];
80*7c478bd9Sstevel@tonic-gate tchar	*mtbufp;
81*7c478bd9Sstevel@tonic-gate int	pendmb = 0;
82*7c478bd9Sstevel@tonic-gate wchar_t	cwc, owc, wceoll;
83*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
84*7c478bd9Sstevel@tonic-gate #endif /* EUC */
85*7c478bd9Sstevel@tonic-gate int	brflg;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate tbreak()
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate 	register pad, k;
90*7c478bd9Sstevel@tonic-gate 	register tchar	*i, j;
91*7c478bd9Sstevel@tonic-gate 	register int resol = 0;
92*7c478bd9Sstevel@tonic-gate #ifdef EUC
93*7c478bd9Sstevel@tonic-gate #ifdef NROFF
94*7c478bd9Sstevel@tonic-gate 	register tchar	l;
95*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
96*7c478bd9Sstevel@tonic-gate #endif /* EUC */
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	trap = 0;
99*7c478bd9Sstevel@tonic-gate 	if (nb)
100*7c478bd9Sstevel@tonic-gate 		return;
101*7c478bd9Sstevel@tonic-gate 	if (dip == d && numtab[NL].val == -1) {
102*7c478bd9Sstevel@tonic-gate 		newline(1);
103*7c478bd9Sstevel@tonic-gate 		return;
104*7c478bd9Sstevel@tonic-gate 	}
105*7c478bd9Sstevel@tonic-gate 	if (!nc) {
106*7c478bd9Sstevel@tonic-gate 		setnel();
107*7c478bd9Sstevel@tonic-gate 		if (!wch)
108*7c478bd9Sstevel@tonic-gate 			return;
109*7c478bd9Sstevel@tonic-gate 		if (pendw)
110*7c478bd9Sstevel@tonic-gate 			getword(1);
111*7c478bd9Sstevel@tonic-gate 		movword();
112*7c478bd9Sstevel@tonic-gate 	} else if (pendw && !brflg) {
113*7c478bd9Sstevel@tonic-gate 		getword(1);
114*7c478bd9Sstevel@tonic-gate 		movword();
115*7c478bd9Sstevel@tonic-gate 	}
116*7c478bd9Sstevel@tonic-gate 	*linep = dip->nls = 0;
117*7c478bd9Sstevel@tonic-gate #ifdef NROFF
118*7c478bd9Sstevel@tonic-gate 	if (dip == d)
119*7c478bd9Sstevel@tonic-gate 		horiz(po);
120*7c478bd9Sstevel@tonic-gate #endif
121*7c478bd9Sstevel@tonic-gate 	if (lnmod)
122*7c478bd9Sstevel@tonic-gate 		donum();
123*7c478bd9Sstevel@tonic-gate 	lastl = ne;
124*7c478bd9Sstevel@tonic-gate 	if (brflg != 1) {
125*7c478bd9Sstevel@tonic-gate 		totout = 0;
126*7c478bd9Sstevel@tonic-gate 	} else if (ad) {
127*7c478bd9Sstevel@tonic-gate 		if ((lastl = ll - un) < ne)
128*7c478bd9Sstevel@tonic-gate 			lastl = ne;
129*7c478bd9Sstevel@tonic-gate 	}
130*7c478bd9Sstevel@tonic-gate 	if (admod && ad && (brflg != 2)) {
131*7c478bd9Sstevel@tonic-gate 		lastl = ne;
132*7c478bd9Sstevel@tonic-gate 		adsp = adrem = 0;
133*7c478bd9Sstevel@tonic-gate 		if (admod == 1)
134*7c478bd9Sstevel@tonic-gate 			un +=  quant(nel / 2, HOR);
135*7c478bd9Sstevel@tonic-gate 		else if (admod == 2)
136*7c478bd9Sstevel@tonic-gate 			un += nel;
137*7c478bd9Sstevel@tonic-gate 	}
138*7c478bd9Sstevel@tonic-gate 	totout++;
139*7c478bd9Sstevel@tonic-gate 	brflg = 0;
140*7c478bd9Sstevel@tonic-gate 	if (lastl + un > dip->maxl)
141*7c478bd9Sstevel@tonic-gate 		dip->maxl = lastl + un;
142*7c478bd9Sstevel@tonic-gate 	horiz(un);
143*7c478bd9Sstevel@tonic-gate #ifdef NROFF
144*7c478bd9Sstevel@tonic-gate 	if (adrem % t.Adj)
145*7c478bd9Sstevel@tonic-gate 		resol = t.Hor;
146*7c478bd9Sstevel@tonic-gate 	else
147*7c478bd9Sstevel@tonic-gate 		resol = t.Adj;
148*7c478bd9Sstevel@tonic-gate #else
149*7c478bd9Sstevel@tonic-gate 	resol = HOR;
150*7c478bd9Sstevel@tonic-gate #endif
151*7c478bd9Sstevel@tonic-gate 	adrem = (adrem / resol) * resol;
152*7c478bd9Sstevel@tonic-gate 	for (i = line; nc > 0; ) {
153*7c478bd9Sstevel@tonic-gate #ifndef EUC
154*7c478bd9Sstevel@tonic-gate 		if ((cbits(j = *i++)) == ' ') {
155*7c478bd9Sstevel@tonic-gate #else
156*7c478bd9Sstevel@tonic-gate #ifndef NROFF
157*7c478bd9Sstevel@tonic-gate 		if ((cbits(j = *i++)) == ' ') {
158*7c478bd9Sstevel@tonic-gate #else
159*7c478bd9Sstevel@tonic-gate 		if ((cbits(j = *i++) & ~MBMASK) == ' ') {
160*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
161*7c478bd9Sstevel@tonic-gate #endif /* EUC */
162*7c478bd9Sstevel@tonic-gate 			pad = 0;
163*7c478bd9Sstevel@tonic-gate 			do {
164*7c478bd9Sstevel@tonic-gate 				pad += width(j);
165*7c478bd9Sstevel@tonic-gate 				nc--;
166*7c478bd9Sstevel@tonic-gate #ifndef EUC
167*7c478bd9Sstevel@tonic-gate 			} while ((cbits(j = *i++)) == ' ');
168*7c478bd9Sstevel@tonic-gate #else
169*7c478bd9Sstevel@tonic-gate #ifndef NROFF
170*7c478bd9Sstevel@tonic-gate 			} while ((cbits(j = *i++)) == ' ');
171*7c478bd9Sstevel@tonic-gate #else
172*7c478bd9Sstevel@tonic-gate 			} while ((cbits(j = *i++) & ~MBMASK) == ' ');
173*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
174*7c478bd9Sstevel@tonic-gate #endif /* EUC */
175*7c478bd9Sstevel@tonic-gate 			i--;
176*7c478bd9Sstevel@tonic-gate 			pad += adsp;
177*7c478bd9Sstevel@tonic-gate 			--nwd;
178*7c478bd9Sstevel@tonic-gate 			if (adrem) {
179*7c478bd9Sstevel@tonic-gate 				if (adrem < 0) {
180*7c478bd9Sstevel@tonic-gate 					pad -= resol;
181*7c478bd9Sstevel@tonic-gate 					adrem += resol;
182*7c478bd9Sstevel@tonic-gate 				} else if ((totout & 01) || adrem / resol >= nwd) {
183*7c478bd9Sstevel@tonic-gate 					pad += resol;
184*7c478bd9Sstevel@tonic-gate 					adrem -= resol;
185*7c478bd9Sstevel@tonic-gate 				}
186*7c478bd9Sstevel@tonic-gate 			}
187*7c478bd9Sstevel@tonic-gate 			pchar((tchar) WORDSP);
188*7c478bd9Sstevel@tonic-gate 			horiz(pad);
189*7c478bd9Sstevel@tonic-gate 		} else {
190*7c478bd9Sstevel@tonic-gate 			pchar(j);
191*7c478bd9Sstevel@tonic-gate 			nc--;
192*7c478bd9Sstevel@tonic-gate 		}
193*7c478bd9Sstevel@tonic-gate 	}
194*7c478bd9Sstevel@tonic-gate 	if (ic) {
195*7c478bd9Sstevel@tonic-gate 		if ((k = ll - un - lastl + ics) > 0)
196*7c478bd9Sstevel@tonic-gate 			horiz(k);
197*7c478bd9Sstevel@tonic-gate 		pchar(ic);
198*7c478bd9Sstevel@tonic-gate 	}
199*7c478bd9Sstevel@tonic-gate 	if (icf)
200*7c478bd9Sstevel@tonic-gate 		icf++;
201*7c478bd9Sstevel@tonic-gate 	else
202*7c478bd9Sstevel@tonic-gate 		ic = 0;
203*7c478bd9Sstevel@tonic-gate 	ne = nwd = 0;
204*7c478bd9Sstevel@tonic-gate 	un = in;
205*7c478bd9Sstevel@tonic-gate 	setnel();
206*7c478bd9Sstevel@tonic-gate 	newline(0);
207*7c478bd9Sstevel@tonic-gate 	if (dip != d) {
208*7c478bd9Sstevel@tonic-gate 		if (dip->dnl > dip->hnl)
209*7c478bd9Sstevel@tonic-gate 			dip->hnl = dip->dnl;
210*7c478bd9Sstevel@tonic-gate 	} else {
211*7c478bd9Sstevel@tonic-gate 		if (numtab[NL].val > dip->hnl)
212*7c478bd9Sstevel@tonic-gate 			dip->hnl = numtab[NL].val;
213*7c478bd9Sstevel@tonic-gate 	}
214*7c478bd9Sstevel@tonic-gate 	for (k = ls - 1; k > 0 && !trap; k--)
215*7c478bd9Sstevel@tonic-gate 		newline(0);
216*7c478bd9Sstevel@tonic-gate 	spread = 0;
217*7c478bd9Sstevel@tonic-gate }
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate donum()
220*7c478bd9Sstevel@tonic-gate {
221*7c478bd9Sstevel@tonic-gate 	register i, nw;
222*7c478bd9Sstevel@tonic-gate 	extern pchar();
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 	nrbits = nmbits;
225*7c478bd9Sstevel@tonic-gate 	nw = width('1' | nrbits);
226*7c478bd9Sstevel@tonic-gate 	if (nn) {
227*7c478bd9Sstevel@tonic-gate 		nn--;
228*7c478bd9Sstevel@tonic-gate 		goto d1;
229*7c478bd9Sstevel@tonic-gate 	}
230*7c478bd9Sstevel@tonic-gate 	if (numtab[LN].val % ndf) {
231*7c478bd9Sstevel@tonic-gate 		numtab[LN].val++;
232*7c478bd9Sstevel@tonic-gate d1:
233*7c478bd9Sstevel@tonic-gate 		un += nw * (3 + nms + ni);
234*7c478bd9Sstevel@tonic-gate 		return;
235*7c478bd9Sstevel@tonic-gate 	}
236*7c478bd9Sstevel@tonic-gate 	i = 0;
237*7c478bd9Sstevel@tonic-gate 	if (numtab[LN].val < 100)
238*7c478bd9Sstevel@tonic-gate 		i++;
239*7c478bd9Sstevel@tonic-gate 	if (numtab[LN].val < 10)
240*7c478bd9Sstevel@tonic-gate 		i++;
241*7c478bd9Sstevel@tonic-gate 	horiz(nw * (ni + i));
242*7c478bd9Sstevel@tonic-gate 	nform = 0;
243*7c478bd9Sstevel@tonic-gate 	fnumb(numtab[LN].val, pchar);
244*7c478bd9Sstevel@tonic-gate 	un += nw * nms;
245*7c478bd9Sstevel@tonic-gate 	numtab[LN].val++;
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate extern int logf;
249*7c478bd9Sstevel@tonic-gate text()
250*7c478bd9Sstevel@tonic-gate {
251*7c478bd9Sstevel@tonic-gate 	register tchar i;
252*7c478bd9Sstevel@tonic-gate 	static int	spcnt;
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 	nflush++;
255*7c478bd9Sstevel@tonic-gate 	numtab[HP].val = 0;
256*7c478bd9Sstevel@tonic-gate 	if ((dip == d) && (numtab[NL].val == -1)) {
257*7c478bd9Sstevel@tonic-gate 		newline(1);
258*7c478bd9Sstevel@tonic-gate 		return;
259*7c478bd9Sstevel@tonic-gate 	}
260*7c478bd9Sstevel@tonic-gate 	setnel();
261*7c478bd9Sstevel@tonic-gate 	if (ce || !fi) {
262*7c478bd9Sstevel@tonic-gate 		nofill();
263*7c478bd9Sstevel@tonic-gate 		return;
264*7c478bd9Sstevel@tonic-gate 	}
265*7c478bd9Sstevel@tonic-gate 	if (pendw)
266*7c478bd9Sstevel@tonic-gate 		goto t4;
267*7c478bd9Sstevel@tonic-gate 	if (pendt)
268*7c478bd9Sstevel@tonic-gate 		if (spcnt)
269*7c478bd9Sstevel@tonic-gate 			goto t2;
270*7c478bd9Sstevel@tonic-gate 		else
271*7c478bd9Sstevel@tonic-gate 			goto t3;
272*7c478bd9Sstevel@tonic-gate 	pendt++;
273*7c478bd9Sstevel@tonic-gate 	if (spcnt)
274*7c478bd9Sstevel@tonic-gate 		goto t2;
275*7c478bd9Sstevel@tonic-gate 	while ((cbits(i = GETCH())) == ' ') {
276*7c478bd9Sstevel@tonic-gate 		spcnt++;
277*7c478bd9Sstevel@tonic-gate 		numtab[HP].val += sps;
278*7c478bd9Sstevel@tonic-gate 		widthp = sps;
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate 	if (nlflg) {
281*7c478bd9Sstevel@tonic-gate t1:
282*7c478bd9Sstevel@tonic-gate 		nflush = pendt = ch = spcnt = 0;
283*7c478bd9Sstevel@tonic-gate 		callsp();
284*7c478bd9Sstevel@tonic-gate 		return;
285*7c478bd9Sstevel@tonic-gate 	}
286*7c478bd9Sstevel@tonic-gate 	ch = i;
287*7c478bd9Sstevel@tonic-gate 	if (spcnt) {
288*7c478bd9Sstevel@tonic-gate t2:
289*7c478bd9Sstevel@tonic-gate 		tbreak();
290*7c478bd9Sstevel@tonic-gate 		if (nc || wch)
291*7c478bd9Sstevel@tonic-gate 			goto rtn;
292*7c478bd9Sstevel@tonic-gate 		un += spcnt * sps;
293*7c478bd9Sstevel@tonic-gate 		spcnt = 0;
294*7c478bd9Sstevel@tonic-gate 		setnel();
295*7c478bd9Sstevel@tonic-gate 		if (trap)
296*7c478bd9Sstevel@tonic-gate 			goto rtn;
297*7c478bd9Sstevel@tonic-gate 		if (nlflg)
298*7c478bd9Sstevel@tonic-gate 			goto t1;
299*7c478bd9Sstevel@tonic-gate 	}
300*7c478bd9Sstevel@tonic-gate t3:
301*7c478bd9Sstevel@tonic-gate 	if (spread)
302*7c478bd9Sstevel@tonic-gate 		goto t5;
303*7c478bd9Sstevel@tonic-gate 	if (pendw || !wch)
304*7c478bd9Sstevel@tonic-gate t4:
305*7c478bd9Sstevel@tonic-gate 		if (getword(0))
306*7c478bd9Sstevel@tonic-gate 			goto t6;
307*7c478bd9Sstevel@tonic-gate 	if (!movword())
308*7c478bd9Sstevel@tonic-gate 		goto t3;
309*7c478bd9Sstevel@tonic-gate t5:
310*7c478bd9Sstevel@tonic-gate 	if (nlflg)
311*7c478bd9Sstevel@tonic-gate 		pendt = 0;
312*7c478bd9Sstevel@tonic-gate 	adsp = adrem = 0;
313*7c478bd9Sstevel@tonic-gate 	if (ad) {
314*7c478bd9Sstevel@tonic-gate 		if (nwd == 1)
315*7c478bd9Sstevel@tonic-gate 			adsp = nel;
316*7c478bd9Sstevel@tonic-gate 		else
317*7c478bd9Sstevel@tonic-gate 			adsp = nel / (nwd - 1);
318*7c478bd9Sstevel@tonic-gate 		adsp = (adsp / HOR) * HOR;
319*7c478bd9Sstevel@tonic-gate 		adrem = nel - adsp*(nwd-1);
320*7c478bd9Sstevel@tonic-gate 	}
321*7c478bd9Sstevel@tonic-gate 	brflg = 1;
322*7c478bd9Sstevel@tonic-gate 	tbreak();
323*7c478bd9Sstevel@tonic-gate 	spread = 0;
324*7c478bd9Sstevel@tonic-gate 	if (!trap)
325*7c478bd9Sstevel@tonic-gate 		goto t3;
326*7c478bd9Sstevel@tonic-gate 	if (!nlflg)
327*7c478bd9Sstevel@tonic-gate 		goto rtn;
328*7c478bd9Sstevel@tonic-gate t6:
329*7c478bd9Sstevel@tonic-gate 	pendt = 0;
330*7c478bd9Sstevel@tonic-gate 	ckul();
331*7c478bd9Sstevel@tonic-gate rtn:
332*7c478bd9Sstevel@tonic-gate 	nflush = 0;
333*7c478bd9Sstevel@tonic-gate }
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate nofill()
337*7c478bd9Sstevel@tonic-gate {
338*7c478bd9Sstevel@tonic-gate 	register j;
339*7c478bd9Sstevel@tonic-gate 	register tchar i;
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate 	if (!pendnf) {
342*7c478bd9Sstevel@tonic-gate 		over = 0;
343*7c478bd9Sstevel@tonic-gate 		tbreak();
344*7c478bd9Sstevel@tonic-gate 		if (trap)
345*7c478bd9Sstevel@tonic-gate 			goto rtn;
346*7c478bd9Sstevel@tonic-gate 		if (nlflg) {
347*7c478bd9Sstevel@tonic-gate 			ch = nflush = 0;
348*7c478bd9Sstevel@tonic-gate 			callsp();
349*7c478bd9Sstevel@tonic-gate 			return;
350*7c478bd9Sstevel@tonic-gate 		}
351*7c478bd9Sstevel@tonic-gate 		adsp = adrem = 0;
352*7c478bd9Sstevel@tonic-gate 		nwd = 10000;
353*7c478bd9Sstevel@tonic-gate 	}
354*7c478bd9Sstevel@tonic-gate 	while ((j = (cbits(i = GETCH()))) != '\n') {
355*7c478bd9Sstevel@tonic-gate 		if (j == ohc)
356*7c478bd9Sstevel@tonic-gate 			continue;
357*7c478bd9Sstevel@tonic-gate 		if (j == CONT) {
358*7c478bd9Sstevel@tonic-gate 			pendnf++;
359*7c478bd9Sstevel@tonic-gate 			nflush = 0;
360*7c478bd9Sstevel@tonic-gate 			flushi();
361*7c478bd9Sstevel@tonic-gate 			ckul();
362*7c478bd9Sstevel@tonic-gate 			return;
363*7c478bd9Sstevel@tonic-gate 		}
364*7c478bd9Sstevel@tonic-gate 		j = width(i);
365*7c478bd9Sstevel@tonic-gate 		widthp = j;
366*7c478bd9Sstevel@tonic-gate 		numtab[HP].val += j;
367*7c478bd9Sstevel@tonic-gate 		storeline(i, j);
368*7c478bd9Sstevel@tonic-gate 	}
369*7c478bd9Sstevel@tonic-gate 	if (ce) {
370*7c478bd9Sstevel@tonic-gate 		ce--;
371*7c478bd9Sstevel@tonic-gate 		if ((i = quant(nel / 2, HOR)) > 0)
372*7c478bd9Sstevel@tonic-gate 			un += i;
373*7c478bd9Sstevel@tonic-gate 	}
374*7c478bd9Sstevel@tonic-gate 	if (!nc)
375*7c478bd9Sstevel@tonic-gate 		storeline((tchar)FILLER, 0);
376*7c478bd9Sstevel@tonic-gate 	brflg = 2;
377*7c478bd9Sstevel@tonic-gate 	tbreak();
378*7c478bd9Sstevel@tonic-gate 	ckul();
379*7c478bd9Sstevel@tonic-gate rtn:
380*7c478bd9Sstevel@tonic-gate 	pendnf = nflush = 0;
381*7c478bd9Sstevel@tonic-gate }
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 
384*7c478bd9Sstevel@tonic-gate callsp()
385*7c478bd9Sstevel@tonic-gate {
386*7c478bd9Sstevel@tonic-gate 	register i;
387*7c478bd9Sstevel@tonic-gate 
388*7c478bd9Sstevel@tonic-gate 	if (flss)
389*7c478bd9Sstevel@tonic-gate 		i = flss;
390*7c478bd9Sstevel@tonic-gate 	else
391*7c478bd9Sstevel@tonic-gate 		i = lss;
392*7c478bd9Sstevel@tonic-gate 	flss = 0;
393*7c478bd9Sstevel@tonic-gate 	casesp(i);
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate ckul()
398*7c478bd9Sstevel@tonic-gate {
399*7c478bd9Sstevel@tonic-gate 	if (ul && (--ul == 0)) {
400*7c478bd9Sstevel@tonic-gate 		cu = 0;
401*7c478bd9Sstevel@tonic-gate 		font = sfont;
402*7c478bd9Sstevel@tonic-gate 		mchbits();
403*7c478bd9Sstevel@tonic-gate 	}
404*7c478bd9Sstevel@tonic-gate 	if (it && (--it == 0) && itmac)
405*7c478bd9Sstevel@tonic-gate 		control(itmac, 0);
406*7c478bd9Sstevel@tonic-gate }
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate storeline(c, w)
410*7c478bd9Sstevel@tonic-gate register tchar c;
411*7c478bd9Sstevel@tonic-gate {
412*7c478bd9Sstevel@tonic-gate 	if (linep >= line + lnsize - 1) {
413*7c478bd9Sstevel@tonic-gate 		if (!over) {
414*7c478bd9Sstevel@tonic-gate 			flusho();
415*7c478bd9Sstevel@tonic-gate 			errprint(gettext("Line overflow."));
416*7c478bd9Sstevel@tonic-gate 			over++;
417*7c478bd9Sstevel@tonic-gate 			c = LEFTHAND;
418*7c478bd9Sstevel@tonic-gate 			w = -1;
419*7c478bd9Sstevel@tonic-gate 			goto s1;
420*7c478bd9Sstevel@tonic-gate 		}
421*7c478bd9Sstevel@tonic-gate 		return;
422*7c478bd9Sstevel@tonic-gate 	}
423*7c478bd9Sstevel@tonic-gate s1:
424*7c478bd9Sstevel@tonic-gate 	if (w == -1)
425*7c478bd9Sstevel@tonic-gate 		w = width(c);
426*7c478bd9Sstevel@tonic-gate 	ne += w;
427*7c478bd9Sstevel@tonic-gate 	nel -= w;
428*7c478bd9Sstevel@tonic-gate 	*linep++ = c;
429*7c478bd9Sstevel@tonic-gate 	nc++;
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate newline(a)
434*7c478bd9Sstevel@tonic-gate int	a;
435*7c478bd9Sstevel@tonic-gate {
436*7c478bd9Sstevel@tonic-gate 	register i, j, nlss;
437*7c478bd9Sstevel@tonic-gate 	int	opn;
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 	if (a)
440*7c478bd9Sstevel@tonic-gate 		goto nl1;
441*7c478bd9Sstevel@tonic-gate 	if (dip != d) {
442*7c478bd9Sstevel@tonic-gate 		j = lss;
443*7c478bd9Sstevel@tonic-gate 		pchar1((tchar)FLSS);
444*7c478bd9Sstevel@tonic-gate 		if (flss)
445*7c478bd9Sstevel@tonic-gate 			lss = flss;
446*7c478bd9Sstevel@tonic-gate 		i = lss + dip->blss;
447*7c478bd9Sstevel@tonic-gate 		dip->dnl += i;
448*7c478bd9Sstevel@tonic-gate 		pchar1((tchar)i);
449*7c478bd9Sstevel@tonic-gate 		pchar1((tchar)'\n');
450*7c478bd9Sstevel@tonic-gate 		lss = j;
451*7c478bd9Sstevel@tonic-gate 		dip->blss = flss = 0;
452*7c478bd9Sstevel@tonic-gate 		if (dip->alss) {
453*7c478bd9Sstevel@tonic-gate 			pchar1((tchar)FLSS);
454*7c478bd9Sstevel@tonic-gate 			pchar1((tchar)dip->alss);
455*7c478bd9Sstevel@tonic-gate 			pchar1((tchar)'\n');
456*7c478bd9Sstevel@tonic-gate 			dip->dnl += dip->alss;
457*7c478bd9Sstevel@tonic-gate 			dip->alss = 0;
458*7c478bd9Sstevel@tonic-gate 		}
459*7c478bd9Sstevel@tonic-gate 		if (dip->ditrap && !dip->ditf && dip->dnl >= dip->ditrap && dip->dimac)
460*7c478bd9Sstevel@tonic-gate 			if (control(dip->dimac, 0)) {
461*7c478bd9Sstevel@tonic-gate 				trap++;
462*7c478bd9Sstevel@tonic-gate 				dip->ditf++;
463*7c478bd9Sstevel@tonic-gate 			}
464*7c478bd9Sstevel@tonic-gate 		return;
465*7c478bd9Sstevel@tonic-gate 	}
466*7c478bd9Sstevel@tonic-gate 	j = lss;
467*7c478bd9Sstevel@tonic-gate 	if (flss)
468*7c478bd9Sstevel@tonic-gate 		lss = flss;
469*7c478bd9Sstevel@tonic-gate 	nlss = dip->alss + dip->blss + lss;
470*7c478bd9Sstevel@tonic-gate 	numtab[NL].val += nlss;
471*7c478bd9Sstevel@tonic-gate #ifndef NROFF
472*7c478bd9Sstevel@tonic-gate 	if (ascii) {
473*7c478bd9Sstevel@tonic-gate 		dip->alss = dip->blss = 0;
474*7c478bd9Sstevel@tonic-gate 	}
475*7c478bd9Sstevel@tonic-gate #endif
476*7c478bd9Sstevel@tonic-gate 	pchar1((tchar)'\n');
477*7c478bd9Sstevel@tonic-gate 	flss = 0;
478*7c478bd9Sstevel@tonic-gate 	lss = j;
479*7c478bd9Sstevel@tonic-gate 	if (numtab[NL].val < pl)
480*7c478bd9Sstevel@tonic-gate 		goto nl2;
481*7c478bd9Sstevel@tonic-gate nl1:
482*7c478bd9Sstevel@tonic-gate 	ejf = dip->hnl = numtab[NL].val = 0;
483*7c478bd9Sstevel@tonic-gate 	ejl = frame;
484*7c478bd9Sstevel@tonic-gate 	if (donef) {
485*7c478bd9Sstevel@tonic-gate 		if ((!nc && !wch) || ndone)
486*7c478bd9Sstevel@tonic-gate 			done1(0);
487*7c478bd9Sstevel@tonic-gate 		ndone++;
488*7c478bd9Sstevel@tonic-gate 		donef = 0;
489*7c478bd9Sstevel@tonic-gate 		if (frame == stk)
490*7c478bd9Sstevel@tonic-gate 			nflush++;
491*7c478bd9Sstevel@tonic-gate 	}
492*7c478bd9Sstevel@tonic-gate 	opn = numtab[PN].val;
493*7c478bd9Sstevel@tonic-gate 	numtab[PN].val++;
494*7c478bd9Sstevel@tonic-gate 	if (npnflg) {
495*7c478bd9Sstevel@tonic-gate 		numtab[PN].val = npn;
496*7c478bd9Sstevel@tonic-gate 		npn = npnflg = 0;
497*7c478bd9Sstevel@tonic-gate 	}
498*7c478bd9Sstevel@tonic-gate nlpn:
499*7c478bd9Sstevel@tonic-gate 	if (numtab[PN].val == pfrom) {
500*7c478bd9Sstevel@tonic-gate 		print++;
501*7c478bd9Sstevel@tonic-gate 		pfrom = -1;
502*7c478bd9Sstevel@tonic-gate 	} else if (opn == pto) {
503*7c478bd9Sstevel@tonic-gate 		print = 0;
504*7c478bd9Sstevel@tonic-gate 		opn = -1;
505*7c478bd9Sstevel@tonic-gate 		chkpn();
506*7c478bd9Sstevel@tonic-gate 		goto nlpn;
507*7c478bd9Sstevel@tonic-gate 	}
508*7c478bd9Sstevel@tonic-gate 	if (print)
509*7c478bd9Sstevel@tonic-gate 		newpage(numtab[PN].val);	/* supposedly in a clean state so can pause */
510*7c478bd9Sstevel@tonic-gate 	if (stop && print) {
511*7c478bd9Sstevel@tonic-gate 		dpn++;
512*7c478bd9Sstevel@tonic-gate 		if (dpn >= stop) {
513*7c478bd9Sstevel@tonic-gate 			dpn = 0;
514*7c478bd9Sstevel@tonic-gate 			dostop();
515*7c478bd9Sstevel@tonic-gate 		}
516*7c478bd9Sstevel@tonic-gate 	}
517*7c478bd9Sstevel@tonic-gate nl2:
518*7c478bd9Sstevel@tonic-gate 	trap = 0;
519*7c478bd9Sstevel@tonic-gate 	if (numtab[NL].val == 0) {
520*7c478bd9Sstevel@tonic-gate 		if ((j = findn(0)) != NTRAP)
521*7c478bd9Sstevel@tonic-gate 			trap = control(mlist[j], 0);
522*7c478bd9Sstevel@tonic-gate 	} else if ((i = findt(numtab[NL].val - nlss)) <= nlss) {
523*7c478bd9Sstevel@tonic-gate 		if ((j = findn1(numtab[NL].val - nlss + i)) == NTRAP) {
524*7c478bd9Sstevel@tonic-gate 			flusho();
525*7c478bd9Sstevel@tonic-gate 			errprint(gettext("Trap botch."));
526*7c478bd9Sstevel@tonic-gate 			done2(-5);
527*7c478bd9Sstevel@tonic-gate 		}
528*7c478bd9Sstevel@tonic-gate 		trap = control(mlist[j], 0);
529*7c478bd9Sstevel@tonic-gate 	}
530*7c478bd9Sstevel@tonic-gate }
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate findn1(a)
534*7c478bd9Sstevel@tonic-gate int	a;
535*7c478bd9Sstevel@tonic-gate {
536*7c478bd9Sstevel@tonic-gate 	register i, j;
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NTRAP; i++) {
539*7c478bd9Sstevel@tonic-gate 		if (mlist[i]) {
540*7c478bd9Sstevel@tonic-gate 			if ((j = nlist[i]) < 0)
541*7c478bd9Sstevel@tonic-gate 				j += pl;
542*7c478bd9Sstevel@tonic-gate 			if (j == a)
543*7c478bd9Sstevel@tonic-gate 				break;
544*7c478bd9Sstevel@tonic-gate 		}
545*7c478bd9Sstevel@tonic-gate 	}
546*7c478bd9Sstevel@tonic-gate 	return(i);
547*7c478bd9Sstevel@tonic-gate }
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate chkpn()
551*7c478bd9Sstevel@tonic-gate {
552*7c478bd9Sstevel@tonic-gate 	pto = *(pnp++);
553*7c478bd9Sstevel@tonic-gate 	pfrom = pto>=0 ? pto : -pto;
554*7c478bd9Sstevel@tonic-gate 	if (pto == -32767) {
555*7c478bd9Sstevel@tonic-gate 		flusho();
556*7c478bd9Sstevel@tonic-gate 		done1(0);
557*7c478bd9Sstevel@tonic-gate 	}
558*7c478bd9Sstevel@tonic-gate 	if (pto < 0) {
559*7c478bd9Sstevel@tonic-gate 		pto = -pto;
560*7c478bd9Sstevel@tonic-gate 		print++;
561*7c478bd9Sstevel@tonic-gate 		pfrom = 0;
562*7c478bd9Sstevel@tonic-gate 	}
563*7c478bd9Sstevel@tonic-gate }
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate 
566*7c478bd9Sstevel@tonic-gate findt(a)
567*7c478bd9Sstevel@tonic-gate int	a;
568*7c478bd9Sstevel@tonic-gate {
569*7c478bd9Sstevel@tonic-gate 	register i, j, k;
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate 	k = 32767;
572*7c478bd9Sstevel@tonic-gate 	if (dip != d) {
573*7c478bd9Sstevel@tonic-gate 		if (dip->dimac && (i = dip->ditrap - a) > 0)
574*7c478bd9Sstevel@tonic-gate 			k = i;
575*7c478bd9Sstevel@tonic-gate 		return(k);
576*7c478bd9Sstevel@tonic-gate 	}
577*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NTRAP; i++) {
578*7c478bd9Sstevel@tonic-gate 		if (mlist[i]) {
579*7c478bd9Sstevel@tonic-gate 			if ((j = nlist[i]) < 0)
580*7c478bd9Sstevel@tonic-gate 				j += pl;
581*7c478bd9Sstevel@tonic-gate 			if ((j -= a) <= 0)
582*7c478bd9Sstevel@tonic-gate 				continue;
583*7c478bd9Sstevel@tonic-gate 			if (j < k)
584*7c478bd9Sstevel@tonic-gate 				k = j;
585*7c478bd9Sstevel@tonic-gate 		}
586*7c478bd9Sstevel@tonic-gate 	}
587*7c478bd9Sstevel@tonic-gate 	i = pl - a;
588*7c478bd9Sstevel@tonic-gate 	if (k > i)
589*7c478bd9Sstevel@tonic-gate 		k = i;
590*7c478bd9Sstevel@tonic-gate 	return(k);
591*7c478bd9Sstevel@tonic-gate }
592*7c478bd9Sstevel@tonic-gate 
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate findt1()
595*7c478bd9Sstevel@tonic-gate {
596*7c478bd9Sstevel@tonic-gate 	register i;
597*7c478bd9Sstevel@tonic-gate 
598*7c478bd9Sstevel@tonic-gate 	if (dip != d)
599*7c478bd9Sstevel@tonic-gate 		i = dip->dnl;
600*7c478bd9Sstevel@tonic-gate 	else
601*7c478bd9Sstevel@tonic-gate 		i = numtab[NL].val;
602*7c478bd9Sstevel@tonic-gate 	return(findt(i));
603*7c478bd9Sstevel@tonic-gate }
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate 
606*7c478bd9Sstevel@tonic-gate eject(a)
607*7c478bd9Sstevel@tonic-gate struct s *a;
608*7c478bd9Sstevel@tonic-gate {
609*7c478bd9Sstevel@tonic-gate 	register savlss;
610*7c478bd9Sstevel@tonic-gate 
611*7c478bd9Sstevel@tonic-gate 	if (dip != d)
612*7c478bd9Sstevel@tonic-gate 		return;
613*7c478bd9Sstevel@tonic-gate 	ejf++;
614*7c478bd9Sstevel@tonic-gate 	if (a)
615*7c478bd9Sstevel@tonic-gate 		ejl = a;
616*7c478bd9Sstevel@tonic-gate 	else
617*7c478bd9Sstevel@tonic-gate 		ejl = frame;
618*7c478bd9Sstevel@tonic-gate 	if (trap)
619*7c478bd9Sstevel@tonic-gate 		return;
620*7c478bd9Sstevel@tonic-gate e1:
621*7c478bd9Sstevel@tonic-gate 	savlss = lss;
622*7c478bd9Sstevel@tonic-gate 	lss = findt(numtab[NL].val);
623*7c478bd9Sstevel@tonic-gate 	newline(0);
624*7c478bd9Sstevel@tonic-gate 	lss = savlss;
625*7c478bd9Sstevel@tonic-gate 	if (numtab[NL].val && !trap)
626*7c478bd9Sstevel@tonic-gate 		goto e1;
627*7c478bd9Sstevel@tonic-gate }
628*7c478bd9Sstevel@tonic-gate 
629*7c478bd9Sstevel@tonic-gate 
630*7c478bd9Sstevel@tonic-gate movword()
631*7c478bd9Sstevel@tonic-gate {
632*7c478bd9Sstevel@tonic-gate 	register w;
633*7c478bd9Sstevel@tonic-gate 	register tchar i, *wp;
634*7c478bd9Sstevel@tonic-gate 	int	savwch, hys;
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate 	over = 0;
637*7c478bd9Sstevel@tonic-gate 	wp = wordp;
638*7c478bd9Sstevel@tonic-gate 	if (!nwd) {
639*7c478bd9Sstevel@tonic-gate #ifndef EUC
640*7c478bd9Sstevel@tonic-gate 		while (cbits(i = *wp++) == ' ') {
641*7c478bd9Sstevel@tonic-gate #else
642*7c478bd9Sstevel@tonic-gate #ifndef NROFF
643*7c478bd9Sstevel@tonic-gate 		while (cbits(i = *wp++) == ' ') {
644*7c478bd9Sstevel@tonic-gate #else
645*7c478bd9Sstevel@tonic-gate 		while ((cbits(i = *wp++) & ~MBMASK) == ' ') {
646*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
647*7c478bd9Sstevel@tonic-gate #endif /* EUC */
648*7c478bd9Sstevel@tonic-gate 			wch--;
649*7c478bd9Sstevel@tonic-gate 			wne -= sps;
650*7c478bd9Sstevel@tonic-gate 		}
651*7c478bd9Sstevel@tonic-gate 		wp--;
652*7c478bd9Sstevel@tonic-gate 	}
653*7c478bd9Sstevel@tonic-gate 	if (wne > nel && !hyoff && hyf && (!nwd || nel > 3 * sps) &&
654*7c478bd9Sstevel@tonic-gate 	   (!(hyf & 02) || (findt1() > lss)))
655*7c478bd9Sstevel@tonic-gate 		hyphen(wp);
656*7c478bd9Sstevel@tonic-gate 	savwch = wch;
657*7c478bd9Sstevel@tonic-gate 	hyp = hyptr;
658*7c478bd9Sstevel@tonic-gate 	nhyp = 0;
659*7c478bd9Sstevel@tonic-gate 	while (*hyp && *hyp <= wp)
660*7c478bd9Sstevel@tonic-gate 		hyp++;
661*7c478bd9Sstevel@tonic-gate 	while (wch) {
662*7c478bd9Sstevel@tonic-gate 		if (hyoff != 1 && *hyp == wp) {
663*7c478bd9Sstevel@tonic-gate 			hyp++;
664*7c478bd9Sstevel@tonic-gate 			if (!wdstart || (wp > wdstart + 1 && wp < wdend &&
665*7c478bd9Sstevel@tonic-gate 			   (!(hyf & 04) || wp < wdend - 1) &&		/* 04 => last 2 */
666*7c478bd9Sstevel@tonic-gate 			   (!(hyf & 010) || wp > wdstart + 2))) {	/* 010 => 1st 2 */
667*7c478bd9Sstevel@tonic-gate 				nhyp++;
668*7c478bd9Sstevel@tonic-gate 				storeline((tchar)IMP, 0);
669*7c478bd9Sstevel@tonic-gate 			}
670*7c478bd9Sstevel@tonic-gate 		}
671*7c478bd9Sstevel@tonic-gate 		i = *wp++;
672*7c478bd9Sstevel@tonic-gate 		w = width(i);
673*7c478bd9Sstevel@tonic-gate 		wne -= w;
674*7c478bd9Sstevel@tonic-gate 		wch--;
675*7c478bd9Sstevel@tonic-gate 		storeline(i, w);
676*7c478bd9Sstevel@tonic-gate 	}
677*7c478bd9Sstevel@tonic-gate 	if (nel >= 0) {
678*7c478bd9Sstevel@tonic-gate 		nwd++;
679*7c478bd9Sstevel@tonic-gate 		return(0);	/* line didn't fill up */
680*7c478bd9Sstevel@tonic-gate 	}
681*7c478bd9Sstevel@tonic-gate #ifndef NROFF
682*7c478bd9Sstevel@tonic-gate 	xbits((tchar)HYPHEN, 1);
683*7c478bd9Sstevel@tonic-gate #endif
684*7c478bd9Sstevel@tonic-gate 	hys = width((tchar)HYPHEN);
685*7c478bd9Sstevel@tonic-gate m1:
686*7c478bd9Sstevel@tonic-gate 	if (!nhyp) {
687*7c478bd9Sstevel@tonic-gate 		if (!nwd)
688*7c478bd9Sstevel@tonic-gate 			goto m3;
689*7c478bd9Sstevel@tonic-gate 		if (wch == savwch)
690*7c478bd9Sstevel@tonic-gate 			goto m4;
691*7c478bd9Sstevel@tonic-gate 	}
692*7c478bd9Sstevel@tonic-gate 	if (*--linep != IMP)
693*7c478bd9Sstevel@tonic-gate 		goto m5;
694*7c478bd9Sstevel@tonic-gate 	if (!(--nhyp))
695*7c478bd9Sstevel@tonic-gate 		if (!nwd)
696*7c478bd9Sstevel@tonic-gate 			goto m2;
697*7c478bd9Sstevel@tonic-gate 	if (nel < hys) {
698*7c478bd9Sstevel@tonic-gate 		nc--;
699*7c478bd9Sstevel@tonic-gate 		goto m1;
700*7c478bd9Sstevel@tonic-gate 	}
701*7c478bd9Sstevel@tonic-gate m2:
702*7c478bd9Sstevel@tonic-gate 	if ((i = cbits(*(linep - 1))) != '-' && i != EMDASH) {
703*7c478bd9Sstevel@tonic-gate 		*linep = (*(linep - 1) & SFMASK) | HYPHEN;
704*7c478bd9Sstevel@tonic-gate 		w = width(*linep);
705*7c478bd9Sstevel@tonic-gate 		nel -= w;
706*7c478bd9Sstevel@tonic-gate 		ne += w;
707*7c478bd9Sstevel@tonic-gate 		linep++;
708*7c478bd9Sstevel@tonic-gate 	}
709*7c478bd9Sstevel@tonic-gate m3:
710*7c478bd9Sstevel@tonic-gate 	nwd++;
711*7c478bd9Sstevel@tonic-gate m4:
712*7c478bd9Sstevel@tonic-gate 	wordp = wp;
713*7c478bd9Sstevel@tonic-gate 	return(1);	/* line filled up */
714*7c478bd9Sstevel@tonic-gate m5:
715*7c478bd9Sstevel@tonic-gate 	nc--;
716*7c478bd9Sstevel@tonic-gate 	w = width(*linep);
717*7c478bd9Sstevel@tonic-gate 	ne -= w;
718*7c478bd9Sstevel@tonic-gate 	nel += w;
719*7c478bd9Sstevel@tonic-gate 	wne += w;
720*7c478bd9Sstevel@tonic-gate 	wch++;
721*7c478bd9Sstevel@tonic-gate 	wp--;
722*7c478bd9Sstevel@tonic-gate 	goto m1;
723*7c478bd9Sstevel@tonic-gate }
724*7c478bd9Sstevel@tonic-gate 
725*7c478bd9Sstevel@tonic-gate 
726*7c478bd9Sstevel@tonic-gate horiz(i)
727*7c478bd9Sstevel@tonic-gate int	i;
728*7c478bd9Sstevel@tonic-gate {
729*7c478bd9Sstevel@tonic-gate 	vflag = 0;
730*7c478bd9Sstevel@tonic-gate 	if (i)
731*7c478bd9Sstevel@tonic-gate 		pchar(makem(i));
732*7c478bd9Sstevel@tonic-gate }
733*7c478bd9Sstevel@tonic-gate 
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate setnel()
736*7c478bd9Sstevel@tonic-gate {
737*7c478bd9Sstevel@tonic-gate 	if (!nc) {
738*7c478bd9Sstevel@tonic-gate 		linep = line;
739*7c478bd9Sstevel@tonic-gate 		if (un1 >= 0) {
740*7c478bd9Sstevel@tonic-gate 			un = un1;
741*7c478bd9Sstevel@tonic-gate 			un1 = -1;
742*7c478bd9Sstevel@tonic-gate 		}
743*7c478bd9Sstevel@tonic-gate 		nel = ll - un;
744*7c478bd9Sstevel@tonic-gate 		ne = adsp = adrem = 0;
745*7c478bd9Sstevel@tonic-gate 	}
746*7c478bd9Sstevel@tonic-gate }
747*7c478bd9Sstevel@tonic-gate 
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate getword(x)
750*7c478bd9Sstevel@tonic-gate int	x;
751*7c478bd9Sstevel@tonic-gate {
752*7c478bd9Sstevel@tonic-gate 	register int j, k;
753*7c478bd9Sstevel@tonic-gate 	register tchar i, *wp;
754*7c478bd9Sstevel@tonic-gate 	int noword;
755*7c478bd9Sstevel@tonic-gate #ifdef EUC
756*7c478bd9Sstevel@tonic-gate #ifdef NROFF
757*7c478bd9Sstevel@tonic-gate 	wchar_t *wddelim;
758*7c478bd9Sstevel@tonic-gate 	char mbbuf3[MB_LEN_MAX + 1];
759*7c478bd9Sstevel@tonic-gate 	char *mbbuf3p;
760*7c478bd9Sstevel@tonic-gate 	int wbf, n;
761*7c478bd9Sstevel@tonic-gate 	tchar m;
762*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
763*7c478bd9Sstevel@tonic-gate #endif /* EUC */
764*7c478bd9Sstevel@tonic-gate 
765*7c478bd9Sstevel@tonic-gate 	noword = 0;
766*7c478bd9Sstevel@tonic-gate 	if (x)
767*7c478bd9Sstevel@tonic-gate 		if (pendw) {
768*7c478bd9Sstevel@tonic-gate 			*pendw = 0;
769*7c478bd9Sstevel@tonic-gate 			goto rtn;
770*7c478bd9Sstevel@tonic-gate 		}
771*7c478bd9Sstevel@tonic-gate 	if (wordp = pendw)
772*7c478bd9Sstevel@tonic-gate 		goto g1;
773*7c478bd9Sstevel@tonic-gate 	hyp = hyptr;
774*7c478bd9Sstevel@tonic-gate 	wordp = word;
775*7c478bd9Sstevel@tonic-gate 	over = wne = wch = 0;
776*7c478bd9Sstevel@tonic-gate 	hyoff = 0;
777*7c478bd9Sstevel@tonic-gate #ifdef EUC
778*7c478bd9Sstevel@tonic-gate #ifdef NROFF
779*7c478bd9Sstevel@tonic-gate 	mtbufp = mtbuf;
780*7c478bd9Sstevel@tonic-gate 	if (pendmb) {
781*7c478bd9Sstevel@tonic-gate 		while(*mtbufp) {
782*7c478bd9Sstevel@tonic-gate 			switch(*mtbufp & MBMASK) {
783*7c478bd9Sstevel@tonic-gate 			case LASTOFMB:
784*7c478bd9Sstevel@tonic-gate 			case BYTE_CHR:
785*7c478bd9Sstevel@tonic-gate 				storeword(*mtbufp++, -1);
786*7c478bd9Sstevel@tonic-gate 				break;
787*7c478bd9Sstevel@tonic-gate 
788*7c478bd9Sstevel@tonic-gate 			default:
789*7c478bd9Sstevel@tonic-gate 				storeword(*mtbufp++, 0);
790*7c478bd9Sstevel@tonic-gate 			}
791*7c478bd9Sstevel@tonic-gate 		}
792*7c478bd9Sstevel@tonic-gate 		mtbufp = mtbuf;
793*7c478bd9Sstevel@tonic-gate 		pendmb = 0;
794*7c478bd9Sstevel@tonic-gate 		goto g1;
795*7c478bd9Sstevel@tonic-gate 	}
796*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
797*7c478bd9Sstevel@tonic-gate #endif /* EUC */
798*7c478bd9Sstevel@tonic-gate 	while (1) {	/* picks up 1st char of word */
799*7c478bd9Sstevel@tonic-gate 		j = cbits(i = GETCH());
800*7c478bd9Sstevel@tonic-gate #ifdef EUC
801*7c478bd9Sstevel@tonic-gate #ifdef NROFF
802*7c478bd9Sstevel@tonic-gate 		if (multi_locale)
803*7c478bd9Sstevel@tonic-gate 			if (collectmb(i))
804*7c478bd9Sstevel@tonic-gate 				continue;
805*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
806*7c478bd9Sstevel@tonic-gate #endif /* EUC */
807*7c478bd9Sstevel@tonic-gate 		if (j == '\n') {
808*7c478bd9Sstevel@tonic-gate 			wne = wch = 0;
809*7c478bd9Sstevel@tonic-gate 			noword = 1;
810*7c478bd9Sstevel@tonic-gate 			goto rtn;
811*7c478bd9Sstevel@tonic-gate 		}
812*7c478bd9Sstevel@tonic-gate 		if (j == ohc) {
813*7c478bd9Sstevel@tonic-gate 			hyoff = 1;	/* 1 => don't hyphenate */
814*7c478bd9Sstevel@tonic-gate 			continue;
815*7c478bd9Sstevel@tonic-gate 		}
816*7c478bd9Sstevel@tonic-gate 		if (j == ' ') {
817*7c478bd9Sstevel@tonic-gate 			numtab[HP].val += sps;
818*7c478bd9Sstevel@tonic-gate 			widthp = sps;
819*7c478bd9Sstevel@tonic-gate 			storeword(i, sps);
820*7c478bd9Sstevel@tonic-gate 			continue;
821*7c478bd9Sstevel@tonic-gate 		}
822*7c478bd9Sstevel@tonic-gate 		break;
823*7c478bd9Sstevel@tonic-gate 	}
824*7c478bd9Sstevel@tonic-gate #ifdef EUC
825*7c478bd9Sstevel@tonic-gate #ifdef NROFF
826*7c478bd9Sstevel@tonic-gate 	if (!multi_locale)
827*7c478bd9Sstevel@tonic-gate 		goto a0;
828*7c478bd9Sstevel@tonic-gate 	if (wddlm && iswprint(wceoll) && iswprint(cwc) &&
829*7c478bd9Sstevel@tonic-gate 	    (!iswascii(wceoll) || !iswascii(cwc)) &&
830*7c478bd9Sstevel@tonic-gate 	    !iswspace(wceoll) && !iswspace(cwc)) {
831*7c478bd9Sstevel@tonic-gate 		wddelim = (*wddlm)(wceoll, cwc, 1);
832*7c478bd9Sstevel@tonic-gate 		wceoll = 0;
833*7c478bd9Sstevel@tonic-gate 		if (*wddelim != ' ') {
834*7c478bd9Sstevel@tonic-gate 			if (!*wddelim) {
835*7c478bd9Sstevel@tonic-gate 				storeword(((*wdbdg)(wceoll, cwc, 1) < 3) ?
836*7c478bd9Sstevel@tonic-gate 					  ZWDELIM(1) : ZWDELIM(2), 0);
837*7c478bd9Sstevel@tonic-gate 			} else {
838*7c478bd9Sstevel@tonic-gate 				while (*wddelim) {
839*7c478bd9Sstevel@tonic-gate 					if ((n = wctomb(mbbuf3, *wddelim++))
840*7c478bd9Sstevel@tonic-gate 					    > 0) {
841*7c478bd9Sstevel@tonic-gate 						mbbuf3[n] = 0;
842*7c478bd9Sstevel@tonic-gate 						n--;
843*7c478bd9Sstevel@tonic-gate 						mbbuf3p = mbbuf3 + n;
844*7c478bd9Sstevel@tonic-gate 						while(n) {
845*7c478bd9Sstevel@tonic-gate 							m = *(mbbuf3p-- - n--) &
846*7c478bd9Sstevel@tonic-gate 							    0xff | MIDDLEOFMB |
847*7c478bd9Sstevel@tonic-gate 							    ZBIT;
848*7c478bd9Sstevel@tonic-gate 							storeword(m, 0);
849*7c478bd9Sstevel@tonic-gate 						}
850*7c478bd9Sstevel@tonic-gate 						m = *mbbuf3p & 0xff | LASTOFMB;
851*7c478bd9Sstevel@tonic-gate 						storeword(m, -1);
852*7c478bd9Sstevel@tonic-gate 					} else {
853*7c478bd9Sstevel@tonic-gate 						storeword(' ' | chbits, sps);
854*7c478bd9Sstevel@tonic-gate 						break;
855*7c478bd9Sstevel@tonic-gate 					}
856*7c478bd9Sstevel@tonic-gate 				}
857*7c478bd9Sstevel@tonic-gate 			}
858*7c478bd9Sstevel@tonic-gate 			spflg = 0;
859*7c478bd9Sstevel@tonic-gate 			goto g0;
860*7c478bd9Sstevel@tonic-gate 		}
861*7c478bd9Sstevel@tonic-gate 	}
862*7c478bd9Sstevel@tonic-gate a0:
863*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
864*7c478bd9Sstevel@tonic-gate #endif /* EUC */
865*7c478bd9Sstevel@tonic-gate 	storeword(' ' | chbits, sps);
866*7c478bd9Sstevel@tonic-gate 	if (spflg) {
867*7c478bd9Sstevel@tonic-gate 		storeword(' ' | chbits, sps);
868*7c478bd9Sstevel@tonic-gate 		spflg = 0;
869*7c478bd9Sstevel@tonic-gate 	}
870*7c478bd9Sstevel@tonic-gate g0:
871*7c478bd9Sstevel@tonic-gate 	if (j == CONT) {
872*7c478bd9Sstevel@tonic-gate 		pendw = wordp;
873*7c478bd9Sstevel@tonic-gate 		nflush = 0;
874*7c478bd9Sstevel@tonic-gate 		flushi();
875*7c478bd9Sstevel@tonic-gate 		return(1);
876*7c478bd9Sstevel@tonic-gate 	}
877*7c478bd9Sstevel@tonic-gate 	if (hyoff != 1) {
878*7c478bd9Sstevel@tonic-gate 		if (j == ohc) {
879*7c478bd9Sstevel@tonic-gate 			hyoff = 2;
880*7c478bd9Sstevel@tonic-gate 			*hyp++ = wordp;
881*7c478bd9Sstevel@tonic-gate 			if (hyp > (hyptr + NHYP - 1))
882*7c478bd9Sstevel@tonic-gate 				hyp = hyptr + NHYP - 1;
883*7c478bd9Sstevel@tonic-gate 			goto g1;
884*7c478bd9Sstevel@tonic-gate 		}
885*7c478bd9Sstevel@tonic-gate 		if (j == '-' || j == EMDASH)
886*7c478bd9Sstevel@tonic-gate 			if (wordp > word + 1) {
887*7c478bd9Sstevel@tonic-gate 				hyoff = 2;
888*7c478bd9Sstevel@tonic-gate 				*hyp++ = wordp + 1;
889*7c478bd9Sstevel@tonic-gate 				if (hyp > (hyptr + NHYP - 1))
890*7c478bd9Sstevel@tonic-gate 					hyp = hyptr + NHYP - 1;
891*7c478bd9Sstevel@tonic-gate 			}
892*7c478bd9Sstevel@tonic-gate 	}
893*7c478bd9Sstevel@tonic-gate 	j = width(i);
894*7c478bd9Sstevel@tonic-gate 	numtab[HP].val += j;
895*7c478bd9Sstevel@tonic-gate #ifndef EUC
896*7c478bd9Sstevel@tonic-gate 	storeword(i, j);
897*7c478bd9Sstevel@tonic-gate #else
898*7c478bd9Sstevel@tonic-gate #ifndef NROFF
899*7c478bd9Sstevel@tonic-gate 	storeword(i, j);
900*7c478bd9Sstevel@tonic-gate #else
901*7c478bd9Sstevel@tonic-gate 	if (multi_locale) {
902*7c478bd9Sstevel@tonic-gate 		mtbufp = mtbuf;
903*7c478bd9Sstevel@tonic-gate 		while(*mtbufp) {
904*7c478bd9Sstevel@tonic-gate 			switch(*mtbufp & MBMASK) {
905*7c478bd9Sstevel@tonic-gate 			case LASTOFMB:
906*7c478bd9Sstevel@tonic-gate 			case BYTE_CHR:
907*7c478bd9Sstevel@tonic-gate 				storeword(*mtbufp++, j);
908*7c478bd9Sstevel@tonic-gate 				break;
909*7c478bd9Sstevel@tonic-gate 
910*7c478bd9Sstevel@tonic-gate 			default:
911*7c478bd9Sstevel@tonic-gate 				storeword(*mtbufp++, 0);
912*7c478bd9Sstevel@tonic-gate 			}
913*7c478bd9Sstevel@tonic-gate 		}
914*7c478bd9Sstevel@tonic-gate 		mtbufp = mtbuf;
915*7c478bd9Sstevel@tonic-gate 	} else {
916*7c478bd9Sstevel@tonic-gate 		storeword(i, j);
917*7c478bd9Sstevel@tonic-gate 	}
918*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
919*7c478bd9Sstevel@tonic-gate #endif /* EUC */
920*7c478bd9Sstevel@tonic-gate g1:
921*7c478bd9Sstevel@tonic-gate 	j = cbits(i = GETCH());
922*7c478bd9Sstevel@tonic-gate #ifdef EUC
923*7c478bd9Sstevel@tonic-gate #ifdef NROFF
924*7c478bd9Sstevel@tonic-gate 	if (multi_locale)
925*7c478bd9Sstevel@tonic-gate 		if (collectmb(i))
926*7c478bd9Sstevel@tonic-gate 			goto g1;
927*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
928*7c478bd9Sstevel@tonic-gate #endif /* EUC */
929*7c478bd9Sstevel@tonic-gate 	if (j != ' ') {
930*7c478bd9Sstevel@tonic-gate 		static char *sentchar = ".?!:";	/* sentence terminators */
931*7c478bd9Sstevel@tonic-gate 		if (j != '\n')
932*7c478bd9Sstevel@tonic-gate #ifdef EUC
933*7c478bd9Sstevel@tonic-gate #ifdef NROFF
934*7c478bd9Sstevel@tonic-gate 			if (!multi_locale)
935*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
936*7c478bd9Sstevel@tonic-gate #endif /* EUC */
937*7c478bd9Sstevel@tonic-gate 			goto g0;
938*7c478bd9Sstevel@tonic-gate #ifdef EUC
939*7c478bd9Sstevel@tonic-gate #ifdef NROFF
940*7c478bd9Sstevel@tonic-gate 			else {
941*7c478bd9Sstevel@tonic-gate 				if (!wdbdg || (iswascii(cwc) && iswascii(owc)))
942*7c478bd9Sstevel@tonic-gate 					goto g0;
943*7c478bd9Sstevel@tonic-gate 				if ((wbf = (*wdbdg)(owc, cwc, 1)) < 5) {
944*7c478bd9Sstevel@tonic-gate 					pendmb++;
945*7c478bd9Sstevel@tonic-gate 					storeword((wbf < 3) ? ZWDELIM(1) :
946*7c478bd9Sstevel@tonic-gate 						  ZWDELIM(2), 0);
947*7c478bd9Sstevel@tonic-gate 					*wordp = 0;
948*7c478bd9Sstevel@tonic-gate 					goto rtn;
949*7c478bd9Sstevel@tonic-gate 				} else goto g0;
950*7c478bd9Sstevel@tonic-gate 			}
951*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
952*7c478bd9Sstevel@tonic-gate #endif /* EUC */
953*7c478bd9Sstevel@tonic-gate 		wp = wordp-1;	/* handle extra space at end of sentence */
954*7c478bd9Sstevel@tonic-gate 		while (wp >= word) {
955*7c478bd9Sstevel@tonic-gate 			j = cbits(*wp--);
956*7c478bd9Sstevel@tonic-gate 			if (j=='"' || j=='\'' || j==')' || j==']' || j=='*' || j==DAGGER)
957*7c478bd9Sstevel@tonic-gate 				continue;
958*7c478bd9Sstevel@tonic-gate 			for (k = 0; sentchar[k]; k++)
959*7c478bd9Sstevel@tonic-gate 				if (j == sentchar[k]) {
960*7c478bd9Sstevel@tonic-gate 					spflg++;
961*7c478bd9Sstevel@tonic-gate 					break;
962*7c478bd9Sstevel@tonic-gate 				}
963*7c478bd9Sstevel@tonic-gate 			break;
964*7c478bd9Sstevel@tonic-gate 		}
965*7c478bd9Sstevel@tonic-gate 	}
966*7c478bd9Sstevel@tonic-gate #ifdef EUC
967*7c478bd9Sstevel@tonic-gate #ifdef NROFF
968*7c478bd9Sstevel@tonic-gate 	wceoll = owc;
969*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
970*7c478bd9Sstevel@tonic-gate #endif /* EUC */
971*7c478bd9Sstevel@tonic-gate 	*wordp = 0;
972*7c478bd9Sstevel@tonic-gate 	numtab[HP].val += sps;
973*7c478bd9Sstevel@tonic-gate rtn:
974*7c478bd9Sstevel@tonic-gate 	for (wp = word; *wp; wp++) {
975*7c478bd9Sstevel@tonic-gate 		j = cbits(*wp);
976*7c478bd9Sstevel@tonic-gate 		if (j == ' ')
977*7c478bd9Sstevel@tonic-gate 			continue;
978*7c478bd9Sstevel@tonic-gate 		if (!ischar(j) || (!isdigit(j) && j != '-'))
979*7c478bd9Sstevel@tonic-gate 			break;
980*7c478bd9Sstevel@tonic-gate 	}
981*7c478bd9Sstevel@tonic-gate 	if (*wp == 0)	/* all numbers, so don't hyphenate */
982*7c478bd9Sstevel@tonic-gate 		hyoff = 1;
983*7c478bd9Sstevel@tonic-gate 	wdstart = 0;
984*7c478bd9Sstevel@tonic-gate 	wordp = word;
985*7c478bd9Sstevel@tonic-gate 	pendw = 0;
986*7c478bd9Sstevel@tonic-gate 	*hyp++ = 0;
987*7c478bd9Sstevel@tonic-gate 	setnel();
988*7c478bd9Sstevel@tonic-gate 	return(noword);
989*7c478bd9Sstevel@tonic-gate }
990*7c478bd9Sstevel@tonic-gate 
991*7c478bd9Sstevel@tonic-gate 
992*7c478bd9Sstevel@tonic-gate storeword(c, w)
993*7c478bd9Sstevel@tonic-gate register tchar c;
994*7c478bd9Sstevel@tonic-gate register int	w;
995*7c478bd9Sstevel@tonic-gate {
996*7c478bd9Sstevel@tonic-gate 
997*7c478bd9Sstevel@tonic-gate 	if (wordp >= &word[WDSIZE - 3]) {
998*7c478bd9Sstevel@tonic-gate 		if (!over) {
999*7c478bd9Sstevel@tonic-gate 			flusho();
1000*7c478bd9Sstevel@tonic-gate 			errprint(gettext("Word overflow."));
1001*7c478bd9Sstevel@tonic-gate 			over++;
1002*7c478bd9Sstevel@tonic-gate 			c = LEFTHAND;
1003*7c478bd9Sstevel@tonic-gate 			w = -1;
1004*7c478bd9Sstevel@tonic-gate 			goto s1;
1005*7c478bd9Sstevel@tonic-gate 		}
1006*7c478bd9Sstevel@tonic-gate 		return;
1007*7c478bd9Sstevel@tonic-gate 	}
1008*7c478bd9Sstevel@tonic-gate s1:
1009*7c478bd9Sstevel@tonic-gate 	if (w == -1)
1010*7c478bd9Sstevel@tonic-gate 		w = width(c);
1011*7c478bd9Sstevel@tonic-gate 	widthp = w;
1012*7c478bd9Sstevel@tonic-gate 	wne += w;
1013*7c478bd9Sstevel@tonic-gate 	*wordp++ = c;
1014*7c478bd9Sstevel@tonic-gate 	wch++;
1015*7c478bd9Sstevel@tonic-gate }
1016*7c478bd9Sstevel@tonic-gate 
1017*7c478bd9Sstevel@tonic-gate 
1018*7c478bd9Sstevel@tonic-gate #ifdef NROFF
1019*7c478bd9Sstevel@tonic-gate tchar gettch()
1020*7c478bd9Sstevel@tonic-gate {
1021*7c478bd9Sstevel@tonic-gate 	extern int c_isalnum;
1022*7c478bd9Sstevel@tonic-gate 	tchar i;
1023*7c478bd9Sstevel@tonic-gate 	int j;
1024*7c478bd9Sstevel@tonic-gate 
1025*7c478bd9Sstevel@tonic-gate 	i = getch();
1026*7c478bd9Sstevel@tonic-gate 	j = cbits(i);
1027*7c478bd9Sstevel@tonic-gate 	if (ismot(i) || fbits(i) != ulfont)
1028*7c478bd9Sstevel@tonic-gate 		return(i);
1029*7c478bd9Sstevel@tonic-gate 	if (cu) {
1030*7c478bd9Sstevel@tonic-gate 		if (trtab[j] == ' ') {
1031*7c478bd9Sstevel@tonic-gate 			setcbits(i, '_');
1032*7c478bd9Sstevel@tonic-gate 			setfbits(i, FT);	/* default */
1033*7c478bd9Sstevel@tonic-gate 		}
1034*7c478bd9Sstevel@tonic-gate 		return(i);
1035*7c478bd9Sstevel@tonic-gate 	}
1036*7c478bd9Sstevel@tonic-gate 	/* should test here for characters that ought to be underlined */
1037*7c478bd9Sstevel@tonic-gate 	/* in the old nroff, that was the 200 bit on the width! */
1038*7c478bd9Sstevel@tonic-gate 	/* for now, just do letters, digits and certain special chars */
1039*7c478bd9Sstevel@tonic-gate 	if (j <= 127) {
1040*7c478bd9Sstevel@tonic-gate 		if (!isalnum(j))
1041*7c478bd9Sstevel@tonic-gate 			setfbits(i, FT);
1042*7c478bd9Sstevel@tonic-gate 	} else {
1043*7c478bd9Sstevel@tonic-gate 		if (j < c_isalnum)
1044*7c478bd9Sstevel@tonic-gate 			setfbits(i, FT);
1045*7c478bd9Sstevel@tonic-gate 	}
1046*7c478bd9Sstevel@tonic-gate 	return(i);
1047*7c478bd9Sstevel@tonic-gate }
1048*7c478bd9Sstevel@tonic-gate 
1049*7c478bd9Sstevel@tonic-gate 
1050*7c478bd9Sstevel@tonic-gate #endif
1051*7c478bd9Sstevel@tonic-gate #ifdef EUC
1052*7c478bd9Sstevel@tonic-gate #ifdef NROFF
1053*7c478bd9Sstevel@tonic-gate collectmb(i)
1054*7c478bd9Sstevel@tonic-gate tchar	i;
1055*7c478bd9Sstevel@tonic-gate {
1056*7c478bd9Sstevel@tonic-gate 	int busy;
1057*7c478bd9Sstevel@tonic-gate 
1058*7c478bd9Sstevel@tonic-gate 	*mtbufp++ = i;
1059*7c478bd9Sstevel@tonic-gate 	*mbbuf2p++ = i & BYTEMASK;
1060*7c478bd9Sstevel@tonic-gate 	*mtbufp = *mbbuf2p = 0;
1061*7c478bd9Sstevel@tonic-gate 	if (ismot(i)) {
1062*7c478bd9Sstevel@tonic-gate 		mtbufp = mtbuf;
1063*7c478bd9Sstevel@tonic-gate 		mbbuf2p = mbbuf2;
1064*7c478bd9Sstevel@tonic-gate 		owc = 0;
1065*7c478bd9Sstevel@tonic-gate 		cwc = 0;
1066*7c478bd9Sstevel@tonic-gate 		return(busy = 0);
1067*7c478bd9Sstevel@tonic-gate 	}
1068*7c478bd9Sstevel@tonic-gate 	if ((i & MBMASK) == MIDDLEOFMB) {
1069*7c478bd9Sstevel@tonic-gate 		if (mtbufp <= (mtbuf + MB_CUR_MAX)) {
1070*7c478bd9Sstevel@tonic-gate 			busy = 1;
1071*7c478bd9Sstevel@tonic-gate 		} else {
1072*7c478bd9Sstevel@tonic-gate 			*(mtbufp - 1) &= ~MBMASK;
1073*7c478bd9Sstevel@tonic-gate 			goto gotmb;
1074*7c478bd9Sstevel@tonic-gate 		}
1075*7c478bd9Sstevel@tonic-gate 	} else {
1076*7c478bd9Sstevel@tonic-gate 		if ((i & MBMASK) == LASTOFMB)
1077*7c478bd9Sstevel@tonic-gate 			*(mtbufp - 1) &= ~MBMASK;
1078*7c478bd9Sstevel@tonic-gate gotmb:
1079*7c478bd9Sstevel@tonic-gate 		mtbufp = mtbuf;
1080*7c478bd9Sstevel@tonic-gate 		owc = cwc;
1081*7c478bd9Sstevel@tonic-gate 		if (mbtowc(&cwc, mbbuf2, MB_CUR_MAX) <= 0) {
1082*7c478bd9Sstevel@tonic-gate 			mtbufp = mtbuf;
1083*7c478bd9Sstevel@tonic-gate 			while (*mtbufp) {
1084*7c478bd9Sstevel@tonic-gate 				setcbits(*mtbufp, (*mtbufp & 0x1ff));
1085*7c478bd9Sstevel@tonic-gate 				mtbufp++;
1086*7c478bd9Sstevel@tonic-gate 			}
1087*7c478bd9Sstevel@tonic-gate 			mtbufp = mtbuf;
1088*7c478bd9Sstevel@tonic-gate 		}
1089*7c478bd9Sstevel@tonic-gate 		mbbuf2p = mbbuf2;
1090*7c478bd9Sstevel@tonic-gate 		busy = 0;
1091*7c478bd9Sstevel@tonic-gate 	}
1092*7c478bd9Sstevel@tonic-gate 	return(busy);
1093*7c478bd9Sstevel@tonic-gate }
1094*7c478bd9Sstevel@tonic-gate 
1095*7c478bd9Sstevel@tonic-gate 
1096*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
1097*7c478bd9Sstevel@tonic-gate #endif /* EUC */
1098