xref: /titanic_41/usr/src/cmd/troff/n5.c (revision e5190c108bde19ca4d7c03b1d1eab7b00bd3a1ed)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
40*e5190c10Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*e5190c10Smuffin 
427c478bd9Sstevel@tonic-gate #ifdef 	EUC
437c478bd9Sstevel@tonic-gate #ifdef	NROFF
447c478bd9Sstevel@tonic-gate #include <stddef.h>
457c478bd9Sstevel@tonic-gate #include <stdlib.h>
467c478bd9Sstevel@tonic-gate #include <widec.h>
477c478bd9Sstevel@tonic-gate #endif	/* NROFF */
487c478bd9Sstevel@tonic-gate #endif	/* EUC */
497c478bd9Sstevel@tonic-gate #include <string.h>
507c478bd9Sstevel@tonic-gate #include "tdef.h"
517c478bd9Sstevel@tonic-gate #include "ext.h"
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * troff5.c
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * misc processing requests
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate int	iflist[NIF];
607c478bd9Sstevel@tonic-gate int	ifx;
617c478bd9Sstevel@tonic-gate 
62*e5190c10Smuffin int
casead()637c478bd9Sstevel@tonic-gate casead()
647c478bd9Sstevel@tonic-gate {
65*e5190c10Smuffin 	int	i;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	ad = 1;
687c478bd9Sstevel@tonic-gate 	/*leave admod alone*/
697c478bd9Sstevel@tonic-gate 	if (skip())
70*e5190c10Smuffin 		return (0);
717c478bd9Sstevel@tonic-gate 	switch (i = cbits(getch())) {
727c478bd9Sstevel@tonic-gate 	case 'r':	/*right adj, left ragged*/
737c478bd9Sstevel@tonic-gate 		admod = 2;
747c478bd9Sstevel@tonic-gate 		break;
757c478bd9Sstevel@tonic-gate 	case 'l':	/*left adj, right ragged*/
767c478bd9Sstevel@tonic-gate 		admod = ad = 0;	/*same as casena*/
777c478bd9Sstevel@tonic-gate 		break;
787c478bd9Sstevel@tonic-gate 	case 'c':	/*centered adj*/
797c478bd9Sstevel@tonic-gate 		admod = 1;
807c478bd9Sstevel@tonic-gate 		break;
817c478bd9Sstevel@tonic-gate 	case 'b':
827c478bd9Sstevel@tonic-gate 	case 'n':
837c478bd9Sstevel@tonic-gate 		admod = 0;
847c478bd9Sstevel@tonic-gate 		break;
857c478bd9Sstevel@tonic-gate 	case '0':
867c478bd9Sstevel@tonic-gate 	case '2':
877c478bd9Sstevel@tonic-gate 	case '4':
887c478bd9Sstevel@tonic-gate 		ad = 0;
897c478bd9Sstevel@tonic-gate 	case '1':
907c478bd9Sstevel@tonic-gate 	case '3':
917c478bd9Sstevel@tonic-gate 	case '5':
927c478bd9Sstevel@tonic-gate 		admod = (i - '0') / 2;
937c478bd9Sstevel@tonic-gate 	}
94*e5190c10Smuffin 
95*e5190c10Smuffin 	return (0);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 
99*e5190c10Smuffin int
casena()1007c478bd9Sstevel@tonic-gate casena()
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	ad = 0;
103*e5190c10Smuffin 
104*e5190c10Smuffin 	return (0);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 
108*e5190c10Smuffin int
casefi()1097c478bd9Sstevel@tonic-gate casefi()
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	tbreak();
1127c478bd9Sstevel@tonic-gate 	fi++;
1137c478bd9Sstevel@tonic-gate 	pendnf = 0;
1147c478bd9Sstevel@tonic-gate 	lnsize = LNSIZE;
115*e5190c10Smuffin 
116*e5190c10Smuffin 	return (0);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
120*e5190c10Smuffin int
casenf()1217c478bd9Sstevel@tonic-gate casenf()
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	tbreak();
1247c478bd9Sstevel@tonic-gate 	fi = 0;
125*e5190c10Smuffin 
126*e5190c10Smuffin 	return (0);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
130*e5190c10Smuffin int
casers()1317c478bd9Sstevel@tonic-gate casers()
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	dip->nls = 0;
134*e5190c10Smuffin 
135*e5190c10Smuffin 	return (0);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 
139*e5190c10Smuffin int
casens()1407c478bd9Sstevel@tonic-gate casens()
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate 	dip->nls++;
143*e5190c10Smuffin 
144*e5190c10Smuffin 	return (0);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 
148*e5190c10Smuffin int
chget(c)1497c478bd9Sstevel@tonic-gate chget(c)
1507c478bd9Sstevel@tonic-gate int	c;
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate 	tchar i;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
1557c478bd9Sstevel@tonic-gate 		ch = i;
1567c478bd9Sstevel@tonic-gate 		return(c);
1577c478bd9Sstevel@tonic-gate 	} else
1587c478bd9Sstevel@tonic-gate 		return(i & BYTEMASK);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
162*e5190c10Smuffin int
casecc()1637c478bd9Sstevel@tonic-gate casecc()
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	cc = chget('.');
166*e5190c10Smuffin 
167*e5190c10Smuffin 	return (0);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 
171*e5190c10Smuffin int
casec2()1727c478bd9Sstevel@tonic-gate casec2()
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	c2 = chget('\'');
175*e5190c10Smuffin 
176*e5190c10Smuffin 	return (0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 
180*e5190c10Smuffin int
casehc()1817c478bd9Sstevel@tonic-gate casehc()
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	ohc = chget(OHC);
184*e5190c10Smuffin 
185*e5190c10Smuffin 	return (0);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 
189*e5190c10Smuffin int
casetc()1907c478bd9Sstevel@tonic-gate casetc()
1917c478bd9Sstevel@tonic-gate {
1927c478bd9Sstevel@tonic-gate 	tabc = chget(0);
193*e5190c10Smuffin 
194*e5190c10Smuffin 	return (0);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 
198*e5190c10Smuffin int
caselc()1997c478bd9Sstevel@tonic-gate caselc()
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate 	dotc = chget(0);
202*e5190c10Smuffin 
203*e5190c10Smuffin 	return (0);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 
207*e5190c10Smuffin int
casehy()2087c478bd9Sstevel@tonic-gate casehy()
2097c478bd9Sstevel@tonic-gate {
210*e5190c10Smuffin 	int	i;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	hyf = 1;
2137c478bd9Sstevel@tonic-gate 	if (skip())
214*e5190c10Smuffin 		return (0);
2157c478bd9Sstevel@tonic-gate 	noscale++;
2167c478bd9Sstevel@tonic-gate 	i = atoi();
2177c478bd9Sstevel@tonic-gate 	noscale = 0;
2187c478bd9Sstevel@tonic-gate 	if (nonumb)
219*e5190c10Smuffin 		return (0);
2207c478bd9Sstevel@tonic-gate 	hyf = max(i, 0);
221*e5190c10Smuffin 
222*e5190c10Smuffin 	return (0);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 
226*e5190c10Smuffin int
casenh()2277c478bd9Sstevel@tonic-gate casenh()
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	hyf = 0;
230*e5190c10Smuffin 
231*e5190c10Smuffin 	return (0);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 
235*e5190c10Smuffin int
max(aa,bb)2367c478bd9Sstevel@tonic-gate max(aa, bb)
2377c478bd9Sstevel@tonic-gate int	aa, bb;
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate 	if (aa > bb)
2407c478bd9Sstevel@tonic-gate 		return(aa);
2417c478bd9Sstevel@tonic-gate 	else
2427c478bd9Sstevel@tonic-gate 		return(bb);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 
246*e5190c10Smuffin int
casece()2477c478bd9Sstevel@tonic-gate casece()
2487c478bd9Sstevel@tonic-gate {
249*e5190c10Smuffin 	int	i;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	noscale++;
2527c478bd9Sstevel@tonic-gate 	skip();
2537c478bd9Sstevel@tonic-gate 	i = max(atoi(), 0);
2547c478bd9Sstevel@tonic-gate 	if (nonumb)
2557c478bd9Sstevel@tonic-gate 		i = 1;
2567c478bd9Sstevel@tonic-gate 	tbreak();
2577c478bd9Sstevel@tonic-gate 	ce = i;
2587c478bd9Sstevel@tonic-gate 	noscale = 0;
259*e5190c10Smuffin 
260*e5190c10Smuffin 	return (0);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 
264*e5190c10Smuffin int
casein()2657c478bd9Sstevel@tonic-gate casein()
2667c478bd9Sstevel@tonic-gate {
267*e5190c10Smuffin 	int	i;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	if (skip())
2707c478bd9Sstevel@tonic-gate 		i = in1;
2717c478bd9Sstevel@tonic-gate 	else
2727c478bd9Sstevel@tonic-gate 		i = max(hnumb(&in), 0);
2737c478bd9Sstevel@tonic-gate 	tbreak();
2747c478bd9Sstevel@tonic-gate 	in1 = in;
2757c478bd9Sstevel@tonic-gate 	in = i;
2767c478bd9Sstevel@tonic-gate 	if (!nc) {
2777c478bd9Sstevel@tonic-gate 		un = in;
2787c478bd9Sstevel@tonic-gate 		setnel();
2797c478bd9Sstevel@tonic-gate 	}
280*e5190c10Smuffin 
281*e5190c10Smuffin 	return (0);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 
285*e5190c10Smuffin int
casell()2867c478bd9Sstevel@tonic-gate casell()
2877c478bd9Sstevel@tonic-gate {
288*e5190c10Smuffin 	int	i;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	if (skip())
2917c478bd9Sstevel@tonic-gate 		i = ll1;
2927c478bd9Sstevel@tonic-gate 	else
2937c478bd9Sstevel@tonic-gate 		i = max(hnumb(&ll), INCH / 10);
2947c478bd9Sstevel@tonic-gate 	ll1 = ll;
2957c478bd9Sstevel@tonic-gate 	ll = i;
2967c478bd9Sstevel@tonic-gate 	setnel();
297*e5190c10Smuffin 
298*e5190c10Smuffin 	return (0);
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 
302*e5190c10Smuffin int
caselt()3037c478bd9Sstevel@tonic-gate caselt()
3047c478bd9Sstevel@tonic-gate {
305*e5190c10Smuffin 	int	i;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	if (skip())
3087c478bd9Sstevel@tonic-gate 		i = lt1;
3097c478bd9Sstevel@tonic-gate 	else
3107c478bd9Sstevel@tonic-gate 		i = max(hnumb(&lt), 0);
3117c478bd9Sstevel@tonic-gate 	lt1 = lt;
3127c478bd9Sstevel@tonic-gate 	lt = i;
313*e5190c10Smuffin 
314*e5190c10Smuffin 	return (0);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 
318*e5190c10Smuffin int
caseti()3197c478bd9Sstevel@tonic-gate caseti()
3207c478bd9Sstevel@tonic-gate {
321*e5190c10Smuffin 	int	i;
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	if (skip())
324*e5190c10Smuffin 		return (0);
3257c478bd9Sstevel@tonic-gate 	i = max(hnumb(&in), 0);
3267c478bd9Sstevel@tonic-gate 	tbreak();
3277c478bd9Sstevel@tonic-gate 	un1 = i;
3287c478bd9Sstevel@tonic-gate 	setnel();
329*e5190c10Smuffin 
330*e5190c10Smuffin 	return (0);
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 
334*e5190c10Smuffin int
casels()3357c478bd9Sstevel@tonic-gate casels()
3367c478bd9Sstevel@tonic-gate {
337*e5190c10Smuffin 	int	i;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	noscale++;
3407c478bd9Sstevel@tonic-gate 	if (skip())
3417c478bd9Sstevel@tonic-gate 		i = ls1;
3427c478bd9Sstevel@tonic-gate 	else
3437c478bd9Sstevel@tonic-gate 		i = max(inumb(&ls), 1);
3447c478bd9Sstevel@tonic-gate 	ls1 = ls;
3457c478bd9Sstevel@tonic-gate 	ls = i;
3467c478bd9Sstevel@tonic-gate 	noscale = 0;
347*e5190c10Smuffin 
348*e5190c10Smuffin 	return (0);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 
352*e5190c10Smuffin int
casepo()3537c478bd9Sstevel@tonic-gate casepo()
3547c478bd9Sstevel@tonic-gate {
355*e5190c10Smuffin 	int	i;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	if (skip())
3587c478bd9Sstevel@tonic-gate 		i = po1;
3597c478bd9Sstevel@tonic-gate 	else
3607c478bd9Sstevel@tonic-gate 		i = max(hnumb(&po), 0);
3617c478bd9Sstevel@tonic-gate 	po1 = po;
3627c478bd9Sstevel@tonic-gate 	po = i;
3637c478bd9Sstevel@tonic-gate #ifndef NROFF
3647c478bd9Sstevel@tonic-gate 	if (!ascii)
3657c478bd9Sstevel@tonic-gate 		esc += po - po1;
3667c478bd9Sstevel@tonic-gate #endif
367*e5190c10Smuffin 	return (0);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 
371*e5190c10Smuffin int
casepl()3727c478bd9Sstevel@tonic-gate casepl()
3737c478bd9Sstevel@tonic-gate {
374*e5190c10Smuffin 	int	i;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	skip();
3777c478bd9Sstevel@tonic-gate 	if ((i = vnumb(&pl)) == 0)
3787c478bd9Sstevel@tonic-gate 		pl = 11 * INCH; /*11in*/
3797c478bd9Sstevel@tonic-gate 	else
3807c478bd9Sstevel@tonic-gate 		pl = i;
3817c478bd9Sstevel@tonic-gate 	if (numtab[NL].val > pl)
3827c478bd9Sstevel@tonic-gate 		numtab[NL].val = pl;
383*e5190c10Smuffin 
384*e5190c10Smuffin 	return (0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 
388*e5190c10Smuffin int
casewh()3897c478bd9Sstevel@tonic-gate casewh()
3907c478bd9Sstevel@tonic-gate {
391*e5190c10Smuffin 	int	i, j, k;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	lgf++;
3947c478bd9Sstevel@tonic-gate 	skip();
3957c478bd9Sstevel@tonic-gate 	i = vnumb((int *)0);
3967c478bd9Sstevel@tonic-gate 	if (nonumb)
397*e5190c10Smuffin 		return (0);
3987c478bd9Sstevel@tonic-gate 	skip();
3997c478bd9Sstevel@tonic-gate 	j = getrq();
4007c478bd9Sstevel@tonic-gate 	if ((k = findn(i)) != NTRAP) {
4017c478bd9Sstevel@tonic-gate 		mlist[k] = j;
402*e5190c10Smuffin 		return (0);
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 	for (k = 0; k < NTRAP; k++)
4057c478bd9Sstevel@tonic-gate 		if (mlist[k] == 0)
4067c478bd9Sstevel@tonic-gate 			break;
4077c478bd9Sstevel@tonic-gate 	if (k == NTRAP) {
4087c478bd9Sstevel@tonic-gate 		flusho();
4097c478bd9Sstevel@tonic-gate 		errprint(gettext("cannot plant trap."));
410*e5190c10Smuffin 		return (0);
4117c478bd9Sstevel@tonic-gate 	}
4127c478bd9Sstevel@tonic-gate 	mlist[k] = j;
4137c478bd9Sstevel@tonic-gate 	nlist[k] = i;
414*e5190c10Smuffin 
415*e5190c10Smuffin 	return (0);
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 
419*e5190c10Smuffin int
casech()4207c478bd9Sstevel@tonic-gate casech()
4217c478bd9Sstevel@tonic-gate {
422*e5190c10Smuffin 	int	i, j, k;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	lgf++;
4257c478bd9Sstevel@tonic-gate 	skip();
4267c478bd9Sstevel@tonic-gate 	if (!(j = getrq()))
427*e5190c10Smuffin 		return (0);
4287c478bd9Sstevel@tonic-gate 	else
4297c478bd9Sstevel@tonic-gate 		for (k = 0; k < NTRAP; k++)
4307c478bd9Sstevel@tonic-gate 			if (mlist[k] == j)
4317c478bd9Sstevel@tonic-gate 				break;
4327c478bd9Sstevel@tonic-gate 	if (k == NTRAP)
433*e5190c10Smuffin 		return (0);
4347c478bd9Sstevel@tonic-gate 	skip();
4357c478bd9Sstevel@tonic-gate 	i = vnumb((int *)0);
4367c478bd9Sstevel@tonic-gate 	if (nonumb)
4377c478bd9Sstevel@tonic-gate 		mlist[k] = 0;
4387c478bd9Sstevel@tonic-gate 	nlist[k] = i;
439*e5190c10Smuffin 
440*e5190c10Smuffin 	return (0);
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 
444*e5190c10Smuffin int
findn(i)4457c478bd9Sstevel@tonic-gate findn(i)
4467c478bd9Sstevel@tonic-gate int	i;
4477c478bd9Sstevel@tonic-gate {
448*e5190c10Smuffin 	int	k;
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	for (k = 0; k < NTRAP; k++)
4517c478bd9Sstevel@tonic-gate 		if ((nlist[k] == i) && (mlist[k] != 0))
4527c478bd9Sstevel@tonic-gate 			break;
4537c478bd9Sstevel@tonic-gate 	return(k);
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 
457*e5190c10Smuffin int
casepn()4587c478bd9Sstevel@tonic-gate casepn()
4597c478bd9Sstevel@tonic-gate {
460*e5190c10Smuffin 	int	i;
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	skip();
4637c478bd9Sstevel@tonic-gate 	noscale++;
4647c478bd9Sstevel@tonic-gate 	i = max(inumb(&numtab[PN].val), 0);
4657c478bd9Sstevel@tonic-gate 	noscale = 0;
4667c478bd9Sstevel@tonic-gate 	if (!nonumb) {
4677c478bd9Sstevel@tonic-gate 		npn = i;
4687c478bd9Sstevel@tonic-gate 		npnflg++;
4697c478bd9Sstevel@tonic-gate 	}
470*e5190c10Smuffin 
471*e5190c10Smuffin 	return (0);
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 
475*e5190c10Smuffin int
casebp()4767c478bd9Sstevel@tonic-gate casebp()
4777c478bd9Sstevel@tonic-gate {
478*e5190c10Smuffin 	int	i;
479*e5190c10Smuffin 	struct s *savframe;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	if (dip != d)
482*e5190c10Smuffin 		return (0);
4837c478bd9Sstevel@tonic-gate 	savframe = frame;
4847c478bd9Sstevel@tonic-gate 	skip();
4857c478bd9Sstevel@tonic-gate 	if ((i = inumb(&numtab[PN].val)) < 0)
4867c478bd9Sstevel@tonic-gate 		i = 0;
4877c478bd9Sstevel@tonic-gate 	tbreak();
4887c478bd9Sstevel@tonic-gate 	if (!nonumb) {
4897c478bd9Sstevel@tonic-gate 		npn = i;
4907c478bd9Sstevel@tonic-gate 		npnflg++;
4917c478bd9Sstevel@tonic-gate 	} else if (dip->nls)
492*e5190c10Smuffin 		return (0);
4937c478bd9Sstevel@tonic-gate 	eject(savframe);
494*e5190c10Smuffin 
495*e5190c10Smuffin 	return (0);
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 
499*e5190c10Smuffin int
casetm(ab)5007c478bd9Sstevel@tonic-gate casetm(ab)
5017c478bd9Sstevel@tonic-gate 	int ab;
5027c478bd9Sstevel@tonic-gate {
503*e5190c10Smuffin 	int	i;
5047c478bd9Sstevel@tonic-gate 	char	tmbuf[NTM];
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	lgf++;
5077c478bd9Sstevel@tonic-gate 	copyf++;
5087c478bd9Sstevel@tonic-gate 	if (skip() && ab)
5097c478bd9Sstevel@tonic-gate 		errprint(gettext("User Abort"));
5107c478bd9Sstevel@tonic-gate 	for (i = 0; i < NTM - 2; )
5117c478bd9Sstevel@tonic-gate 		if ((tmbuf[i++] = getch()) == '\n')
5127c478bd9Sstevel@tonic-gate 			break;
5137c478bd9Sstevel@tonic-gate 	if (i == NTM - 2)
5147c478bd9Sstevel@tonic-gate 		tmbuf[i++] = '\n';
5157c478bd9Sstevel@tonic-gate 	tmbuf[i] = 0;
5167c478bd9Sstevel@tonic-gate 	if (ab)	/* truncate output */
5177c478bd9Sstevel@tonic-gate 		obufp = obuf;	/* should be a function in n2.c */
5187c478bd9Sstevel@tonic-gate 	flusho();
5197c478bd9Sstevel@tonic-gate 	fdprintf(stderr, "%s", tmbuf);
5207c478bd9Sstevel@tonic-gate 	copyf--;
5217c478bd9Sstevel@tonic-gate 	lgf--;
522*e5190c10Smuffin 
523*e5190c10Smuffin 	return (0);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 
527*e5190c10Smuffin int
casesp(a)5287c478bd9Sstevel@tonic-gate casesp(a)
5297c478bd9Sstevel@tonic-gate int	a;
5307c478bd9Sstevel@tonic-gate {
531*e5190c10Smuffin 	int	i, j, savlss;
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	tbreak();
5347c478bd9Sstevel@tonic-gate 	if (dip->nls || trap)
535*e5190c10Smuffin 		return (0);
5367c478bd9Sstevel@tonic-gate 	i = findt1();
5377c478bd9Sstevel@tonic-gate 	if (!a) {
5387c478bd9Sstevel@tonic-gate 		skip();
5397c478bd9Sstevel@tonic-gate 		j = vnumb((int *)0);
5407c478bd9Sstevel@tonic-gate 		if (nonumb)
5417c478bd9Sstevel@tonic-gate 			j = lss;
5427c478bd9Sstevel@tonic-gate 	} else
5437c478bd9Sstevel@tonic-gate 		j = a;
5447c478bd9Sstevel@tonic-gate 	if (j == 0)
545*e5190c10Smuffin 		return (0);
5467c478bd9Sstevel@tonic-gate 	if (i < j)
5477c478bd9Sstevel@tonic-gate 		j = i;
5487c478bd9Sstevel@tonic-gate 	savlss = lss;
5497c478bd9Sstevel@tonic-gate 	if (dip != d)
5507c478bd9Sstevel@tonic-gate 		i = dip->dnl;
5517c478bd9Sstevel@tonic-gate 	else
5527c478bd9Sstevel@tonic-gate 		i = numtab[NL].val;
5537c478bd9Sstevel@tonic-gate 	if ((i + j) < 0)
5547c478bd9Sstevel@tonic-gate 		j = -i;
5557c478bd9Sstevel@tonic-gate 	lss = j;
5567c478bd9Sstevel@tonic-gate 	newline(0);
5577c478bd9Sstevel@tonic-gate 	lss = savlss;
558*e5190c10Smuffin 
559*e5190c10Smuffin 	return (0);
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 
563*e5190c10Smuffin int
casert()5647c478bd9Sstevel@tonic-gate casert()
5657c478bd9Sstevel@tonic-gate {
566*e5190c10Smuffin 	int	a, *p;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	skip();
5697c478bd9Sstevel@tonic-gate 	if (dip != d)
5707c478bd9Sstevel@tonic-gate 		p = &dip->dnl;
5717c478bd9Sstevel@tonic-gate 	else
5727c478bd9Sstevel@tonic-gate 		p = &numtab[NL].val;
5737c478bd9Sstevel@tonic-gate 	a = vnumb(p);
5747c478bd9Sstevel@tonic-gate 	if (nonumb)
5757c478bd9Sstevel@tonic-gate 		a = dip->mkline;
5767c478bd9Sstevel@tonic-gate 	if ((a < 0) || (a >= *p))
577*e5190c10Smuffin 		return (0);
5787c478bd9Sstevel@tonic-gate 	nb++;
5797c478bd9Sstevel@tonic-gate 	casesp(a - *p);
580*e5190c10Smuffin 
581*e5190c10Smuffin 	return (0);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 
585*e5190c10Smuffin int
caseem()5867c478bd9Sstevel@tonic-gate caseem()
5877c478bd9Sstevel@tonic-gate {
5887c478bd9Sstevel@tonic-gate 	lgf++;
5897c478bd9Sstevel@tonic-gate 	skip();
5907c478bd9Sstevel@tonic-gate 	em = getrq();
591*e5190c10Smuffin 
592*e5190c10Smuffin 	return (0);
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 
596*e5190c10Smuffin int
casefl()5977c478bd9Sstevel@tonic-gate casefl()
5987c478bd9Sstevel@tonic-gate {
5997c478bd9Sstevel@tonic-gate 	tbreak();
6007c478bd9Sstevel@tonic-gate 	flusho();
601*e5190c10Smuffin 
602*e5190c10Smuffin 	return (0);
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 
606*e5190c10Smuffin int
caseev()6077c478bd9Sstevel@tonic-gate caseev()
6087c478bd9Sstevel@tonic-gate {
609*e5190c10Smuffin 	int	nxev;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	if (skip()) {
6127c478bd9Sstevel@tonic-gate e0:
6137c478bd9Sstevel@tonic-gate 		if (evi == 0)
614*e5190c10Smuffin 			return (0);
6157c478bd9Sstevel@tonic-gate 		nxev =  evlist[--evi];
6167c478bd9Sstevel@tonic-gate 		goto e1;
6177c478bd9Sstevel@tonic-gate 	}
6187c478bd9Sstevel@tonic-gate 	noscale++;
6197c478bd9Sstevel@tonic-gate 	nxev = atoi();
6207c478bd9Sstevel@tonic-gate 	noscale = 0;
6217c478bd9Sstevel@tonic-gate 	if (nonumb)
6227c478bd9Sstevel@tonic-gate 		goto e0;
6237c478bd9Sstevel@tonic-gate 	flushi();
6247c478bd9Sstevel@tonic-gate 	if ((nxev >= NEV) || (nxev < 0) || (evi >= EVLSZ)) {
6257c478bd9Sstevel@tonic-gate 		flusho();
6267c478bd9Sstevel@tonic-gate 		errprint(gettext("cannot do ev."));
6277c478bd9Sstevel@tonic-gate 		if (error)
6287c478bd9Sstevel@tonic-gate 			done2(040);
6297c478bd9Sstevel@tonic-gate 		else
6307c478bd9Sstevel@tonic-gate 			edone(040);
631*e5190c10Smuffin 		return (0);
6327c478bd9Sstevel@tonic-gate 	}
6337c478bd9Sstevel@tonic-gate 	evlist[evi++] = ev;
6347c478bd9Sstevel@tonic-gate e1:
6357c478bd9Sstevel@tonic-gate 	if (ev == nxev)
636*e5190c10Smuffin 		return (0);
6377c478bd9Sstevel@tonic-gate #ifdef INCORE
6387c478bd9Sstevel@tonic-gate 	{
6397c478bd9Sstevel@tonic-gate 		extern tchar corebuf[];
6407c478bd9Sstevel@tonic-gate 		*(struct env *)&corebuf[ev * sizeof(env)/sizeof(tchar)] = env;
6417c478bd9Sstevel@tonic-gate 		env = *(struct env *)&corebuf[nxev * sizeof(env)/sizeof(tchar)];
6427c478bd9Sstevel@tonic-gate 	}
6437c478bd9Sstevel@tonic-gate #else
6447c478bd9Sstevel@tonic-gate 	lseek(ibf, ev * (long)sizeof(env), 0);
6457c478bd9Sstevel@tonic-gate 	write(ibf, (char *) & env, sizeof(env));
6467c478bd9Sstevel@tonic-gate 	lseek(ibf, nxev * (long)sizeof(env), 0);
6477c478bd9Sstevel@tonic-gate 	read(ibf, (char *) & env, sizeof(env));
6487c478bd9Sstevel@tonic-gate #endif
6497c478bd9Sstevel@tonic-gate 	ev = nxev;
650*e5190c10Smuffin 
651*e5190c10Smuffin 	return (0);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate 
654*e5190c10Smuffin int
caseel()6557c478bd9Sstevel@tonic-gate caseel()
6567c478bd9Sstevel@tonic-gate {
6577c478bd9Sstevel@tonic-gate 	if (--ifx < 0) {
6587c478bd9Sstevel@tonic-gate 		ifx = 0;
6597c478bd9Sstevel@tonic-gate 		iflist[0] = 0;
6607c478bd9Sstevel@tonic-gate 	}
6617c478bd9Sstevel@tonic-gate 	caseif(2);
662*e5190c10Smuffin 
663*e5190c10Smuffin 	return (0);
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 
667*e5190c10Smuffin int
caseie()6687c478bd9Sstevel@tonic-gate caseie()
6697c478bd9Sstevel@tonic-gate {
6707c478bd9Sstevel@tonic-gate 	if (ifx >= NIF) {
6717c478bd9Sstevel@tonic-gate 		errprint(gettext("if-else overflow."));
6727c478bd9Sstevel@tonic-gate 		ifx = 0;
6737c478bd9Sstevel@tonic-gate 		edone(040);
6747c478bd9Sstevel@tonic-gate 	}
6757c478bd9Sstevel@tonic-gate 	caseif(1);
6767c478bd9Sstevel@tonic-gate 	ifx++;
677*e5190c10Smuffin 
678*e5190c10Smuffin 	return (0);
6797c478bd9Sstevel@tonic-gate }
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 
682*e5190c10Smuffin int
caseif(x)6837c478bd9Sstevel@tonic-gate caseif(x)
6847c478bd9Sstevel@tonic-gate int	x;
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate 	extern int falsef;
687*e5190c10Smuffin 	int	notflag, true;
6887c478bd9Sstevel@tonic-gate 	tchar i;
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	if (x == 2) {
6917c478bd9Sstevel@tonic-gate 		notflag = 0;
6927c478bd9Sstevel@tonic-gate 		true = iflist[ifx];
6937c478bd9Sstevel@tonic-gate 		goto i1;
6947c478bd9Sstevel@tonic-gate 	}
6957c478bd9Sstevel@tonic-gate 	true = 0;
6967c478bd9Sstevel@tonic-gate 	skip();
6977c478bd9Sstevel@tonic-gate 	if ((cbits(i = getch())) == '!') {
6987c478bd9Sstevel@tonic-gate 		notflag = 1;
6997c478bd9Sstevel@tonic-gate 	} else {
7007c478bd9Sstevel@tonic-gate 		notflag = 0;
7017c478bd9Sstevel@tonic-gate 		ch = i;
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	i = atoi();
7047c478bd9Sstevel@tonic-gate 	if (!nonumb) {
7057c478bd9Sstevel@tonic-gate 		if (i > 0)
7067c478bd9Sstevel@tonic-gate 			true++;
7077c478bd9Sstevel@tonic-gate 		goto i1;
7087c478bd9Sstevel@tonic-gate 	}
7097c478bd9Sstevel@tonic-gate 	i = getch();
7107c478bd9Sstevel@tonic-gate 	switch (cbits(i)) {
7117c478bd9Sstevel@tonic-gate 	case 'e':
7127c478bd9Sstevel@tonic-gate 		if (!(numtab[PN].val & 01))
7137c478bd9Sstevel@tonic-gate 			true++;
7147c478bd9Sstevel@tonic-gate 		break;
7157c478bd9Sstevel@tonic-gate 	case 'o':
7167c478bd9Sstevel@tonic-gate 		if (numtab[PN].val & 01)
7177c478bd9Sstevel@tonic-gate 			true++;
7187c478bd9Sstevel@tonic-gate 		break;
7197c478bd9Sstevel@tonic-gate #ifdef NROFF
7207c478bd9Sstevel@tonic-gate 	case 'n':
7217c478bd9Sstevel@tonic-gate 		true++;
7227c478bd9Sstevel@tonic-gate 	case 't':
7237c478bd9Sstevel@tonic-gate #endif
7247c478bd9Sstevel@tonic-gate #ifndef NROFF
7257c478bd9Sstevel@tonic-gate 	case 't':
7267c478bd9Sstevel@tonic-gate 		true++;
7277c478bd9Sstevel@tonic-gate 	case 'n':
7287c478bd9Sstevel@tonic-gate #endif
7297c478bd9Sstevel@tonic-gate 	case ' ':
7307c478bd9Sstevel@tonic-gate 		break;
7317c478bd9Sstevel@tonic-gate 	default:
7327c478bd9Sstevel@tonic-gate 		true = cmpstr(i);
7337c478bd9Sstevel@tonic-gate 	}
7347c478bd9Sstevel@tonic-gate i1:
7357c478bd9Sstevel@tonic-gate 	true ^= notflag;
7367c478bd9Sstevel@tonic-gate 	if (x == 1)
7377c478bd9Sstevel@tonic-gate 		iflist[ifx] = !true;
7387c478bd9Sstevel@tonic-gate 	if (true) {
7397c478bd9Sstevel@tonic-gate i2:
7407c478bd9Sstevel@tonic-gate 		while ((cbits(i = getch())) == ' ')
7417c478bd9Sstevel@tonic-gate 			;
7427c478bd9Sstevel@tonic-gate 		if (cbits(i) == LEFT)
7437c478bd9Sstevel@tonic-gate 			goto i2;
7447c478bd9Sstevel@tonic-gate 		ch = i;
7457c478bd9Sstevel@tonic-gate 		nflush++;
7467c478bd9Sstevel@tonic-gate 	} else {
7477c478bd9Sstevel@tonic-gate 		copyf++;
7487c478bd9Sstevel@tonic-gate 		falsef++;
7497c478bd9Sstevel@tonic-gate 		eatblk(0);
7507c478bd9Sstevel@tonic-gate 		copyf--;
7517c478bd9Sstevel@tonic-gate 		falsef--;
7527c478bd9Sstevel@tonic-gate 	}
753*e5190c10Smuffin 
754*e5190c10Smuffin 	return (0);
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate 
757*e5190c10Smuffin int
eatblk(inblk)7587c478bd9Sstevel@tonic-gate eatblk(inblk)
7597c478bd9Sstevel@tonic-gate int inblk;
760*e5190c10Smuffin {	int cnt, i;
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	cnt = 0;
7637c478bd9Sstevel@tonic-gate 	do {
7647c478bd9Sstevel@tonic-gate 		if (ch)	{
7657c478bd9Sstevel@tonic-gate 			i = cbits(ch);
7667c478bd9Sstevel@tonic-gate 			ch = 0;
7677c478bd9Sstevel@tonic-gate 		} else
7687c478bd9Sstevel@tonic-gate 			i = cbits(getch0());
7697c478bd9Sstevel@tonic-gate 		if (i == ESC)
7707c478bd9Sstevel@tonic-gate 			cnt++;
7717c478bd9Sstevel@tonic-gate 		else {
7727c478bd9Sstevel@tonic-gate 			if (cnt == 1)
7737c478bd9Sstevel@tonic-gate 				switch (i) {
7747c478bd9Sstevel@tonic-gate 				case '{':  i = LEFT; break;
7757c478bd9Sstevel@tonic-gate 				case '}':  i = RIGHT; break;
7767c478bd9Sstevel@tonic-gate 				case '\n': i = 'x'; break;
7777c478bd9Sstevel@tonic-gate 				}
7787c478bd9Sstevel@tonic-gate 			cnt = 0;
7797c478bd9Sstevel@tonic-gate 		}
7807c478bd9Sstevel@tonic-gate 		if (i == LEFT) eatblk(1);
7817c478bd9Sstevel@tonic-gate 	} while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT)));
7827c478bd9Sstevel@tonic-gate 	if (i == '\n')
7837c478bd9Sstevel@tonic-gate 		nlflg++;
784*e5190c10Smuffin 
785*e5190c10Smuffin 	return (0);
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 
789*e5190c10Smuffin int
cmpstr(c)7907c478bd9Sstevel@tonic-gate cmpstr(c)
7917c478bd9Sstevel@tonic-gate tchar c;
7927c478bd9Sstevel@tonic-gate {
793*e5190c10Smuffin 	int	j, delim;
794*e5190c10Smuffin 	tchar i;
795*e5190c10Smuffin 	int	val;
7967c478bd9Sstevel@tonic-gate 	int savapts, savapts1, savfont, savfont1, savpts, savpts1;
7977c478bd9Sstevel@tonic-gate 	tchar string[1280];
798*e5190c10Smuffin 	tchar *sp;
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	if (ismot(c))
8017c478bd9Sstevel@tonic-gate 		return(0);
8027c478bd9Sstevel@tonic-gate 	delim = cbits(c);
8037c478bd9Sstevel@tonic-gate 	savapts = apts;
8047c478bd9Sstevel@tonic-gate 	savapts1 = apts1;
8057c478bd9Sstevel@tonic-gate 	savfont = font;
8067c478bd9Sstevel@tonic-gate 	savfont1 = font1;
8077c478bd9Sstevel@tonic-gate 	savpts = pts;
8087c478bd9Sstevel@tonic-gate 	savpts1 = pts1;
8097c478bd9Sstevel@tonic-gate 	sp = string;
8107c478bd9Sstevel@tonic-gate 	while ((j = cbits(i = getch()))!=delim && j!='\n' && sp<&string[1280-1])
8117c478bd9Sstevel@tonic-gate 		*sp++ = i;
8127c478bd9Sstevel@tonic-gate 	if (sp >= string + 1280) {
8137c478bd9Sstevel@tonic-gate 		errprint(gettext("too-long string compare."));
8147c478bd9Sstevel@tonic-gate 		edone(0100);
8157c478bd9Sstevel@tonic-gate 	}
8167c478bd9Sstevel@tonic-gate 	if (nlflg) {
8177c478bd9Sstevel@tonic-gate 		val = sp==string;
8187c478bd9Sstevel@tonic-gate 		goto rtn;
8197c478bd9Sstevel@tonic-gate 	}
8207c478bd9Sstevel@tonic-gate 	*sp++ = 0;
8217c478bd9Sstevel@tonic-gate 	apts = savapts;
8227c478bd9Sstevel@tonic-gate 	apts1 = savapts1;
8237c478bd9Sstevel@tonic-gate 	font = savfont;
8247c478bd9Sstevel@tonic-gate 	font1 = savfont1;
8257c478bd9Sstevel@tonic-gate 	pts = savpts;
8267c478bd9Sstevel@tonic-gate 	pts1 = savpts1;
8277c478bd9Sstevel@tonic-gate 	mchbits();
8287c478bd9Sstevel@tonic-gate 	val = 1;
8297c478bd9Sstevel@tonic-gate 	sp = string;
8307c478bd9Sstevel@tonic-gate 	while ((j = cbits(i = getch())) != delim && j != '\n') {
8317c478bd9Sstevel@tonic-gate 		if (*sp != i) {
8327c478bd9Sstevel@tonic-gate 			eat(delim);
8337c478bd9Sstevel@tonic-gate 			val = 0;
8347c478bd9Sstevel@tonic-gate 			goto rtn;
8357c478bd9Sstevel@tonic-gate 		}
8367c478bd9Sstevel@tonic-gate 		sp++;
8377c478bd9Sstevel@tonic-gate 	}
8387c478bd9Sstevel@tonic-gate 	if (*sp)
8397c478bd9Sstevel@tonic-gate 		val = 0;
8407c478bd9Sstevel@tonic-gate rtn:
8417c478bd9Sstevel@tonic-gate 	apts = savapts;
8427c478bd9Sstevel@tonic-gate 	apts1 = savapts1;
8437c478bd9Sstevel@tonic-gate 	font = savfont;
8447c478bd9Sstevel@tonic-gate 	font1 = savfont1;
8457c478bd9Sstevel@tonic-gate 	pts = savpts;
8467c478bd9Sstevel@tonic-gate 	pts1 = savpts1;
8477c478bd9Sstevel@tonic-gate 	mchbits();
8487c478bd9Sstevel@tonic-gate 	return(val);
8497c478bd9Sstevel@tonic-gate }
8507c478bd9Sstevel@tonic-gate 
8517c478bd9Sstevel@tonic-gate 
852*e5190c10Smuffin int
caserd()8537c478bd9Sstevel@tonic-gate caserd()
8547c478bd9Sstevel@tonic-gate {
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	lgf++;
8577c478bd9Sstevel@tonic-gate 	skip();
8587c478bd9Sstevel@tonic-gate 	getname();
8597c478bd9Sstevel@tonic-gate 	if (!iflg) {
8607c478bd9Sstevel@tonic-gate 		if (quiet) {
8617c478bd9Sstevel@tonic-gate #ifdef	NROFF
8627c478bd9Sstevel@tonic-gate 			echo_off();
8637c478bd9Sstevel@tonic-gate 			flusho();
864*e5190c10Smuffin #endif	/* NROFF */
8657c478bd9Sstevel@tonic-gate 			fdprintf(stderr, "\007"); /*bell*/
8667c478bd9Sstevel@tonic-gate 		} else {
8677c478bd9Sstevel@tonic-gate 			if (nextf[0]) {
8687c478bd9Sstevel@tonic-gate 				fdprintf(stderr, "%s:", nextf);
8697c478bd9Sstevel@tonic-gate 			} else {
8707c478bd9Sstevel@tonic-gate 				fdprintf(stderr, "\007"); /*bell*/
8717c478bd9Sstevel@tonic-gate 			}
8727c478bd9Sstevel@tonic-gate 		}
8737c478bd9Sstevel@tonic-gate 	}
8747c478bd9Sstevel@tonic-gate 	collect();
8757c478bd9Sstevel@tonic-gate 	tty++;
8767c478bd9Sstevel@tonic-gate 	pushi(NBLIST*BLK, PAIR('r','d'));
877*e5190c10Smuffin 
878*e5190c10Smuffin 	return (0);
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 
882*e5190c10Smuffin int
rdtty()8837c478bd9Sstevel@tonic-gate rdtty()
8847c478bd9Sstevel@tonic-gate {
8857c478bd9Sstevel@tonic-gate 	char	onechar;
8867c478bd9Sstevel@tonic-gate #ifdef EUC
8877c478bd9Sstevel@tonic-gate #ifdef NROFF
8887c478bd9Sstevel@tonic-gate 	int	i, n, col_index;
8897c478bd9Sstevel@tonic-gate #endif /* NROFF */
8907c478bd9Sstevel@tonic-gate #endif /* EUC */
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	onechar = 0;
8937c478bd9Sstevel@tonic-gate 	if (read(0, &onechar, 1) == 1) {
8947c478bd9Sstevel@tonic-gate 		if (onechar == '\n')
8957c478bd9Sstevel@tonic-gate 			tty++;
8967c478bd9Sstevel@tonic-gate 		else
8977c478bd9Sstevel@tonic-gate 			tty = 1;
8987c478bd9Sstevel@tonic-gate #ifndef EUC
8997c478bd9Sstevel@tonic-gate 		if (tty != 3)
9007c478bd9Sstevel@tonic-gate 			return(onechar);
9017c478bd9Sstevel@tonic-gate #else
9027c478bd9Sstevel@tonic-gate #ifndef NROFF
9037c478bd9Sstevel@tonic-gate 		if (tty != 3)
9047c478bd9Sstevel@tonic-gate 			return(onechar);
9057c478bd9Sstevel@tonic-gate #else
9067c478bd9Sstevel@tonic-gate 		if (tty != 3) {
9077c478bd9Sstevel@tonic-gate 			if (!multi_locale)
9087c478bd9Sstevel@tonic-gate 				return(onechar);
9097c478bd9Sstevel@tonic-gate 			i = onechar & 0377;
9107c478bd9Sstevel@tonic-gate 			*mbbuf1p++ = i;
9117c478bd9Sstevel@tonic-gate 			*mbbuf1p = 0;
9127c478bd9Sstevel@tonic-gate 			if ((n = mbtowc(&twc, mbbuf1, MB_CUR_MAX)) <= 0) {
9137c478bd9Sstevel@tonic-gate 				if (mbbuf1p >= mbbuf1 + MB_CUR_MAX) {
9147c478bd9Sstevel@tonic-gate 					i &= ~(MBMASK | CSMASK);
9157c478bd9Sstevel@tonic-gate 					twc = 0;
9167c478bd9Sstevel@tonic-gate 					mbbuf1p = mbbuf1;
9177c478bd9Sstevel@tonic-gate 					*mbbuf1p = 0;
9187c478bd9Sstevel@tonic-gate 				} else {
9197c478bd9Sstevel@tonic-gate 					i |= (MIDDLEOFMB);
9207c478bd9Sstevel@tonic-gate 				}
9217c478bd9Sstevel@tonic-gate 			} else {
9227c478bd9Sstevel@tonic-gate 				if (n > 1)
9237c478bd9Sstevel@tonic-gate 					i |= (LASTOFMB);
9247c478bd9Sstevel@tonic-gate 				else
9257c478bd9Sstevel@tonic-gate 					i |= (BYTE_CHR);
9267c478bd9Sstevel@tonic-gate 				if (isascii(twc)) {
9277c478bd9Sstevel@tonic-gate 					col_index = 0;
9287c478bd9Sstevel@tonic-gate 				} else {
9297c478bd9Sstevel@tonic-gate 					if ((col_index = wcwidth(twc)) < 0)
9307c478bd9Sstevel@tonic-gate 						col_index = 0;
9317c478bd9Sstevel@tonic-gate 				}
9327c478bd9Sstevel@tonic-gate 				setcsbits(i, col_index);
9337c478bd9Sstevel@tonic-gate 				twc = 0;
9347c478bd9Sstevel@tonic-gate 				mbbuf1p = mbbuf1;
9357c478bd9Sstevel@tonic-gate 			}
9367c478bd9Sstevel@tonic-gate 			return(i);
9377c478bd9Sstevel@tonic-gate 		}
9387c478bd9Sstevel@tonic-gate #endif /* NROFF */
9397c478bd9Sstevel@tonic-gate #endif /* EUC */
9407c478bd9Sstevel@tonic-gate 	}
9417c478bd9Sstevel@tonic-gate 	popi();
9427c478bd9Sstevel@tonic-gate 	tty = 0;
9437c478bd9Sstevel@tonic-gate #ifdef	NROFF
9447c478bd9Sstevel@tonic-gate 	if (quiet)
9457c478bd9Sstevel@tonic-gate 		echo_on();
946*e5190c10Smuffin #endif	/* NROFF */
9477c478bd9Sstevel@tonic-gate 	return(0);
9487c478bd9Sstevel@tonic-gate }
9497c478bd9Sstevel@tonic-gate 
9507c478bd9Sstevel@tonic-gate 
951*e5190c10Smuffin int
caseec()9527c478bd9Sstevel@tonic-gate caseec()
9537c478bd9Sstevel@tonic-gate {
9547c478bd9Sstevel@tonic-gate 	eschar = chget('\\');
955*e5190c10Smuffin 
956*e5190c10Smuffin 	return (0);
9577c478bd9Sstevel@tonic-gate }
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 
960*e5190c10Smuffin int
caseeo()9617c478bd9Sstevel@tonic-gate caseeo()
9627c478bd9Sstevel@tonic-gate {
9637c478bd9Sstevel@tonic-gate 	eschar = 0;
964*e5190c10Smuffin 
965*e5190c10Smuffin 	return (0);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 
969*e5190c10Smuffin int
caseta()9707c478bd9Sstevel@tonic-gate caseta()
9717c478bd9Sstevel@tonic-gate {
972*e5190c10Smuffin 	int	i;
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate 	tabtab[0] = nonumb = 0;
9757c478bd9Sstevel@tonic-gate 	for (i = 0; ((i < (NTAB - 1)) && !nonumb); i++) {
9767c478bd9Sstevel@tonic-gate 		if (skip())
9777c478bd9Sstevel@tonic-gate 			break;
9787c478bd9Sstevel@tonic-gate 		tabtab[i] = max(hnumb(&tabtab[max(i-1,0)]), 0) & TABMASK;
9797c478bd9Sstevel@tonic-gate 		if (!nonumb)
9807c478bd9Sstevel@tonic-gate 			switch (cbits(ch)) {
9817c478bd9Sstevel@tonic-gate 			case 'C':
9827c478bd9Sstevel@tonic-gate 				tabtab[i] |= CTAB;
9837c478bd9Sstevel@tonic-gate 				break;
9847c478bd9Sstevel@tonic-gate 			case 'R':
9857c478bd9Sstevel@tonic-gate 				tabtab[i] |= RTAB;
9867c478bd9Sstevel@tonic-gate 				break;
9877c478bd9Sstevel@tonic-gate 			default: /*includes L*/
9887c478bd9Sstevel@tonic-gate 				break;
9897c478bd9Sstevel@tonic-gate 			}
9907c478bd9Sstevel@tonic-gate 		nonumb = ch = 0;
9917c478bd9Sstevel@tonic-gate 	}
9927c478bd9Sstevel@tonic-gate 	tabtab[i] = 0;
993*e5190c10Smuffin 
994*e5190c10Smuffin 	return (0);
9957c478bd9Sstevel@tonic-gate }
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 
998*e5190c10Smuffin int
casene()9997c478bd9Sstevel@tonic-gate casene()
10007c478bd9Sstevel@tonic-gate {
1001*e5190c10Smuffin 	int	i, j;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	skip();
10047c478bd9Sstevel@tonic-gate 	i = vnumb((int *)0);
10057c478bd9Sstevel@tonic-gate 	if (nonumb)
10067c478bd9Sstevel@tonic-gate 		i = lss;
10077c478bd9Sstevel@tonic-gate 	if (i > (j = findt1())) {
10087c478bd9Sstevel@tonic-gate 		i = lss;
10097c478bd9Sstevel@tonic-gate 		lss = j;
10107c478bd9Sstevel@tonic-gate 		dip->nls = 0;
10117c478bd9Sstevel@tonic-gate 		newline(0);
10127c478bd9Sstevel@tonic-gate 		lss = i;
10137c478bd9Sstevel@tonic-gate 	}
1014*e5190c10Smuffin 
1015*e5190c10Smuffin 	return (0);
10167c478bd9Sstevel@tonic-gate }
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 
1019*e5190c10Smuffin int
casetr()10207c478bd9Sstevel@tonic-gate casetr()
10217c478bd9Sstevel@tonic-gate {
1022*e5190c10Smuffin 	int	i, j;
10237c478bd9Sstevel@tonic-gate 	tchar k;
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	lgf++;
10267c478bd9Sstevel@tonic-gate 	skip();
10277c478bd9Sstevel@tonic-gate 	while ((i = cbits(k=getch())) != '\n') {
10287c478bd9Sstevel@tonic-gate 		if (ismot(k))
1029*e5190c10Smuffin 			return (0);
10307c478bd9Sstevel@tonic-gate 		if (ismot(k = getch()))
1031*e5190c10Smuffin 			return (0);
10327c478bd9Sstevel@tonic-gate 		if ((j = cbits(k)) == '\n')
10337c478bd9Sstevel@tonic-gate 			j = ' ';
10347c478bd9Sstevel@tonic-gate 		trtab[i] = j;
10357c478bd9Sstevel@tonic-gate 	}
1036*e5190c10Smuffin 
1037*e5190c10Smuffin 	return (0);
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 
1041*e5190c10Smuffin int
casecu()10427c478bd9Sstevel@tonic-gate casecu()
10437c478bd9Sstevel@tonic-gate {
10447c478bd9Sstevel@tonic-gate 	cu++;
10457c478bd9Sstevel@tonic-gate 	caseul();
1046*e5190c10Smuffin 
1047*e5190c10Smuffin 	return (0);
10487c478bd9Sstevel@tonic-gate }
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 
1051*e5190c10Smuffin int
caseul()10527c478bd9Sstevel@tonic-gate caseul()
10537c478bd9Sstevel@tonic-gate {
1054*e5190c10Smuffin 	int	i;
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate 	noscale++;
10577c478bd9Sstevel@tonic-gate 	if (skip())
10587c478bd9Sstevel@tonic-gate 		i = 1;
10597c478bd9Sstevel@tonic-gate 	else
10607c478bd9Sstevel@tonic-gate 		i = atoi();
10617c478bd9Sstevel@tonic-gate 	if (ul && (i == 0)) {
10627c478bd9Sstevel@tonic-gate 		font = sfont;
10637c478bd9Sstevel@tonic-gate 		ul = cu = 0;
10647c478bd9Sstevel@tonic-gate 	}
10657c478bd9Sstevel@tonic-gate 	if (i) {
10667c478bd9Sstevel@tonic-gate 		if (!ul) {
10677c478bd9Sstevel@tonic-gate 			sfont = font;
10687c478bd9Sstevel@tonic-gate 			font = ulfont;
10697c478bd9Sstevel@tonic-gate 		}
10707c478bd9Sstevel@tonic-gate 		ul = i;
10717c478bd9Sstevel@tonic-gate 	}
10727c478bd9Sstevel@tonic-gate 	noscale = 0;
10737c478bd9Sstevel@tonic-gate 	mchbits();
1074*e5190c10Smuffin 
1075*e5190c10Smuffin 	return (0);
10767c478bd9Sstevel@tonic-gate }
10777c478bd9Sstevel@tonic-gate 
10787c478bd9Sstevel@tonic-gate 
1079*e5190c10Smuffin int
caseuf()10807c478bd9Sstevel@tonic-gate caseuf()
10817c478bd9Sstevel@tonic-gate {
1082*e5190c10Smuffin 	int	i, j;
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate 	if (skip() || !(i = getrq()) || i == 'S' ||  (j = findft(i))  == -1)
10857c478bd9Sstevel@tonic-gate 		ulfont = ULFONT; /*default underline position*/
10867c478bd9Sstevel@tonic-gate 	else
10877c478bd9Sstevel@tonic-gate 		ulfont = j;
10887c478bd9Sstevel@tonic-gate #ifdef NROFF
10897c478bd9Sstevel@tonic-gate 	if (ulfont == FT)
10907c478bd9Sstevel@tonic-gate 		ulfont = ULFONT;
10917c478bd9Sstevel@tonic-gate #endif
1092*e5190c10Smuffin 	return (0);
10937c478bd9Sstevel@tonic-gate }
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate 
1096*e5190c10Smuffin int
caseit()10977c478bd9Sstevel@tonic-gate caseit()
10987c478bd9Sstevel@tonic-gate {
1099*e5190c10Smuffin 	int	i;
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate 	lgf++;
11027c478bd9Sstevel@tonic-gate 	it = itmac = 0;
11037c478bd9Sstevel@tonic-gate 	noscale++;
11047c478bd9Sstevel@tonic-gate 	skip();
11057c478bd9Sstevel@tonic-gate 	i = atoi();
11067c478bd9Sstevel@tonic-gate 	skip();
11077c478bd9Sstevel@tonic-gate 	if (!nonumb && (itmac = getrq()))
11087c478bd9Sstevel@tonic-gate 		it = i;
11097c478bd9Sstevel@tonic-gate 	noscale = 0;
1110*e5190c10Smuffin 
1111*e5190c10Smuffin 	return (0);
11127c478bd9Sstevel@tonic-gate }
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 
1115*e5190c10Smuffin int
casemc()11167c478bd9Sstevel@tonic-gate casemc()
11177c478bd9Sstevel@tonic-gate {
1118*e5190c10Smuffin 	int	i;
11197c478bd9Sstevel@tonic-gate 
11207c478bd9Sstevel@tonic-gate 	if (icf > 1)
11217c478bd9Sstevel@tonic-gate 		ic = 0;
11227c478bd9Sstevel@tonic-gate 	icf = 0;
11237c478bd9Sstevel@tonic-gate 	if (skip())
1124*e5190c10Smuffin 		return (0);
11257c478bd9Sstevel@tonic-gate 	ic = getch();
11267c478bd9Sstevel@tonic-gate 	icf = 1;
11277c478bd9Sstevel@tonic-gate 	skip();
11287c478bd9Sstevel@tonic-gate 	i = max(hnumb((int *)0), 0);
11297c478bd9Sstevel@tonic-gate 	if (!nonumb)
11307c478bd9Sstevel@tonic-gate 		ics = i;
1131*e5190c10Smuffin 
1132*e5190c10Smuffin 	return (0);
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate 
11357c478bd9Sstevel@tonic-gate 
1136*e5190c10Smuffin int
casemk()11377c478bd9Sstevel@tonic-gate casemk()
11387c478bd9Sstevel@tonic-gate {
1139*e5190c10Smuffin 	int	i, j;
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate 	if (dip != d)
11427c478bd9Sstevel@tonic-gate 		j = dip->dnl;
11437c478bd9Sstevel@tonic-gate 	else
11447c478bd9Sstevel@tonic-gate 		j = numtab[NL].val;
11457c478bd9Sstevel@tonic-gate 	if (skip()) {
11467c478bd9Sstevel@tonic-gate 		dip->mkline = j;
1147*e5190c10Smuffin 		return (0);
11487c478bd9Sstevel@tonic-gate 	}
11497c478bd9Sstevel@tonic-gate 	if ((i = getrq()) == 0)
1150*e5190c10Smuffin 		return (0);
11517c478bd9Sstevel@tonic-gate 	numtab[findr(i)].val = j;
1152*e5190c10Smuffin 
1153*e5190c10Smuffin 	return (0);
11547c478bd9Sstevel@tonic-gate }
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 
1157*e5190c10Smuffin int
casesv()11587c478bd9Sstevel@tonic-gate casesv()
11597c478bd9Sstevel@tonic-gate {
1160*e5190c10Smuffin 	int	i;
11617c478bd9Sstevel@tonic-gate 
11627c478bd9Sstevel@tonic-gate 	skip();
11637c478bd9Sstevel@tonic-gate 	if ((i = vnumb((int *)0)) < 0)
1164*e5190c10Smuffin 		return (0);
11657c478bd9Sstevel@tonic-gate 	if (nonumb)
11667c478bd9Sstevel@tonic-gate 		i = 1;
11677c478bd9Sstevel@tonic-gate 	sv += i;
11687c478bd9Sstevel@tonic-gate 	caseos();
1169*e5190c10Smuffin 
1170*e5190c10Smuffin 	return (0);
11717c478bd9Sstevel@tonic-gate }
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate 
1174*e5190c10Smuffin int
caseos()11757c478bd9Sstevel@tonic-gate caseos()
11767c478bd9Sstevel@tonic-gate {
1177*e5190c10Smuffin 	int	savlss;
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	if (sv <= findt1()) {
11807c478bd9Sstevel@tonic-gate 		savlss = lss;
11817c478bd9Sstevel@tonic-gate 		lss = sv;
11827c478bd9Sstevel@tonic-gate 		newline(0);
11837c478bd9Sstevel@tonic-gate 		lss = savlss;
11847c478bd9Sstevel@tonic-gate 		sv = 0;
11857c478bd9Sstevel@tonic-gate 	}
1186*e5190c10Smuffin 
1187*e5190c10Smuffin 	return (0);
11887c478bd9Sstevel@tonic-gate }
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 
1191*e5190c10Smuffin int
casenm()11927c478bd9Sstevel@tonic-gate casenm()
11937c478bd9Sstevel@tonic-gate {
1194*e5190c10Smuffin 	int	i;
11957c478bd9Sstevel@tonic-gate 
11967c478bd9Sstevel@tonic-gate 	lnmod = nn = 0;
11977c478bd9Sstevel@tonic-gate 	if (skip())
1198*e5190c10Smuffin 		return (0);
11997c478bd9Sstevel@tonic-gate 	lnmod++;
12007c478bd9Sstevel@tonic-gate 	noscale++;
12017c478bd9Sstevel@tonic-gate 	i = inumb(&numtab[LN].val);
12027c478bd9Sstevel@tonic-gate 	if (!nonumb)
12037c478bd9Sstevel@tonic-gate 		numtab[LN].val = max(i, 0);
12047c478bd9Sstevel@tonic-gate 	getnm(&ndf, 1);
12057c478bd9Sstevel@tonic-gate 	getnm(&nms, 0);
12067c478bd9Sstevel@tonic-gate 	getnm(&ni, 0);
12077c478bd9Sstevel@tonic-gate 	noscale = 0;
12087c478bd9Sstevel@tonic-gate 	nmbits = chbits;
1209*e5190c10Smuffin 
1210*e5190c10Smuffin 	return (0);
12117c478bd9Sstevel@tonic-gate }
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 
1214*e5190c10Smuffin int
getnm(p,min)12157c478bd9Sstevel@tonic-gate getnm(p, min)
12167c478bd9Sstevel@tonic-gate int	*p, min;
12177c478bd9Sstevel@tonic-gate {
1218*e5190c10Smuffin 	int	i;
12197c478bd9Sstevel@tonic-gate 
12207c478bd9Sstevel@tonic-gate 	eat(' ');
12217c478bd9Sstevel@tonic-gate 	if (skip())
1222*e5190c10Smuffin 		return (0);
12237c478bd9Sstevel@tonic-gate 	i = atoi();
12247c478bd9Sstevel@tonic-gate 	if (nonumb)
1225*e5190c10Smuffin 		return (0);
12267c478bd9Sstevel@tonic-gate 	*p = max(i, min);
1227*e5190c10Smuffin 
1228*e5190c10Smuffin 	return (0);
12297c478bd9Sstevel@tonic-gate }
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate 
1232*e5190c10Smuffin int
casenn()12337c478bd9Sstevel@tonic-gate casenn()
12347c478bd9Sstevel@tonic-gate {
12357c478bd9Sstevel@tonic-gate 	noscale++;
12367c478bd9Sstevel@tonic-gate 	skip();
12377c478bd9Sstevel@tonic-gate 	nn = max(atoi(), 1);
12387c478bd9Sstevel@tonic-gate 	noscale = 0;
1239*e5190c10Smuffin 
1240*e5190c10Smuffin 	return (0);
12417c478bd9Sstevel@tonic-gate }
12427c478bd9Sstevel@tonic-gate 
12437c478bd9Sstevel@tonic-gate 
1244*e5190c10Smuffin int
caseab()12457c478bd9Sstevel@tonic-gate caseab()
12467c478bd9Sstevel@tonic-gate {
12477c478bd9Sstevel@tonic-gate 	casetm(1);
12487c478bd9Sstevel@tonic-gate 	done3(0);
1249*e5190c10Smuffin 
1250*e5190c10Smuffin 	return (0);
12517c478bd9Sstevel@tonic-gate }
12527c478bd9Sstevel@tonic-gate 
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate #ifdef	NROFF
12557c478bd9Sstevel@tonic-gate /*
12567c478bd9Sstevel@tonic-gate  * The following routines are concerned with setting terminal options.
12577c478bd9Sstevel@tonic-gate  *	The manner of doing this differs between research/Berkeley systems
12587c478bd9Sstevel@tonic-gate  *	and UNIX System V systems (i.e. DOCUMENTER'S WORKBENCH)
12597c478bd9Sstevel@tonic-gate  *	The distinction is controlled by the #define'd variable USG,
12607c478bd9Sstevel@tonic-gate  *	which must be set by System V users.
12617c478bd9Sstevel@tonic-gate  */
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate #ifdef	USG
12657c478bd9Sstevel@tonic-gate #include <termio.h>
12667c478bd9Sstevel@tonic-gate #define	ECHO_USG (ECHO | ECHOE | ECHOK | ECHONL)
12677c478bd9Sstevel@tonic-gate struct termio	ttys;
12687c478bd9Sstevel@tonic-gate #else
12697c478bd9Sstevel@tonic-gate #include <sgtty.h>
12707c478bd9Sstevel@tonic-gate struct	sgttyb	ttys[2];
1271*e5190c10Smuffin #endif	/* USG */
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate int	ttysave[2] = {-1, -1};
12747c478bd9Sstevel@tonic-gate 
1275*e5190c10Smuffin int
save_tty()12767c478bd9Sstevel@tonic-gate save_tty()			/*save any tty settings that may be changed*/
12777c478bd9Sstevel@tonic-gate {
12787c478bd9Sstevel@tonic-gate 
12797c478bd9Sstevel@tonic-gate #ifdef	USG
12807c478bd9Sstevel@tonic-gate 	if (ioctl(0, TCGETA, &ttys) >= 0)
12817c478bd9Sstevel@tonic-gate 		ttysave[0] = ttys.c_lflag;
12827c478bd9Sstevel@tonic-gate #else
12837c478bd9Sstevel@tonic-gate 	if (gtty(0, &ttys[0]) >= 0)
12847c478bd9Sstevel@tonic-gate 		ttysave[0] = ttys[0].sg_flags;
12857c478bd9Sstevel@tonic-gate 	if (gtty(1, &ttys[1]) >= 0)
12867c478bd9Sstevel@tonic-gate 		ttysave[1] = ttys[1].sg_flags;
1287*e5190c10Smuffin #endif	/* USG */
12887c478bd9Sstevel@tonic-gate 
1289*e5190c10Smuffin 	return (0);
12907c478bd9Sstevel@tonic-gate }
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 
1293*e5190c10Smuffin int
restore_tty()12947c478bd9Sstevel@tonic-gate restore_tty()			/*restore tty settings from beginning*/
12957c478bd9Sstevel@tonic-gate {
12967c478bd9Sstevel@tonic-gate 
12977c478bd9Sstevel@tonic-gate 	if (ttysave[0] != -1) {
12987c478bd9Sstevel@tonic-gate #ifdef	USG
12997c478bd9Sstevel@tonic-gate 		ttys.c_lflag = ttysave[0];
13007c478bd9Sstevel@tonic-gate 		ioctl(0, TCSETAW, &ttys);
13017c478bd9Sstevel@tonic-gate #else
13027c478bd9Sstevel@tonic-gate 		ttys[0].sg_flags = ttysave[0];
13037c478bd9Sstevel@tonic-gate 		stty(0, &ttys[0]);
13047c478bd9Sstevel@tonic-gate 	}
13057c478bd9Sstevel@tonic-gate 	if (ttysave[1] != -1) {
13067c478bd9Sstevel@tonic-gate 		ttys[1].sg_flags = ttysave[1];
13077c478bd9Sstevel@tonic-gate 		stty(1, &ttys[1]);
1308*e5190c10Smuffin #endif	/* USG */
13097c478bd9Sstevel@tonic-gate 	}
1310*e5190c10Smuffin 
1311*e5190c10Smuffin 	return (0);
13127c478bd9Sstevel@tonic-gate }
13137c478bd9Sstevel@tonic-gate 
13147c478bd9Sstevel@tonic-gate 
1315*e5190c10Smuffin int
set_tty()13167c478bd9Sstevel@tonic-gate set_tty()			/*this replaces the use of bset and breset*/
13177c478bd9Sstevel@tonic-gate {
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate #ifndef	USG			/*for research/BSD only, reset CRMOD*/
13207c478bd9Sstevel@tonic-gate 	if (ttysave[1] == -1)
13217c478bd9Sstevel@tonic-gate 		save_tty();
13227c478bd9Sstevel@tonic-gate 	if (ttysave[1] != -1) {
13237c478bd9Sstevel@tonic-gate 		ttys[1].sg_flags &= ~CRMOD;
13247c478bd9Sstevel@tonic-gate 		stty(1, &ttys[1]);
13257c478bd9Sstevel@tonic-gate 	}
1326*e5190c10Smuffin #endif	/* USG */
13277c478bd9Sstevel@tonic-gate 
1328*e5190c10Smuffin 	return (0);
13297c478bd9Sstevel@tonic-gate }
13307c478bd9Sstevel@tonic-gate 
13317c478bd9Sstevel@tonic-gate 
1332*e5190c10Smuffin int
echo_off()13337c478bd9Sstevel@tonic-gate echo_off()			/*turn off ECHO for .rd in "-q" mode*/
13347c478bd9Sstevel@tonic-gate {
13357c478bd9Sstevel@tonic-gate 	if (ttysave[0] == -1)
1336*e5190c10Smuffin 		return (0);
13377c478bd9Sstevel@tonic-gate 
13387c478bd9Sstevel@tonic-gate #ifdef	USG
13397c478bd9Sstevel@tonic-gate 	ttys.c_lflag &= ~ECHO_USG;
13407c478bd9Sstevel@tonic-gate 	ioctl(0, TCSETAW, &ttys);
13417c478bd9Sstevel@tonic-gate #else
13427c478bd9Sstevel@tonic-gate 	ttys[0].sg_flags &= ~ECHO;
13437c478bd9Sstevel@tonic-gate 	stty(0, &ttys[0]);
1344*e5190c10Smuffin #endif	/* USG */
1345*e5190c10Smuffin 
1346*e5190c10Smuffin 	return (0);
13477c478bd9Sstevel@tonic-gate 
13487c478bd9Sstevel@tonic-gate }
13497c478bd9Sstevel@tonic-gate 
13507c478bd9Sstevel@tonic-gate 
1351*e5190c10Smuffin int
echo_on()13527c478bd9Sstevel@tonic-gate echo_on()			/*restore ECHO after .rd in "-q" mode*/
13537c478bd9Sstevel@tonic-gate {
13547c478bd9Sstevel@tonic-gate 	if (ttysave[0] == -1)
1355*e5190c10Smuffin 		return (0);
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate #ifdef	USG
13587c478bd9Sstevel@tonic-gate 	ttys.c_lflag |= ECHO_USG;
13597c478bd9Sstevel@tonic-gate 	ioctl(0, TCSETAW, &ttys);
13607c478bd9Sstevel@tonic-gate #else
13617c478bd9Sstevel@tonic-gate 	ttys[0].sg_flags |= ECHO;
13627c478bd9Sstevel@tonic-gate 	stty(0, &ttys[0]);
1363*e5190c10Smuffin #endif	/* USG */
13647c478bd9Sstevel@tonic-gate 
1365*e5190c10Smuffin 	return (0);
13667c478bd9Sstevel@tonic-gate }
1367*e5190c10Smuffin #endif	/* NROFF */
1368