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
407c478bd9Sstevel@tonic-gate #ifdef EUC
417c478bd9Sstevel@tonic-gate #ifdef NROFF
427c478bd9Sstevel@tonic-gate #include <stddef.h>
437c478bd9Sstevel@tonic-gate #include <stdlib.h>
447c478bd9Sstevel@tonic-gate #include <widec.h>
457c478bd9Sstevel@tonic-gate #endif /* NROFF */
467c478bd9Sstevel@tonic-gate #endif /* EUC */
477c478bd9Sstevel@tonic-gate #include <string.h>
487c478bd9Sstevel@tonic-gate #include "tdef.h"
497c478bd9Sstevel@tonic-gate #include "ext.h"
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * troff5.c
53*2a8bcb4eSToomas Soome *
547c478bd9Sstevel@tonic-gate * misc processing requests
557c478bd9Sstevel@tonic-gate */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate int iflist[NIF];
587c478bd9Sstevel@tonic-gate int ifx;
597c478bd9Sstevel@tonic-gate
60e5190c10Smuffin int
casead()617c478bd9Sstevel@tonic-gate casead()
627c478bd9Sstevel@tonic-gate {
63e5190c10Smuffin int i;
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate ad = 1;
667c478bd9Sstevel@tonic-gate /*leave admod alone*/
677c478bd9Sstevel@tonic-gate if (skip())
68e5190c10Smuffin return (0);
697c478bd9Sstevel@tonic-gate switch (i = cbits(getch())) {
707c478bd9Sstevel@tonic-gate case 'r': /*right adj, left ragged*/
717c478bd9Sstevel@tonic-gate admod = 2;
727c478bd9Sstevel@tonic-gate break;
737c478bd9Sstevel@tonic-gate case 'l': /*left adj, right ragged*/
747c478bd9Sstevel@tonic-gate admod = ad = 0; /*same as casena*/
757c478bd9Sstevel@tonic-gate break;
767c478bd9Sstevel@tonic-gate case 'c': /*centered adj*/
777c478bd9Sstevel@tonic-gate admod = 1;
787c478bd9Sstevel@tonic-gate break;
79*2a8bcb4eSToomas Soome case 'b':
807c478bd9Sstevel@tonic-gate case 'n':
817c478bd9Sstevel@tonic-gate admod = 0;
827c478bd9Sstevel@tonic-gate break;
83*2a8bcb4eSToomas Soome case '0':
84*2a8bcb4eSToomas Soome case '2':
857c478bd9Sstevel@tonic-gate case '4':
867c478bd9Sstevel@tonic-gate ad = 0;
87*2a8bcb4eSToomas Soome case '1':
88*2a8bcb4eSToomas Soome case '3':
897c478bd9Sstevel@tonic-gate case '5':
907c478bd9Sstevel@tonic-gate admod = (i - '0') / 2;
917c478bd9Sstevel@tonic-gate }
92e5190c10Smuffin
93e5190c10Smuffin return (0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate
97e5190c10Smuffin int
casena()987c478bd9Sstevel@tonic-gate casena()
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate ad = 0;
101e5190c10Smuffin
102e5190c10Smuffin return (0);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate
106e5190c10Smuffin int
casefi()1077c478bd9Sstevel@tonic-gate casefi()
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate tbreak();
1107c478bd9Sstevel@tonic-gate fi++;
1117c478bd9Sstevel@tonic-gate pendnf = 0;
1127c478bd9Sstevel@tonic-gate lnsize = LNSIZE;
113e5190c10Smuffin
114e5190c10Smuffin return (0);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate
118e5190c10Smuffin int
casenf()1197c478bd9Sstevel@tonic-gate casenf()
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate tbreak();
1227c478bd9Sstevel@tonic-gate fi = 0;
123e5190c10Smuffin
124e5190c10Smuffin return (0);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate
128e5190c10Smuffin int
casers()1297c478bd9Sstevel@tonic-gate casers()
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate dip->nls = 0;
132e5190c10Smuffin
133e5190c10Smuffin return (0);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate
137e5190c10Smuffin int
casens()1387c478bd9Sstevel@tonic-gate casens()
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate dip->nls++;
141e5190c10Smuffin
142e5190c10Smuffin return (0);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate
146e5190c10Smuffin int
chget(c)1477c478bd9Sstevel@tonic-gate chget(c)
1487c478bd9Sstevel@tonic-gate int c;
1497c478bd9Sstevel@tonic-gate {
1507c478bd9Sstevel@tonic-gate tchar i;
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
1537c478bd9Sstevel@tonic-gate ch = i;
1547c478bd9Sstevel@tonic-gate return(c);
155*2a8bcb4eSToomas Soome } else
1567c478bd9Sstevel@tonic-gate return(i & BYTEMASK);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate
160e5190c10Smuffin int
casecc()1617c478bd9Sstevel@tonic-gate casecc()
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate cc = chget('.');
164e5190c10Smuffin
165e5190c10Smuffin return (0);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate
169e5190c10Smuffin int
casec2()1707c478bd9Sstevel@tonic-gate casec2()
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate c2 = chget('\'');
173e5190c10Smuffin
174e5190c10Smuffin return (0);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate
178e5190c10Smuffin int
casehc()1797c478bd9Sstevel@tonic-gate casehc()
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate ohc = chget(OHC);
182e5190c10Smuffin
183e5190c10Smuffin return (0);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate
187e5190c10Smuffin int
casetc()1887c478bd9Sstevel@tonic-gate casetc()
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate tabc = chget(0);
191e5190c10Smuffin
192e5190c10Smuffin return (0);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate
196e5190c10Smuffin int
caselc()1977c478bd9Sstevel@tonic-gate caselc()
1987c478bd9Sstevel@tonic-gate {
1997c478bd9Sstevel@tonic-gate dotc = chget(0);
200e5190c10Smuffin
201e5190c10Smuffin return (0);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate
205e5190c10Smuffin int
casehy()2067c478bd9Sstevel@tonic-gate casehy()
2077c478bd9Sstevel@tonic-gate {
208e5190c10Smuffin int i;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate hyf = 1;
2117c478bd9Sstevel@tonic-gate if (skip())
212e5190c10Smuffin return (0);
2137c478bd9Sstevel@tonic-gate noscale++;
2147c478bd9Sstevel@tonic-gate i = atoi();
2157c478bd9Sstevel@tonic-gate noscale = 0;
2167c478bd9Sstevel@tonic-gate if (nonumb)
217e5190c10Smuffin return (0);
2187c478bd9Sstevel@tonic-gate hyf = max(i, 0);
219e5190c10Smuffin
220e5190c10Smuffin return (0);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate
224e5190c10Smuffin int
casenh()2257c478bd9Sstevel@tonic-gate casenh()
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate hyf = 0;
228e5190c10Smuffin
229e5190c10Smuffin return (0);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate
233e5190c10Smuffin int
max(aa,bb)2347c478bd9Sstevel@tonic-gate max(aa, bb)
2357c478bd9Sstevel@tonic-gate int aa, bb;
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate if (aa > bb)
2387c478bd9Sstevel@tonic-gate return(aa);
239*2a8bcb4eSToomas Soome else
2407c478bd9Sstevel@tonic-gate return(bb);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate
244e5190c10Smuffin int
casece()2457c478bd9Sstevel@tonic-gate casece()
2467c478bd9Sstevel@tonic-gate {
247e5190c10Smuffin int i;
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate noscale++;
2507c478bd9Sstevel@tonic-gate skip();
2517c478bd9Sstevel@tonic-gate i = max(atoi(), 0);
2527c478bd9Sstevel@tonic-gate if (nonumb)
2537c478bd9Sstevel@tonic-gate i = 1;
2547c478bd9Sstevel@tonic-gate tbreak();
2557c478bd9Sstevel@tonic-gate ce = i;
2567c478bd9Sstevel@tonic-gate noscale = 0;
257e5190c10Smuffin
258e5190c10Smuffin return (0);
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate
262e5190c10Smuffin int
casein()2637c478bd9Sstevel@tonic-gate casein()
2647c478bd9Sstevel@tonic-gate {
265e5190c10Smuffin int i;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (skip())
2687c478bd9Sstevel@tonic-gate i = in1;
269*2a8bcb4eSToomas Soome else
2707c478bd9Sstevel@tonic-gate i = max(hnumb(&in), 0);
2717c478bd9Sstevel@tonic-gate tbreak();
2727c478bd9Sstevel@tonic-gate in1 = in;
2737c478bd9Sstevel@tonic-gate in = i;
2747c478bd9Sstevel@tonic-gate if (!nc) {
2757c478bd9Sstevel@tonic-gate un = in;
2767c478bd9Sstevel@tonic-gate setnel();
2777c478bd9Sstevel@tonic-gate }
278e5190c10Smuffin
279e5190c10Smuffin return (0);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate
283e5190c10Smuffin int
casell()2847c478bd9Sstevel@tonic-gate casell()
2857c478bd9Sstevel@tonic-gate {
286e5190c10Smuffin int i;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate if (skip())
2897c478bd9Sstevel@tonic-gate i = ll1;
290*2a8bcb4eSToomas Soome else
2917c478bd9Sstevel@tonic-gate i = max(hnumb(&ll), INCH / 10);
2927c478bd9Sstevel@tonic-gate ll1 = ll;
2937c478bd9Sstevel@tonic-gate ll = i;
2947c478bd9Sstevel@tonic-gate setnel();
295e5190c10Smuffin
296e5190c10Smuffin return (0);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate
300e5190c10Smuffin int
caselt()3017c478bd9Sstevel@tonic-gate caselt()
3027c478bd9Sstevel@tonic-gate {
303e5190c10Smuffin int i;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate if (skip())
3067c478bd9Sstevel@tonic-gate i = lt1;
307*2a8bcb4eSToomas Soome else
3087c478bd9Sstevel@tonic-gate i = max(hnumb(<), 0);
3097c478bd9Sstevel@tonic-gate lt1 = lt;
3107c478bd9Sstevel@tonic-gate lt = i;
311e5190c10Smuffin
312e5190c10Smuffin return (0);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate
316e5190c10Smuffin int
caseti()3177c478bd9Sstevel@tonic-gate caseti()
3187c478bd9Sstevel@tonic-gate {
319e5190c10Smuffin int i;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate if (skip())
322e5190c10Smuffin return (0);
3237c478bd9Sstevel@tonic-gate i = max(hnumb(&in), 0);
3247c478bd9Sstevel@tonic-gate tbreak();
3257c478bd9Sstevel@tonic-gate un1 = i;
3267c478bd9Sstevel@tonic-gate setnel();
327e5190c10Smuffin
328e5190c10Smuffin return (0);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate
332e5190c10Smuffin int
casels()3337c478bd9Sstevel@tonic-gate casels()
3347c478bd9Sstevel@tonic-gate {
335e5190c10Smuffin int i;
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate noscale++;
3387c478bd9Sstevel@tonic-gate if (skip())
3397c478bd9Sstevel@tonic-gate i = ls1;
340*2a8bcb4eSToomas Soome else
3417c478bd9Sstevel@tonic-gate i = max(inumb(&ls), 1);
3427c478bd9Sstevel@tonic-gate ls1 = ls;
3437c478bd9Sstevel@tonic-gate ls = i;
3447c478bd9Sstevel@tonic-gate noscale = 0;
345e5190c10Smuffin
346e5190c10Smuffin return (0);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate
350e5190c10Smuffin int
casepo()3517c478bd9Sstevel@tonic-gate casepo()
3527c478bd9Sstevel@tonic-gate {
353e5190c10Smuffin int i;
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate if (skip())
3567c478bd9Sstevel@tonic-gate i = po1;
357*2a8bcb4eSToomas Soome else
3587c478bd9Sstevel@tonic-gate i = max(hnumb(&po), 0);
3597c478bd9Sstevel@tonic-gate po1 = po;
3607c478bd9Sstevel@tonic-gate po = i;
3617c478bd9Sstevel@tonic-gate #ifndef NROFF
3627c478bd9Sstevel@tonic-gate if (!ascii)
3637c478bd9Sstevel@tonic-gate esc += po - po1;
3647c478bd9Sstevel@tonic-gate #endif
365e5190c10Smuffin return (0);
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate
369e5190c10Smuffin int
casepl()3707c478bd9Sstevel@tonic-gate casepl()
3717c478bd9Sstevel@tonic-gate {
372e5190c10Smuffin int i;
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate skip();
3757c478bd9Sstevel@tonic-gate if ((i = vnumb(&pl)) == 0)
3767c478bd9Sstevel@tonic-gate pl = 11 * INCH; /*11in*/
377*2a8bcb4eSToomas Soome else
3787c478bd9Sstevel@tonic-gate pl = i;
3797c478bd9Sstevel@tonic-gate if (numtab[NL].val > pl)
3807c478bd9Sstevel@tonic-gate numtab[NL].val = pl;
381e5190c10Smuffin
382e5190c10Smuffin return (0);
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate
386e5190c10Smuffin int
casewh()3877c478bd9Sstevel@tonic-gate casewh()
3887c478bd9Sstevel@tonic-gate {
389e5190c10Smuffin int i, j, k;
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate lgf++;
3927c478bd9Sstevel@tonic-gate skip();
3937c478bd9Sstevel@tonic-gate i = vnumb((int *)0);
3947c478bd9Sstevel@tonic-gate if (nonumb)
395e5190c10Smuffin return (0);
3967c478bd9Sstevel@tonic-gate skip();
3977c478bd9Sstevel@tonic-gate j = getrq();
3987c478bd9Sstevel@tonic-gate if ((k = findn(i)) != NTRAP) {
3997c478bd9Sstevel@tonic-gate mlist[k] = j;
400e5190c10Smuffin return (0);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate for (k = 0; k < NTRAP; k++)
4037c478bd9Sstevel@tonic-gate if (mlist[k] == 0)
4047c478bd9Sstevel@tonic-gate break;
4057c478bd9Sstevel@tonic-gate if (k == NTRAP) {
4067c478bd9Sstevel@tonic-gate flusho();
4077c478bd9Sstevel@tonic-gate errprint(gettext("cannot plant trap."));
408e5190c10Smuffin return (0);
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate mlist[k] = j;
4117c478bd9Sstevel@tonic-gate nlist[k] = i;
412e5190c10Smuffin
413e5190c10Smuffin return (0);
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate
417e5190c10Smuffin int
casech()4187c478bd9Sstevel@tonic-gate casech()
4197c478bd9Sstevel@tonic-gate {
420e5190c10Smuffin int i, j, k;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate lgf++;
4237c478bd9Sstevel@tonic-gate skip();
4247c478bd9Sstevel@tonic-gate if (!(j = getrq()))
425e5190c10Smuffin return (0);
426*2a8bcb4eSToomas Soome else
4277c478bd9Sstevel@tonic-gate for (k = 0; k < NTRAP; k++)
4287c478bd9Sstevel@tonic-gate if (mlist[k] == j)
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate if (k == NTRAP)
431e5190c10Smuffin return (0);
4327c478bd9Sstevel@tonic-gate skip();
4337c478bd9Sstevel@tonic-gate i = vnumb((int *)0);
4347c478bd9Sstevel@tonic-gate if (nonumb)
4357c478bd9Sstevel@tonic-gate mlist[k] = 0;
4367c478bd9Sstevel@tonic-gate nlist[k] = i;
437e5190c10Smuffin
438e5190c10Smuffin return (0);
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate
442e5190c10Smuffin int
findn(i)4437c478bd9Sstevel@tonic-gate findn(i)
4447c478bd9Sstevel@tonic-gate int i;
4457c478bd9Sstevel@tonic-gate {
446e5190c10Smuffin int k;
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate for (k = 0; k < NTRAP; k++)
4497c478bd9Sstevel@tonic-gate if ((nlist[k] == i) && (mlist[k] != 0))
4507c478bd9Sstevel@tonic-gate break;
4517c478bd9Sstevel@tonic-gate return(k);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate
455e5190c10Smuffin int
casepn()4567c478bd9Sstevel@tonic-gate casepn()
4577c478bd9Sstevel@tonic-gate {
458e5190c10Smuffin int i;
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate skip();
4617c478bd9Sstevel@tonic-gate noscale++;
4627c478bd9Sstevel@tonic-gate i = max(inumb(&numtab[PN].val), 0);
4637c478bd9Sstevel@tonic-gate noscale = 0;
4647c478bd9Sstevel@tonic-gate if (!nonumb) {
4657c478bd9Sstevel@tonic-gate npn = i;
4667c478bd9Sstevel@tonic-gate npnflg++;
4677c478bd9Sstevel@tonic-gate }
468e5190c10Smuffin
469e5190c10Smuffin return (0);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate
473e5190c10Smuffin int
casebp()4747c478bd9Sstevel@tonic-gate casebp()
4757c478bd9Sstevel@tonic-gate {
476e5190c10Smuffin int i;
477e5190c10Smuffin struct s *savframe;
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate if (dip != d)
480e5190c10Smuffin return (0);
4817c478bd9Sstevel@tonic-gate savframe = frame;
4827c478bd9Sstevel@tonic-gate skip();
4837c478bd9Sstevel@tonic-gate if ((i = inumb(&numtab[PN].val)) < 0)
4847c478bd9Sstevel@tonic-gate i = 0;
4857c478bd9Sstevel@tonic-gate tbreak();
4867c478bd9Sstevel@tonic-gate if (!nonumb) {
4877c478bd9Sstevel@tonic-gate npn = i;
4887c478bd9Sstevel@tonic-gate npnflg++;
4897c478bd9Sstevel@tonic-gate } else if (dip->nls)
490e5190c10Smuffin return (0);
4917c478bd9Sstevel@tonic-gate eject(savframe);
492e5190c10Smuffin
493e5190c10Smuffin return (0);
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate
497e5190c10Smuffin int
casetm(ab)498*2a8bcb4eSToomas Soome casetm(ab)
4997c478bd9Sstevel@tonic-gate int ab;
5007c478bd9Sstevel@tonic-gate {
501e5190c10Smuffin int i;
5027c478bd9Sstevel@tonic-gate char tmbuf[NTM];
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate lgf++;
5057c478bd9Sstevel@tonic-gate copyf++;
5067c478bd9Sstevel@tonic-gate if (skip() && ab)
5077c478bd9Sstevel@tonic-gate errprint(gettext("User Abort"));
5087c478bd9Sstevel@tonic-gate for (i = 0; i < NTM - 2; )
5097c478bd9Sstevel@tonic-gate if ((tmbuf[i++] = getch()) == '\n')
5107c478bd9Sstevel@tonic-gate break;
5117c478bd9Sstevel@tonic-gate if (i == NTM - 2)
5127c478bd9Sstevel@tonic-gate tmbuf[i++] = '\n';
5137c478bd9Sstevel@tonic-gate tmbuf[i] = 0;
5147c478bd9Sstevel@tonic-gate if (ab) /* truncate output */
5157c478bd9Sstevel@tonic-gate obufp = obuf; /* should be a function in n2.c */
5167c478bd9Sstevel@tonic-gate flusho();
5177c478bd9Sstevel@tonic-gate fdprintf(stderr, "%s", tmbuf);
5187c478bd9Sstevel@tonic-gate copyf--;
5197c478bd9Sstevel@tonic-gate lgf--;
520e5190c10Smuffin
521e5190c10Smuffin return (0);
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate
525e5190c10Smuffin int
casesp(a)5267c478bd9Sstevel@tonic-gate casesp(a)
5277c478bd9Sstevel@tonic-gate int a;
5287c478bd9Sstevel@tonic-gate {
529e5190c10Smuffin int i, j, savlss;
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate tbreak();
5327c478bd9Sstevel@tonic-gate if (dip->nls || trap)
533e5190c10Smuffin return (0);
5347c478bd9Sstevel@tonic-gate i = findt1();
5357c478bd9Sstevel@tonic-gate if (!a) {
5367c478bd9Sstevel@tonic-gate skip();
5377c478bd9Sstevel@tonic-gate j = vnumb((int *)0);
5387c478bd9Sstevel@tonic-gate if (nonumb)
5397c478bd9Sstevel@tonic-gate j = lss;
540*2a8bcb4eSToomas Soome } else
5417c478bd9Sstevel@tonic-gate j = a;
5427c478bd9Sstevel@tonic-gate if (j == 0)
543e5190c10Smuffin return (0);
5447c478bd9Sstevel@tonic-gate if (i < j)
5457c478bd9Sstevel@tonic-gate j = i;
5467c478bd9Sstevel@tonic-gate savlss = lss;
5477c478bd9Sstevel@tonic-gate if (dip != d)
548*2a8bcb4eSToomas Soome i = dip->dnl;
549*2a8bcb4eSToomas Soome else
5507c478bd9Sstevel@tonic-gate i = numtab[NL].val;
5517c478bd9Sstevel@tonic-gate if ((i + j) < 0)
5527c478bd9Sstevel@tonic-gate j = -i;
5537c478bd9Sstevel@tonic-gate lss = j;
5547c478bd9Sstevel@tonic-gate newline(0);
5557c478bd9Sstevel@tonic-gate lss = savlss;
556e5190c10Smuffin
557e5190c10Smuffin return (0);
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate
561e5190c10Smuffin int
casert()5627c478bd9Sstevel@tonic-gate casert()
5637c478bd9Sstevel@tonic-gate {
564e5190c10Smuffin int a, *p;
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate skip();
5677c478bd9Sstevel@tonic-gate if (dip != d)
568*2a8bcb4eSToomas Soome p = &dip->dnl;
569*2a8bcb4eSToomas Soome else
5707c478bd9Sstevel@tonic-gate p = &numtab[NL].val;
5717c478bd9Sstevel@tonic-gate a = vnumb(p);
5727c478bd9Sstevel@tonic-gate if (nonumb)
5737c478bd9Sstevel@tonic-gate a = dip->mkline;
5747c478bd9Sstevel@tonic-gate if ((a < 0) || (a >= *p))
575e5190c10Smuffin return (0);
5767c478bd9Sstevel@tonic-gate nb++;
5777c478bd9Sstevel@tonic-gate casesp(a - *p);
578e5190c10Smuffin
579e5190c10Smuffin return (0);
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate
583e5190c10Smuffin int
caseem()5847c478bd9Sstevel@tonic-gate caseem()
5857c478bd9Sstevel@tonic-gate {
5867c478bd9Sstevel@tonic-gate lgf++;
5877c478bd9Sstevel@tonic-gate skip();
5887c478bd9Sstevel@tonic-gate em = getrq();
589e5190c10Smuffin
590e5190c10Smuffin return (0);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate
594e5190c10Smuffin int
casefl()5957c478bd9Sstevel@tonic-gate casefl()
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate tbreak();
5987c478bd9Sstevel@tonic-gate flusho();
599e5190c10Smuffin
600e5190c10Smuffin return (0);
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate
604e5190c10Smuffin int
caseev()6057c478bd9Sstevel@tonic-gate caseev()
6067c478bd9Sstevel@tonic-gate {
607e5190c10Smuffin int nxev;
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate if (skip()) {
6107c478bd9Sstevel@tonic-gate e0:
6117c478bd9Sstevel@tonic-gate if (evi == 0)
612e5190c10Smuffin return (0);
6137c478bd9Sstevel@tonic-gate nxev = evlist[--evi];
6147c478bd9Sstevel@tonic-gate goto e1;
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate noscale++;
6177c478bd9Sstevel@tonic-gate nxev = atoi();
6187c478bd9Sstevel@tonic-gate noscale = 0;
6197c478bd9Sstevel@tonic-gate if (nonumb)
6207c478bd9Sstevel@tonic-gate goto e0;
6217c478bd9Sstevel@tonic-gate flushi();
6227c478bd9Sstevel@tonic-gate if ((nxev >= NEV) || (nxev < 0) || (evi >= EVLSZ)) {
6237c478bd9Sstevel@tonic-gate flusho();
6247c478bd9Sstevel@tonic-gate errprint(gettext("cannot do ev."));
6257c478bd9Sstevel@tonic-gate if (error)
6267c478bd9Sstevel@tonic-gate done2(040);
627*2a8bcb4eSToomas Soome else
6287c478bd9Sstevel@tonic-gate edone(040);
629e5190c10Smuffin return (0);
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate evlist[evi++] = ev;
6327c478bd9Sstevel@tonic-gate e1:
6337c478bd9Sstevel@tonic-gate if (ev == nxev)
634e5190c10Smuffin return (0);
6357c478bd9Sstevel@tonic-gate #ifdef INCORE
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate extern tchar corebuf[];
6387c478bd9Sstevel@tonic-gate *(struct env *)&corebuf[ev * sizeof(env)/sizeof(tchar)] = env;
6397c478bd9Sstevel@tonic-gate env = *(struct env *)&corebuf[nxev * sizeof(env)/sizeof(tchar)];
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate #else
6427c478bd9Sstevel@tonic-gate lseek(ibf, ev * (long)sizeof(env), 0);
6437c478bd9Sstevel@tonic-gate write(ibf, (char *) & env, sizeof(env));
6447c478bd9Sstevel@tonic-gate lseek(ibf, nxev * (long)sizeof(env), 0);
6457c478bd9Sstevel@tonic-gate read(ibf, (char *) & env, sizeof(env));
6467c478bd9Sstevel@tonic-gate #endif
6477c478bd9Sstevel@tonic-gate ev = nxev;
648e5190c10Smuffin
649e5190c10Smuffin return (0);
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate
652e5190c10Smuffin int
caseel()6537c478bd9Sstevel@tonic-gate caseel()
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate if (--ifx < 0) {
6567c478bd9Sstevel@tonic-gate ifx = 0;
6577c478bd9Sstevel@tonic-gate iflist[0] = 0;
6587c478bd9Sstevel@tonic-gate }
6597c478bd9Sstevel@tonic-gate caseif(2);
660e5190c10Smuffin
661e5190c10Smuffin return (0);
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate
665e5190c10Smuffin int
caseie()6667c478bd9Sstevel@tonic-gate caseie()
6677c478bd9Sstevel@tonic-gate {
6687c478bd9Sstevel@tonic-gate if (ifx >= NIF) {
6697c478bd9Sstevel@tonic-gate errprint(gettext("if-else overflow."));
6707c478bd9Sstevel@tonic-gate ifx = 0;
6717c478bd9Sstevel@tonic-gate edone(040);
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate caseif(1);
6747c478bd9Sstevel@tonic-gate ifx++;
675e5190c10Smuffin
676e5190c10Smuffin return (0);
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate
680e5190c10Smuffin int
caseif(x)6817c478bd9Sstevel@tonic-gate caseif(x)
6827c478bd9Sstevel@tonic-gate int x;
6837c478bd9Sstevel@tonic-gate {
6847c478bd9Sstevel@tonic-gate extern int falsef;
685e5190c10Smuffin int notflag, true;
6867c478bd9Sstevel@tonic-gate tchar i;
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate if (x == 2) {
6897c478bd9Sstevel@tonic-gate notflag = 0;
6907c478bd9Sstevel@tonic-gate true = iflist[ifx];
6917c478bd9Sstevel@tonic-gate goto i1;
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate true = 0;
6947c478bd9Sstevel@tonic-gate skip();
6957c478bd9Sstevel@tonic-gate if ((cbits(i = getch())) == '!') {
6967c478bd9Sstevel@tonic-gate notflag = 1;
6977c478bd9Sstevel@tonic-gate } else {
6987c478bd9Sstevel@tonic-gate notflag = 0;
6997c478bd9Sstevel@tonic-gate ch = i;
7007c478bd9Sstevel@tonic-gate }
7017c478bd9Sstevel@tonic-gate i = atoi();
7027c478bd9Sstevel@tonic-gate if (!nonumb) {
7037c478bd9Sstevel@tonic-gate if (i > 0)
7047c478bd9Sstevel@tonic-gate true++;
7057c478bd9Sstevel@tonic-gate goto i1;
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate i = getch();
7087c478bd9Sstevel@tonic-gate switch (cbits(i)) {
7097c478bd9Sstevel@tonic-gate case 'e':
7107c478bd9Sstevel@tonic-gate if (!(numtab[PN].val & 01))
7117c478bd9Sstevel@tonic-gate true++;
7127c478bd9Sstevel@tonic-gate break;
7137c478bd9Sstevel@tonic-gate case 'o':
7147c478bd9Sstevel@tonic-gate if (numtab[PN].val & 01)
7157c478bd9Sstevel@tonic-gate true++;
7167c478bd9Sstevel@tonic-gate break;
7177c478bd9Sstevel@tonic-gate #ifdef NROFF
7187c478bd9Sstevel@tonic-gate case 'n':
7197c478bd9Sstevel@tonic-gate true++;
7207c478bd9Sstevel@tonic-gate case 't':
7217c478bd9Sstevel@tonic-gate #endif
7227c478bd9Sstevel@tonic-gate #ifndef NROFF
7237c478bd9Sstevel@tonic-gate case 't':
7247c478bd9Sstevel@tonic-gate true++;
7257c478bd9Sstevel@tonic-gate case 'n':
7267c478bd9Sstevel@tonic-gate #endif
7277c478bd9Sstevel@tonic-gate case ' ':
7287c478bd9Sstevel@tonic-gate break;
7297c478bd9Sstevel@tonic-gate default:
7307c478bd9Sstevel@tonic-gate true = cmpstr(i);
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate i1:
7337c478bd9Sstevel@tonic-gate true ^= notflag;
7347c478bd9Sstevel@tonic-gate if (x == 1)
7357c478bd9Sstevel@tonic-gate iflist[ifx] = !true;
7367c478bd9Sstevel@tonic-gate if (true) {
7377c478bd9Sstevel@tonic-gate i2:
7387c478bd9Sstevel@tonic-gate while ((cbits(i = getch())) == ' ')
7397c478bd9Sstevel@tonic-gate ;
7407c478bd9Sstevel@tonic-gate if (cbits(i) == LEFT)
7417c478bd9Sstevel@tonic-gate goto i2;
7427c478bd9Sstevel@tonic-gate ch = i;
7437c478bd9Sstevel@tonic-gate nflush++;
7447c478bd9Sstevel@tonic-gate } else {
7457c478bd9Sstevel@tonic-gate copyf++;
7467c478bd9Sstevel@tonic-gate falsef++;
7477c478bd9Sstevel@tonic-gate eatblk(0);
7487c478bd9Sstevel@tonic-gate copyf--;
7497c478bd9Sstevel@tonic-gate falsef--;
7507c478bd9Sstevel@tonic-gate }
751e5190c10Smuffin
752e5190c10Smuffin return (0);
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate
755e5190c10Smuffin int
eatblk(inblk)7567c478bd9Sstevel@tonic-gate eatblk(inblk)
7577c478bd9Sstevel@tonic-gate int inblk;
758e5190c10Smuffin { int cnt, i;
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate cnt = 0;
7617c478bd9Sstevel@tonic-gate do {
7627c478bd9Sstevel@tonic-gate if (ch) {
7637c478bd9Sstevel@tonic-gate i = cbits(ch);
7647c478bd9Sstevel@tonic-gate ch = 0;
7657c478bd9Sstevel@tonic-gate } else
7667c478bd9Sstevel@tonic-gate i = cbits(getch0());
7677c478bd9Sstevel@tonic-gate if (i == ESC)
7687c478bd9Sstevel@tonic-gate cnt++;
7697c478bd9Sstevel@tonic-gate else {
7707c478bd9Sstevel@tonic-gate if (cnt == 1)
7717c478bd9Sstevel@tonic-gate switch (i) {
7727c478bd9Sstevel@tonic-gate case '{': i = LEFT; break;
7737c478bd9Sstevel@tonic-gate case '}': i = RIGHT; break;
7747c478bd9Sstevel@tonic-gate case '\n': i = 'x'; break;
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate cnt = 0;
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate if (i == LEFT) eatblk(1);
7797c478bd9Sstevel@tonic-gate } while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT)));
7807c478bd9Sstevel@tonic-gate if (i == '\n')
7817c478bd9Sstevel@tonic-gate nlflg++;
782e5190c10Smuffin
783e5190c10Smuffin return (0);
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate
787e5190c10Smuffin int
cmpstr(c)7887c478bd9Sstevel@tonic-gate cmpstr(c)
7897c478bd9Sstevel@tonic-gate tchar c;
7907c478bd9Sstevel@tonic-gate {
791e5190c10Smuffin int j, delim;
792e5190c10Smuffin tchar i;
793e5190c10Smuffin int val;
7947c478bd9Sstevel@tonic-gate int savapts, savapts1, savfont, savfont1, savpts, savpts1;
7957c478bd9Sstevel@tonic-gate tchar string[1280];
796e5190c10Smuffin tchar *sp;
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate if (ismot(c))
7997c478bd9Sstevel@tonic-gate return(0);
8007c478bd9Sstevel@tonic-gate delim = cbits(c);
8017c478bd9Sstevel@tonic-gate savapts = apts;
8027c478bd9Sstevel@tonic-gate savapts1 = apts1;
8037c478bd9Sstevel@tonic-gate savfont = font;
8047c478bd9Sstevel@tonic-gate savfont1 = font1;
8057c478bd9Sstevel@tonic-gate savpts = pts;
8067c478bd9Sstevel@tonic-gate savpts1 = pts1;
8077c478bd9Sstevel@tonic-gate sp = string;
8087c478bd9Sstevel@tonic-gate while ((j = cbits(i = getch()))!=delim && j!='\n' && sp<&string[1280-1])
8097c478bd9Sstevel@tonic-gate *sp++ = i;
8107c478bd9Sstevel@tonic-gate if (sp >= string + 1280) {
8117c478bd9Sstevel@tonic-gate errprint(gettext("too-long string compare."));
8127c478bd9Sstevel@tonic-gate edone(0100);
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate if (nlflg) {
8157c478bd9Sstevel@tonic-gate val = sp==string;
8167c478bd9Sstevel@tonic-gate goto rtn;
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate *sp++ = 0;
8197c478bd9Sstevel@tonic-gate apts = savapts;
8207c478bd9Sstevel@tonic-gate apts1 = savapts1;
8217c478bd9Sstevel@tonic-gate font = savfont;
8227c478bd9Sstevel@tonic-gate font1 = savfont1;
8237c478bd9Sstevel@tonic-gate pts = savpts;
8247c478bd9Sstevel@tonic-gate pts1 = savpts1;
8257c478bd9Sstevel@tonic-gate mchbits();
8267c478bd9Sstevel@tonic-gate val = 1;
8277c478bd9Sstevel@tonic-gate sp = string;
8287c478bd9Sstevel@tonic-gate while ((j = cbits(i = getch())) != delim && j != '\n') {
8297c478bd9Sstevel@tonic-gate if (*sp != i) {
8307c478bd9Sstevel@tonic-gate eat(delim);
8317c478bd9Sstevel@tonic-gate val = 0;
8327c478bd9Sstevel@tonic-gate goto rtn;
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate sp++;
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate if (*sp)
8377c478bd9Sstevel@tonic-gate val = 0;
8387c478bd9Sstevel@tonic-gate rtn:
8397c478bd9Sstevel@tonic-gate apts = savapts;
8407c478bd9Sstevel@tonic-gate apts1 = savapts1;
8417c478bd9Sstevel@tonic-gate font = savfont;
8427c478bd9Sstevel@tonic-gate font1 = savfont1;
8437c478bd9Sstevel@tonic-gate pts = savpts;
8447c478bd9Sstevel@tonic-gate pts1 = savpts1;
8457c478bd9Sstevel@tonic-gate mchbits();
8467c478bd9Sstevel@tonic-gate return(val);
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate
850e5190c10Smuffin int
caserd()8517c478bd9Sstevel@tonic-gate caserd()
8527c478bd9Sstevel@tonic-gate {
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate lgf++;
8557c478bd9Sstevel@tonic-gate skip();
8567c478bd9Sstevel@tonic-gate getname();
8577c478bd9Sstevel@tonic-gate if (!iflg) {
8587c478bd9Sstevel@tonic-gate if (quiet) {
8597c478bd9Sstevel@tonic-gate #ifdef NROFF
8607c478bd9Sstevel@tonic-gate echo_off();
8617c478bd9Sstevel@tonic-gate flusho();
862e5190c10Smuffin #endif /* NROFF */
8637c478bd9Sstevel@tonic-gate fdprintf(stderr, "\007"); /*bell*/
8647c478bd9Sstevel@tonic-gate } else {
8657c478bd9Sstevel@tonic-gate if (nextf[0]) {
8667c478bd9Sstevel@tonic-gate fdprintf(stderr, "%s:", nextf);
8677c478bd9Sstevel@tonic-gate } else {
8687c478bd9Sstevel@tonic-gate fdprintf(stderr, "\007"); /*bell*/
8697c478bd9Sstevel@tonic-gate }
8707c478bd9Sstevel@tonic-gate }
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate collect();
8737c478bd9Sstevel@tonic-gate tty++;
8747c478bd9Sstevel@tonic-gate pushi(NBLIST*BLK, PAIR('r','d'));
875e5190c10Smuffin
876e5190c10Smuffin return (0);
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate
880e5190c10Smuffin int
rdtty()8817c478bd9Sstevel@tonic-gate rdtty()
8827c478bd9Sstevel@tonic-gate {
8837c478bd9Sstevel@tonic-gate char onechar;
8847c478bd9Sstevel@tonic-gate #ifdef EUC
8857c478bd9Sstevel@tonic-gate #ifdef NROFF
8867c478bd9Sstevel@tonic-gate int i, n, col_index;
8877c478bd9Sstevel@tonic-gate #endif /* NROFF */
8887c478bd9Sstevel@tonic-gate #endif /* EUC */
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate onechar = 0;
8917c478bd9Sstevel@tonic-gate if (read(0, &onechar, 1) == 1) {
8927c478bd9Sstevel@tonic-gate if (onechar == '\n')
8937c478bd9Sstevel@tonic-gate tty++;
894*2a8bcb4eSToomas Soome else
8957c478bd9Sstevel@tonic-gate tty = 1;
8967c478bd9Sstevel@tonic-gate #ifndef EUC
8977c478bd9Sstevel@tonic-gate if (tty != 3)
8987c478bd9Sstevel@tonic-gate return(onechar);
8997c478bd9Sstevel@tonic-gate #else
9007c478bd9Sstevel@tonic-gate #ifndef NROFF
9017c478bd9Sstevel@tonic-gate if (tty != 3)
9027c478bd9Sstevel@tonic-gate return(onechar);
9037c478bd9Sstevel@tonic-gate #else
9047c478bd9Sstevel@tonic-gate if (tty != 3) {
9057c478bd9Sstevel@tonic-gate if (!multi_locale)
9067c478bd9Sstevel@tonic-gate return(onechar);
9077c478bd9Sstevel@tonic-gate i = onechar & 0377;
9087c478bd9Sstevel@tonic-gate *mbbuf1p++ = i;
9097c478bd9Sstevel@tonic-gate *mbbuf1p = 0;
9107c478bd9Sstevel@tonic-gate if ((n = mbtowc(&twc, mbbuf1, MB_CUR_MAX)) <= 0) {
9117c478bd9Sstevel@tonic-gate if (mbbuf1p >= mbbuf1 + MB_CUR_MAX) {
9127c478bd9Sstevel@tonic-gate i &= ~(MBMASK | CSMASK);
9137c478bd9Sstevel@tonic-gate twc = 0;
9147c478bd9Sstevel@tonic-gate mbbuf1p = mbbuf1;
9157c478bd9Sstevel@tonic-gate *mbbuf1p = 0;
9167c478bd9Sstevel@tonic-gate } else {
9177c478bd9Sstevel@tonic-gate i |= (MIDDLEOFMB);
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate } else {
9207c478bd9Sstevel@tonic-gate if (n > 1)
9217c478bd9Sstevel@tonic-gate i |= (LASTOFMB);
9227c478bd9Sstevel@tonic-gate else
9237c478bd9Sstevel@tonic-gate i |= (BYTE_CHR);
9247c478bd9Sstevel@tonic-gate if (isascii(twc)) {
9257c478bd9Sstevel@tonic-gate col_index = 0;
9267c478bd9Sstevel@tonic-gate } else {
9277c478bd9Sstevel@tonic-gate if ((col_index = wcwidth(twc)) < 0)
9287c478bd9Sstevel@tonic-gate col_index = 0;
9297c478bd9Sstevel@tonic-gate }
9307c478bd9Sstevel@tonic-gate setcsbits(i, col_index);
9317c478bd9Sstevel@tonic-gate twc = 0;
9327c478bd9Sstevel@tonic-gate mbbuf1p = mbbuf1;
9337c478bd9Sstevel@tonic-gate }
9347c478bd9Sstevel@tonic-gate return(i);
9357c478bd9Sstevel@tonic-gate }
9367c478bd9Sstevel@tonic-gate #endif /* NROFF */
9377c478bd9Sstevel@tonic-gate #endif /* EUC */
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate popi();
9407c478bd9Sstevel@tonic-gate tty = 0;
9417c478bd9Sstevel@tonic-gate #ifdef NROFF
9427c478bd9Sstevel@tonic-gate if (quiet)
9437c478bd9Sstevel@tonic-gate echo_on();
944e5190c10Smuffin #endif /* NROFF */
9457c478bd9Sstevel@tonic-gate return(0);
9467c478bd9Sstevel@tonic-gate }
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gate
949e5190c10Smuffin int
caseec()9507c478bd9Sstevel@tonic-gate caseec()
9517c478bd9Sstevel@tonic-gate {
9527c478bd9Sstevel@tonic-gate eschar = chget('\\');
953e5190c10Smuffin
954e5190c10Smuffin return (0);
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate
9577c478bd9Sstevel@tonic-gate
958e5190c10Smuffin int
caseeo()9597c478bd9Sstevel@tonic-gate caseeo()
9607c478bd9Sstevel@tonic-gate {
9617c478bd9Sstevel@tonic-gate eschar = 0;
962e5190c10Smuffin
963e5190c10Smuffin return (0);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate
967e5190c10Smuffin int
caseta()9687c478bd9Sstevel@tonic-gate caseta()
9697c478bd9Sstevel@tonic-gate {
970e5190c10Smuffin int i;
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate tabtab[0] = nonumb = 0;
9737c478bd9Sstevel@tonic-gate for (i = 0; ((i < (NTAB - 1)) && !nonumb); i++) {
9747c478bd9Sstevel@tonic-gate if (skip())
9757c478bd9Sstevel@tonic-gate break;
9767c478bd9Sstevel@tonic-gate tabtab[i] = max(hnumb(&tabtab[max(i-1,0)]), 0) & TABMASK;
977*2a8bcb4eSToomas Soome if (!nonumb)
9787c478bd9Sstevel@tonic-gate switch (cbits(ch)) {
9797c478bd9Sstevel@tonic-gate case 'C':
9807c478bd9Sstevel@tonic-gate tabtab[i] |= CTAB;
9817c478bd9Sstevel@tonic-gate break;
9827c478bd9Sstevel@tonic-gate case 'R':
9837c478bd9Sstevel@tonic-gate tabtab[i] |= RTAB;
9847c478bd9Sstevel@tonic-gate break;
9857c478bd9Sstevel@tonic-gate default: /*includes L*/
9867c478bd9Sstevel@tonic-gate break;
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate nonumb = ch = 0;
9897c478bd9Sstevel@tonic-gate }
9907c478bd9Sstevel@tonic-gate tabtab[i] = 0;
991e5190c10Smuffin
992e5190c10Smuffin return (0);
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate
996e5190c10Smuffin int
casene()9977c478bd9Sstevel@tonic-gate casene()
9987c478bd9Sstevel@tonic-gate {
999e5190c10Smuffin int i, j;
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate skip();
10027c478bd9Sstevel@tonic-gate i = vnumb((int *)0);
10037c478bd9Sstevel@tonic-gate if (nonumb)
10047c478bd9Sstevel@tonic-gate i = lss;
10057c478bd9Sstevel@tonic-gate if (i > (j = findt1())) {
10067c478bd9Sstevel@tonic-gate i = lss;
10077c478bd9Sstevel@tonic-gate lss = j;
10087c478bd9Sstevel@tonic-gate dip->nls = 0;
10097c478bd9Sstevel@tonic-gate newline(0);
10107c478bd9Sstevel@tonic-gate lss = i;
10117c478bd9Sstevel@tonic-gate }
1012e5190c10Smuffin
1013e5190c10Smuffin return (0);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate
1017e5190c10Smuffin int
casetr()10187c478bd9Sstevel@tonic-gate casetr()
10197c478bd9Sstevel@tonic-gate {
1020e5190c10Smuffin int i, j;
10217c478bd9Sstevel@tonic-gate tchar k;
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gate lgf++;
10247c478bd9Sstevel@tonic-gate skip();
10257c478bd9Sstevel@tonic-gate while ((i = cbits(k=getch())) != '\n') {
10267c478bd9Sstevel@tonic-gate if (ismot(k))
1027e5190c10Smuffin return (0);
10287c478bd9Sstevel@tonic-gate if (ismot(k = getch()))
1029e5190c10Smuffin return (0);
10307c478bd9Sstevel@tonic-gate if ((j = cbits(k)) == '\n')
10317c478bd9Sstevel@tonic-gate j = ' ';
10327c478bd9Sstevel@tonic-gate trtab[i] = j;
10337c478bd9Sstevel@tonic-gate }
1034e5190c10Smuffin
1035e5190c10Smuffin return (0);
10367c478bd9Sstevel@tonic-gate }
10377c478bd9Sstevel@tonic-gate
10387c478bd9Sstevel@tonic-gate
1039e5190c10Smuffin int
casecu()10407c478bd9Sstevel@tonic-gate casecu()
10417c478bd9Sstevel@tonic-gate {
10427c478bd9Sstevel@tonic-gate cu++;
10437c478bd9Sstevel@tonic-gate caseul();
1044e5190c10Smuffin
1045e5190c10Smuffin return (0);
10467c478bd9Sstevel@tonic-gate }
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate
1049e5190c10Smuffin int
caseul()10507c478bd9Sstevel@tonic-gate caseul()
10517c478bd9Sstevel@tonic-gate {
1052e5190c10Smuffin int i;
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate noscale++;
10557c478bd9Sstevel@tonic-gate if (skip())
10567c478bd9Sstevel@tonic-gate i = 1;
1057*2a8bcb4eSToomas Soome else
10587c478bd9Sstevel@tonic-gate i = atoi();
10597c478bd9Sstevel@tonic-gate if (ul && (i == 0)) {
10607c478bd9Sstevel@tonic-gate font = sfont;
10617c478bd9Sstevel@tonic-gate ul = cu = 0;
10627c478bd9Sstevel@tonic-gate }
10637c478bd9Sstevel@tonic-gate if (i) {
10647c478bd9Sstevel@tonic-gate if (!ul) {
10657c478bd9Sstevel@tonic-gate sfont = font;
10667c478bd9Sstevel@tonic-gate font = ulfont;
10677c478bd9Sstevel@tonic-gate }
10687c478bd9Sstevel@tonic-gate ul = i;
10697c478bd9Sstevel@tonic-gate }
10707c478bd9Sstevel@tonic-gate noscale = 0;
10717c478bd9Sstevel@tonic-gate mchbits();
1072e5190c10Smuffin
1073e5190c10Smuffin return (0);
10747c478bd9Sstevel@tonic-gate }
10757c478bd9Sstevel@tonic-gate
10767c478bd9Sstevel@tonic-gate
1077e5190c10Smuffin int
caseuf()10787c478bd9Sstevel@tonic-gate caseuf()
10797c478bd9Sstevel@tonic-gate {
1080e5190c10Smuffin int i, j;
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate if (skip() || !(i = getrq()) || i == 'S' || (j = findft(i)) == -1)
10837c478bd9Sstevel@tonic-gate ulfont = ULFONT; /*default underline position*/
1084*2a8bcb4eSToomas Soome else
10857c478bd9Sstevel@tonic-gate ulfont = j;
10867c478bd9Sstevel@tonic-gate #ifdef NROFF
10877c478bd9Sstevel@tonic-gate if (ulfont == FT)
10887c478bd9Sstevel@tonic-gate ulfont = ULFONT;
10897c478bd9Sstevel@tonic-gate #endif
1090e5190c10Smuffin return (0);
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate
10937c478bd9Sstevel@tonic-gate
1094e5190c10Smuffin int
caseit()10957c478bd9Sstevel@tonic-gate caseit()
10967c478bd9Sstevel@tonic-gate {
1097e5190c10Smuffin int i;
10987c478bd9Sstevel@tonic-gate
10997c478bd9Sstevel@tonic-gate lgf++;
11007c478bd9Sstevel@tonic-gate it = itmac = 0;
11017c478bd9Sstevel@tonic-gate noscale++;
11027c478bd9Sstevel@tonic-gate skip();
11037c478bd9Sstevel@tonic-gate i = atoi();
11047c478bd9Sstevel@tonic-gate skip();
11057c478bd9Sstevel@tonic-gate if (!nonumb && (itmac = getrq()))
11067c478bd9Sstevel@tonic-gate it = i;
11077c478bd9Sstevel@tonic-gate noscale = 0;
1108e5190c10Smuffin
1109e5190c10Smuffin return (0);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate
1113e5190c10Smuffin int
casemc()11147c478bd9Sstevel@tonic-gate casemc()
11157c478bd9Sstevel@tonic-gate {
1116e5190c10Smuffin int i;
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate if (icf > 1)
11197c478bd9Sstevel@tonic-gate ic = 0;
11207c478bd9Sstevel@tonic-gate icf = 0;
11217c478bd9Sstevel@tonic-gate if (skip())
1122e5190c10Smuffin return (0);
11237c478bd9Sstevel@tonic-gate ic = getch();
11247c478bd9Sstevel@tonic-gate icf = 1;
11257c478bd9Sstevel@tonic-gate skip();
11267c478bd9Sstevel@tonic-gate i = max(hnumb((int *)0), 0);
11277c478bd9Sstevel@tonic-gate if (!nonumb)
11287c478bd9Sstevel@tonic-gate ics = i;
1129e5190c10Smuffin
1130e5190c10Smuffin return (0);
11317c478bd9Sstevel@tonic-gate }
11327c478bd9Sstevel@tonic-gate
11337c478bd9Sstevel@tonic-gate
1134e5190c10Smuffin int
casemk()11357c478bd9Sstevel@tonic-gate casemk()
11367c478bd9Sstevel@tonic-gate {
1137e5190c10Smuffin int i, j;
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate if (dip != d)
1140*2a8bcb4eSToomas Soome j = dip->dnl;
1141*2a8bcb4eSToomas Soome else
11427c478bd9Sstevel@tonic-gate j = numtab[NL].val;
11437c478bd9Sstevel@tonic-gate if (skip()) {
11447c478bd9Sstevel@tonic-gate dip->mkline = j;
1145e5190c10Smuffin return (0);
11467c478bd9Sstevel@tonic-gate }
11477c478bd9Sstevel@tonic-gate if ((i = getrq()) == 0)
1148e5190c10Smuffin return (0);
11497c478bd9Sstevel@tonic-gate numtab[findr(i)].val = j;
1150e5190c10Smuffin
1151e5190c10Smuffin return (0);
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate
1155e5190c10Smuffin int
casesv()11567c478bd9Sstevel@tonic-gate casesv()
11577c478bd9Sstevel@tonic-gate {
1158e5190c10Smuffin int i;
11597c478bd9Sstevel@tonic-gate
11607c478bd9Sstevel@tonic-gate skip();
11617c478bd9Sstevel@tonic-gate if ((i = vnumb((int *)0)) < 0)
1162e5190c10Smuffin return (0);
11637c478bd9Sstevel@tonic-gate if (nonumb)
11647c478bd9Sstevel@tonic-gate i = 1;
11657c478bd9Sstevel@tonic-gate sv += i;
11667c478bd9Sstevel@tonic-gate caseos();
1167e5190c10Smuffin
1168e5190c10Smuffin return (0);
11697c478bd9Sstevel@tonic-gate }
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate
1172e5190c10Smuffin int
caseos()11737c478bd9Sstevel@tonic-gate caseos()
11747c478bd9Sstevel@tonic-gate {
1175e5190c10Smuffin int savlss;
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate if (sv <= findt1()) {
11787c478bd9Sstevel@tonic-gate savlss = lss;
11797c478bd9Sstevel@tonic-gate lss = sv;
11807c478bd9Sstevel@tonic-gate newline(0);
11817c478bd9Sstevel@tonic-gate lss = savlss;
11827c478bd9Sstevel@tonic-gate sv = 0;
11837c478bd9Sstevel@tonic-gate }
1184e5190c10Smuffin
1185e5190c10Smuffin return (0);
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate
11887c478bd9Sstevel@tonic-gate
1189e5190c10Smuffin int
casenm()11907c478bd9Sstevel@tonic-gate casenm()
11917c478bd9Sstevel@tonic-gate {
1192e5190c10Smuffin int i;
11937c478bd9Sstevel@tonic-gate
11947c478bd9Sstevel@tonic-gate lnmod = nn = 0;
11957c478bd9Sstevel@tonic-gate if (skip())
1196e5190c10Smuffin return (0);
11977c478bd9Sstevel@tonic-gate lnmod++;
11987c478bd9Sstevel@tonic-gate noscale++;
11997c478bd9Sstevel@tonic-gate i = inumb(&numtab[LN].val);
12007c478bd9Sstevel@tonic-gate if (!nonumb)
12017c478bd9Sstevel@tonic-gate numtab[LN].val = max(i, 0);
12027c478bd9Sstevel@tonic-gate getnm(&ndf, 1);
12037c478bd9Sstevel@tonic-gate getnm(&nms, 0);
12047c478bd9Sstevel@tonic-gate getnm(&ni, 0);
12057c478bd9Sstevel@tonic-gate noscale = 0;
12067c478bd9Sstevel@tonic-gate nmbits = chbits;
1207e5190c10Smuffin
1208e5190c10Smuffin return (0);
12097c478bd9Sstevel@tonic-gate }
12107c478bd9Sstevel@tonic-gate
12117c478bd9Sstevel@tonic-gate
1212e5190c10Smuffin int
getnm(p,min)12137c478bd9Sstevel@tonic-gate getnm(p, min)
12147c478bd9Sstevel@tonic-gate int *p, min;
12157c478bd9Sstevel@tonic-gate {
1216e5190c10Smuffin int i;
12177c478bd9Sstevel@tonic-gate
12187c478bd9Sstevel@tonic-gate eat(' ');
12197c478bd9Sstevel@tonic-gate if (skip())
1220e5190c10Smuffin return (0);
12217c478bd9Sstevel@tonic-gate i = atoi();
12227c478bd9Sstevel@tonic-gate if (nonumb)
1223e5190c10Smuffin return (0);
12247c478bd9Sstevel@tonic-gate *p = max(i, min);
1225e5190c10Smuffin
1226e5190c10Smuffin return (0);
12277c478bd9Sstevel@tonic-gate }
12287c478bd9Sstevel@tonic-gate
12297c478bd9Sstevel@tonic-gate
1230e5190c10Smuffin int
casenn()12317c478bd9Sstevel@tonic-gate casenn()
12327c478bd9Sstevel@tonic-gate {
12337c478bd9Sstevel@tonic-gate noscale++;
12347c478bd9Sstevel@tonic-gate skip();
12357c478bd9Sstevel@tonic-gate nn = max(atoi(), 1);
12367c478bd9Sstevel@tonic-gate noscale = 0;
1237e5190c10Smuffin
1238e5190c10Smuffin return (0);
12397c478bd9Sstevel@tonic-gate }
12407c478bd9Sstevel@tonic-gate
12417c478bd9Sstevel@tonic-gate
1242e5190c10Smuffin int
caseab()12437c478bd9Sstevel@tonic-gate caseab()
12447c478bd9Sstevel@tonic-gate {
12457c478bd9Sstevel@tonic-gate casetm(1);
12467c478bd9Sstevel@tonic-gate done3(0);
1247e5190c10Smuffin
1248e5190c10Smuffin return (0);
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate
12517c478bd9Sstevel@tonic-gate
12527c478bd9Sstevel@tonic-gate #ifdef NROFF
12537c478bd9Sstevel@tonic-gate /*
12547c478bd9Sstevel@tonic-gate * The following routines are concerned with setting terminal options.
12557c478bd9Sstevel@tonic-gate * The manner of doing this differs between research/Berkeley systems
12567c478bd9Sstevel@tonic-gate * and UNIX System V systems (i.e. DOCUMENTER'S WORKBENCH)
12577c478bd9Sstevel@tonic-gate * The distinction is controlled by the #define'd variable USG,
12587c478bd9Sstevel@tonic-gate * which must be set by System V users.
12597c478bd9Sstevel@tonic-gate */
12607c478bd9Sstevel@tonic-gate
12617c478bd9Sstevel@tonic-gate
12627c478bd9Sstevel@tonic-gate #ifdef USG
12637c478bd9Sstevel@tonic-gate #include <termio.h>
12647c478bd9Sstevel@tonic-gate #define ECHO_USG (ECHO | ECHOE | ECHOK | ECHONL)
12657c478bd9Sstevel@tonic-gate struct termio ttys;
12667c478bd9Sstevel@tonic-gate #else
12677c478bd9Sstevel@tonic-gate #include <sgtty.h>
12687c478bd9Sstevel@tonic-gate struct sgttyb ttys[2];
1269e5190c10Smuffin #endif /* USG */
12707c478bd9Sstevel@tonic-gate
12717c478bd9Sstevel@tonic-gate int ttysave[2] = {-1, -1};
12727c478bd9Sstevel@tonic-gate
1273e5190c10Smuffin int
save_tty()12747c478bd9Sstevel@tonic-gate save_tty() /*save any tty settings that may be changed*/
12757c478bd9Sstevel@tonic-gate {
12767c478bd9Sstevel@tonic-gate
12777c478bd9Sstevel@tonic-gate #ifdef USG
12787c478bd9Sstevel@tonic-gate if (ioctl(0, TCGETA, &ttys) >= 0)
12797c478bd9Sstevel@tonic-gate ttysave[0] = ttys.c_lflag;
12807c478bd9Sstevel@tonic-gate #else
12817c478bd9Sstevel@tonic-gate if (gtty(0, &ttys[0]) >= 0)
12827c478bd9Sstevel@tonic-gate ttysave[0] = ttys[0].sg_flags;
12837c478bd9Sstevel@tonic-gate if (gtty(1, &ttys[1]) >= 0)
12847c478bd9Sstevel@tonic-gate ttysave[1] = ttys[1].sg_flags;
1285e5190c10Smuffin #endif /* USG */
12867c478bd9Sstevel@tonic-gate
1287e5190c10Smuffin return (0);
12887c478bd9Sstevel@tonic-gate }
12897c478bd9Sstevel@tonic-gate
12907c478bd9Sstevel@tonic-gate
1291e5190c10Smuffin int
restore_tty()12927c478bd9Sstevel@tonic-gate restore_tty() /*restore tty settings from beginning*/
12937c478bd9Sstevel@tonic-gate {
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gate if (ttysave[0] != -1) {
12967c478bd9Sstevel@tonic-gate #ifdef USG
12977c478bd9Sstevel@tonic-gate ttys.c_lflag = ttysave[0];
12987c478bd9Sstevel@tonic-gate ioctl(0, TCSETAW, &ttys);
12997c478bd9Sstevel@tonic-gate #else
13007c478bd9Sstevel@tonic-gate ttys[0].sg_flags = ttysave[0];
13017c478bd9Sstevel@tonic-gate stty(0, &ttys[0]);
13027c478bd9Sstevel@tonic-gate }
13037c478bd9Sstevel@tonic-gate if (ttysave[1] != -1) {
13047c478bd9Sstevel@tonic-gate ttys[1].sg_flags = ttysave[1];
13057c478bd9Sstevel@tonic-gate stty(1, &ttys[1]);
1306e5190c10Smuffin #endif /* USG */
13077c478bd9Sstevel@tonic-gate }
1308e5190c10Smuffin
1309e5190c10Smuffin return (0);
13107c478bd9Sstevel@tonic-gate }
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate
1313e5190c10Smuffin int
set_tty()13147c478bd9Sstevel@tonic-gate set_tty() /*this replaces the use of bset and breset*/
13157c478bd9Sstevel@tonic-gate {
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate #ifndef USG /*for research/BSD only, reset CRMOD*/
13187c478bd9Sstevel@tonic-gate if (ttysave[1] == -1)
13197c478bd9Sstevel@tonic-gate save_tty();
13207c478bd9Sstevel@tonic-gate if (ttysave[1] != -1) {
13217c478bd9Sstevel@tonic-gate ttys[1].sg_flags &= ~CRMOD;
13227c478bd9Sstevel@tonic-gate stty(1, &ttys[1]);
13237c478bd9Sstevel@tonic-gate }
1324e5190c10Smuffin #endif /* USG */
13257c478bd9Sstevel@tonic-gate
1326e5190c10Smuffin return (0);
13277c478bd9Sstevel@tonic-gate }
13287c478bd9Sstevel@tonic-gate
13297c478bd9Sstevel@tonic-gate
1330e5190c10Smuffin int
echo_off()13317c478bd9Sstevel@tonic-gate echo_off() /*turn off ECHO for .rd in "-q" mode*/
13327c478bd9Sstevel@tonic-gate {
13337c478bd9Sstevel@tonic-gate if (ttysave[0] == -1)
1334e5190c10Smuffin return (0);
13357c478bd9Sstevel@tonic-gate
13367c478bd9Sstevel@tonic-gate #ifdef USG
13377c478bd9Sstevel@tonic-gate ttys.c_lflag &= ~ECHO_USG;
13387c478bd9Sstevel@tonic-gate ioctl(0, TCSETAW, &ttys);
13397c478bd9Sstevel@tonic-gate #else
13407c478bd9Sstevel@tonic-gate ttys[0].sg_flags &= ~ECHO;
13417c478bd9Sstevel@tonic-gate stty(0, &ttys[0]);
1342e5190c10Smuffin #endif /* USG */
1343e5190c10Smuffin
1344e5190c10Smuffin return (0);
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate }
13477c478bd9Sstevel@tonic-gate
13487c478bd9Sstevel@tonic-gate
1349e5190c10Smuffin int
echo_on()13507c478bd9Sstevel@tonic-gate echo_on() /*restore ECHO after .rd in "-q" mode*/
13517c478bd9Sstevel@tonic-gate {
13527c478bd9Sstevel@tonic-gate if (ttysave[0] == -1)
1353e5190c10Smuffin return (0);
13547c478bd9Sstevel@tonic-gate
13557c478bd9Sstevel@tonic-gate #ifdef USG
13567c478bd9Sstevel@tonic-gate ttys.c_lflag |= ECHO_USG;
13577c478bd9Sstevel@tonic-gate ioctl(0, TCSETAW, &ttys);
13587c478bd9Sstevel@tonic-gate #else
13597c478bd9Sstevel@tonic-gate ttys[0].sg_flags |= ECHO;
13607c478bd9Sstevel@tonic-gate stty(0, &ttys[0]);
1361e5190c10Smuffin #endif /* USG */
13627c478bd9Sstevel@tonic-gate
1363e5190c10Smuffin return (0);
13647c478bd9Sstevel@tonic-gate }
1365e5190c10Smuffin #endif /* NROFF */
1366