xref: /onnv-gate/usr/src/cmd/troff/n5.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 #ifdef 	EUC
430Sstevel@tonic-gate #ifdef	NROFF
440Sstevel@tonic-gate #include <stddef.h>
450Sstevel@tonic-gate #include <stdlib.h>
460Sstevel@tonic-gate #include <widec.h>
470Sstevel@tonic-gate #endif	/* NROFF */
480Sstevel@tonic-gate #endif	/* EUC */
490Sstevel@tonic-gate #include <string.h>
500Sstevel@tonic-gate #include "tdef.h"
510Sstevel@tonic-gate #include "ext.h"
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * troff5.c
550Sstevel@tonic-gate  *
560Sstevel@tonic-gate  * misc processing requests
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate int	iflist[NIF];
600Sstevel@tonic-gate int	ifx;
610Sstevel@tonic-gate 
62*217Smuffin int
casead()630Sstevel@tonic-gate casead()
640Sstevel@tonic-gate {
65*217Smuffin 	int	i;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	ad = 1;
680Sstevel@tonic-gate 	/*leave admod alone*/
690Sstevel@tonic-gate 	if (skip())
70*217Smuffin 		return (0);
710Sstevel@tonic-gate 	switch (i = cbits(getch())) {
720Sstevel@tonic-gate 	case 'r':	/*right adj, left ragged*/
730Sstevel@tonic-gate 		admod = 2;
740Sstevel@tonic-gate 		break;
750Sstevel@tonic-gate 	case 'l':	/*left adj, right ragged*/
760Sstevel@tonic-gate 		admod = ad = 0;	/*same as casena*/
770Sstevel@tonic-gate 		break;
780Sstevel@tonic-gate 	case 'c':	/*centered adj*/
790Sstevel@tonic-gate 		admod = 1;
800Sstevel@tonic-gate 		break;
810Sstevel@tonic-gate 	case 'b':
820Sstevel@tonic-gate 	case 'n':
830Sstevel@tonic-gate 		admod = 0;
840Sstevel@tonic-gate 		break;
850Sstevel@tonic-gate 	case '0':
860Sstevel@tonic-gate 	case '2':
870Sstevel@tonic-gate 	case '4':
880Sstevel@tonic-gate 		ad = 0;
890Sstevel@tonic-gate 	case '1':
900Sstevel@tonic-gate 	case '3':
910Sstevel@tonic-gate 	case '5':
920Sstevel@tonic-gate 		admod = (i - '0') / 2;
930Sstevel@tonic-gate 	}
94*217Smuffin 
95*217Smuffin 	return (0);
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 
99*217Smuffin int
casena()1000Sstevel@tonic-gate casena()
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate 	ad = 0;
103*217Smuffin 
104*217Smuffin 	return (0);
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 
108*217Smuffin int
casefi()1090Sstevel@tonic-gate casefi()
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	tbreak();
1120Sstevel@tonic-gate 	fi++;
1130Sstevel@tonic-gate 	pendnf = 0;
1140Sstevel@tonic-gate 	lnsize = LNSIZE;
115*217Smuffin 
116*217Smuffin 	return (0);
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 
120*217Smuffin int
casenf()1210Sstevel@tonic-gate casenf()
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate 	tbreak();
1240Sstevel@tonic-gate 	fi = 0;
125*217Smuffin 
126*217Smuffin 	return (0);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 
130*217Smuffin int
casers()1310Sstevel@tonic-gate casers()
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	dip->nls = 0;
134*217Smuffin 
135*217Smuffin 	return (0);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 
139*217Smuffin int
casens()1400Sstevel@tonic-gate casens()
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	dip->nls++;
143*217Smuffin 
144*217Smuffin 	return (0);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 
148*217Smuffin int
chget(c)1490Sstevel@tonic-gate chget(c)
1500Sstevel@tonic-gate int	c;
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	tchar i;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
1550Sstevel@tonic-gate 		ch = i;
1560Sstevel@tonic-gate 		return(c);
1570Sstevel@tonic-gate 	} else
1580Sstevel@tonic-gate 		return(i & BYTEMASK);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 
162*217Smuffin int
casecc()1630Sstevel@tonic-gate casecc()
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate 	cc = chget('.');
166*217Smuffin 
167*217Smuffin 	return (0);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 
171*217Smuffin int
casec2()1720Sstevel@tonic-gate casec2()
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate 	c2 = chget('\'');
175*217Smuffin 
176*217Smuffin 	return (0);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 
180*217Smuffin int
casehc()1810Sstevel@tonic-gate casehc()
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	ohc = chget(OHC);
184*217Smuffin 
185*217Smuffin 	return (0);
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 
189*217Smuffin int
casetc()1900Sstevel@tonic-gate casetc()
1910Sstevel@tonic-gate {
1920Sstevel@tonic-gate 	tabc = chget(0);
193*217Smuffin 
194*217Smuffin 	return (0);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 
198*217Smuffin int
caselc()1990Sstevel@tonic-gate caselc()
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate 	dotc = chget(0);
202*217Smuffin 
203*217Smuffin 	return (0);
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 
207*217Smuffin int
casehy()2080Sstevel@tonic-gate casehy()
2090Sstevel@tonic-gate {
210*217Smuffin 	int	i;
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	hyf = 1;
2130Sstevel@tonic-gate 	if (skip())
214*217Smuffin 		return (0);
2150Sstevel@tonic-gate 	noscale++;
2160Sstevel@tonic-gate 	i = atoi();
2170Sstevel@tonic-gate 	noscale = 0;
2180Sstevel@tonic-gate 	if (nonumb)
219*217Smuffin 		return (0);
2200Sstevel@tonic-gate 	hyf = max(i, 0);
221*217Smuffin 
222*217Smuffin 	return (0);
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 
226*217Smuffin int
casenh()2270Sstevel@tonic-gate casenh()
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate 	hyf = 0;
230*217Smuffin 
231*217Smuffin 	return (0);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 
235*217Smuffin int
max(aa,bb)2360Sstevel@tonic-gate max(aa, bb)
2370Sstevel@tonic-gate int	aa, bb;
2380Sstevel@tonic-gate {
2390Sstevel@tonic-gate 	if (aa > bb)
2400Sstevel@tonic-gate 		return(aa);
2410Sstevel@tonic-gate 	else
2420Sstevel@tonic-gate 		return(bb);
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 
246*217Smuffin int
casece()2470Sstevel@tonic-gate casece()
2480Sstevel@tonic-gate {
249*217Smuffin 	int	i;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	noscale++;
2520Sstevel@tonic-gate 	skip();
2530Sstevel@tonic-gate 	i = max(atoi(), 0);
2540Sstevel@tonic-gate 	if (nonumb)
2550Sstevel@tonic-gate 		i = 1;
2560Sstevel@tonic-gate 	tbreak();
2570Sstevel@tonic-gate 	ce = i;
2580Sstevel@tonic-gate 	noscale = 0;
259*217Smuffin 
260*217Smuffin 	return (0);
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 
264*217Smuffin int
casein()2650Sstevel@tonic-gate casein()
2660Sstevel@tonic-gate {
267*217Smuffin 	int	i;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	if (skip())
2700Sstevel@tonic-gate 		i = in1;
2710Sstevel@tonic-gate 	else
2720Sstevel@tonic-gate 		i = max(hnumb(&in), 0);
2730Sstevel@tonic-gate 	tbreak();
2740Sstevel@tonic-gate 	in1 = in;
2750Sstevel@tonic-gate 	in = i;
2760Sstevel@tonic-gate 	if (!nc) {
2770Sstevel@tonic-gate 		un = in;
2780Sstevel@tonic-gate 		setnel();
2790Sstevel@tonic-gate 	}
280*217Smuffin 
281*217Smuffin 	return (0);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 
285*217Smuffin int
casell()2860Sstevel@tonic-gate casell()
2870Sstevel@tonic-gate {
288*217Smuffin 	int	i;
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	if (skip())
2910Sstevel@tonic-gate 		i = ll1;
2920Sstevel@tonic-gate 	else
2930Sstevel@tonic-gate 		i = max(hnumb(&ll), INCH / 10);
2940Sstevel@tonic-gate 	ll1 = ll;
2950Sstevel@tonic-gate 	ll = i;
2960Sstevel@tonic-gate 	setnel();
297*217Smuffin 
298*217Smuffin 	return (0);
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 
302*217Smuffin int
caselt()3030Sstevel@tonic-gate caselt()
3040Sstevel@tonic-gate {
305*217Smuffin 	int	i;
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	if (skip())
3080Sstevel@tonic-gate 		i = lt1;
3090Sstevel@tonic-gate 	else
3100Sstevel@tonic-gate 		i = max(hnumb(&lt), 0);
3110Sstevel@tonic-gate 	lt1 = lt;
3120Sstevel@tonic-gate 	lt = i;
313*217Smuffin 
314*217Smuffin 	return (0);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 
318*217Smuffin int
caseti()3190Sstevel@tonic-gate caseti()
3200Sstevel@tonic-gate {
321*217Smuffin 	int	i;
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 	if (skip())
324*217Smuffin 		return (0);
3250Sstevel@tonic-gate 	i = max(hnumb(&in), 0);
3260Sstevel@tonic-gate 	tbreak();
3270Sstevel@tonic-gate 	un1 = i;
3280Sstevel@tonic-gate 	setnel();
329*217Smuffin 
330*217Smuffin 	return (0);
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 
334*217Smuffin int
casels()3350Sstevel@tonic-gate casels()
3360Sstevel@tonic-gate {
337*217Smuffin 	int	i;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	noscale++;
3400Sstevel@tonic-gate 	if (skip())
3410Sstevel@tonic-gate 		i = ls1;
3420Sstevel@tonic-gate 	else
3430Sstevel@tonic-gate 		i = max(inumb(&ls), 1);
3440Sstevel@tonic-gate 	ls1 = ls;
3450Sstevel@tonic-gate 	ls = i;
3460Sstevel@tonic-gate 	noscale = 0;
347*217Smuffin 
348*217Smuffin 	return (0);
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 
352*217Smuffin int
casepo()3530Sstevel@tonic-gate casepo()
3540Sstevel@tonic-gate {
355*217Smuffin 	int	i;
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	if (skip())
3580Sstevel@tonic-gate 		i = po1;
3590Sstevel@tonic-gate 	else
3600Sstevel@tonic-gate 		i = max(hnumb(&po), 0);
3610Sstevel@tonic-gate 	po1 = po;
3620Sstevel@tonic-gate 	po = i;
3630Sstevel@tonic-gate #ifndef NROFF
3640Sstevel@tonic-gate 	if (!ascii)
3650Sstevel@tonic-gate 		esc += po - po1;
3660Sstevel@tonic-gate #endif
367*217Smuffin 	return (0);
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 
371*217Smuffin int
casepl()3720Sstevel@tonic-gate casepl()
3730Sstevel@tonic-gate {
374*217Smuffin 	int	i;
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	skip();
3770Sstevel@tonic-gate 	if ((i = vnumb(&pl)) == 0)
3780Sstevel@tonic-gate 		pl = 11 * INCH; /*11in*/
3790Sstevel@tonic-gate 	else
3800Sstevel@tonic-gate 		pl = i;
3810Sstevel@tonic-gate 	if (numtab[NL].val > pl)
3820Sstevel@tonic-gate 		numtab[NL].val = pl;
383*217Smuffin 
384*217Smuffin 	return (0);
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 
388*217Smuffin int
casewh()3890Sstevel@tonic-gate casewh()
3900Sstevel@tonic-gate {
391*217Smuffin 	int	i, j, k;
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	lgf++;
3940Sstevel@tonic-gate 	skip();
3950Sstevel@tonic-gate 	i = vnumb((int *)0);
3960Sstevel@tonic-gate 	if (nonumb)
397*217Smuffin 		return (0);
3980Sstevel@tonic-gate 	skip();
3990Sstevel@tonic-gate 	j = getrq();
4000Sstevel@tonic-gate 	if ((k = findn(i)) != NTRAP) {
4010Sstevel@tonic-gate 		mlist[k] = j;
402*217Smuffin 		return (0);
4030Sstevel@tonic-gate 	}
4040Sstevel@tonic-gate 	for (k = 0; k < NTRAP; k++)
4050Sstevel@tonic-gate 		if (mlist[k] == 0)
4060Sstevel@tonic-gate 			break;
4070Sstevel@tonic-gate 	if (k == NTRAP) {
4080Sstevel@tonic-gate 		flusho();
4090Sstevel@tonic-gate 		errprint(gettext("cannot plant trap."));
410*217Smuffin 		return (0);
4110Sstevel@tonic-gate 	}
4120Sstevel@tonic-gate 	mlist[k] = j;
4130Sstevel@tonic-gate 	nlist[k] = i;
414*217Smuffin 
415*217Smuffin 	return (0);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 
419*217Smuffin int
casech()4200Sstevel@tonic-gate casech()
4210Sstevel@tonic-gate {
422*217Smuffin 	int	i, j, k;
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 	lgf++;
4250Sstevel@tonic-gate 	skip();
4260Sstevel@tonic-gate 	if (!(j = getrq()))
427*217Smuffin 		return (0);
4280Sstevel@tonic-gate 	else
4290Sstevel@tonic-gate 		for (k = 0; k < NTRAP; k++)
4300Sstevel@tonic-gate 			if (mlist[k] == j)
4310Sstevel@tonic-gate 				break;
4320Sstevel@tonic-gate 	if (k == NTRAP)
433*217Smuffin 		return (0);
4340Sstevel@tonic-gate 	skip();
4350Sstevel@tonic-gate 	i = vnumb((int *)0);
4360Sstevel@tonic-gate 	if (nonumb)
4370Sstevel@tonic-gate 		mlist[k] = 0;
4380Sstevel@tonic-gate 	nlist[k] = i;
439*217Smuffin 
440*217Smuffin 	return (0);
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 
444*217Smuffin int
findn(i)4450Sstevel@tonic-gate findn(i)
4460Sstevel@tonic-gate int	i;
4470Sstevel@tonic-gate {
448*217Smuffin 	int	k;
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	for (k = 0; k < NTRAP; k++)
4510Sstevel@tonic-gate 		if ((nlist[k] == i) && (mlist[k] != 0))
4520Sstevel@tonic-gate 			break;
4530Sstevel@tonic-gate 	return(k);
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 
457*217Smuffin int
casepn()4580Sstevel@tonic-gate casepn()
4590Sstevel@tonic-gate {
460*217Smuffin 	int	i;
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 	skip();
4630Sstevel@tonic-gate 	noscale++;
4640Sstevel@tonic-gate 	i = max(inumb(&numtab[PN].val), 0);
4650Sstevel@tonic-gate 	noscale = 0;
4660Sstevel@tonic-gate 	if (!nonumb) {
4670Sstevel@tonic-gate 		npn = i;
4680Sstevel@tonic-gate 		npnflg++;
4690Sstevel@tonic-gate 	}
470*217Smuffin 
471*217Smuffin 	return (0);
4720Sstevel@tonic-gate }
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 
475*217Smuffin int
casebp()4760Sstevel@tonic-gate casebp()
4770Sstevel@tonic-gate {
478*217Smuffin 	int	i;
479*217Smuffin 	struct s *savframe;
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 	if (dip != d)
482*217Smuffin 		return (0);
4830Sstevel@tonic-gate 	savframe = frame;
4840Sstevel@tonic-gate 	skip();
4850Sstevel@tonic-gate 	if ((i = inumb(&numtab[PN].val)) < 0)
4860Sstevel@tonic-gate 		i = 0;
4870Sstevel@tonic-gate 	tbreak();
4880Sstevel@tonic-gate 	if (!nonumb) {
4890Sstevel@tonic-gate 		npn = i;
4900Sstevel@tonic-gate 		npnflg++;
4910Sstevel@tonic-gate 	} else if (dip->nls)
492*217Smuffin 		return (0);
4930Sstevel@tonic-gate 	eject(savframe);
494*217Smuffin 
495*217Smuffin 	return (0);
4960Sstevel@tonic-gate }
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate 
499*217Smuffin int
casetm(ab)5000Sstevel@tonic-gate casetm(ab)
5010Sstevel@tonic-gate 	int ab;
5020Sstevel@tonic-gate {
503*217Smuffin 	int	i;
5040Sstevel@tonic-gate 	char	tmbuf[NTM];
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 	lgf++;
5070Sstevel@tonic-gate 	copyf++;
5080Sstevel@tonic-gate 	if (skip() && ab)
5090Sstevel@tonic-gate 		errprint(gettext("User Abort"));
5100Sstevel@tonic-gate 	for (i = 0; i < NTM - 2; )
5110Sstevel@tonic-gate 		if ((tmbuf[i++] = getch()) == '\n')
5120Sstevel@tonic-gate 			break;
5130Sstevel@tonic-gate 	if (i == NTM - 2)
5140Sstevel@tonic-gate 		tmbuf[i++] = '\n';
5150Sstevel@tonic-gate 	tmbuf[i] = 0;
5160Sstevel@tonic-gate 	if (ab)	/* truncate output */
5170Sstevel@tonic-gate 		obufp = obuf;	/* should be a function in n2.c */
5180Sstevel@tonic-gate 	flusho();
5190Sstevel@tonic-gate 	fdprintf(stderr, "%s", tmbuf);
5200Sstevel@tonic-gate 	copyf--;
5210Sstevel@tonic-gate 	lgf--;
522*217Smuffin 
523*217Smuffin 	return (0);
5240Sstevel@tonic-gate }
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate 
527*217Smuffin int
casesp(a)5280Sstevel@tonic-gate casesp(a)
5290Sstevel@tonic-gate int	a;
5300Sstevel@tonic-gate {
531*217Smuffin 	int	i, j, savlss;
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	tbreak();
5340Sstevel@tonic-gate 	if (dip->nls || trap)
535*217Smuffin 		return (0);
5360Sstevel@tonic-gate 	i = findt1();
5370Sstevel@tonic-gate 	if (!a) {
5380Sstevel@tonic-gate 		skip();
5390Sstevel@tonic-gate 		j = vnumb((int *)0);
5400Sstevel@tonic-gate 		if (nonumb)
5410Sstevel@tonic-gate 			j = lss;
5420Sstevel@tonic-gate 	} else
5430Sstevel@tonic-gate 		j = a;
5440Sstevel@tonic-gate 	if (j == 0)
545*217Smuffin 		return (0);
5460Sstevel@tonic-gate 	if (i < j)
5470Sstevel@tonic-gate 		j = i;
5480Sstevel@tonic-gate 	savlss = lss;
5490Sstevel@tonic-gate 	if (dip != d)
5500Sstevel@tonic-gate 		i = dip->dnl;
5510Sstevel@tonic-gate 	else
5520Sstevel@tonic-gate 		i = numtab[NL].val;
5530Sstevel@tonic-gate 	if ((i + j) < 0)
5540Sstevel@tonic-gate 		j = -i;
5550Sstevel@tonic-gate 	lss = j;
5560Sstevel@tonic-gate 	newline(0);
5570Sstevel@tonic-gate 	lss = savlss;
558*217Smuffin 
559*217Smuffin 	return (0);
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 
563*217Smuffin int
casert()5640Sstevel@tonic-gate casert()
5650Sstevel@tonic-gate {
566*217Smuffin 	int	a, *p;
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	skip();
5690Sstevel@tonic-gate 	if (dip != d)
5700Sstevel@tonic-gate 		p = &dip->dnl;
5710Sstevel@tonic-gate 	else
5720Sstevel@tonic-gate 		p = &numtab[NL].val;
5730Sstevel@tonic-gate 	a = vnumb(p);
5740Sstevel@tonic-gate 	if (nonumb)
5750Sstevel@tonic-gate 		a = dip->mkline;
5760Sstevel@tonic-gate 	if ((a < 0) || (a >= *p))
577*217Smuffin 		return (0);
5780Sstevel@tonic-gate 	nb++;
5790Sstevel@tonic-gate 	casesp(a - *p);
580*217Smuffin 
581*217Smuffin 	return (0);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate 
585*217Smuffin int
caseem()5860Sstevel@tonic-gate caseem()
5870Sstevel@tonic-gate {
5880Sstevel@tonic-gate 	lgf++;
5890Sstevel@tonic-gate 	skip();
5900Sstevel@tonic-gate 	em = getrq();
591*217Smuffin 
592*217Smuffin 	return (0);
5930Sstevel@tonic-gate }
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate 
596*217Smuffin int
casefl()5970Sstevel@tonic-gate casefl()
5980Sstevel@tonic-gate {
5990Sstevel@tonic-gate 	tbreak();
6000Sstevel@tonic-gate 	flusho();
601*217Smuffin 
602*217Smuffin 	return (0);
6030Sstevel@tonic-gate }
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate 
606*217Smuffin int
caseev()6070Sstevel@tonic-gate caseev()
6080Sstevel@tonic-gate {
609*217Smuffin 	int	nxev;
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	if (skip()) {
6120Sstevel@tonic-gate e0:
6130Sstevel@tonic-gate 		if (evi == 0)
614*217Smuffin 			return (0);
6150Sstevel@tonic-gate 		nxev =  evlist[--evi];
6160Sstevel@tonic-gate 		goto e1;
6170Sstevel@tonic-gate 	}
6180Sstevel@tonic-gate 	noscale++;
6190Sstevel@tonic-gate 	nxev = atoi();
6200Sstevel@tonic-gate 	noscale = 0;
6210Sstevel@tonic-gate 	if (nonumb)
6220Sstevel@tonic-gate 		goto e0;
6230Sstevel@tonic-gate 	flushi();
6240Sstevel@tonic-gate 	if ((nxev >= NEV) || (nxev < 0) || (evi >= EVLSZ)) {
6250Sstevel@tonic-gate 		flusho();
6260Sstevel@tonic-gate 		errprint(gettext("cannot do ev."));
6270Sstevel@tonic-gate 		if (error)
6280Sstevel@tonic-gate 			done2(040);
6290Sstevel@tonic-gate 		else
6300Sstevel@tonic-gate 			edone(040);
631*217Smuffin 		return (0);
6320Sstevel@tonic-gate 	}
6330Sstevel@tonic-gate 	evlist[evi++] = ev;
6340Sstevel@tonic-gate e1:
6350Sstevel@tonic-gate 	if (ev == nxev)
636*217Smuffin 		return (0);
6370Sstevel@tonic-gate #ifdef INCORE
6380Sstevel@tonic-gate 	{
6390Sstevel@tonic-gate 		extern tchar corebuf[];
6400Sstevel@tonic-gate 		*(struct env *)&corebuf[ev * sizeof(env)/sizeof(tchar)] = env;
6410Sstevel@tonic-gate 		env = *(struct env *)&corebuf[nxev * sizeof(env)/sizeof(tchar)];
6420Sstevel@tonic-gate 	}
6430Sstevel@tonic-gate #else
6440Sstevel@tonic-gate 	lseek(ibf, ev * (long)sizeof(env), 0);
6450Sstevel@tonic-gate 	write(ibf, (char *) & env, sizeof(env));
6460Sstevel@tonic-gate 	lseek(ibf, nxev * (long)sizeof(env), 0);
6470Sstevel@tonic-gate 	read(ibf, (char *) & env, sizeof(env));
6480Sstevel@tonic-gate #endif
6490Sstevel@tonic-gate 	ev = nxev;
650*217Smuffin 
651*217Smuffin 	return (0);
6520Sstevel@tonic-gate }
6530Sstevel@tonic-gate 
654*217Smuffin int
caseel()6550Sstevel@tonic-gate caseel()
6560Sstevel@tonic-gate {
6570Sstevel@tonic-gate 	if (--ifx < 0) {
6580Sstevel@tonic-gate 		ifx = 0;
6590Sstevel@tonic-gate 		iflist[0] = 0;
6600Sstevel@tonic-gate 	}
6610Sstevel@tonic-gate 	caseif(2);
662*217Smuffin 
663*217Smuffin 	return (0);
6640Sstevel@tonic-gate }
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 
667*217Smuffin int
caseie()6680Sstevel@tonic-gate caseie()
6690Sstevel@tonic-gate {
6700Sstevel@tonic-gate 	if (ifx >= NIF) {
6710Sstevel@tonic-gate 		errprint(gettext("if-else overflow."));
6720Sstevel@tonic-gate 		ifx = 0;
6730Sstevel@tonic-gate 		edone(040);
6740Sstevel@tonic-gate 	}
6750Sstevel@tonic-gate 	caseif(1);
6760Sstevel@tonic-gate 	ifx++;
677*217Smuffin 
678*217Smuffin 	return (0);
6790Sstevel@tonic-gate }
6800Sstevel@tonic-gate 
6810Sstevel@tonic-gate 
682*217Smuffin int
caseif(x)6830Sstevel@tonic-gate caseif(x)
6840Sstevel@tonic-gate int	x;
6850Sstevel@tonic-gate {
6860Sstevel@tonic-gate 	extern int falsef;
687*217Smuffin 	int	notflag, true;
6880Sstevel@tonic-gate 	tchar i;
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate 	if (x == 2) {
6910Sstevel@tonic-gate 		notflag = 0;
6920Sstevel@tonic-gate 		true = iflist[ifx];
6930Sstevel@tonic-gate 		goto i1;
6940Sstevel@tonic-gate 	}
6950Sstevel@tonic-gate 	true = 0;
6960Sstevel@tonic-gate 	skip();
6970Sstevel@tonic-gate 	if ((cbits(i = getch())) == '!') {
6980Sstevel@tonic-gate 		notflag = 1;
6990Sstevel@tonic-gate 	} else {
7000Sstevel@tonic-gate 		notflag = 0;
7010Sstevel@tonic-gate 		ch = i;
7020Sstevel@tonic-gate 	}
7030Sstevel@tonic-gate 	i = atoi();
7040Sstevel@tonic-gate 	if (!nonumb) {
7050Sstevel@tonic-gate 		if (i > 0)
7060Sstevel@tonic-gate 			true++;
7070Sstevel@tonic-gate 		goto i1;
7080Sstevel@tonic-gate 	}
7090Sstevel@tonic-gate 	i = getch();
7100Sstevel@tonic-gate 	switch (cbits(i)) {
7110Sstevel@tonic-gate 	case 'e':
7120Sstevel@tonic-gate 		if (!(numtab[PN].val & 01))
7130Sstevel@tonic-gate 			true++;
7140Sstevel@tonic-gate 		break;
7150Sstevel@tonic-gate 	case 'o':
7160Sstevel@tonic-gate 		if (numtab[PN].val & 01)
7170Sstevel@tonic-gate 			true++;
7180Sstevel@tonic-gate 		break;
7190Sstevel@tonic-gate #ifdef NROFF
7200Sstevel@tonic-gate 	case 'n':
7210Sstevel@tonic-gate 		true++;
7220Sstevel@tonic-gate 	case 't':
7230Sstevel@tonic-gate #endif
7240Sstevel@tonic-gate #ifndef NROFF
7250Sstevel@tonic-gate 	case 't':
7260Sstevel@tonic-gate 		true++;
7270Sstevel@tonic-gate 	case 'n':
7280Sstevel@tonic-gate #endif
7290Sstevel@tonic-gate 	case ' ':
7300Sstevel@tonic-gate 		break;
7310Sstevel@tonic-gate 	default:
7320Sstevel@tonic-gate 		true = cmpstr(i);
7330Sstevel@tonic-gate 	}
7340Sstevel@tonic-gate i1:
7350Sstevel@tonic-gate 	true ^= notflag;
7360Sstevel@tonic-gate 	if (x == 1)
7370Sstevel@tonic-gate 		iflist[ifx] = !true;
7380Sstevel@tonic-gate 	if (true) {
7390Sstevel@tonic-gate i2:
7400Sstevel@tonic-gate 		while ((cbits(i = getch())) == ' ')
7410Sstevel@tonic-gate 			;
7420Sstevel@tonic-gate 		if (cbits(i) == LEFT)
7430Sstevel@tonic-gate 			goto i2;
7440Sstevel@tonic-gate 		ch = i;
7450Sstevel@tonic-gate 		nflush++;
7460Sstevel@tonic-gate 	} else {
7470Sstevel@tonic-gate 		copyf++;
7480Sstevel@tonic-gate 		falsef++;
7490Sstevel@tonic-gate 		eatblk(0);
7500Sstevel@tonic-gate 		copyf--;
7510Sstevel@tonic-gate 		falsef--;
7520Sstevel@tonic-gate 	}
753*217Smuffin 
754*217Smuffin 	return (0);
7550Sstevel@tonic-gate }
7560Sstevel@tonic-gate 
757*217Smuffin int
eatblk(inblk)7580Sstevel@tonic-gate eatblk(inblk)
7590Sstevel@tonic-gate int inblk;
760*217Smuffin {	int cnt, i;
7610Sstevel@tonic-gate 
7620Sstevel@tonic-gate 	cnt = 0;
7630Sstevel@tonic-gate 	do {
7640Sstevel@tonic-gate 		if (ch)	{
7650Sstevel@tonic-gate 			i = cbits(ch);
7660Sstevel@tonic-gate 			ch = 0;
7670Sstevel@tonic-gate 		} else
7680Sstevel@tonic-gate 			i = cbits(getch0());
7690Sstevel@tonic-gate 		if (i == ESC)
7700Sstevel@tonic-gate 			cnt++;
7710Sstevel@tonic-gate 		else {
7720Sstevel@tonic-gate 			if (cnt == 1)
7730Sstevel@tonic-gate 				switch (i) {
7740Sstevel@tonic-gate 				case '{':  i = LEFT; break;
7750Sstevel@tonic-gate 				case '}':  i = RIGHT; break;
7760Sstevel@tonic-gate 				case '\n': i = 'x'; break;
7770Sstevel@tonic-gate 				}
7780Sstevel@tonic-gate 			cnt = 0;
7790Sstevel@tonic-gate 		}
7800Sstevel@tonic-gate 		if (i == LEFT) eatblk(1);
7810Sstevel@tonic-gate 	} while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT)));
7820Sstevel@tonic-gate 	if (i == '\n')
7830Sstevel@tonic-gate 		nlflg++;
784*217Smuffin 
785*217Smuffin 	return (0);
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate 
789*217Smuffin int
cmpstr(c)7900Sstevel@tonic-gate cmpstr(c)
7910Sstevel@tonic-gate tchar c;
7920Sstevel@tonic-gate {
793*217Smuffin 	int	j, delim;
794*217Smuffin 	tchar i;
795*217Smuffin 	int	val;
7960Sstevel@tonic-gate 	int savapts, savapts1, savfont, savfont1, savpts, savpts1;
7970Sstevel@tonic-gate 	tchar string[1280];
798*217Smuffin 	tchar *sp;
7990Sstevel@tonic-gate 
8000Sstevel@tonic-gate 	if (ismot(c))
8010Sstevel@tonic-gate 		return(0);
8020Sstevel@tonic-gate 	delim = cbits(c);
8030Sstevel@tonic-gate 	savapts = apts;
8040Sstevel@tonic-gate 	savapts1 = apts1;
8050Sstevel@tonic-gate 	savfont = font;
8060Sstevel@tonic-gate 	savfont1 = font1;
8070Sstevel@tonic-gate 	savpts = pts;
8080Sstevel@tonic-gate 	savpts1 = pts1;
8090Sstevel@tonic-gate 	sp = string;
8100Sstevel@tonic-gate 	while ((j = cbits(i = getch()))!=delim && j!='\n' && sp<&string[1280-1])
8110Sstevel@tonic-gate 		*sp++ = i;
8120Sstevel@tonic-gate 	if (sp >= string + 1280) {
8130Sstevel@tonic-gate 		errprint(gettext("too-long string compare."));
8140Sstevel@tonic-gate 		edone(0100);
8150Sstevel@tonic-gate 	}
8160Sstevel@tonic-gate 	if (nlflg) {
8170Sstevel@tonic-gate 		val = sp==string;
8180Sstevel@tonic-gate 		goto rtn;
8190Sstevel@tonic-gate 	}
8200Sstevel@tonic-gate 	*sp++ = 0;
8210Sstevel@tonic-gate 	apts = savapts;
8220Sstevel@tonic-gate 	apts1 = savapts1;
8230Sstevel@tonic-gate 	font = savfont;
8240Sstevel@tonic-gate 	font1 = savfont1;
8250Sstevel@tonic-gate 	pts = savpts;
8260Sstevel@tonic-gate 	pts1 = savpts1;
8270Sstevel@tonic-gate 	mchbits();
8280Sstevel@tonic-gate 	val = 1;
8290Sstevel@tonic-gate 	sp = string;
8300Sstevel@tonic-gate 	while ((j = cbits(i = getch())) != delim && j != '\n') {
8310Sstevel@tonic-gate 		if (*sp != i) {
8320Sstevel@tonic-gate 			eat(delim);
8330Sstevel@tonic-gate 			val = 0;
8340Sstevel@tonic-gate 			goto rtn;
8350Sstevel@tonic-gate 		}
8360Sstevel@tonic-gate 		sp++;
8370Sstevel@tonic-gate 	}
8380Sstevel@tonic-gate 	if (*sp)
8390Sstevel@tonic-gate 		val = 0;
8400Sstevel@tonic-gate rtn:
8410Sstevel@tonic-gate 	apts = savapts;
8420Sstevel@tonic-gate 	apts1 = savapts1;
8430Sstevel@tonic-gate 	font = savfont;
8440Sstevel@tonic-gate 	font1 = savfont1;
8450Sstevel@tonic-gate 	pts = savpts;
8460Sstevel@tonic-gate 	pts1 = savpts1;
8470Sstevel@tonic-gate 	mchbits();
8480Sstevel@tonic-gate 	return(val);
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 
852*217Smuffin int
caserd()8530Sstevel@tonic-gate caserd()
8540Sstevel@tonic-gate {
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate 	lgf++;
8570Sstevel@tonic-gate 	skip();
8580Sstevel@tonic-gate 	getname();
8590Sstevel@tonic-gate 	if (!iflg) {
8600Sstevel@tonic-gate 		if (quiet) {
8610Sstevel@tonic-gate #ifdef	NROFF
8620Sstevel@tonic-gate 			echo_off();
8630Sstevel@tonic-gate 			flusho();
864*217Smuffin #endif	/* NROFF */
8650Sstevel@tonic-gate 			fdprintf(stderr, "\007"); /*bell*/
8660Sstevel@tonic-gate 		} else {
8670Sstevel@tonic-gate 			if (nextf[0]) {
8680Sstevel@tonic-gate 				fdprintf(stderr, "%s:", nextf);
8690Sstevel@tonic-gate 			} else {
8700Sstevel@tonic-gate 				fdprintf(stderr, "\007"); /*bell*/
8710Sstevel@tonic-gate 			}
8720Sstevel@tonic-gate 		}
8730Sstevel@tonic-gate 	}
8740Sstevel@tonic-gate 	collect();
8750Sstevel@tonic-gate 	tty++;
8760Sstevel@tonic-gate 	pushi(NBLIST*BLK, PAIR('r','d'));
877*217Smuffin 
878*217Smuffin 	return (0);
8790Sstevel@tonic-gate }
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate 
882*217Smuffin int
rdtty()8830Sstevel@tonic-gate rdtty()
8840Sstevel@tonic-gate {
8850Sstevel@tonic-gate 	char	onechar;
8860Sstevel@tonic-gate #ifdef EUC
8870Sstevel@tonic-gate #ifdef NROFF
8880Sstevel@tonic-gate 	int	i, n, col_index;
8890Sstevel@tonic-gate #endif /* NROFF */
8900Sstevel@tonic-gate #endif /* EUC */
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 	onechar = 0;
8930Sstevel@tonic-gate 	if (read(0, &onechar, 1) == 1) {
8940Sstevel@tonic-gate 		if (onechar == '\n')
8950Sstevel@tonic-gate 			tty++;
8960Sstevel@tonic-gate 		else
8970Sstevel@tonic-gate 			tty = 1;
8980Sstevel@tonic-gate #ifndef EUC
8990Sstevel@tonic-gate 		if (tty != 3)
9000Sstevel@tonic-gate 			return(onechar);
9010Sstevel@tonic-gate #else
9020Sstevel@tonic-gate #ifndef NROFF
9030Sstevel@tonic-gate 		if (tty != 3)
9040Sstevel@tonic-gate 			return(onechar);
9050Sstevel@tonic-gate #else
9060Sstevel@tonic-gate 		if (tty != 3) {
9070Sstevel@tonic-gate 			if (!multi_locale)
9080Sstevel@tonic-gate 				return(onechar);
9090Sstevel@tonic-gate 			i = onechar & 0377;
9100Sstevel@tonic-gate 			*mbbuf1p++ = i;
9110Sstevel@tonic-gate 			*mbbuf1p = 0;
9120Sstevel@tonic-gate 			if ((n = mbtowc(&twc, mbbuf1, MB_CUR_MAX)) <= 0) {
9130Sstevel@tonic-gate 				if (mbbuf1p >= mbbuf1 + MB_CUR_MAX) {
9140Sstevel@tonic-gate 					i &= ~(MBMASK | CSMASK);
9150Sstevel@tonic-gate 					twc = 0;
9160Sstevel@tonic-gate 					mbbuf1p = mbbuf1;
9170Sstevel@tonic-gate 					*mbbuf1p = 0;
9180Sstevel@tonic-gate 				} else {
9190Sstevel@tonic-gate 					i |= (MIDDLEOFMB);
9200Sstevel@tonic-gate 				}
9210Sstevel@tonic-gate 			} else {
9220Sstevel@tonic-gate 				if (n > 1)
9230Sstevel@tonic-gate 					i |= (LASTOFMB);
9240Sstevel@tonic-gate 				else
9250Sstevel@tonic-gate 					i |= (BYTE_CHR);
9260Sstevel@tonic-gate 				if (isascii(twc)) {
9270Sstevel@tonic-gate 					col_index = 0;
9280Sstevel@tonic-gate 				} else {
9290Sstevel@tonic-gate 					if ((col_index = wcwidth(twc)) < 0)
9300Sstevel@tonic-gate 						col_index = 0;
9310Sstevel@tonic-gate 				}
9320Sstevel@tonic-gate 				setcsbits(i, col_index);
9330Sstevel@tonic-gate 				twc = 0;
9340Sstevel@tonic-gate 				mbbuf1p = mbbuf1;
9350Sstevel@tonic-gate 			}
9360Sstevel@tonic-gate 			return(i);
9370Sstevel@tonic-gate 		}
9380Sstevel@tonic-gate #endif /* NROFF */
9390Sstevel@tonic-gate #endif /* EUC */
9400Sstevel@tonic-gate 	}
9410Sstevel@tonic-gate 	popi();
9420Sstevel@tonic-gate 	tty = 0;
9430Sstevel@tonic-gate #ifdef	NROFF
9440Sstevel@tonic-gate 	if (quiet)
9450Sstevel@tonic-gate 		echo_on();
946*217Smuffin #endif	/* NROFF */
9470Sstevel@tonic-gate 	return(0);
9480Sstevel@tonic-gate }
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate 
951*217Smuffin int
caseec()9520Sstevel@tonic-gate caseec()
9530Sstevel@tonic-gate {
9540Sstevel@tonic-gate 	eschar = chget('\\');
955*217Smuffin 
956*217Smuffin 	return (0);
9570Sstevel@tonic-gate }
9580Sstevel@tonic-gate 
9590Sstevel@tonic-gate 
960*217Smuffin int
caseeo()9610Sstevel@tonic-gate caseeo()
9620Sstevel@tonic-gate {
9630Sstevel@tonic-gate 	eschar = 0;
964*217Smuffin 
965*217Smuffin 	return (0);
9660Sstevel@tonic-gate }
9670Sstevel@tonic-gate 
9680Sstevel@tonic-gate 
969*217Smuffin int
caseta()9700Sstevel@tonic-gate caseta()
9710Sstevel@tonic-gate {
972*217Smuffin 	int	i;
9730Sstevel@tonic-gate 
9740Sstevel@tonic-gate 	tabtab[0] = nonumb = 0;
9750Sstevel@tonic-gate 	for (i = 0; ((i < (NTAB - 1)) && !nonumb); i++) {
9760Sstevel@tonic-gate 		if (skip())
9770Sstevel@tonic-gate 			break;
9780Sstevel@tonic-gate 		tabtab[i] = max(hnumb(&tabtab[max(i-1,0)]), 0) & TABMASK;
9790Sstevel@tonic-gate 		if (!nonumb)
9800Sstevel@tonic-gate 			switch (cbits(ch)) {
9810Sstevel@tonic-gate 			case 'C':
9820Sstevel@tonic-gate 				tabtab[i] |= CTAB;
9830Sstevel@tonic-gate 				break;
9840Sstevel@tonic-gate 			case 'R':
9850Sstevel@tonic-gate 				tabtab[i] |= RTAB;
9860Sstevel@tonic-gate 				break;
9870Sstevel@tonic-gate 			default: /*includes L*/
9880Sstevel@tonic-gate 				break;
9890Sstevel@tonic-gate 			}
9900Sstevel@tonic-gate 		nonumb = ch = 0;
9910Sstevel@tonic-gate 	}
9920Sstevel@tonic-gate 	tabtab[i] = 0;
993*217Smuffin 
994*217Smuffin 	return (0);
9950Sstevel@tonic-gate }
9960Sstevel@tonic-gate 
9970Sstevel@tonic-gate 
998*217Smuffin int
casene()9990Sstevel@tonic-gate casene()
10000Sstevel@tonic-gate {
1001*217Smuffin 	int	i, j;
10020Sstevel@tonic-gate 
10030Sstevel@tonic-gate 	skip();
10040Sstevel@tonic-gate 	i = vnumb((int *)0);
10050Sstevel@tonic-gate 	if (nonumb)
10060Sstevel@tonic-gate 		i = lss;
10070Sstevel@tonic-gate 	if (i > (j = findt1())) {
10080Sstevel@tonic-gate 		i = lss;
10090Sstevel@tonic-gate 		lss = j;
10100Sstevel@tonic-gate 		dip->nls = 0;
10110Sstevel@tonic-gate 		newline(0);
10120Sstevel@tonic-gate 		lss = i;
10130Sstevel@tonic-gate 	}
1014*217Smuffin 
1015*217Smuffin 	return (0);
10160Sstevel@tonic-gate }
10170Sstevel@tonic-gate 
10180Sstevel@tonic-gate 
1019*217Smuffin int
casetr()10200Sstevel@tonic-gate casetr()
10210Sstevel@tonic-gate {
1022*217Smuffin 	int	i, j;
10230Sstevel@tonic-gate 	tchar k;
10240Sstevel@tonic-gate 
10250Sstevel@tonic-gate 	lgf++;
10260Sstevel@tonic-gate 	skip();
10270Sstevel@tonic-gate 	while ((i = cbits(k=getch())) != '\n') {
10280Sstevel@tonic-gate 		if (ismot(k))
1029*217Smuffin 			return (0);
10300Sstevel@tonic-gate 		if (ismot(k = getch()))
1031*217Smuffin 			return (0);
10320Sstevel@tonic-gate 		if ((j = cbits(k)) == '\n')
10330Sstevel@tonic-gate 			j = ' ';
10340Sstevel@tonic-gate 		trtab[i] = j;
10350Sstevel@tonic-gate 	}
1036*217Smuffin 
1037*217Smuffin 	return (0);
10380Sstevel@tonic-gate }
10390Sstevel@tonic-gate 
10400Sstevel@tonic-gate 
1041*217Smuffin int
casecu()10420Sstevel@tonic-gate casecu()
10430Sstevel@tonic-gate {
10440Sstevel@tonic-gate 	cu++;
10450Sstevel@tonic-gate 	caseul();
1046*217Smuffin 
1047*217Smuffin 	return (0);
10480Sstevel@tonic-gate }
10490Sstevel@tonic-gate 
10500Sstevel@tonic-gate 
1051*217Smuffin int
caseul()10520Sstevel@tonic-gate caseul()
10530Sstevel@tonic-gate {
1054*217Smuffin 	int	i;
10550Sstevel@tonic-gate 
10560Sstevel@tonic-gate 	noscale++;
10570Sstevel@tonic-gate 	if (skip())
10580Sstevel@tonic-gate 		i = 1;
10590Sstevel@tonic-gate 	else
10600Sstevel@tonic-gate 		i = atoi();
10610Sstevel@tonic-gate 	if (ul && (i == 0)) {
10620Sstevel@tonic-gate 		font = sfont;
10630Sstevel@tonic-gate 		ul = cu = 0;
10640Sstevel@tonic-gate 	}
10650Sstevel@tonic-gate 	if (i) {
10660Sstevel@tonic-gate 		if (!ul) {
10670Sstevel@tonic-gate 			sfont = font;
10680Sstevel@tonic-gate 			font = ulfont;
10690Sstevel@tonic-gate 		}
10700Sstevel@tonic-gate 		ul = i;
10710Sstevel@tonic-gate 	}
10720Sstevel@tonic-gate 	noscale = 0;
10730Sstevel@tonic-gate 	mchbits();
1074*217Smuffin 
1075*217Smuffin 	return (0);
10760Sstevel@tonic-gate }
10770Sstevel@tonic-gate 
10780Sstevel@tonic-gate 
1079*217Smuffin int
caseuf()10800Sstevel@tonic-gate caseuf()
10810Sstevel@tonic-gate {
1082*217Smuffin 	int	i, j;
10830Sstevel@tonic-gate 
10840Sstevel@tonic-gate 	if (skip() || !(i = getrq()) || i == 'S' ||  (j = findft(i))  == -1)
10850Sstevel@tonic-gate 		ulfont = ULFONT; /*default underline position*/
10860Sstevel@tonic-gate 	else
10870Sstevel@tonic-gate 		ulfont = j;
10880Sstevel@tonic-gate #ifdef NROFF
10890Sstevel@tonic-gate 	if (ulfont == FT)
10900Sstevel@tonic-gate 		ulfont = ULFONT;
10910Sstevel@tonic-gate #endif
1092*217Smuffin 	return (0);
10930Sstevel@tonic-gate }
10940Sstevel@tonic-gate 
10950Sstevel@tonic-gate 
1096*217Smuffin int
caseit()10970Sstevel@tonic-gate caseit()
10980Sstevel@tonic-gate {
1099*217Smuffin 	int	i;
11000Sstevel@tonic-gate 
11010Sstevel@tonic-gate 	lgf++;
11020Sstevel@tonic-gate 	it = itmac = 0;
11030Sstevel@tonic-gate 	noscale++;
11040Sstevel@tonic-gate 	skip();
11050Sstevel@tonic-gate 	i = atoi();
11060Sstevel@tonic-gate 	skip();
11070Sstevel@tonic-gate 	if (!nonumb && (itmac = getrq()))
11080Sstevel@tonic-gate 		it = i;
11090Sstevel@tonic-gate 	noscale = 0;
1110*217Smuffin 
1111*217Smuffin 	return (0);
11120Sstevel@tonic-gate }
11130Sstevel@tonic-gate 
11140Sstevel@tonic-gate 
1115*217Smuffin int
casemc()11160Sstevel@tonic-gate casemc()
11170Sstevel@tonic-gate {
1118*217Smuffin 	int	i;
11190Sstevel@tonic-gate 
11200Sstevel@tonic-gate 	if (icf > 1)
11210Sstevel@tonic-gate 		ic = 0;
11220Sstevel@tonic-gate 	icf = 0;
11230Sstevel@tonic-gate 	if (skip())
1124*217Smuffin 		return (0);
11250Sstevel@tonic-gate 	ic = getch();
11260Sstevel@tonic-gate 	icf = 1;
11270Sstevel@tonic-gate 	skip();
11280Sstevel@tonic-gate 	i = max(hnumb((int *)0), 0);
11290Sstevel@tonic-gate 	if (!nonumb)
11300Sstevel@tonic-gate 		ics = i;
1131*217Smuffin 
1132*217Smuffin 	return (0);
11330Sstevel@tonic-gate }
11340Sstevel@tonic-gate 
11350Sstevel@tonic-gate 
1136*217Smuffin int
casemk()11370Sstevel@tonic-gate casemk()
11380Sstevel@tonic-gate {
1139*217Smuffin 	int	i, j;
11400Sstevel@tonic-gate 
11410Sstevel@tonic-gate 	if (dip != d)
11420Sstevel@tonic-gate 		j = dip->dnl;
11430Sstevel@tonic-gate 	else
11440Sstevel@tonic-gate 		j = numtab[NL].val;
11450Sstevel@tonic-gate 	if (skip()) {
11460Sstevel@tonic-gate 		dip->mkline = j;
1147*217Smuffin 		return (0);
11480Sstevel@tonic-gate 	}
11490Sstevel@tonic-gate 	if ((i = getrq()) == 0)
1150*217Smuffin 		return (0);
11510Sstevel@tonic-gate 	numtab[findr(i)].val = j;
1152*217Smuffin 
1153*217Smuffin 	return (0);
11540Sstevel@tonic-gate }
11550Sstevel@tonic-gate 
11560Sstevel@tonic-gate 
1157*217Smuffin int
casesv()11580Sstevel@tonic-gate casesv()
11590Sstevel@tonic-gate {
1160*217Smuffin 	int	i;
11610Sstevel@tonic-gate 
11620Sstevel@tonic-gate 	skip();
11630Sstevel@tonic-gate 	if ((i = vnumb((int *)0)) < 0)
1164*217Smuffin 		return (0);
11650Sstevel@tonic-gate 	if (nonumb)
11660Sstevel@tonic-gate 		i = 1;
11670Sstevel@tonic-gate 	sv += i;
11680Sstevel@tonic-gate 	caseos();
1169*217Smuffin 
1170*217Smuffin 	return (0);
11710Sstevel@tonic-gate }
11720Sstevel@tonic-gate 
11730Sstevel@tonic-gate 
1174*217Smuffin int
caseos()11750Sstevel@tonic-gate caseos()
11760Sstevel@tonic-gate {
1177*217Smuffin 	int	savlss;
11780Sstevel@tonic-gate 
11790Sstevel@tonic-gate 	if (sv <= findt1()) {
11800Sstevel@tonic-gate 		savlss = lss;
11810Sstevel@tonic-gate 		lss = sv;
11820Sstevel@tonic-gate 		newline(0);
11830Sstevel@tonic-gate 		lss = savlss;
11840Sstevel@tonic-gate 		sv = 0;
11850Sstevel@tonic-gate 	}
1186*217Smuffin 
1187*217Smuffin 	return (0);
11880Sstevel@tonic-gate }
11890Sstevel@tonic-gate 
11900Sstevel@tonic-gate 
1191*217Smuffin int
casenm()11920Sstevel@tonic-gate casenm()
11930Sstevel@tonic-gate {
1194*217Smuffin 	int	i;
11950Sstevel@tonic-gate 
11960Sstevel@tonic-gate 	lnmod = nn = 0;
11970Sstevel@tonic-gate 	if (skip())
1198*217Smuffin 		return (0);
11990Sstevel@tonic-gate 	lnmod++;
12000Sstevel@tonic-gate 	noscale++;
12010Sstevel@tonic-gate 	i = inumb(&numtab[LN].val);
12020Sstevel@tonic-gate 	if (!nonumb)
12030Sstevel@tonic-gate 		numtab[LN].val = max(i, 0);
12040Sstevel@tonic-gate 	getnm(&ndf, 1);
12050Sstevel@tonic-gate 	getnm(&nms, 0);
12060Sstevel@tonic-gate 	getnm(&ni, 0);
12070Sstevel@tonic-gate 	noscale = 0;
12080Sstevel@tonic-gate 	nmbits = chbits;
1209*217Smuffin 
1210*217Smuffin 	return (0);
12110Sstevel@tonic-gate }
12120Sstevel@tonic-gate 
12130Sstevel@tonic-gate 
1214*217Smuffin int
getnm(p,min)12150Sstevel@tonic-gate getnm(p, min)
12160Sstevel@tonic-gate int	*p, min;
12170Sstevel@tonic-gate {
1218*217Smuffin 	int	i;
12190Sstevel@tonic-gate 
12200Sstevel@tonic-gate 	eat(' ');
12210Sstevel@tonic-gate 	if (skip())
1222*217Smuffin 		return (0);
12230Sstevel@tonic-gate 	i = atoi();
12240Sstevel@tonic-gate 	if (nonumb)
1225*217Smuffin 		return (0);
12260Sstevel@tonic-gate 	*p = max(i, min);
1227*217Smuffin 
1228*217Smuffin 	return (0);
12290Sstevel@tonic-gate }
12300Sstevel@tonic-gate 
12310Sstevel@tonic-gate 
1232*217Smuffin int
casenn()12330Sstevel@tonic-gate casenn()
12340Sstevel@tonic-gate {
12350Sstevel@tonic-gate 	noscale++;
12360Sstevel@tonic-gate 	skip();
12370Sstevel@tonic-gate 	nn = max(atoi(), 1);
12380Sstevel@tonic-gate 	noscale = 0;
1239*217Smuffin 
1240*217Smuffin 	return (0);
12410Sstevel@tonic-gate }
12420Sstevel@tonic-gate 
12430Sstevel@tonic-gate 
1244*217Smuffin int
caseab()12450Sstevel@tonic-gate caseab()
12460Sstevel@tonic-gate {
12470Sstevel@tonic-gate 	casetm(1);
12480Sstevel@tonic-gate 	done3(0);
1249*217Smuffin 
1250*217Smuffin 	return (0);
12510Sstevel@tonic-gate }
12520Sstevel@tonic-gate 
12530Sstevel@tonic-gate 
12540Sstevel@tonic-gate #ifdef	NROFF
12550Sstevel@tonic-gate /*
12560Sstevel@tonic-gate  * The following routines are concerned with setting terminal options.
12570Sstevel@tonic-gate  *	The manner of doing this differs between research/Berkeley systems
12580Sstevel@tonic-gate  *	and UNIX System V systems (i.e. DOCUMENTER'S WORKBENCH)
12590Sstevel@tonic-gate  *	The distinction is controlled by the #define'd variable USG,
12600Sstevel@tonic-gate  *	which must be set by System V users.
12610Sstevel@tonic-gate  */
12620Sstevel@tonic-gate 
12630Sstevel@tonic-gate 
12640Sstevel@tonic-gate #ifdef	USG
12650Sstevel@tonic-gate #include <termio.h>
12660Sstevel@tonic-gate #define	ECHO_USG (ECHO | ECHOE | ECHOK | ECHONL)
12670Sstevel@tonic-gate struct termio	ttys;
12680Sstevel@tonic-gate #else
12690Sstevel@tonic-gate #include <sgtty.h>
12700Sstevel@tonic-gate struct	sgttyb	ttys[2];
1271*217Smuffin #endif	/* USG */
12720Sstevel@tonic-gate 
12730Sstevel@tonic-gate int	ttysave[2] = {-1, -1};
12740Sstevel@tonic-gate 
1275*217Smuffin int
save_tty()12760Sstevel@tonic-gate save_tty()			/*save any tty settings that may be changed*/
12770Sstevel@tonic-gate {
12780Sstevel@tonic-gate 
12790Sstevel@tonic-gate #ifdef	USG
12800Sstevel@tonic-gate 	if (ioctl(0, TCGETA, &ttys) >= 0)
12810Sstevel@tonic-gate 		ttysave[0] = ttys.c_lflag;
12820Sstevel@tonic-gate #else
12830Sstevel@tonic-gate 	if (gtty(0, &ttys[0]) >= 0)
12840Sstevel@tonic-gate 		ttysave[0] = ttys[0].sg_flags;
12850Sstevel@tonic-gate 	if (gtty(1, &ttys[1]) >= 0)
12860Sstevel@tonic-gate 		ttysave[1] = ttys[1].sg_flags;
1287*217Smuffin #endif	/* USG */
12880Sstevel@tonic-gate 
1289*217Smuffin 	return (0);
12900Sstevel@tonic-gate }
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 
1293*217Smuffin int
restore_tty()12940Sstevel@tonic-gate restore_tty()			/*restore tty settings from beginning*/
12950Sstevel@tonic-gate {
12960Sstevel@tonic-gate 
12970Sstevel@tonic-gate 	if (ttysave[0] != -1) {
12980Sstevel@tonic-gate #ifdef	USG
12990Sstevel@tonic-gate 		ttys.c_lflag = ttysave[0];
13000Sstevel@tonic-gate 		ioctl(0, TCSETAW, &ttys);
13010Sstevel@tonic-gate #else
13020Sstevel@tonic-gate 		ttys[0].sg_flags = ttysave[0];
13030Sstevel@tonic-gate 		stty(0, &ttys[0]);
13040Sstevel@tonic-gate 	}
13050Sstevel@tonic-gate 	if (ttysave[1] != -1) {
13060Sstevel@tonic-gate 		ttys[1].sg_flags = ttysave[1];
13070Sstevel@tonic-gate 		stty(1, &ttys[1]);
1308*217Smuffin #endif	/* USG */
13090Sstevel@tonic-gate 	}
1310*217Smuffin 
1311*217Smuffin 	return (0);
13120Sstevel@tonic-gate }
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate 
1315*217Smuffin int
set_tty()13160Sstevel@tonic-gate set_tty()			/*this replaces the use of bset and breset*/
13170Sstevel@tonic-gate {
13180Sstevel@tonic-gate 
13190Sstevel@tonic-gate #ifndef	USG			/*for research/BSD only, reset CRMOD*/
13200Sstevel@tonic-gate 	if (ttysave[1] == -1)
13210Sstevel@tonic-gate 		save_tty();
13220Sstevel@tonic-gate 	if (ttysave[1] != -1) {
13230Sstevel@tonic-gate 		ttys[1].sg_flags &= ~CRMOD;
13240Sstevel@tonic-gate 		stty(1, &ttys[1]);
13250Sstevel@tonic-gate 	}
1326*217Smuffin #endif	/* USG */
13270Sstevel@tonic-gate 
1328*217Smuffin 	return (0);
13290Sstevel@tonic-gate }
13300Sstevel@tonic-gate 
13310Sstevel@tonic-gate 
1332*217Smuffin int
echo_off()13330Sstevel@tonic-gate echo_off()			/*turn off ECHO for .rd in "-q" mode*/
13340Sstevel@tonic-gate {
13350Sstevel@tonic-gate 	if (ttysave[0] == -1)
1336*217Smuffin 		return (0);
13370Sstevel@tonic-gate 
13380Sstevel@tonic-gate #ifdef	USG
13390Sstevel@tonic-gate 	ttys.c_lflag &= ~ECHO_USG;
13400Sstevel@tonic-gate 	ioctl(0, TCSETAW, &ttys);
13410Sstevel@tonic-gate #else
13420Sstevel@tonic-gate 	ttys[0].sg_flags &= ~ECHO;
13430Sstevel@tonic-gate 	stty(0, &ttys[0]);
1344*217Smuffin #endif	/* USG */
1345*217Smuffin 
1346*217Smuffin 	return (0);
13470Sstevel@tonic-gate 
13480Sstevel@tonic-gate }
13490Sstevel@tonic-gate 
13500Sstevel@tonic-gate 
1351*217Smuffin int
echo_on()13520Sstevel@tonic-gate echo_on()			/*restore ECHO after .rd in "-q" mode*/
13530Sstevel@tonic-gate {
13540Sstevel@tonic-gate 	if (ttysave[0] == -1)
1355*217Smuffin 		return (0);
13560Sstevel@tonic-gate 
13570Sstevel@tonic-gate #ifdef	USG
13580Sstevel@tonic-gate 	ttys.c_lflag |= ECHO_USG;
13590Sstevel@tonic-gate 	ioctl(0, TCSETAW, &ttys);
13600Sstevel@tonic-gate #else
13610Sstevel@tonic-gate 	ttys[0].sg_flags |= ECHO;
13620Sstevel@tonic-gate 	stty(0, &ttys[0]);
1363*217Smuffin #endif	/* USG */
13640Sstevel@tonic-gate 
1365*217Smuffin 	return (0);
13660Sstevel@tonic-gate }
1367*217Smuffin #endif	/* NROFF */
1368