xref: /titanic_53/usr/src/cmd/troff/n1.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
35*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
36*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
39*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
40*7c478bd9Sstevel@tonic-gate  * contributors.
41*7c478bd9Sstevel@tonic-gate  */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate char *xxxvers = "@(#)roff:n1.c	2.13";
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * n1.c
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  *	consume options, initialization, main loop,
48*7c478bd9Sstevel@tonic-gate  *	input routines, escape function calling
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #include <ctype.h>
52*7c478bd9Sstevel@tonic-gate #include <signal.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
55*7c478bd9Sstevel@tonic-gate #include <setjmp.h>
56*7c478bd9Sstevel@tonic-gate #include <time.h>
57*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
58*7c478bd9Sstevel@tonic-gate #include <locale.h>
59*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
60*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
61*7c478bd9Sstevel@tonic-gate #include <string.h>
62*7c478bd9Sstevel@tonic-gate #ifdef 	EUC
63*7c478bd9Sstevel@tonic-gate #ifdef	NROFF
64*7c478bd9Sstevel@tonic-gate #include <stddef.h>
65*7c478bd9Sstevel@tonic-gate #include <limits.h>
66*7c478bd9Sstevel@tonic-gate #endif	/* NROFF */
67*7c478bd9Sstevel@tonic-gate #endif	/* EUC */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #include "tdef.h"
70*7c478bd9Sstevel@tonic-gate #include "ext.h"
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #ifdef NROFF
73*7c478bd9Sstevel@tonic-gate #include "tw.h"
74*7c478bd9Sstevel@tonic-gate #endif
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate #define	MAX_RECURSION_DEPTH	512
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate jmp_buf sjbuf;
79*7c478bd9Sstevel@tonic-gate extern	void	fdprintf(int, char *, ...);
80*7c478bd9Sstevel@tonic-gate extern	char	*roff_sprintf(char *, char *, ...);
81*7c478bd9Sstevel@tonic-gate filep	ipl[NSO];
82*7c478bd9Sstevel@tonic-gate long	offl[NSO];
83*7c478bd9Sstevel@tonic-gate long	ioff;
84*7c478bd9Sstevel@tonic-gate char	*ttyp;
85*7c478bd9Sstevel@tonic-gate char	cfname[NSO+1][NS];	/*file name stack*/
86*7c478bd9Sstevel@tonic-gate int	cfline[NSO];		/*input line count stack*/
87*7c478bd9Sstevel@tonic-gate char	*progname;	/* program name (troff) */
88*7c478bd9Sstevel@tonic-gate #ifdef	EUC
89*7c478bd9Sstevel@tonic-gate #ifdef	NROFF
90*7c478bd9Sstevel@tonic-gate char	mbbuf1[MB_LEN_MAX + 1];
91*7c478bd9Sstevel@tonic-gate char	*mbbuf1p = mbbuf1;
92*7c478bd9Sstevel@tonic-gate wchar_t	twc = 0;
93*7c478bd9Sstevel@tonic-gate #endif	/* NROFF */
94*7c478bd9Sstevel@tonic-gate #endif	/* EUC */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
97*7c478bd9Sstevel@tonic-gate int	debug = 0;	/*debug flag*/
98*7c478bd9Sstevel@tonic-gate #endif	DEBUG
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate main(argc, argv)
101*7c478bd9Sstevel@tonic-gate int	argc;
102*7c478bd9Sstevel@tonic-gate char	**argv;
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	register char	*p, *q;
105*7c478bd9Sstevel@tonic-gate 	register j;
106*7c478bd9Sstevel@tonic-gate 	register tchar i;
107*7c478bd9Sstevel@tonic-gate 	int eileenct;		/*count to test for "Eileen's loop"*/
108*7c478bd9Sstevel@tonic-gate 	extern void catch(), kcatch();
109*7c478bd9Sstevel@tonic-gate 	char	**oargv, *getenv();
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	(void)setlocale(LC_ALL, "");
112*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
113*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
114*7c478bd9Sstevel@tonic-gate #endif
115*7c478bd9Sstevel@tonic-gate 	(void)textdomain(TEXT_DOMAIN);
116*7c478bd9Sstevel@tonic-gate 	progname = argv[0];
117*7c478bd9Sstevel@tonic-gate 	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
118*7c478bd9Sstevel@tonic-gate 		signal(SIGHUP, catch);
119*7c478bd9Sstevel@tonic-gate 	if (signal(SIGINT, catch) == SIG_IGN) {
120*7c478bd9Sstevel@tonic-gate 		signal(SIGHUP, SIG_IGN);
121*7c478bd9Sstevel@tonic-gate 		signal(SIGINT, SIG_IGN);
122*7c478bd9Sstevel@tonic-gate 		signal(SIGQUIT, SIG_IGN);
123*7c478bd9Sstevel@tonic-gate 	}
124*7c478bd9Sstevel@tonic-gate 	signal(SIGPIPE, catch);
125*7c478bd9Sstevel@tonic-gate 	signal(SIGTERM, kcatch);
126*7c478bd9Sstevel@tonic-gate 	oargv = argv;
127*7c478bd9Sstevel@tonic-gate 	strcpy(cfname[0], "<standard input>");
128*7c478bd9Sstevel@tonic-gate 	mrehash();
129*7c478bd9Sstevel@tonic-gate 	nrehash();
130*7c478bd9Sstevel@tonic-gate 	init0();
131*7c478bd9Sstevel@tonic-gate #ifdef EUC
132*7c478bd9Sstevel@tonic-gate #ifdef NROFF
133*7c478bd9Sstevel@tonic-gate 	(void)localize();
134*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
135*7c478bd9Sstevel@tonic-gate #endif /* EUC */
136*7c478bd9Sstevel@tonic-gate 	if ((p = getenv("TYPESETTER")) != 0)
137*7c478bd9Sstevel@tonic-gate 		strcpy(devname, p);
138*7c478bd9Sstevel@tonic-gate 	while (--argc > 0 && (++argv)[0][0] == '-')
139*7c478bd9Sstevel@tonic-gate 		switch (argv[0][1]) {
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 		case 'F':	/* switch font tables from default */
142*7c478bd9Sstevel@tonic-gate 			if (argv[0][2] != '\0') {
143*7c478bd9Sstevel@tonic-gate 				strcpy(termtab, &argv[0][2]);
144*7c478bd9Sstevel@tonic-gate 				strcpy(fontfile, &argv[0][2]);
145*7c478bd9Sstevel@tonic-gate 			} else {
146*7c478bd9Sstevel@tonic-gate 				argv++; argc--;
147*7c478bd9Sstevel@tonic-gate 				if (argv[0] != '\0') {
148*7c478bd9Sstevel@tonic-gate 					strcpy(termtab, argv[0]);
149*7c478bd9Sstevel@tonic-gate 					strcpy(fontfile, argv[0]);
150*7c478bd9Sstevel@tonic-gate 				} else
151*7c478bd9Sstevel@tonic-gate 					errprint(gettext("missing the font directory"));
152*7c478bd9Sstevel@tonic-gate 			}
153*7c478bd9Sstevel@tonic-gate 			continue;
154*7c478bd9Sstevel@tonic-gate 		case 0:
155*7c478bd9Sstevel@tonic-gate 			goto start;
156*7c478bd9Sstevel@tonic-gate 		case 'i':
157*7c478bd9Sstevel@tonic-gate 			stdi++;
158*7c478bd9Sstevel@tonic-gate 			continue;
159*7c478bd9Sstevel@tonic-gate 		case 'q':
160*7c478bd9Sstevel@tonic-gate #ifdef	NROFF
161*7c478bd9Sstevel@tonic-gate 			quiet++;
162*7c478bd9Sstevel@tonic-gate 			save_tty();
163*7c478bd9Sstevel@tonic-gate #else
164*7c478bd9Sstevel@tonic-gate 			errprint(gettext("-q option ignored in troff"));
165*7c478bd9Sstevel@tonic-gate #endif	NROFF
166*7c478bd9Sstevel@tonic-gate 			continue;
167*7c478bd9Sstevel@tonic-gate 		case 'n':
168*7c478bd9Sstevel@tonic-gate 			npn = ctoi(&argv[0][2]);
169*7c478bd9Sstevel@tonic-gate 			continue;
170*7c478bd9Sstevel@tonic-gate 		case 'u':	/* set emboldening amount */
171*7c478bd9Sstevel@tonic-gate 			bdtab[3] = ctoi(&argv[0][2]);
172*7c478bd9Sstevel@tonic-gate 			if (bdtab[3] < 0 || bdtab[3] > 50)
173*7c478bd9Sstevel@tonic-gate 				bdtab[3] = 0;
174*7c478bd9Sstevel@tonic-gate 			continue;
175*7c478bd9Sstevel@tonic-gate 		case 's':
176*7c478bd9Sstevel@tonic-gate 			if (!(stop = ctoi(&argv[0][2])))
177*7c478bd9Sstevel@tonic-gate 				stop++;
178*7c478bd9Sstevel@tonic-gate 			continue;
179*7c478bd9Sstevel@tonic-gate 		case 't':
180*7c478bd9Sstevel@tonic-gate 			ptid = 1;
181*7c478bd9Sstevel@tonic-gate 			continue;
182*7c478bd9Sstevel@tonic-gate 		case 'r':
183*7c478bd9Sstevel@tonic-gate 			if (&argv[0][2] != '\0' && strlen(&argv[0][2]) >= 2 && &argv[0][3] != '\0')
184*7c478bd9Sstevel@tonic-gate 			eibuf = roff_sprintf(ibuf+strlen(ibuf), ".nr %c %s\n",
185*7c478bd9Sstevel@tonic-gate 				argv[0][2], &argv[0][3]);
186*7c478bd9Sstevel@tonic-gate 			else
187*7c478bd9Sstevel@tonic-gate 				errprint(gettext("wrong options"));
188*7c478bd9Sstevel@tonic-gate 			continue;
189*7c478bd9Sstevel@tonic-gate 		case 'c':
190*7c478bd9Sstevel@tonic-gate 		case 'm':
191*7c478bd9Sstevel@tonic-gate 			if (mflg++ >= NMF) {
192*7c478bd9Sstevel@tonic-gate 				errprint(gettext("Too many macro packages: %s"),
193*7c478bd9Sstevel@tonic-gate 					 argv[0]);
194*7c478bd9Sstevel@tonic-gate 				continue;
195*7c478bd9Sstevel@tonic-gate 			}
196*7c478bd9Sstevel@tonic-gate 		        if (argv[0][2] == '\0') {
197*7c478bd9Sstevel@tonic-gate 				errprint(gettext("No library provided with -m"));
198*7c478bd9Sstevel@tonic-gate 				done(02);
199*7c478bd9Sstevel@tonic-gate 			}
200*7c478bd9Sstevel@tonic-gate 			if (getenv("TROFFMACS") != '\0') {
201*7c478bd9Sstevel@tonic-gate 			     if (tryfile(getenv("TROFFMACS"), &argv[0][2], nmfi))
202*7c478bd9Sstevel@tonic-gate 			       nmfi++;
203*7c478bd9Sstevel@tonic-gate 			} else
204*7c478bd9Sstevel@tonic-gate 			  if (tryfile("/usr/share/lib/tmac/", &argv[0][2], nmfi)
205*7c478bd9Sstevel@tonic-gate 			  || tryfile("/usr/share/lib/tmac/tmac.", &argv[0][2], nmfi))
206*7c478bd9Sstevel@tonic-gate 				nmfi++;
207*7c478bd9Sstevel@tonic-gate 			  else {
208*7c478bd9Sstevel@tonic-gate 				errprint(gettext("Cannot find library %s\n"),
209*7c478bd9Sstevel@tonic-gate 					argv[0]);
210*7c478bd9Sstevel@tonic-gate 				done(02);
211*7c478bd9Sstevel@tonic-gate 			  }
212*7c478bd9Sstevel@tonic-gate 			continue;
213*7c478bd9Sstevel@tonic-gate 		case 'o':
214*7c478bd9Sstevel@tonic-gate 			getpn(&argv[0][2]);
215*7c478bd9Sstevel@tonic-gate 			continue;
216*7c478bd9Sstevel@tonic-gate 		case 'T':
217*7c478bd9Sstevel@tonic-gate 			strcpy(devname, &argv[0][2]);
218*7c478bd9Sstevel@tonic-gate 			dotT++;
219*7c478bd9Sstevel@tonic-gate 			continue;
220*7c478bd9Sstevel@tonic-gate #ifdef NROFF
221*7c478bd9Sstevel@tonic-gate 		case 'h':
222*7c478bd9Sstevel@tonic-gate 			hflg++;
223*7c478bd9Sstevel@tonic-gate 			continue;
224*7c478bd9Sstevel@tonic-gate 		case 'z':
225*7c478bd9Sstevel@tonic-gate 			no_out++;
226*7c478bd9Sstevel@tonic-gate 			continue;
227*7c478bd9Sstevel@tonic-gate 		case 'e':
228*7c478bd9Sstevel@tonic-gate 			eqflg++;
229*7c478bd9Sstevel@tonic-gate 			continue;
230*7c478bd9Sstevel@tonic-gate #endif
231*7c478bd9Sstevel@tonic-gate #ifndef NROFF
232*7c478bd9Sstevel@tonic-gate 		case 'z':
233*7c478bd9Sstevel@tonic-gate 			no_out++;
234*7c478bd9Sstevel@tonic-gate 		case 'a':
235*7c478bd9Sstevel@tonic-gate 			ascii = 1;
236*7c478bd9Sstevel@tonic-gate 			nofeed++;
237*7c478bd9Sstevel@tonic-gate 			continue;
238*7c478bd9Sstevel@tonic-gate 		case 'f':
239*7c478bd9Sstevel@tonic-gate 			nofeed++;
240*7c478bd9Sstevel@tonic-gate 			continue;
241*7c478bd9Sstevel@tonic-gate #endif
242*7c478bd9Sstevel@tonic-gate 		case '#':
243*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
244*7c478bd9Sstevel@tonic-gate 			debug = ctoi(&argv[0][2]);
245*7c478bd9Sstevel@tonic-gate #else
246*7c478bd9Sstevel@tonic-gate 			errprint("DEBUG not enabled");
247*7c478bd9Sstevel@tonic-gate #endif	DEBUG
248*7c478bd9Sstevel@tonic-gate 			continue;
249*7c478bd9Sstevel@tonic-gate 		default:
250*7c478bd9Sstevel@tonic-gate 			errprint(gettext("unknown option %s"), argv[0]);
251*7c478bd9Sstevel@tonic-gate 			done(02);
252*7c478bd9Sstevel@tonic-gate 		}
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate start:
255*7c478bd9Sstevel@tonic-gate 	init1(oargv[0][0]);
256*7c478bd9Sstevel@tonic-gate 	argp = argv;
257*7c478bd9Sstevel@tonic-gate 	rargc = argc;
258*7c478bd9Sstevel@tonic-gate 	nmfi = 0;
259*7c478bd9Sstevel@tonic-gate 	init2();
260*7c478bd9Sstevel@tonic-gate 	setjmp(sjbuf);
261*7c478bd9Sstevel@tonic-gate 	eileenct = 0;		/*reset count for "Eileen's loop"*/
262*7c478bd9Sstevel@tonic-gate loop:
263*7c478bd9Sstevel@tonic-gate 	copyf = lgf = nb = nflush = nlflg = 0;
264*7c478bd9Sstevel@tonic-gate 	if (ip && rbf0(ip) == 0 && ejf && frame->pframe <= ejl) {
265*7c478bd9Sstevel@tonic-gate 		nflush++;
266*7c478bd9Sstevel@tonic-gate 		trap = 0;
267*7c478bd9Sstevel@tonic-gate 		eject((struct s *)0);
268*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
269*7c478bd9Sstevel@tonic-gate 	if (debug & DB_LOOP)
270*7c478bd9Sstevel@tonic-gate 		fdprintf(stderr, "loop: NL=%d, ejf=%d, lss=%d, eileenct=%d\n",
271*7c478bd9Sstevel@tonic-gate 			numtab[NL].val, ejf, lss, eileenct);
272*7c478bd9Sstevel@tonic-gate #endif	DEBUG
273*7c478bd9Sstevel@tonic-gate 		if (eileenct > 20) {
274*7c478bd9Sstevel@tonic-gate 			errprint(gettext("job looping; check abuse of macros"));
275*7c478bd9Sstevel@tonic-gate 			ejf = 0;	/*try to break Eileen's loop*/
276*7c478bd9Sstevel@tonic-gate 			eileenct = 0;
277*7c478bd9Sstevel@tonic-gate 		} else
278*7c478bd9Sstevel@tonic-gate 			eileenct++;
279*7c478bd9Sstevel@tonic-gate 		goto loop;
280*7c478bd9Sstevel@tonic-gate 	}
281*7c478bd9Sstevel@tonic-gate 	eileenct = 0;		/*reset count for "Eileen's loop"*/
282*7c478bd9Sstevel@tonic-gate 	i = getch();
283*7c478bd9Sstevel@tonic-gate 	if (pendt)
284*7c478bd9Sstevel@tonic-gate 		goto Lt;
285*7c478bd9Sstevel@tonic-gate 	if ((j = cbits(i)) == XPAR) {
286*7c478bd9Sstevel@tonic-gate 		copyf++;
287*7c478bd9Sstevel@tonic-gate 		tflg++;
288*7c478bd9Sstevel@tonic-gate 		while (cbits(i) != '\n')
289*7c478bd9Sstevel@tonic-gate 			pchar(i = getch());
290*7c478bd9Sstevel@tonic-gate 		tflg = 0;
291*7c478bd9Sstevel@tonic-gate 		copyf--;
292*7c478bd9Sstevel@tonic-gate 		goto loop;
293*7c478bd9Sstevel@tonic-gate 	}
294*7c478bd9Sstevel@tonic-gate 	if (j == cc || j == c2) {
295*7c478bd9Sstevel@tonic-gate 		if (j == c2)
296*7c478bd9Sstevel@tonic-gate 			nb++;
297*7c478bd9Sstevel@tonic-gate 		copyf++;
298*7c478bd9Sstevel@tonic-gate 		while ((j = cbits(i = getch())) == ' ' || j == '\t')
299*7c478bd9Sstevel@tonic-gate 			;
300*7c478bd9Sstevel@tonic-gate 		ch = i;
301*7c478bd9Sstevel@tonic-gate 		copyf--;
302*7c478bd9Sstevel@tonic-gate 		control(getrq(), 1);
303*7c478bd9Sstevel@tonic-gate 		flushi();
304*7c478bd9Sstevel@tonic-gate 		goto loop;
305*7c478bd9Sstevel@tonic-gate 	}
306*7c478bd9Sstevel@tonic-gate Lt:
307*7c478bd9Sstevel@tonic-gate 	ch = i;
308*7c478bd9Sstevel@tonic-gate 	text();
309*7c478bd9Sstevel@tonic-gate 	if (nlflg)
310*7c478bd9Sstevel@tonic-gate 		numtab[HP].val = 0;
311*7c478bd9Sstevel@tonic-gate 	goto loop;
312*7c478bd9Sstevel@tonic-gate }
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate tryfile(pat, fn, idx)
316*7c478bd9Sstevel@tonic-gate register char *pat, *fn;
317*7c478bd9Sstevel@tonic-gate int idx;
318*7c478bd9Sstevel@tonic-gate {
319*7c478bd9Sstevel@tonic-gate 	strcpy(mfiles[idx], pat);
320*7c478bd9Sstevel@tonic-gate 	strcat(mfiles[idx], fn);
321*7c478bd9Sstevel@tonic-gate 	if (access(mfiles[idx], 4) == -1)
322*7c478bd9Sstevel@tonic-gate 		return(0);
323*7c478bd9Sstevel@tonic-gate 	else return(1);
324*7c478bd9Sstevel@tonic-gate }
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate void catch()
327*7c478bd9Sstevel@tonic-gate {
328*7c478bd9Sstevel@tonic-gate 	done3(01);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate void kcatch()
333*7c478bd9Sstevel@tonic-gate {
334*7c478bd9Sstevel@tonic-gate 	signal(SIGTERM, SIG_IGN);
335*7c478bd9Sstevel@tonic-gate 	done3(01);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate init0()
340*7c478bd9Sstevel@tonic-gate {
341*7c478bd9Sstevel@tonic-gate 	eibuf = ibufp = ibuf;
342*7c478bd9Sstevel@tonic-gate 	ibuf[0] = 0;
343*7c478bd9Sstevel@tonic-gate 	numtab[NL].val = -1;
344*7c478bd9Sstevel@tonic-gate }
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 
347*7c478bd9Sstevel@tonic-gate init1(a)
348*7c478bd9Sstevel@tonic-gate char	a;
349*7c478bd9Sstevel@tonic-gate {
350*7c478bd9Sstevel@tonic-gate 	register char	*p;
351*7c478bd9Sstevel@tonic-gate 	register i;
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate 	p = tmp_name;
354*7c478bd9Sstevel@tonic-gate 	if (a == 'a')
355*7c478bd9Sstevel@tonic-gate 		p = &p[9];
356*7c478bd9Sstevel@tonic-gate 	if ((ibf = mkstemp(p)) == -1) {
357*7c478bd9Sstevel@tonic-gate 		errprint(gettext("cannot create temp file."));
358*7c478bd9Sstevel@tonic-gate 		exit(-1);
359*7c478bd9Sstevel@tonic-gate 	}
360*7c478bd9Sstevel@tonic-gate 	unlkp = p;
361*7c478bd9Sstevel@tonic-gate 	for (i = NTRTAB; --i; )
362*7c478bd9Sstevel@tonic-gate 		trtab[i] = i;
363*7c478bd9Sstevel@tonic-gate 	trtab[UNPAD] = ' ';
364*7c478bd9Sstevel@tonic-gate }
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate init2()
368*7c478bd9Sstevel@tonic-gate {
369*7c478bd9Sstevel@tonic-gate 	register i, j;
370*7c478bd9Sstevel@tonic-gate 	extern char	*setbrk();
371*7c478bd9Sstevel@tonic-gate 	extern char	*ttyname();
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 	ttyod = 2;
374*7c478bd9Sstevel@tonic-gate 	if ((ttyp=ttyname(j=0)) != 0 || (ttyp=ttyname(j=1)) != 0 || (ttyp=ttyname(j=2)) != 0)
375*7c478bd9Sstevel@tonic-gate 		;
376*7c478bd9Sstevel@tonic-gate 	else
377*7c478bd9Sstevel@tonic-gate 		ttyp = "notty";
378*7c478bd9Sstevel@tonic-gate 	iflg = j;
379*7c478bd9Sstevel@tonic-gate 	if (ascii)
380*7c478bd9Sstevel@tonic-gate 		mesg(0);
381*7c478bd9Sstevel@tonic-gate 	obufp = obuf;
382*7c478bd9Sstevel@tonic-gate 	ptinit();
383*7c478bd9Sstevel@tonic-gate 	mchbits();
384*7c478bd9Sstevel@tonic-gate 	cvtime();
385*7c478bd9Sstevel@tonic-gate 	numtab[PID].val = getpid();
386*7c478bd9Sstevel@tonic-gate 	olinep = oline;
387*7c478bd9Sstevel@tonic-gate 	ioff = 0;
388*7c478bd9Sstevel@tonic-gate 	numtab[HP].val = init = 0;
389*7c478bd9Sstevel@tonic-gate 	numtab[NL].val = -1;
390*7c478bd9Sstevel@tonic-gate 	nfo = 0;
391*7c478bd9Sstevel@tonic-gate 	ifile = 0;
392*7c478bd9Sstevel@tonic-gate 	copyf = raw = 0;
393*7c478bd9Sstevel@tonic-gate 	eibuf = roff_sprintf(ibuf+strlen(ibuf), ".ds .T %s\n", devname);
394*7c478bd9Sstevel@tonic-gate 	numtab[CD].val = -1;	/* compensation */
395*7c478bd9Sstevel@tonic-gate 	cpushback(ibuf);
396*7c478bd9Sstevel@tonic-gate 	ibufp = ibuf;
397*7c478bd9Sstevel@tonic-gate 	nx = mflg;
398*7c478bd9Sstevel@tonic-gate 	frame = stk = (struct s *)setbrk(DELTA);
399*7c478bd9Sstevel@tonic-gate 	dip = &d[0];
400*7c478bd9Sstevel@tonic-gate 	nxf = frame + 1;
401*7c478bd9Sstevel@tonic-gate #ifdef INCORE
402*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NEV; i++) {
403*7c478bd9Sstevel@tonic-gate 		extern tchar corebuf[];
404*7c478bd9Sstevel@tonic-gate 		*(struct env *)&corebuf[i * sizeof(env)/sizeof(tchar)] = env;
405*7c478bd9Sstevel@tonic-gate 	}
406*7c478bd9Sstevel@tonic-gate #else
407*7c478bd9Sstevel@tonic-gate 	for (i = NEV; i--; )
408*7c478bd9Sstevel@tonic-gate 		write(ibf, (char *) & env, sizeof(env));
409*7c478bd9Sstevel@tonic-gate #endif
410*7c478bd9Sstevel@tonic-gate }
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate cvtime()
414*7c478bd9Sstevel@tonic-gate {
415*7c478bd9Sstevel@tonic-gate 	time_t	tt;
416*7c478bd9Sstevel@tonic-gate 	register struct tm *tm;
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate 	tt = time((time_t *) 0);
419*7c478bd9Sstevel@tonic-gate 	tm = localtime(&tt);
420*7c478bd9Sstevel@tonic-gate 	numtab[DY].val = tm->tm_mday;
421*7c478bd9Sstevel@tonic-gate 	numtab[DW].val = tm->tm_wday + 1;
422*7c478bd9Sstevel@tonic-gate 	numtab[YR].val = tm->tm_year;
423*7c478bd9Sstevel@tonic-gate 	numtab[MO].val = tm->tm_mon + 1;
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate }
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate ctoi(s)
429*7c478bd9Sstevel@tonic-gate 	register char *s;
430*7c478bd9Sstevel@tonic-gate {
431*7c478bd9Sstevel@tonic-gate 	register n;
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate 	while (*s == ' ')
434*7c478bd9Sstevel@tonic-gate 		s++;
435*7c478bd9Sstevel@tonic-gate 	n = 0;
436*7c478bd9Sstevel@tonic-gate 	while (isdigit((unsigned char)*s))
437*7c478bd9Sstevel@tonic-gate 		n = 10 * n + *s++ - '0';
438*7c478bd9Sstevel@tonic-gate 	return n;
439*7c478bd9Sstevel@tonic-gate }
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate mesg(f)
443*7c478bd9Sstevel@tonic-gate int	f;
444*7c478bd9Sstevel@tonic-gate {
445*7c478bd9Sstevel@tonic-gate 	static int	mode;
446*7c478bd9Sstevel@tonic-gate 	struct stat stbuf;
447*7c478bd9Sstevel@tonic-gate 
448*7c478bd9Sstevel@tonic-gate 	if (!f) {
449*7c478bd9Sstevel@tonic-gate 		stat(ttyp, &stbuf);
450*7c478bd9Sstevel@tonic-gate 		mode = stbuf.st_mode;
451*7c478bd9Sstevel@tonic-gate 		chmod(ttyp, mode & ~0122);	/* turn off writing for others */
452*7c478bd9Sstevel@tonic-gate 	} else {
453*7c478bd9Sstevel@tonic-gate 		if (ttyp && *ttyp && mode)
454*7c478bd9Sstevel@tonic-gate 			chmod(ttyp, mode);
455*7c478bd9Sstevel@tonic-gate 	}
456*7c478bd9Sstevel@tonic-gate }
457*7c478bd9Sstevel@tonic-gate 
458*7c478bd9Sstevel@tonic-gate errprint(s, s1, s2, s3, s4, s5)	/* error message printer */
459*7c478bd9Sstevel@tonic-gate 	char *s, *s1, *s2, *s3, *s4, *s5;
460*7c478bd9Sstevel@tonic-gate {
461*7c478bd9Sstevel@tonic-gate 	fdprintf(stderr, "%s: ", progname);
462*7c478bd9Sstevel@tonic-gate 	fdprintf(stderr, s, s1, s2, s3, s4, s5);
463*7c478bd9Sstevel@tonic-gate 	if (numtab[CD].val > 0)
464*7c478bd9Sstevel@tonic-gate 		fdprintf(stderr, gettext("; line %d, file %s"), numtab[CD].val,
465*7c478bd9Sstevel@tonic-gate 			 cfname[ifi]);
466*7c478bd9Sstevel@tonic-gate 	fdprintf(stderr, "\n");
467*7c478bd9Sstevel@tonic-gate 	stackdump();
468*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
469*7c478bd9Sstevel@tonic-gate 	if (debug)
470*7c478bd9Sstevel@tonic-gate 		abort();
471*7c478bd9Sstevel@tonic-gate #endif	DEBUG
472*7c478bd9Sstevel@tonic-gate }
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate /*
476*7c478bd9Sstevel@tonic-gate  * Scaled down version of C Library printf.
477*7c478bd9Sstevel@tonic-gate  * Only %s %u %d (==%u) %o %c %x %D are recognized.
478*7c478bd9Sstevel@tonic-gate  */
479*7c478bd9Sstevel@tonic-gate #undef putchar
480*7c478bd9Sstevel@tonic-gate #define	putchar(n)	(*pfbp++ = (n))	/* NO CHECKING! */
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate static char	pfbuf[NTM];
483*7c478bd9Sstevel@tonic-gate static char	*pfbp = pfbuf;
484*7c478bd9Sstevel@tonic-gate int	stderr	 = 2;	/* NOT stdio value */
485*7c478bd9Sstevel@tonic-gate 
486*7c478bd9Sstevel@tonic-gate void
487*7c478bd9Sstevel@tonic-gate fdprintf(int fd, char *fmt, ...)
488*7c478bd9Sstevel@tonic-gate {
489*7c478bd9Sstevel@tonic-gate 	register c;
490*7c478bd9Sstevel@tonic-gate 	char	*s;
491*7c478bd9Sstevel@tonic-gate 	register i;
492*7c478bd9Sstevel@tonic-gate 	va_list	ap;
493*7c478bd9Sstevel@tonic-gate 
494*7c478bd9Sstevel@tonic-gate 	pfbp = pfbuf;
495*7c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
496*7c478bd9Sstevel@tonic-gate loop:
497*7c478bd9Sstevel@tonic-gate 	while ((c = *fmt++) != '%') {
498*7c478bd9Sstevel@tonic-gate 		if (c == '\0') {
499*7c478bd9Sstevel@tonic-gate 			if (fd == stderr)
500*7c478bd9Sstevel@tonic-gate 				write(stderr, pfbuf, pfbp - pfbuf);
501*7c478bd9Sstevel@tonic-gate 			else {
502*7c478bd9Sstevel@tonic-gate 				*pfbp = 0;
503*7c478bd9Sstevel@tonic-gate 				pfbp = pfbuf;
504*7c478bd9Sstevel@tonic-gate 				while (*pfbp) {
505*7c478bd9Sstevel@tonic-gate 					*obufp++ = *pfbp++;
506*7c478bd9Sstevel@tonic-gate 					if (obufp >= &obuf[OBUFSZ])
507*7c478bd9Sstevel@tonic-gate 						flusho();
508*7c478bd9Sstevel@tonic-gate 				}
509*7c478bd9Sstevel@tonic-gate 			}
510*7c478bd9Sstevel@tonic-gate 			va_end(ap);
511*7c478bd9Sstevel@tonic-gate 			return;
512*7c478bd9Sstevel@tonic-gate 		}
513*7c478bd9Sstevel@tonic-gate 		putchar(c);
514*7c478bd9Sstevel@tonic-gate 	}
515*7c478bd9Sstevel@tonic-gate 	c = *fmt++;
516*7c478bd9Sstevel@tonic-gate 	if (c == 'd') {
517*7c478bd9Sstevel@tonic-gate 		i = va_arg(ap, int);
518*7c478bd9Sstevel@tonic-gate 		if (i < 0) {
519*7c478bd9Sstevel@tonic-gate 			putchar('-');
520*7c478bd9Sstevel@tonic-gate 			i = -i;
521*7c478bd9Sstevel@tonic-gate 		}
522*7c478bd9Sstevel@tonic-gate 		printn((long)i, 10);
523*7c478bd9Sstevel@tonic-gate 	} else if (c == 'u' || c == 'o' || c == 'x')
524*7c478bd9Sstevel@tonic-gate 		printn(va_arg(ap, long), c == 'o' ? 8 : (c == 'x' ? 16 : 10));
525*7c478bd9Sstevel@tonic-gate 	else if (c == 'c') {
526*7c478bd9Sstevel@tonic-gate 		if (c > 0177 || c < 040)
527*7c478bd9Sstevel@tonic-gate 			putchar('\\');
528*7c478bd9Sstevel@tonic-gate 		putchar(va_arg(ap, int) & 0177);
529*7c478bd9Sstevel@tonic-gate 	} else if (c == 's') {
530*7c478bd9Sstevel@tonic-gate 		s = va_arg(ap, char *);
531*7c478bd9Sstevel@tonic-gate 		while (c = *s++)
532*7c478bd9Sstevel@tonic-gate 			putchar(c);
533*7c478bd9Sstevel@tonic-gate 	} else if (c == 'D') {
534*7c478bd9Sstevel@tonic-gate 		printn(va_arg(ap, long), 10);
535*7c478bd9Sstevel@tonic-gate 	} else if (c == 'O') {
536*7c478bd9Sstevel@tonic-gate 		printn(va_arg(ap, long), 8);
537*7c478bd9Sstevel@tonic-gate 	}
538*7c478bd9Sstevel@tonic-gate 	goto loop;
539*7c478bd9Sstevel@tonic-gate }
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate /*
543*7c478bd9Sstevel@tonic-gate  * Print an unsigned integer in base b.
544*7c478bd9Sstevel@tonic-gate  */
545*7c478bd9Sstevel@tonic-gate static printn(n, b)
546*7c478bd9Sstevel@tonic-gate 	register long	n;
547*7c478bd9Sstevel@tonic-gate {
548*7c478bd9Sstevel@tonic-gate 	register long	a;
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate 	if (n < 0) {	/* shouldn't happen */
551*7c478bd9Sstevel@tonic-gate 		putchar('-');
552*7c478bd9Sstevel@tonic-gate 		n = -n;
553*7c478bd9Sstevel@tonic-gate 	}
554*7c478bd9Sstevel@tonic-gate 	if (a = n / b)
555*7c478bd9Sstevel@tonic-gate 		printn(a, b);
556*7c478bd9Sstevel@tonic-gate 	putchar("0123456789ABCDEF"[(int)(n%b)]);
557*7c478bd9Sstevel@tonic-gate }
558*7c478bd9Sstevel@tonic-gate 
559*7c478bd9Sstevel@tonic-gate /* scaled down version of library roff_sprintf */
560*7c478bd9Sstevel@tonic-gate /* same limits as fdprintf */
561*7c478bd9Sstevel@tonic-gate /* returns pointer to \0 that ends the string */
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate /* VARARGS2 */
564*7c478bd9Sstevel@tonic-gate char *roff_sprintf(char *str, char *fmt, ...)
565*7c478bd9Sstevel@tonic-gate {
566*7c478bd9Sstevel@tonic-gate 	register c;
567*7c478bd9Sstevel@tonic-gate 	char *sprintn();
568*7c478bd9Sstevel@tonic-gate 	char	*s;
569*7c478bd9Sstevel@tonic-gate 	register i;
570*7c478bd9Sstevel@tonic-gate 	va_list ap;
571*7c478bd9Sstevel@tonic-gate 
572*7c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
573*7c478bd9Sstevel@tonic-gate loop:
574*7c478bd9Sstevel@tonic-gate 	while ((c = *fmt++) != '%') {
575*7c478bd9Sstevel@tonic-gate 		if (c == '\0') {
576*7c478bd9Sstevel@tonic-gate 			*str = 0;
577*7c478bd9Sstevel@tonic-gate 			va_end(ap);
578*7c478bd9Sstevel@tonic-gate 			return str;
579*7c478bd9Sstevel@tonic-gate 		}
580*7c478bd9Sstevel@tonic-gate 		*str++ = c;
581*7c478bd9Sstevel@tonic-gate 	}
582*7c478bd9Sstevel@tonic-gate 	c = *fmt++;
583*7c478bd9Sstevel@tonic-gate 	if (c == 'd') {
584*7c478bd9Sstevel@tonic-gate 		i = va_arg(ap, int);
585*7c478bd9Sstevel@tonic-gate 		if (i < 0) {
586*7c478bd9Sstevel@tonic-gate 			*str++ = '-';
587*7c478bd9Sstevel@tonic-gate 			i = -i;
588*7c478bd9Sstevel@tonic-gate 		}
589*7c478bd9Sstevel@tonic-gate 		str = sprintn(str, (long)i, 10);
590*7c478bd9Sstevel@tonic-gate 	} else if (c == 'u' || c == 'o' || c == 'x')
591*7c478bd9Sstevel@tonic-gate 		str = sprintn(str, va_arg(ap, long), c == 'o' ? 8 : (c == 'x' ? 16 : 10));
592*7c478bd9Sstevel@tonic-gate 	else if (c == 'c') {
593*7c478bd9Sstevel@tonic-gate 		if (c > 0177 || c < 040)
594*7c478bd9Sstevel@tonic-gate 			*str++ = '\\';
595*7c478bd9Sstevel@tonic-gate 		*str++ = va_arg(ap, int) & 0177;
596*7c478bd9Sstevel@tonic-gate 	} else if (c == 's') {
597*7c478bd9Sstevel@tonic-gate 		s = va_arg(ap, char *);
598*7c478bd9Sstevel@tonic-gate 		while (c = *s++)
599*7c478bd9Sstevel@tonic-gate 			*str++ = c;
600*7c478bd9Sstevel@tonic-gate 	} else if (c == 'D') {
601*7c478bd9Sstevel@tonic-gate 		str = sprintn(str, va_arg(ap, long), 10);
602*7c478bd9Sstevel@tonic-gate 	} else if (c == 'O') {
603*7c478bd9Sstevel@tonic-gate 		str = sprintn(str, va_arg(ap, unsigned) , 8);
604*7c478bd9Sstevel@tonic-gate 	}
605*7c478bd9Sstevel@tonic-gate 	goto loop;
606*7c478bd9Sstevel@tonic-gate }
607*7c478bd9Sstevel@tonic-gate 
608*7c478bd9Sstevel@tonic-gate /*
609*7c478bd9Sstevel@tonic-gate  * Print an unsigned integer in base b.
610*7c478bd9Sstevel@tonic-gate  */
611*7c478bd9Sstevel@tonic-gate static char *sprintn(s, n, b)
612*7c478bd9Sstevel@tonic-gate 	register char *s;
613*7c478bd9Sstevel@tonic-gate 	register long n;
614*7c478bd9Sstevel@tonic-gate {
615*7c478bd9Sstevel@tonic-gate 	register long	a;
616*7c478bd9Sstevel@tonic-gate 
617*7c478bd9Sstevel@tonic-gate 	if (n < 0) {	/* shouldn't happen */
618*7c478bd9Sstevel@tonic-gate 		*s++ = '-';
619*7c478bd9Sstevel@tonic-gate 		n = -n;
620*7c478bd9Sstevel@tonic-gate 	}
621*7c478bd9Sstevel@tonic-gate 	if (a = n / b)
622*7c478bd9Sstevel@tonic-gate 		s = sprintn(s, a, b);
623*7c478bd9Sstevel@tonic-gate 	*s++ = "0123456789ABCDEF"[(int)(n%b)];
624*7c478bd9Sstevel@tonic-gate 	return s;
625*7c478bd9Sstevel@tonic-gate }
626*7c478bd9Sstevel@tonic-gate 
627*7c478bd9Sstevel@tonic-gate 
628*7c478bd9Sstevel@tonic-gate control(a, b)
629*7c478bd9Sstevel@tonic-gate register int	a, b;
630*7c478bd9Sstevel@tonic-gate {
631*7c478bd9Sstevel@tonic-gate 	register int	j;
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate 	if (a == 0 || (j = findmn(a)) == -1)
634*7c478bd9Sstevel@tonic-gate 		return(0);
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate 	/*
637*7c478bd9Sstevel@tonic-gate 	 * Attempt to find endless recursion at runtime. Arbitrary
638*7c478bd9Sstevel@tonic-gate 	 * recursion limit of MAX_RECURSION_DEPTH was chosen as
639*7c478bd9Sstevel@tonic-gate 	 * it is extremely unlikely that a correct nroff/troff
640*7c478bd9Sstevel@tonic-gate 	 * invocation would exceed this value.
641*7c478bd9Sstevel@tonic-gate 	 */
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	if (frame != stk) {
644*7c478bd9Sstevel@tonic-gate 		int frame_cnt = 0;
645*7c478bd9Sstevel@tonic-gate 		struct s *p;
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate 		for (p = frame; p != stk; p = p->pframe)
648*7c478bd9Sstevel@tonic-gate 			frame_cnt++;
649*7c478bd9Sstevel@tonic-gate 		if (frame_cnt > MAX_RECURSION_DEPTH) {
650*7c478bd9Sstevel@tonic-gate 			errprint(
651*7c478bd9Sstevel@tonic-gate 			    gettext("Exceeded maximum stack size (%d) when "
652*7c478bd9Sstevel@tonic-gate 			    "executing macro %c%c. Stack dump follows"),
653*7c478bd9Sstevel@tonic-gate 			    MAX_RECURSION_DEPTH,
654*7c478bd9Sstevel@tonic-gate 			    frame->mname & 0177, (frame->mname >> BYTE) & 0177);
655*7c478bd9Sstevel@tonic-gate 			edone(02);
656*7c478bd9Sstevel@tonic-gate 		}
657*7c478bd9Sstevel@tonic-gate 	}
658*7c478bd9Sstevel@tonic-gate 
659*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
660*7c478bd9Sstevel@tonic-gate 	if (debug & DB_MAC)
661*7c478bd9Sstevel@tonic-gate 		fdprintf(stderr, "control: macro %c%c, contab[%d]\n",
662*7c478bd9Sstevel@tonic-gate 			a&0177, (a>>BYTE)&0177 ? (a>>BYTE)&0177 : ' ', j);
663*7c478bd9Sstevel@tonic-gate #endif	DEBUG
664*7c478bd9Sstevel@tonic-gate 	if (contab[j].f == 0) {
665*7c478bd9Sstevel@tonic-gate 		nxf->nargs = 0;
666*7c478bd9Sstevel@tonic-gate 		if (b)
667*7c478bd9Sstevel@tonic-gate 			collect();
668*7c478bd9Sstevel@tonic-gate 		flushi();
669*7c478bd9Sstevel@tonic-gate 		return pushi((filep)contab[j].mx, a);
670*7c478bd9Sstevel@tonic-gate 	} else if (b)
671*7c478bd9Sstevel@tonic-gate 		return((*contab[j].f)(0));
672*7c478bd9Sstevel@tonic-gate 	else
673*7c478bd9Sstevel@tonic-gate 		return(0);
674*7c478bd9Sstevel@tonic-gate }
675*7c478bd9Sstevel@tonic-gate 
676*7c478bd9Sstevel@tonic-gate 
677*7c478bd9Sstevel@tonic-gate getrq()
678*7c478bd9Sstevel@tonic-gate {
679*7c478bd9Sstevel@tonic-gate 	register i, j;
680*7c478bd9Sstevel@tonic-gate 
681*7c478bd9Sstevel@tonic-gate 	if (((i = getach()) == 0) || ((j = getach()) == 0))
682*7c478bd9Sstevel@tonic-gate 		goto rtn;
683*7c478bd9Sstevel@tonic-gate 	i = PAIR(i, j);
684*7c478bd9Sstevel@tonic-gate rtn:
685*7c478bd9Sstevel@tonic-gate 	return(i);
686*7c478bd9Sstevel@tonic-gate }
687*7c478bd9Sstevel@tonic-gate 
688*7c478bd9Sstevel@tonic-gate /*
689*7c478bd9Sstevel@tonic-gate  * table encodes some special characters, to speed up tests
690*7c478bd9Sstevel@tonic-gate  * in getchar, viz FLSS, RPT, f, \b, \n, fc, tabch, ldrch
691*7c478bd9Sstevel@tonic-gate  */
692*7c478bd9Sstevel@tonic-gate 
693*7c478bd9Sstevel@tonic-gate char
694*7c478bd9Sstevel@tonic-gate gchtab[] = {
695*7c478bd9Sstevel@tonic-gate 	000,004,000,000,010,000,000,000, /* fc, ldr */
696*7c478bd9Sstevel@tonic-gate 	001,002,001,000,001,000,000,000, /* \b, tab, nl, RPT */
697*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
698*7c478bd9Sstevel@tonic-gate 	000,001,000,000,000,000,000,000, /* FLSS */
699*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
700*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
701*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
702*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
703*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
704*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
705*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
706*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
707*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,001,000, /* f */
708*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
709*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
710*7c478bd9Sstevel@tonic-gate 	000,000,000,000,000,000,000,000,
711*7c478bd9Sstevel@tonic-gate };
712*7c478bd9Sstevel@tonic-gate 
713*7c478bd9Sstevel@tonic-gate tchar
714*7c478bd9Sstevel@tonic-gate getch()
715*7c478bd9Sstevel@tonic-gate {
716*7c478bd9Sstevel@tonic-gate 	register int	k;
717*7c478bd9Sstevel@tonic-gate 	register tchar i, j;
718*7c478bd9Sstevel@tonic-gate 	tchar setht(), setslant();
719*7c478bd9Sstevel@tonic-gate 
720*7c478bd9Sstevel@tonic-gate g0:
721*7c478bd9Sstevel@tonic-gate 	if (i = ch) {
722*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
723*7c478bd9Sstevel@tonic-gate 		if (debug & DB_GETC)
724*7c478bd9Sstevel@tonic-gate 			fdprintf(stderr, "getch: ch is %x (%c)\n",
725*7c478bd9Sstevel@tonic-gate 				ch, (ch&0177) < 040 ? 0177 : ch&0177);
726*7c478bd9Sstevel@tonic-gate #endif	DEBUG
727*7c478bd9Sstevel@tonic-gate 		if (cbits(i) == '\n')
728*7c478bd9Sstevel@tonic-gate 			nlflg++;
729*7c478bd9Sstevel@tonic-gate 		ch = 0;
730*7c478bd9Sstevel@tonic-gate 		return(i);
731*7c478bd9Sstevel@tonic-gate 	}
732*7c478bd9Sstevel@tonic-gate 
733*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
734*7c478bd9Sstevel@tonic-gate 	if (nlflg)
735*7c478bd9Sstevel@tonic-gate 		if (debug & DB_GETC)
736*7c478bd9Sstevel@tonic-gate 			fdprintf(stderr,"getch: nlflg is %x\n", nlflg);
737*7c478bd9Sstevel@tonic-gate #endif	DEBUG
738*7c478bd9Sstevel@tonic-gate 	if (nlflg)
739*7c478bd9Sstevel@tonic-gate 		return('\n');
740*7c478bd9Sstevel@tonic-gate 	i = getch0();
741*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
742*7c478bd9Sstevel@tonic-gate 	if (debug & DB_GETC)
743*7c478bd9Sstevel@tonic-gate 		fdprintf(stderr, "getch: getch0 returns %x (%c)\n",
744*7c478bd9Sstevel@tonic-gate 			i, (i&0177) < 040 ? 0177 : i&0177);
745*7c478bd9Sstevel@tonic-gate #endif	DEBUG
746*7c478bd9Sstevel@tonic-gate 	if (ismot(i))
747*7c478bd9Sstevel@tonic-gate 		return(i);
748*7c478bd9Sstevel@tonic-gate 	k = cbits(i);
749*7c478bd9Sstevel@tonic-gate 	if (k != ESC) {
750*7c478bd9Sstevel@tonic-gate 		/*
751*7c478bd9Sstevel@tonic-gate 		 * gchtab[] has only 128 entries
752*7c478bd9Sstevel@tonic-gate 		 * if k is out of the range, it should be
753*7c478bd9Sstevel@tonic-gate 		 * handled as gchtab[k] == 0
754*7c478bd9Sstevel@tonic-gate 		 */
755*7c478bd9Sstevel@tonic-gate 		if (!isascii(k) || gchtab[k]==0)
756*7c478bd9Sstevel@tonic-gate 			return(i);
757*7c478bd9Sstevel@tonic-gate 		if (k == '\n') {
758*7c478bd9Sstevel@tonic-gate 			if (cbits(i) == '\n') {
759*7c478bd9Sstevel@tonic-gate 				nlflg++;
760*7c478bd9Sstevel@tonic-gate 				if (ip == 0)
761*7c478bd9Sstevel@tonic-gate 					numtab[CD].val++; /* line number */
762*7c478bd9Sstevel@tonic-gate 			}
763*7c478bd9Sstevel@tonic-gate 			return(k);
764*7c478bd9Sstevel@tonic-gate 		}
765*7c478bd9Sstevel@tonic-gate 		if (k == FLSS) {
766*7c478bd9Sstevel@tonic-gate 			copyf++;
767*7c478bd9Sstevel@tonic-gate 			raw++;
768*7c478bd9Sstevel@tonic-gate 			i = getch0();
769*7c478bd9Sstevel@tonic-gate 			if (!fi)
770*7c478bd9Sstevel@tonic-gate 				flss = i;
771*7c478bd9Sstevel@tonic-gate 			copyf--;
772*7c478bd9Sstevel@tonic-gate 			raw--;
773*7c478bd9Sstevel@tonic-gate 			goto g0;
774*7c478bd9Sstevel@tonic-gate 		}
775*7c478bd9Sstevel@tonic-gate 		if (k == RPT) {
776*7c478bd9Sstevel@tonic-gate 			setrpt();
777*7c478bd9Sstevel@tonic-gate 			goto g0;
778*7c478bd9Sstevel@tonic-gate 		}
779*7c478bd9Sstevel@tonic-gate 		if (!copyf) {
780*7c478bd9Sstevel@tonic-gate 			if (k == 'f' && lg && !lgf) {
781*7c478bd9Sstevel@tonic-gate 				i = getlg(i);
782*7c478bd9Sstevel@tonic-gate 				return(i);
783*7c478bd9Sstevel@tonic-gate 			}
784*7c478bd9Sstevel@tonic-gate 			if (k == fc || k == tabch || k == ldrch) {
785*7c478bd9Sstevel@tonic-gate 				if ((i = setfield(k)) == 0)
786*7c478bd9Sstevel@tonic-gate 					goto g0;
787*7c478bd9Sstevel@tonic-gate 				else
788*7c478bd9Sstevel@tonic-gate 					return(i);
789*7c478bd9Sstevel@tonic-gate 			}
790*7c478bd9Sstevel@tonic-gate 			if (k == '\b') {
791*7c478bd9Sstevel@tonic-gate 				i = makem(-width(' ' | chbits));
792*7c478bd9Sstevel@tonic-gate 				return(i);
793*7c478bd9Sstevel@tonic-gate 			}
794*7c478bd9Sstevel@tonic-gate 		}
795*7c478bd9Sstevel@tonic-gate 		return(i);
796*7c478bd9Sstevel@tonic-gate 	}
797*7c478bd9Sstevel@tonic-gate 	k = cbits(j = getch0());
798*7c478bd9Sstevel@tonic-gate 	if (ismot(j))
799*7c478bd9Sstevel@tonic-gate 		return(j);
800*7c478bd9Sstevel@tonic-gate 	switch (k) {
801*7c478bd9Sstevel@tonic-gate 
802*7c478bd9Sstevel@tonic-gate 	case 'X':	/* \X'...' for copy through */
803*7c478bd9Sstevel@tonic-gate 		setxon();
804*7c478bd9Sstevel@tonic-gate 		goto g0;
805*7c478bd9Sstevel@tonic-gate 	case '\n':	/* concealed newline */
806*7c478bd9Sstevel@tonic-gate 		goto g0;
807*7c478bd9Sstevel@tonic-gate 	case 'n':	/* number register */
808*7c478bd9Sstevel@tonic-gate 		setn();
809*7c478bd9Sstevel@tonic-gate 		goto g0;
810*7c478bd9Sstevel@tonic-gate 	case '*':	/* string indicator */
811*7c478bd9Sstevel@tonic-gate 		setstr();
812*7c478bd9Sstevel@tonic-gate 		goto g0;
813*7c478bd9Sstevel@tonic-gate 	case '$':	/* argument indicator */
814*7c478bd9Sstevel@tonic-gate 		seta();
815*7c478bd9Sstevel@tonic-gate 		goto g0;
816*7c478bd9Sstevel@tonic-gate 	case '{':	/* LEFT */
817*7c478bd9Sstevel@tonic-gate 		i = LEFT;
818*7c478bd9Sstevel@tonic-gate 		goto gx;
819*7c478bd9Sstevel@tonic-gate 	case '}':	/* RIGHT */
820*7c478bd9Sstevel@tonic-gate 		i = RIGHT;
821*7c478bd9Sstevel@tonic-gate 		goto gx;
822*7c478bd9Sstevel@tonic-gate 	case '"':	/* comment */
823*7c478bd9Sstevel@tonic-gate 		while (cbits(i = getch0()) != '\n')
824*7c478bd9Sstevel@tonic-gate 			;
825*7c478bd9Sstevel@tonic-gate 		nlflg++;
826*7c478bd9Sstevel@tonic-gate 		if (ip == 0)
827*7c478bd9Sstevel@tonic-gate 			numtab[CD].val++;
828*7c478bd9Sstevel@tonic-gate 		return(i);
829*7c478bd9Sstevel@tonic-gate 	case ESC:	/* double backslash */
830*7c478bd9Sstevel@tonic-gate 		i = eschar;
831*7c478bd9Sstevel@tonic-gate 		goto gx;
832*7c478bd9Sstevel@tonic-gate 	case 'e':	/* printable version of current eschar */
833*7c478bd9Sstevel@tonic-gate 		i = PRESC;
834*7c478bd9Sstevel@tonic-gate 		goto gx;
835*7c478bd9Sstevel@tonic-gate 	case ' ':	/* unpaddable space */
836*7c478bd9Sstevel@tonic-gate 		i = UNPAD;
837*7c478bd9Sstevel@tonic-gate 		goto gx;
838*7c478bd9Sstevel@tonic-gate 	case '\'':	/* \(aa */
839*7c478bd9Sstevel@tonic-gate 		i = ACUTE;
840*7c478bd9Sstevel@tonic-gate 		goto gx;
841*7c478bd9Sstevel@tonic-gate 	case '`':	/* \(ga */
842*7c478bd9Sstevel@tonic-gate 		i = GRAVE;
843*7c478bd9Sstevel@tonic-gate 		goto gx;
844*7c478bd9Sstevel@tonic-gate 	case '_':	/* \(ul */
845*7c478bd9Sstevel@tonic-gate 		i = UNDERLINE;
846*7c478bd9Sstevel@tonic-gate 		goto gx;
847*7c478bd9Sstevel@tonic-gate 	case '-':	/* current font minus */
848*7c478bd9Sstevel@tonic-gate 		i = MINUS;
849*7c478bd9Sstevel@tonic-gate 		goto gx;
850*7c478bd9Sstevel@tonic-gate 	case '&':	/* filler */
851*7c478bd9Sstevel@tonic-gate 		i = FILLER;
852*7c478bd9Sstevel@tonic-gate 		goto gx;
853*7c478bd9Sstevel@tonic-gate 	case 'c':	/* to be continued */
854*7c478bd9Sstevel@tonic-gate 		i = CONT;
855*7c478bd9Sstevel@tonic-gate 		goto gx;
856*7c478bd9Sstevel@tonic-gate 	case '!':	/* transparent indicator */
857*7c478bd9Sstevel@tonic-gate 		i = XPAR;
858*7c478bd9Sstevel@tonic-gate 		goto gx;
859*7c478bd9Sstevel@tonic-gate 	case 't':	/* tab */
860*7c478bd9Sstevel@tonic-gate 		i = '\t';
861*7c478bd9Sstevel@tonic-gate 		return(i);
862*7c478bd9Sstevel@tonic-gate 	case 'a':	/* leader (SOH) */
863*7c478bd9Sstevel@tonic-gate 		i = LEADER;
864*7c478bd9Sstevel@tonic-gate 		return(i);
865*7c478bd9Sstevel@tonic-gate 	case '%':	/* ohc */
866*7c478bd9Sstevel@tonic-gate 		i = OHC;
867*7c478bd9Sstevel@tonic-gate 		return(i);
868*7c478bd9Sstevel@tonic-gate 	case 'g':	/* return format of a number register */
869*7c478bd9Sstevel@tonic-gate 		setaf();
870*7c478bd9Sstevel@tonic-gate 		goto g0;
871*7c478bd9Sstevel@tonic-gate 	case 'N':	/* absolute character number */
872*7c478bd9Sstevel@tonic-gate 		i = setabs();
873*7c478bd9Sstevel@tonic-gate 		goto gx;
874*7c478bd9Sstevel@tonic-gate 	case '.':	/* . */
875*7c478bd9Sstevel@tonic-gate 		i = '.';
876*7c478bd9Sstevel@tonic-gate gx:
877*7c478bd9Sstevel@tonic-gate 		setsfbits(i, sfbits(j));
878*7c478bd9Sstevel@tonic-gate 		return(i);
879*7c478bd9Sstevel@tonic-gate 	}
880*7c478bd9Sstevel@tonic-gate 	if (copyf) {
881*7c478bd9Sstevel@tonic-gate 		*pbp++ = j;
882*7c478bd9Sstevel@tonic-gate 		return(eschar);
883*7c478bd9Sstevel@tonic-gate 	}
884*7c478bd9Sstevel@tonic-gate 	switch (k) {
885*7c478bd9Sstevel@tonic-gate 
886*7c478bd9Sstevel@tonic-gate 	case 'p':	/* spread */
887*7c478bd9Sstevel@tonic-gate 		spread++;
888*7c478bd9Sstevel@tonic-gate 		goto g0;
889*7c478bd9Sstevel@tonic-gate 	case '(':	/* special char name */
890*7c478bd9Sstevel@tonic-gate 		if ((i = setch()) == 0)
891*7c478bd9Sstevel@tonic-gate 			goto g0;
892*7c478bd9Sstevel@tonic-gate 		return(i);
893*7c478bd9Sstevel@tonic-gate 	case 's':	/* size indicator */
894*7c478bd9Sstevel@tonic-gate 		setps();
895*7c478bd9Sstevel@tonic-gate 		goto g0;
896*7c478bd9Sstevel@tonic-gate 	case 'H':	/* character height */
897*7c478bd9Sstevel@tonic-gate 		return(setht());
898*7c478bd9Sstevel@tonic-gate 	case 'S':	/* slant */
899*7c478bd9Sstevel@tonic-gate 		return(setslant());
900*7c478bd9Sstevel@tonic-gate 	case 'f':	/* font indicator */
901*7c478bd9Sstevel@tonic-gate 		setfont(0);
902*7c478bd9Sstevel@tonic-gate 		goto g0;
903*7c478bd9Sstevel@tonic-gate 	case 'w':	/* width function */
904*7c478bd9Sstevel@tonic-gate 		setwd();
905*7c478bd9Sstevel@tonic-gate 		goto g0;
906*7c478bd9Sstevel@tonic-gate 	case 'v':	/* vert mot */
907*7c478bd9Sstevel@tonic-gate 		if (i = vmot())
908*7c478bd9Sstevel@tonic-gate 			return(i);
909*7c478bd9Sstevel@tonic-gate 		goto g0;
910*7c478bd9Sstevel@tonic-gate 	case 'h': 	/* horiz mot */
911*7c478bd9Sstevel@tonic-gate 		if (i = hmot())
912*7c478bd9Sstevel@tonic-gate 			return(i);
913*7c478bd9Sstevel@tonic-gate 		goto g0;
914*7c478bd9Sstevel@tonic-gate 	case 'z':	/* zero with char */
915*7c478bd9Sstevel@tonic-gate 		return(setz());
916*7c478bd9Sstevel@tonic-gate 	case 'l':	/* hor line */
917*7c478bd9Sstevel@tonic-gate 		setline();
918*7c478bd9Sstevel@tonic-gate 		goto g0;
919*7c478bd9Sstevel@tonic-gate 	case 'L':	/* vert line */
920*7c478bd9Sstevel@tonic-gate 		setvline();
921*7c478bd9Sstevel@tonic-gate 		goto g0;
922*7c478bd9Sstevel@tonic-gate 	case 'D':	/* drawing function */
923*7c478bd9Sstevel@tonic-gate 		setdraw();
924*7c478bd9Sstevel@tonic-gate 		goto g0;
925*7c478bd9Sstevel@tonic-gate 	case 'b':	/* bracket */
926*7c478bd9Sstevel@tonic-gate 		setbra();
927*7c478bd9Sstevel@tonic-gate 		goto g0;
928*7c478bd9Sstevel@tonic-gate 	case 'o':	/* overstrike */
929*7c478bd9Sstevel@tonic-gate 		setov();
930*7c478bd9Sstevel@tonic-gate 		goto g0;
931*7c478bd9Sstevel@tonic-gate 	case 'k':	/* mark hor place */
932*7c478bd9Sstevel@tonic-gate 		if ((k = findr(getsn())) != -1) {
933*7c478bd9Sstevel@tonic-gate 			numtab[k].val = numtab[HP].val;
934*7c478bd9Sstevel@tonic-gate 		}
935*7c478bd9Sstevel@tonic-gate 		goto g0;
936*7c478bd9Sstevel@tonic-gate 	case '0':	/* number space */
937*7c478bd9Sstevel@tonic-gate 		return(makem(width('0' | chbits)));
938*7c478bd9Sstevel@tonic-gate #ifdef NROFF
939*7c478bd9Sstevel@tonic-gate 	case '|':
940*7c478bd9Sstevel@tonic-gate 	case '^':
941*7c478bd9Sstevel@tonic-gate 		goto g0;
942*7c478bd9Sstevel@tonic-gate #else
943*7c478bd9Sstevel@tonic-gate 	case '|':	/* narrow space */
944*7c478bd9Sstevel@tonic-gate 		return(makem((int)(EM)/6));
945*7c478bd9Sstevel@tonic-gate 	case '^':	/* half narrow space */
946*7c478bd9Sstevel@tonic-gate 		return(makem((int)(EM)/12));
947*7c478bd9Sstevel@tonic-gate #endif
948*7c478bd9Sstevel@tonic-gate 	case 'x':	/* extra line space */
949*7c478bd9Sstevel@tonic-gate 		if (i = xlss())
950*7c478bd9Sstevel@tonic-gate 			return(i);
951*7c478bd9Sstevel@tonic-gate 		goto g0;
952*7c478bd9Sstevel@tonic-gate 	case 'u':	/* half em up */
953*7c478bd9Sstevel@tonic-gate 	case 'r':	/* full em up */
954*7c478bd9Sstevel@tonic-gate 	case 'd':	/* half em down */
955*7c478bd9Sstevel@tonic-gate 		return(sethl(k));
956*7c478bd9Sstevel@tonic-gate 	default:
957*7c478bd9Sstevel@tonic-gate 		return(j);
958*7c478bd9Sstevel@tonic-gate 	}
959*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
960*7c478bd9Sstevel@tonic-gate }
961*7c478bd9Sstevel@tonic-gate 
962*7c478bd9Sstevel@tonic-gate setxon()	/* \X'...' for copy through */
963*7c478bd9Sstevel@tonic-gate {
964*7c478bd9Sstevel@tonic-gate 	tchar xbuf[NC];
965*7c478bd9Sstevel@tonic-gate 	register tchar *i;
966*7c478bd9Sstevel@tonic-gate 	tchar c;
967*7c478bd9Sstevel@tonic-gate 	int delim, k;
968*7c478bd9Sstevel@tonic-gate 
969*7c478bd9Sstevel@tonic-gate 	if (ismot(c = getch()))
970*7c478bd9Sstevel@tonic-gate 		return;
971*7c478bd9Sstevel@tonic-gate 	delim = cbits(c);
972*7c478bd9Sstevel@tonic-gate 	i = xbuf;
973*7c478bd9Sstevel@tonic-gate 	*i++ = XON;
974*7c478bd9Sstevel@tonic-gate 	while ((k = cbits(c = getch())) != delim && k != '\n' && i < xbuf+NC-1) {
975*7c478bd9Sstevel@tonic-gate 		if (k == ' ')
976*7c478bd9Sstevel@tonic-gate 			setcbits(c, UNPAD);
977*7c478bd9Sstevel@tonic-gate 		*i++ = c | ZBIT;
978*7c478bd9Sstevel@tonic-gate 	}
979*7c478bd9Sstevel@tonic-gate 	*i++ = XOFF;
980*7c478bd9Sstevel@tonic-gate 	*i = 0;
981*7c478bd9Sstevel@tonic-gate 	pushback(xbuf);
982*7c478bd9Sstevel@tonic-gate }
983*7c478bd9Sstevel@tonic-gate 
984*7c478bd9Sstevel@tonic-gate 
985*7c478bd9Sstevel@tonic-gate char	ifilt[32] = {
986*7c478bd9Sstevel@tonic-gate 	0, 001, 002, 003, 0, 005, 006, 007, 010, 011, 012};
987*7c478bd9Sstevel@tonic-gate 
988*7c478bd9Sstevel@tonic-gate tchar getch0()
989*7c478bd9Sstevel@tonic-gate {
990*7c478bd9Sstevel@tonic-gate 	register int	j;
991*7c478bd9Sstevel@tonic-gate 	register tchar i;
992*7c478bd9Sstevel@tonic-gate #ifdef	EUC
993*7c478bd9Sstevel@tonic-gate #ifdef	NROFF
994*7c478bd9Sstevel@tonic-gate 	register int	n;
995*7c478bd9Sstevel@tonic-gate 	int col_index;
996*7c478bd9Sstevel@tonic-gate #endif	/* NROFF */
997*7c478bd9Sstevel@tonic-gate #endif	/* EUC */
998*7c478bd9Sstevel@tonic-gate 
999*7c478bd9Sstevel@tonic-gate again:
1000*7c478bd9Sstevel@tonic-gate 	if (pbp > lastpbp)
1001*7c478bd9Sstevel@tonic-gate 		i = *--pbp;
1002*7c478bd9Sstevel@tonic-gate 	else if (ip) {
1003*7c478bd9Sstevel@tonic-gate #ifdef INCORE
1004*7c478bd9Sstevel@tonic-gate 		extern tchar corebuf[];
1005*7c478bd9Sstevel@tonic-gate 		i = corebuf[ip];
1006*7c478bd9Sstevel@tonic-gate 		if (i == 0)
1007*7c478bd9Sstevel@tonic-gate 			i = rbf();
1008*7c478bd9Sstevel@tonic-gate 		else {
1009*7c478bd9Sstevel@tonic-gate 			if ((++ip & (BLK - 1)) == 0) {
1010*7c478bd9Sstevel@tonic-gate 				--ip;
1011*7c478bd9Sstevel@tonic-gate 				(void)rbf();
1012*7c478bd9Sstevel@tonic-gate 			}
1013*7c478bd9Sstevel@tonic-gate 		}
1014*7c478bd9Sstevel@tonic-gate #else
1015*7c478bd9Sstevel@tonic-gate 		i = rbf();
1016*7c478bd9Sstevel@tonic-gate #endif
1017*7c478bd9Sstevel@tonic-gate 	} else {
1018*7c478bd9Sstevel@tonic-gate 		if (donef || ndone)
1019*7c478bd9Sstevel@tonic-gate 			done(0);
1020*7c478bd9Sstevel@tonic-gate 		if (nx || ibufp >= eibuf) {
1021*7c478bd9Sstevel@tonic-gate 			if (nfo==0) {
1022*7c478bd9Sstevel@tonic-gate g0:
1023*7c478bd9Sstevel@tonic-gate 				if (nextfile()) {
1024*7c478bd9Sstevel@tonic-gate 					if (ip)
1025*7c478bd9Sstevel@tonic-gate 						goto again;
1026*7c478bd9Sstevel@tonic-gate 					if (ibufp < eibuf)
1027*7c478bd9Sstevel@tonic-gate 						goto g2;
1028*7c478bd9Sstevel@tonic-gate 				}
1029*7c478bd9Sstevel@tonic-gate 			}
1030*7c478bd9Sstevel@tonic-gate 			nx = 0;
1031*7c478bd9Sstevel@tonic-gate 			if ((j = read(ifile, ibuf, IBUFSZ)) <= 0)
1032*7c478bd9Sstevel@tonic-gate 				goto g0;
1033*7c478bd9Sstevel@tonic-gate 			ibufp = ibuf;
1034*7c478bd9Sstevel@tonic-gate 			eibuf = ibuf + j;
1035*7c478bd9Sstevel@tonic-gate 			if (ip)
1036*7c478bd9Sstevel@tonic-gate 				goto again;
1037*7c478bd9Sstevel@tonic-gate 		}
1038*7c478bd9Sstevel@tonic-gate g2:
1039*7c478bd9Sstevel@tonic-gate #ifndef	EUC
1040*7c478bd9Sstevel@tonic-gate 		i = *ibufp++ & 0177;
1041*7c478bd9Sstevel@tonic-gate 		ioff++;
1042*7c478bd9Sstevel@tonic-gate 		if (i >= 040 && i < 0177)
1043*7c478bd9Sstevel@tonic-gate #else
1044*7c478bd9Sstevel@tonic-gate #ifndef	NROFF
1045*7c478bd9Sstevel@tonic-gate 		i = *ibufp++ & 0177;
1046*7c478bd9Sstevel@tonic-gate 		ioff++;
1047*7c478bd9Sstevel@tonic-gate 		if (i >= 040 && i < 0177)
1048*7c478bd9Sstevel@tonic-gate #else
1049*7c478bd9Sstevel@tonic-gate 		i = *ibufp++ & 0377;
1050*7c478bd9Sstevel@tonic-gate 		*mbbuf1p++ = i;
1051*7c478bd9Sstevel@tonic-gate 		*mbbuf1p = 0;
1052*7c478bd9Sstevel@tonic-gate 		if (!multi_locale) {
1053*7c478bd9Sstevel@tonic-gate 			twc = 0;
1054*7c478bd9Sstevel@tonic-gate 			mbbuf1p = mbbuf1;
1055*7c478bd9Sstevel@tonic-gate 		} else if ((n = mbtowc(&twc, mbbuf1, MB_CUR_MAX)) <= 0) {
1056*7c478bd9Sstevel@tonic-gate 			if (mbbuf1p >= mbbuf1 + MB_CUR_MAX) {
1057*7c478bd9Sstevel@tonic-gate 				i &= ~(MBMASK | CSMASK);
1058*7c478bd9Sstevel@tonic-gate 				twc = 0;
1059*7c478bd9Sstevel@tonic-gate 				mbbuf1p = mbbuf1;
1060*7c478bd9Sstevel@tonic-gate 				*mbbuf1p = 0;
1061*7c478bd9Sstevel@tonic-gate 			} else {
1062*7c478bd9Sstevel@tonic-gate 				i |= (MIDDLEOFMB);
1063*7c478bd9Sstevel@tonic-gate 			}
1064*7c478bd9Sstevel@tonic-gate 		} else {
1065*7c478bd9Sstevel@tonic-gate 			if (n > 1)
1066*7c478bd9Sstevel@tonic-gate 				i |= (LASTOFMB);
1067*7c478bd9Sstevel@tonic-gate 			else
1068*7c478bd9Sstevel@tonic-gate 				i |= (BYTE_CHR);
1069*7c478bd9Sstevel@tonic-gate 			if (isascii(twc)) {
1070*7c478bd9Sstevel@tonic-gate 				col_index = 0;
1071*7c478bd9Sstevel@tonic-gate 			} else {
1072*7c478bd9Sstevel@tonic-gate 				if ((col_index = wcwidth(twc)) < 0)
1073*7c478bd9Sstevel@tonic-gate 					col_index = 0;
1074*7c478bd9Sstevel@tonic-gate 			}
1075*7c478bd9Sstevel@tonic-gate 			setcsbits(i, col_index);
1076*7c478bd9Sstevel@tonic-gate 			twc = 0;
1077*7c478bd9Sstevel@tonic-gate 			mbbuf1p = mbbuf1;
1078*7c478bd9Sstevel@tonic-gate 		}
1079*7c478bd9Sstevel@tonic-gate 		ioff++;
1080*7c478bd9Sstevel@tonic-gate 		if (i >= 040 && i != 0177)
1081*7c478bd9Sstevel@tonic-gate #endif	/* NROFF */
1082*7c478bd9Sstevel@tonic-gate #endif	/* EUC */
1083*7c478bd9Sstevel@tonic-gate 			goto g4;
1084*7c478bd9Sstevel@tonic-gate 		if (i != 0177)
1085*7c478bd9Sstevel@tonic-gate 			i = ifilt[i];
1086*7c478bd9Sstevel@tonic-gate 	}
1087*7c478bd9Sstevel@tonic-gate 	if (cbits(i) == IMP && !raw)
1088*7c478bd9Sstevel@tonic-gate 		goto again;
1089*7c478bd9Sstevel@tonic-gate 	if ((i == 0 || i == 0177) && !init && !raw) {
1090*7c478bd9Sstevel@tonic-gate 		goto again;
1091*7c478bd9Sstevel@tonic-gate 	}
1092*7c478bd9Sstevel@tonic-gate g4:
1093*7c478bd9Sstevel@tonic-gate #ifndef EUC
1094*7c478bd9Sstevel@tonic-gate 	if (copyf == 0 && (i & ~BYTEMASK) == 0)
1095*7c478bd9Sstevel@tonic-gate #else
1096*7c478bd9Sstevel@tonic-gate #ifndef NROFF
1097*7c478bd9Sstevel@tonic-gate 	if (copyf == 0 && (i & ~BYTEMASK) == 0)
1098*7c478bd9Sstevel@tonic-gate #else
1099*7c478bd9Sstevel@tonic-gate 	if (copyf == 0 && (i & ~CHMASK) == 0)
1100*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
1101*7c478bd9Sstevel@tonic-gate #endif /* EUC */
1102*7c478bd9Sstevel@tonic-gate 		i |= chbits;
1103*7c478bd9Sstevel@tonic-gate #ifdef EUC
1104*7c478bd9Sstevel@tonic-gate #ifdef NROFF
1105*7c478bd9Sstevel@tonic-gate 	if (multi_locale)
1106*7c478bd9Sstevel@tonic-gate 		if (i & MBMASK1)
1107*7c478bd9Sstevel@tonic-gate 			i |= ZBIT;
1108*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
1109*7c478bd9Sstevel@tonic-gate #endif /* EUC */
1110*7c478bd9Sstevel@tonic-gate 	if (cbits(i) == eschar && !raw)
1111*7c478bd9Sstevel@tonic-gate 		setcbits(i, ESC);
1112*7c478bd9Sstevel@tonic-gate 	return(i);
1113*7c478bd9Sstevel@tonic-gate }
1114*7c478bd9Sstevel@tonic-gate 
1115*7c478bd9Sstevel@tonic-gate pushback(b)
1116*7c478bd9Sstevel@tonic-gate register tchar *b;
1117*7c478bd9Sstevel@tonic-gate {
1118*7c478bd9Sstevel@tonic-gate 	register tchar *ob = b;
1119*7c478bd9Sstevel@tonic-gate 
1120*7c478bd9Sstevel@tonic-gate 	while (*b++)
1121*7c478bd9Sstevel@tonic-gate 		;
1122*7c478bd9Sstevel@tonic-gate 	b--;
1123*7c478bd9Sstevel@tonic-gate 	while (b > ob && pbp < &pbbuf[NC-3])
1124*7c478bd9Sstevel@tonic-gate 		*pbp++ = *--b;
1125*7c478bd9Sstevel@tonic-gate 	if (pbp >= &pbbuf[NC-3]) {
1126*7c478bd9Sstevel@tonic-gate 		errprint(gettext("pushback overflow"));
1127*7c478bd9Sstevel@tonic-gate 		done(2);
1128*7c478bd9Sstevel@tonic-gate 	}
1129*7c478bd9Sstevel@tonic-gate }
1130*7c478bd9Sstevel@tonic-gate 
1131*7c478bd9Sstevel@tonic-gate cpushback(b)
1132*7c478bd9Sstevel@tonic-gate register char *b;
1133*7c478bd9Sstevel@tonic-gate {
1134*7c478bd9Sstevel@tonic-gate 	register char *ob = b;
1135*7c478bd9Sstevel@tonic-gate 
1136*7c478bd9Sstevel@tonic-gate 	while (*b++)
1137*7c478bd9Sstevel@tonic-gate 		;
1138*7c478bd9Sstevel@tonic-gate 	b--;
1139*7c478bd9Sstevel@tonic-gate 	while (b > ob && pbp < &pbbuf[NC-3])
1140*7c478bd9Sstevel@tonic-gate 		*pbp++ = *--b;
1141*7c478bd9Sstevel@tonic-gate 	if (pbp >= &pbbuf[NC-3]) {
1142*7c478bd9Sstevel@tonic-gate 		errprint(gettext("cpushback overflow"));
1143*7c478bd9Sstevel@tonic-gate 		done(2);
1144*7c478bd9Sstevel@tonic-gate 	}
1145*7c478bd9Sstevel@tonic-gate }
1146*7c478bd9Sstevel@tonic-gate 
1147*7c478bd9Sstevel@tonic-gate nextfile()
1148*7c478bd9Sstevel@tonic-gate {
1149*7c478bd9Sstevel@tonic-gate 	register char	*p;
1150*7c478bd9Sstevel@tonic-gate 
1151*7c478bd9Sstevel@tonic-gate n0:
1152*7c478bd9Sstevel@tonic-gate 	if (ifile)
1153*7c478bd9Sstevel@tonic-gate 		close(ifile);
1154*7c478bd9Sstevel@tonic-gate 	if (nx  ||  nmfi < mflg) {
1155*7c478bd9Sstevel@tonic-gate 		p = mfiles[nmfi++];
1156*7c478bd9Sstevel@tonic-gate 		if (*p != 0)
1157*7c478bd9Sstevel@tonic-gate 			goto n1;
1158*7c478bd9Sstevel@tonic-gate 	}
1159*7c478bd9Sstevel@tonic-gate 	if (ifi > 0) {
1160*7c478bd9Sstevel@tonic-gate 		if (popf())
1161*7c478bd9Sstevel@tonic-gate 			goto n0; /* popf error */
1162*7c478bd9Sstevel@tonic-gate 		return(1); /* popf ok */
1163*7c478bd9Sstevel@tonic-gate 	}
1164*7c478bd9Sstevel@tonic-gate 	if (rargc-- <= 0) {
1165*7c478bd9Sstevel@tonic-gate 		if ((nfo -= mflg) && !stdi)
1166*7c478bd9Sstevel@tonic-gate 			done(0);
1167*7c478bd9Sstevel@tonic-gate 		nfo++;
1168*7c478bd9Sstevel@tonic-gate 		numtab[CD].val = ifile = stdi = mflg = 0;
1169*7c478bd9Sstevel@tonic-gate 		strcpy(cfname[ifi], "<standard input>");
1170*7c478bd9Sstevel@tonic-gate 		ioff = 0;
1171*7c478bd9Sstevel@tonic-gate 		return(0);
1172*7c478bd9Sstevel@tonic-gate 	}
1173*7c478bd9Sstevel@tonic-gate 	p = (argp++)[0];
1174*7c478bd9Sstevel@tonic-gate n1:
1175*7c478bd9Sstevel@tonic-gate 	numtab[CD].val = 0;
1176*7c478bd9Sstevel@tonic-gate 	if (p[0] == '-' && p[1] == 0) {
1177*7c478bd9Sstevel@tonic-gate 		ifile = 0;
1178*7c478bd9Sstevel@tonic-gate 		strcpy(cfname[ifi], "<standard input>");
1179*7c478bd9Sstevel@tonic-gate 	} else if ((ifile = open(p, 0)) < 0) {
1180*7c478bd9Sstevel@tonic-gate 		errprint(gettext("cannot open file %s"), p);
1181*7c478bd9Sstevel@tonic-gate 		nfo -= mflg;
1182*7c478bd9Sstevel@tonic-gate 		done(02);
1183*7c478bd9Sstevel@tonic-gate 	} else
1184*7c478bd9Sstevel@tonic-gate 		strcpy(cfname[ifi],p);
1185*7c478bd9Sstevel@tonic-gate 	nfo++;
1186*7c478bd9Sstevel@tonic-gate 	ioff = 0;
1187*7c478bd9Sstevel@tonic-gate 	return(0);
1188*7c478bd9Sstevel@tonic-gate }
1189*7c478bd9Sstevel@tonic-gate 
1190*7c478bd9Sstevel@tonic-gate 
1191*7c478bd9Sstevel@tonic-gate popf()
1192*7c478bd9Sstevel@tonic-gate {
1193*7c478bd9Sstevel@tonic-gate 	register i;
1194*7c478bd9Sstevel@tonic-gate 	register char	*p, *q;
1195*7c478bd9Sstevel@tonic-gate 	extern char	*ttyname();
1196*7c478bd9Sstevel@tonic-gate 
1197*7c478bd9Sstevel@tonic-gate 	ioff = offl[--ifi];
1198*7c478bd9Sstevel@tonic-gate 	numtab[CD].val = cfline[ifi];		/*restore line counter*/
1199*7c478bd9Sstevel@tonic-gate 	ip = ipl[ifi];
1200*7c478bd9Sstevel@tonic-gate 	if ((ifile = ifl[ifi]) == 0) {
1201*7c478bd9Sstevel@tonic-gate 		p = xbuf;
1202*7c478bd9Sstevel@tonic-gate 		q = ibuf;
1203*7c478bd9Sstevel@tonic-gate 		ibufp = xbufp;
1204*7c478bd9Sstevel@tonic-gate 		eibuf = xeibuf;
1205*7c478bd9Sstevel@tonic-gate 		while (q < eibuf)
1206*7c478bd9Sstevel@tonic-gate 			*q++ = *p++;
1207*7c478bd9Sstevel@tonic-gate 		return(0);
1208*7c478bd9Sstevel@tonic-gate 	}
1209*7c478bd9Sstevel@tonic-gate 	if (lseek(ifile, (long)(ioff & ~(IBUFSZ-1)), 0) == (long) -1
1210*7c478bd9Sstevel@tonic-gate 	   || (i = read(ifile, ibuf, IBUFSZ)) < 0)
1211*7c478bd9Sstevel@tonic-gate 		return(1);
1212*7c478bd9Sstevel@tonic-gate 	eibuf = ibuf + i;
1213*7c478bd9Sstevel@tonic-gate 	ibufp = ibuf;
1214*7c478bd9Sstevel@tonic-gate 	if (ttyname(ifile) == 0)
1215*7c478bd9Sstevel@tonic-gate 		/* was >= ... */
1216*7c478bd9Sstevel@tonic-gate 		if ((ibufp = ibuf + (int)(ioff & (IBUFSZ - 1))) > eibuf)
1217*7c478bd9Sstevel@tonic-gate 			return(1);
1218*7c478bd9Sstevel@tonic-gate 	return(0);
1219*7c478bd9Sstevel@tonic-gate }
1220*7c478bd9Sstevel@tonic-gate 
1221*7c478bd9Sstevel@tonic-gate 
1222*7c478bd9Sstevel@tonic-gate flushi()
1223*7c478bd9Sstevel@tonic-gate {
1224*7c478bd9Sstevel@tonic-gate 	if (nflush)
1225*7c478bd9Sstevel@tonic-gate 		return;
1226*7c478bd9Sstevel@tonic-gate 	ch = 0;
1227*7c478bd9Sstevel@tonic-gate 	copyf++;
1228*7c478bd9Sstevel@tonic-gate 	while (!nlflg) {
1229*7c478bd9Sstevel@tonic-gate 		if (donef && (frame == stk))
1230*7c478bd9Sstevel@tonic-gate 			break;
1231*7c478bd9Sstevel@tonic-gate 		getch();
1232*7c478bd9Sstevel@tonic-gate 	}
1233*7c478bd9Sstevel@tonic-gate 	copyf--;
1234*7c478bd9Sstevel@tonic-gate }
1235*7c478bd9Sstevel@tonic-gate 
1236*7c478bd9Sstevel@tonic-gate 
1237*7c478bd9Sstevel@tonic-gate getach()
1238*7c478bd9Sstevel@tonic-gate {
1239*7c478bd9Sstevel@tonic-gate 	register tchar i;
1240*7c478bd9Sstevel@tonic-gate 	register j;
1241*7c478bd9Sstevel@tonic-gate 
1242*7c478bd9Sstevel@tonic-gate 	lgf++;
1243*7c478bd9Sstevel@tonic-gate 	j = cbits(i = getch());
1244*7c478bd9Sstevel@tonic-gate #ifndef	EUC
1245*7c478bd9Sstevel@tonic-gate 	if (ismot(i) || j == ' ' || j == '\n' || j & 0200) {
1246*7c478bd9Sstevel@tonic-gate #else
1247*7c478bd9Sstevel@tonic-gate #ifndef	NROFF
1248*7c478bd9Sstevel@tonic-gate 	if (ismot(i) || j == ' ' || j == '\n' || j & 0200) {
1249*7c478bd9Sstevel@tonic-gate #else
1250*7c478bd9Sstevel@tonic-gate 	if (ismot(i) || j == ' ' || j == '\n' || j > 0200) {
1251*7c478bd9Sstevel@tonic-gate #endif	/* NROFF */
1252*7c478bd9Sstevel@tonic-gate #endif	/* EUC */
1253*7c478bd9Sstevel@tonic-gate 
1254*7c478bd9Sstevel@tonic-gate 		ch = i;
1255*7c478bd9Sstevel@tonic-gate 		j = 0;
1256*7c478bd9Sstevel@tonic-gate 	}
1257*7c478bd9Sstevel@tonic-gate 	lgf--;
1258*7c478bd9Sstevel@tonic-gate 	return(j & 0177);
1259*7c478bd9Sstevel@tonic-gate }
1260*7c478bd9Sstevel@tonic-gate 
1261*7c478bd9Sstevel@tonic-gate 
1262*7c478bd9Sstevel@tonic-gate casenx()
1263*7c478bd9Sstevel@tonic-gate {
1264*7c478bd9Sstevel@tonic-gate 	lgf++;
1265*7c478bd9Sstevel@tonic-gate 	skip();
1266*7c478bd9Sstevel@tonic-gate 	getname();
1267*7c478bd9Sstevel@tonic-gate 	nx++;
1268*7c478bd9Sstevel@tonic-gate 	if (nmfi > 0)
1269*7c478bd9Sstevel@tonic-gate 		nmfi--;
1270*7c478bd9Sstevel@tonic-gate 	strcpy(mfiles[nmfi], nextf);
1271*7c478bd9Sstevel@tonic-gate 	nextfile();
1272*7c478bd9Sstevel@tonic-gate 	nlflg++;
1273*7c478bd9Sstevel@tonic-gate 	ip = 0;
1274*7c478bd9Sstevel@tonic-gate 	pendt = 0;
1275*7c478bd9Sstevel@tonic-gate 	frame = stk;
1276*7c478bd9Sstevel@tonic-gate 	nxf = frame + 1;
1277*7c478bd9Sstevel@tonic-gate }
1278*7c478bd9Sstevel@tonic-gate 
1279*7c478bd9Sstevel@tonic-gate 
1280*7c478bd9Sstevel@tonic-gate getname()
1281*7c478bd9Sstevel@tonic-gate {
1282*7c478bd9Sstevel@tonic-gate 	register int	j, k;
1283*7c478bd9Sstevel@tonic-gate 	tchar i;
1284*7c478bd9Sstevel@tonic-gate 
1285*7c478bd9Sstevel@tonic-gate 	lgf++;
1286*7c478bd9Sstevel@tonic-gate 	for (k = 0; k < (NS - 1); k++) {
1287*7c478bd9Sstevel@tonic-gate #ifndef EUC
1288*7c478bd9Sstevel@tonic-gate 		if (((j = cbits(i = getch())) <= ' ') || (j > 0176))
1289*7c478bd9Sstevel@tonic-gate #else
1290*7c478bd9Sstevel@tonic-gate #ifndef NROFF
1291*7c478bd9Sstevel@tonic-gate 		if (((j = cbits(i = getch())) <= ' ') || (j > 0176))
1292*7c478bd9Sstevel@tonic-gate #else
1293*7c478bd9Sstevel@tonic-gate 		if (((j = cbits(i = getch())) <= ' ') || (j == 0177))
1294*7c478bd9Sstevel@tonic-gate #endif /* NROFF */
1295*7c478bd9Sstevel@tonic-gate #endif /* EUC */
1296*7c478bd9Sstevel@tonic-gate 			break;
1297*7c478bd9Sstevel@tonic-gate 		nextf[k] = j & BYTEMASK;
1298*7c478bd9Sstevel@tonic-gate 	}
1299*7c478bd9Sstevel@tonic-gate 	nextf[k] = 0;
1300*7c478bd9Sstevel@tonic-gate 	ch = i;
1301*7c478bd9Sstevel@tonic-gate 	lgf--;
1302*7c478bd9Sstevel@tonic-gate 	return(nextf[0]);
1303*7c478bd9Sstevel@tonic-gate }
1304*7c478bd9Sstevel@tonic-gate 
1305*7c478bd9Sstevel@tonic-gate 
1306*7c478bd9Sstevel@tonic-gate caseso()
1307*7c478bd9Sstevel@tonic-gate {
1308*7c478bd9Sstevel@tonic-gate 	register i;
1309*7c478bd9Sstevel@tonic-gate 	register char	*p, *q;
1310*7c478bd9Sstevel@tonic-gate 
1311*7c478bd9Sstevel@tonic-gate 	lgf++;
1312*7c478bd9Sstevel@tonic-gate 	nextf[0] = 0;
1313*7c478bd9Sstevel@tonic-gate 	if (skip() || !getname() || ((i = open(nextf, 0)) < 0) || (ifi >= NSO)) {
1314*7c478bd9Sstevel@tonic-gate 		errprint(gettext("can't open file %s"), nextf);
1315*7c478bd9Sstevel@tonic-gate 		done(02);
1316*7c478bd9Sstevel@tonic-gate 	}
1317*7c478bd9Sstevel@tonic-gate 	strcpy(cfname[ifi+1], nextf);
1318*7c478bd9Sstevel@tonic-gate 	cfline[ifi] = numtab[CD].val;		/*hold line counter*/
1319*7c478bd9Sstevel@tonic-gate 	numtab[CD].val = 0;
1320*7c478bd9Sstevel@tonic-gate 	flushi();
1321*7c478bd9Sstevel@tonic-gate 	ifl[ifi] = ifile;
1322*7c478bd9Sstevel@tonic-gate 	ifile = i;
1323*7c478bd9Sstevel@tonic-gate 	offl[ifi] = ioff;
1324*7c478bd9Sstevel@tonic-gate 	ioff = 0;
1325*7c478bd9Sstevel@tonic-gate 	ipl[ifi] = ip;
1326*7c478bd9Sstevel@tonic-gate 	ip = 0;
1327*7c478bd9Sstevel@tonic-gate 	nx++;
1328*7c478bd9Sstevel@tonic-gate 	nflush++;
1329*7c478bd9Sstevel@tonic-gate 	if (!ifl[ifi++]) {
1330*7c478bd9Sstevel@tonic-gate 		p = ibuf;
1331*7c478bd9Sstevel@tonic-gate 		q = xbuf;
1332*7c478bd9Sstevel@tonic-gate 		xbufp = ibufp;
1333*7c478bd9Sstevel@tonic-gate 		xeibuf = eibuf;
1334*7c478bd9Sstevel@tonic-gate 		while (p < eibuf)
1335*7c478bd9Sstevel@tonic-gate 			*q++ = *p++;
1336*7c478bd9Sstevel@tonic-gate 	}
1337*7c478bd9Sstevel@tonic-gate }
1338*7c478bd9Sstevel@tonic-gate 
1339*7c478bd9Sstevel@tonic-gate caself()	/* set line number and file */
1340*7c478bd9Sstevel@tonic-gate {
1341*7c478bd9Sstevel@tonic-gate 	int n;
1342*7c478bd9Sstevel@tonic-gate 
1343*7c478bd9Sstevel@tonic-gate 	if (skip())
1344*7c478bd9Sstevel@tonic-gate 		return;
1345*7c478bd9Sstevel@tonic-gate 	n = atoi();
1346*7c478bd9Sstevel@tonic-gate 	cfline[ifi] = numtab[CD].val = n - 2;
1347*7c478bd9Sstevel@tonic-gate 	if (skip())
1348*7c478bd9Sstevel@tonic-gate 		return;
1349*7c478bd9Sstevel@tonic-gate 	if (getname())
1350*7c478bd9Sstevel@tonic-gate 		strcpy(cfname[ifi], nextf);
1351*7c478bd9Sstevel@tonic-gate }
1352*7c478bd9Sstevel@tonic-gate 
1353*7c478bd9Sstevel@tonic-gate 
1354*7c478bd9Sstevel@tonic-gate casecf()
1355*7c478bd9Sstevel@tonic-gate {	/* copy file without change */
1356*7c478bd9Sstevel@tonic-gate #ifndef NROFF
1357*7c478bd9Sstevel@tonic-gate 	int	fd, n;
1358*7c478bd9Sstevel@tonic-gate 	char	buf[512];
1359*7c478bd9Sstevel@tonic-gate 	extern int hpos, esc, po;
1360*7c478bd9Sstevel@tonic-gate 	nextf[0] = 0;
1361*7c478bd9Sstevel@tonic-gate 	if (skip() || !getname() || (fd = open(nextf, 0)) < 0) {
1362*7c478bd9Sstevel@tonic-gate 		errprint(gettext("can't open file %s"), nextf);
1363*7c478bd9Sstevel@tonic-gate 		done(02);
1364*7c478bd9Sstevel@tonic-gate 	}
1365*7c478bd9Sstevel@tonic-gate 	tbreak();
1366*7c478bd9Sstevel@tonic-gate 	/* make it into a clean state, be sure that everything is out */
1367*7c478bd9Sstevel@tonic-gate 	hpos = po;
1368*7c478bd9Sstevel@tonic-gate 	esc = un;
1369*7c478bd9Sstevel@tonic-gate 	ptesc();
1370*7c478bd9Sstevel@tonic-gate 	ptlead();
1371*7c478bd9Sstevel@tonic-gate 	ptps();
1372*7c478bd9Sstevel@tonic-gate 	ptfont();
1373*7c478bd9Sstevel@tonic-gate 	flusho();
1374*7c478bd9Sstevel@tonic-gate 	while ((n = read(fd, buf, sizeof buf)) > 0)
1375*7c478bd9Sstevel@tonic-gate 		write(ptid, buf, n);
1376*7c478bd9Sstevel@tonic-gate 	close(fd);
1377*7c478bd9Sstevel@tonic-gate #endif
1378*7c478bd9Sstevel@tonic-gate }
1379*7c478bd9Sstevel@tonic-gate 
1380*7c478bd9Sstevel@tonic-gate 
1381*7c478bd9Sstevel@tonic-gate casesy()	/* call system */
1382*7c478bd9Sstevel@tonic-gate {
1383*7c478bd9Sstevel@tonic-gate 	char	sybuf[NTM];
1384*7c478bd9Sstevel@tonic-gate 	int	i;
1385*7c478bd9Sstevel@tonic-gate 
1386*7c478bd9Sstevel@tonic-gate 	lgf++;
1387*7c478bd9Sstevel@tonic-gate 	copyf++;
1388*7c478bd9Sstevel@tonic-gate 	skip();
1389*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NTM - 2; i++)
1390*7c478bd9Sstevel@tonic-gate 		if ((sybuf[i] = getch()) == '\n')
1391*7c478bd9Sstevel@tonic-gate 			break;
1392*7c478bd9Sstevel@tonic-gate 	sybuf[i] = 0;
1393*7c478bd9Sstevel@tonic-gate 	system(sybuf);
1394*7c478bd9Sstevel@tonic-gate 	copyf--;
1395*7c478bd9Sstevel@tonic-gate 	lgf--;
1396*7c478bd9Sstevel@tonic-gate }
1397*7c478bd9Sstevel@tonic-gate 
1398*7c478bd9Sstevel@tonic-gate 
1399*7c478bd9Sstevel@tonic-gate getpn(a)
1400*7c478bd9Sstevel@tonic-gate 	register char *a;
1401*7c478bd9Sstevel@tonic-gate {
1402*7c478bd9Sstevel@tonic-gate 	register int n, neg;
1403*7c478bd9Sstevel@tonic-gate 
1404*7c478bd9Sstevel@tonic-gate 	if (*a == 0)
1405*7c478bd9Sstevel@tonic-gate 		return;
1406*7c478bd9Sstevel@tonic-gate 	neg = 0;
1407*7c478bd9Sstevel@tonic-gate 	for ( ; *a; a++)
1408*7c478bd9Sstevel@tonic-gate 		switch (*a) {
1409*7c478bd9Sstevel@tonic-gate 		case '+':
1410*7c478bd9Sstevel@tonic-gate 		case ',':
1411*7c478bd9Sstevel@tonic-gate 			continue;
1412*7c478bd9Sstevel@tonic-gate 		case '-':
1413*7c478bd9Sstevel@tonic-gate 			neg = 1;
1414*7c478bd9Sstevel@tonic-gate 			continue;
1415*7c478bd9Sstevel@tonic-gate 		default:
1416*7c478bd9Sstevel@tonic-gate 			n = 0;
1417*7c478bd9Sstevel@tonic-gate 			if (isdigit((unsigned char)*a)) {
1418*7c478bd9Sstevel@tonic-gate 				do
1419*7c478bd9Sstevel@tonic-gate 					n = 10 * n + *a++ - '0';
1420*7c478bd9Sstevel@tonic-gate 				while (isdigit((unsigned char)*a));
1421*7c478bd9Sstevel@tonic-gate 				a--;
1422*7c478bd9Sstevel@tonic-gate 			} else
1423*7c478bd9Sstevel@tonic-gate 				n = 9999;
1424*7c478bd9Sstevel@tonic-gate 			*pnp++ = neg ? -n : n;
1425*7c478bd9Sstevel@tonic-gate 			neg = 0;
1426*7c478bd9Sstevel@tonic-gate 			if (pnp >= &pnlist[NPN-2]) {
1427*7c478bd9Sstevel@tonic-gate 				errprint(gettext("too many page numbers"));
1428*7c478bd9Sstevel@tonic-gate 				done3(-3);
1429*7c478bd9Sstevel@tonic-gate 			}
1430*7c478bd9Sstevel@tonic-gate 		}
1431*7c478bd9Sstevel@tonic-gate 	if (neg)
1432*7c478bd9Sstevel@tonic-gate 		*pnp++ = -9999;
1433*7c478bd9Sstevel@tonic-gate 	*pnp = -32767;
1434*7c478bd9Sstevel@tonic-gate 	print = 0;
1435*7c478bd9Sstevel@tonic-gate 	pnp = pnlist;
1436*7c478bd9Sstevel@tonic-gate 	if (*pnp != -32767)
1437*7c478bd9Sstevel@tonic-gate 		chkpn();
1438*7c478bd9Sstevel@tonic-gate }
1439*7c478bd9Sstevel@tonic-gate 
1440*7c478bd9Sstevel@tonic-gate 
1441*7c478bd9Sstevel@tonic-gate setrpt()
1442*7c478bd9Sstevel@tonic-gate {
1443*7c478bd9Sstevel@tonic-gate 	tchar i, j;
1444*7c478bd9Sstevel@tonic-gate 
1445*7c478bd9Sstevel@tonic-gate 	copyf++;
1446*7c478bd9Sstevel@tonic-gate 	raw++;
1447*7c478bd9Sstevel@tonic-gate 	i = getch0();
1448*7c478bd9Sstevel@tonic-gate 	copyf--;
1449*7c478bd9Sstevel@tonic-gate 	raw--;
1450*7c478bd9Sstevel@tonic-gate 	if (i < 0 || cbits(j = getch0()) == RPT)
1451*7c478bd9Sstevel@tonic-gate 		return;
1452*7c478bd9Sstevel@tonic-gate 	i &= BYTEMASK;
1453*7c478bd9Sstevel@tonic-gate 	while (i>0 && pbp < &pbbuf[NC-3]) {
1454*7c478bd9Sstevel@tonic-gate 		i--;
1455*7c478bd9Sstevel@tonic-gate 		*pbp++ = j;
1456*7c478bd9Sstevel@tonic-gate 	}
1457*7c478bd9Sstevel@tonic-gate }
1458*7c478bd9Sstevel@tonic-gate 
1459*7c478bd9Sstevel@tonic-gate 
1460*7c478bd9Sstevel@tonic-gate casedb()
1461*7c478bd9Sstevel@tonic-gate {
1462*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
1463*7c478bd9Sstevel@tonic-gate 	debug = 0;
1464*7c478bd9Sstevel@tonic-gate 	if (skip())
1465*7c478bd9Sstevel@tonic-gate 		return;
1466*7c478bd9Sstevel@tonic-gate 	noscale++;
1467*7c478bd9Sstevel@tonic-gate 	debug = max(atoi(), 0);
1468*7c478bd9Sstevel@tonic-gate 	noscale = 0;
1469*7c478bd9Sstevel@tonic-gate #endif	DEBUG
1470*7c478bd9Sstevel@tonic-gate }
1471