xref: /titanic_50/usr/src/cmd/troff/n4.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
35*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
36*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
39*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
40*7c478bd9Sstevel@tonic-gate  * contributors.
41*7c478bd9Sstevel@tonic-gate  */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include	<ctype.h>
44*7c478bd9Sstevel@tonic-gate #include "tdef.h"
45*7c478bd9Sstevel@tonic-gate #ifdef NROFF
46*7c478bd9Sstevel@tonic-gate #include "tw.h"
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate #include "ext.h"
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * troff4.c
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * number registers, conversion, arithmetic
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate int	regcnt = NNAMES;
57*7c478bd9Sstevel@tonic-gate int	falsef	= 0;	/* on if inside false branch of if */
58*7c478bd9Sstevel@tonic-gate #define	NHASH(i)	((i>>6)^i)&0177
59*7c478bd9Sstevel@tonic-gate struct	numtab	*nhash[128];	/* 128 == the 0177 on line above */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate setn()
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate 	register i, j;
64*7c478bd9Sstevel@tonic-gate 	register tchar ii;
65*7c478bd9Sstevel@tonic-gate 	int	f;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	f = nform = 0;
68*7c478bd9Sstevel@tonic-gate 	if ((i = cbits(ii = getach())) == '+')
69*7c478bd9Sstevel@tonic-gate 		f = 1;
70*7c478bd9Sstevel@tonic-gate 	else if (i == '-')
71*7c478bd9Sstevel@tonic-gate 		f = -1;
72*7c478bd9Sstevel@tonic-gate 	else
73*7c478bd9Sstevel@tonic-gate 		ch = ii;
74*7c478bd9Sstevel@tonic-gate 	if (falsef)
75*7c478bd9Sstevel@tonic-gate 		f = 0;
76*7c478bd9Sstevel@tonic-gate 	if ((i = getsn()) == 0)
77*7c478bd9Sstevel@tonic-gate 		return;
78*7c478bd9Sstevel@tonic-gate 	if ((i & 0177) == '.')
79*7c478bd9Sstevel@tonic-gate 		switch (i >> BYTE) {
80*7c478bd9Sstevel@tonic-gate 		case 's':
81*7c478bd9Sstevel@tonic-gate 			i = pts;
82*7c478bd9Sstevel@tonic-gate 			break;
83*7c478bd9Sstevel@tonic-gate 		case 'v':
84*7c478bd9Sstevel@tonic-gate 			i = lss;
85*7c478bd9Sstevel@tonic-gate 			break;
86*7c478bd9Sstevel@tonic-gate 		case 'f':
87*7c478bd9Sstevel@tonic-gate 			i = font;
88*7c478bd9Sstevel@tonic-gate 			break;
89*7c478bd9Sstevel@tonic-gate 		case 'p':
90*7c478bd9Sstevel@tonic-gate 			i = pl;
91*7c478bd9Sstevel@tonic-gate 			break;
92*7c478bd9Sstevel@tonic-gate 		case 't':
93*7c478bd9Sstevel@tonic-gate 			i = findt1();
94*7c478bd9Sstevel@tonic-gate 			break;
95*7c478bd9Sstevel@tonic-gate 		case 'o':
96*7c478bd9Sstevel@tonic-gate 			i = po;
97*7c478bd9Sstevel@tonic-gate 			break;
98*7c478bd9Sstevel@tonic-gate 		case 'l':
99*7c478bd9Sstevel@tonic-gate 			i = ll;
100*7c478bd9Sstevel@tonic-gate 			break;
101*7c478bd9Sstevel@tonic-gate 		case 'i':
102*7c478bd9Sstevel@tonic-gate 			i = in;
103*7c478bd9Sstevel@tonic-gate 			break;
104*7c478bd9Sstevel@tonic-gate 		case '$':
105*7c478bd9Sstevel@tonic-gate 			i = frame->nargs;
106*7c478bd9Sstevel@tonic-gate 			break;
107*7c478bd9Sstevel@tonic-gate 		case 'A':
108*7c478bd9Sstevel@tonic-gate 			i = ascii;
109*7c478bd9Sstevel@tonic-gate 			break;
110*7c478bd9Sstevel@tonic-gate 		case 'c':
111*7c478bd9Sstevel@tonic-gate 			i = numtab[CD].val;
112*7c478bd9Sstevel@tonic-gate 			break;
113*7c478bd9Sstevel@tonic-gate 		case 'n':
114*7c478bd9Sstevel@tonic-gate 			i = lastl;
115*7c478bd9Sstevel@tonic-gate 			break;
116*7c478bd9Sstevel@tonic-gate 		case 'a':
117*7c478bd9Sstevel@tonic-gate 			i = ralss;
118*7c478bd9Sstevel@tonic-gate 			break;
119*7c478bd9Sstevel@tonic-gate 		case 'h':
120*7c478bd9Sstevel@tonic-gate 			i = dip->hnl;
121*7c478bd9Sstevel@tonic-gate 			break;
122*7c478bd9Sstevel@tonic-gate 		case 'd':
123*7c478bd9Sstevel@tonic-gate 			if (dip != d)
124*7c478bd9Sstevel@tonic-gate 				i = dip->dnl;
125*7c478bd9Sstevel@tonic-gate 			else
126*7c478bd9Sstevel@tonic-gate 				i = numtab[NL].val;
127*7c478bd9Sstevel@tonic-gate 			break;
128*7c478bd9Sstevel@tonic-gate 		case 'u':
129*7c478bd9Sstevel@tonic-gate 			i = fi;
130*7c478bd9Sstevel@tonic-gate 			break;
131*7c478bd9Sstevel@tonic-gate 		case 'j':
132*7c478bd9Sstevel@tonic-gate 			i = ad + 2 * admod;
133*7c478bd9Sstevel@tonic-gate 			break;
134*7c478bd9Sstevel@tonic-gate 		case 'w':
135*7c478bd9Sstevel@tonic-gate 			i = widthp;
136*7c478bd9Sstevel@tonic-gate 			break;
137*7c478bd9Sstevel@tonic-gate 		case 'x':
138*7c478bd9Sstevel@tonic-gate 			i = nel;
139*7c478bd9Sstevel@tonic-gate 			break;
140*7c478bd9Sstevel@tonic-gate 		case 'y':
141*7c478bd9Sstevel@tonic-gate 			i = un;
142*7c478bd9Sstevel@tonic-gate 			break;
143*7c478bd9Sstevel@tonic-gate 		case 'T':
144*7c478bd9Sstevel@tonic-gate 			i = dotT;
145*7c478bd9Sstevel@tonic-gate 			break; /*-Tterm used in nroff*/
146*7c478bd9Sstevel@tonic-gate 		case 'V':
147*7c478bd9Sstevel@tonic-gate 			i = VERT;
148*7c478bd9Sstevel@tonic-gate 			break;
149*7c478bd9Sstevel@tonic-gate 		case 'H':
150*7c478bd9Sstevel@tonic-gate 			i = HOR;
151*7c478bd9Sstevel@tonic-gate 			break;
152*7c478bd9Sstevel@tonic-gate 		case 'k':
153*7c478bd9Sstevel@tonic-gate 			i = ne;
154*7c478bd9Sstevel@tonic-gate 			break;
155*7c478bd9Sstevel@tonic-gate 		case 'P':
156*7c478bd9Sstevel@tonic-gate 			i = print;
157*7c478bd9Sstevel@tonic-gate 			break;
158*7c478bd9Sstevel@tonic-gate 		case 'L':
159*7c478bd9Sstevel@tonic-gate 			i = ls;
160*7c478bd9Sstevel@tonic-gate 			break;
161*7c478bd9Sstevel@tonic-gate 		case 'R':
162*7c478bd9Sstevel@tonic-gate 			i = NN - regcnt;
163*7c478bd9Sstevel@tonic-gate 			break;
164*7c478bd9Sstevel@tonic-gate 		case 'z':
165*7c478bd9Sstevel@tonic-gate 			i = dip->curd;
166*7c478bd9Sstevel@tonic-gate 			*pbp++ = (i >> BYTE) & BYTEMASK;
167*7c478bd9Sstevel@tonic-gate 			*pbp++ = i & BYTEMASK;
168*7c478bd9Sstevel@tonic-gate 			return;
169*7c478bd9Sstevel@tonic-gate 		case 'b':
170*7c478bd9Sstevel@tonic-gate 			i = bdtab[font];
171*7c478bd9Sstevel@tonic-gate 			break;
172*7c478bd9Sstevel@tonic-gate 		case 'F':
173*7c478bd9Sstevel@tonic-gate 			cpushback(cfname[ifi]);
174*7c478bd9Sstevel@tonic-gate 			return;
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 		default:
177*7c478bd9Sstevel@tonic-gate 			goto s0;
178*7c478bd9Sstevel@tonic-gate 		}
179*7c478bd9Sstevel@tonic-gate 	else {
180*7c478bd9Sstevel@tonic-gate s0:
181*7c478bd9Sstevel@tonic-gate 		if ((j = findr(i)) == -1)
182*7c478bd9Sstevel@tonic-gate 			i = 0;
183*7c478bd9Sstevel@tonic-gate 		else {
184*7c478bd9Sstevel@tonic-gate 			i = numtab[j].val = (numtab[j].val+numtab[j].inc*f);
185*7c478bd9Sstevel@tonic-gate 			nform = numtab[j].fmt;
186*7c478bd9Sstevel@tonic-gate 		}
187*7c478bd9Sstevel@tonic-gate 	}
188*7c478bd9Sstevel@tonic-gate 	setn1(i, nform, (tchar) 0);
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate tchar	numbuf[17];
192*7c478bd9Sstevel@tonic-gate tchar	*numbufp;
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate wrc(i)
195*7c478bd9Sstevel@tonic-gate tchar i;
196*7c478bd9Sstevel@tonic-gate {
197*7c478bd9Sstevel@tonic-gate 	if (numbufp >= &numbuf[16])
198*7c478bd9Sstevel@tonic-gate 		return(0);
199*7c478bd9Sstevel@tonic-gate 	*numbufp++ = i;
200*7c478bd9Sstevel@tonic-gate 	return(1);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate /* insert into input number i, in format form, with size-font bits bits */
206*7c478bd9Sstevel@tonic-gate setn1(i, form, bits)
207*7c478bd9Sstevel@tonic-gate int	i;
208*7c478bd9Sstevel@tonic-gate tchar bits;
209*7c478bd9Sstevel@tonic-gate {
210*7c478bd9Sstevel@tonic-gate 	extern int	wrc();
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	numbufp = numbuf;
213*7c478bd9Sstevel@tonic-gate 	nrbits = bits;
214*7c478bd9Sstevel@tonic-gate 	nform = form;
215*7c478bd9Sstevel@tonic-gate 	fnumb(i, wrc);
216*7c478bd9Sstevel@tonic-gate 	*numbufp = 0;
217*7c478bd9Sstevel@tonic-gate 	pushback(numbuf);
218*7c478bd9Sstevel@tonic-gate }
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate nrehash()
222*7c478bd9Sstevel@tonic-gate {
223*7c478bd9Sstevel@tonic-gate 	register struct numtab *p;
224*7c478bd9Sstevel@tonic-gate 	register i;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 	for (i=0; i<128; i++)
227*7c478bd9Sstevel@tonic-gate 		nhash[i] = 0;
228*7c478bd9Sstevel@tonic-gate 	for (p=numtab; p < &numtab[NN]; p++)
229*7c478bd9Sstevel@tonic-gate 		p->link = 0;
230*7c478bd9Sstevel@tonic-gate 	for (p=numtab; p < &numtab[NN]; p++) {
231*7c478bd9Sstevel@tonic-gate 		if (p->r == 0)
232*7c478bd9Sstevel@tonic-gate 			continue;
233*7c478bd9Sstevel@tonic-gate 		i = NHASH(p->r);
234*7c478bd9Sstevel@tonic-gate 		p->link = nhash[i];
235*7c478bd9Sstevel@tonic-gate 		nhash[i] = p;
236*7c478bd9Sstevel@tonic-gate 	}
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate nunhash(rp)
240*7c478bd9Sstevel@tonic-gate register struct numtab *rp;
241*7c478bd9Sstevel@tonic-gate {
242*7c478bd9Sstevel@tonic-gate 	register struct numtab *p;
243*7c478bd9Sstevel@tonic-gate 	register struct numtab **lp;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	if (rp->r == 0)
246*7c478bd9Sstevel@tonic-gate 		return;
247*7c478bd9Sstevel@tonic-gate 	lp = &nhash[NHASH(rp->r)];
248*7c478bd9Sstevel@tonic-gate 	p = *lp;
249*7c478bd9Sstevel@tonic-gate 	while (p) {
250*7c478bd9Sstevel@tonic-gate 		if (p == rp) {
251*7c478bd9Sstevel@tonic-gate 			*lp = p->link;
252*7c478bd9Sstevel@tonic-gate 			p->link = 0;
253*7c478bd9Sstevel@tonic-gate 			return;
254*7c478bd9Sstevel@tonic-gate 		}
255*7c478bd9Sstevel@tonic-gate 		lp = &p->link;
256*7c478bd9Sstevel@tonic-gate 		p = p->link;
257*7c478bd9Sstevel@tonic-gate 	}
258*7c478bd9Sstevel@tonic-gate }
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate findr(i)
261*7c478bd9Sstevel@tonic-gate register int	i;
262*7c478bd9Sstevel@tonic-gate {
263*7c478bd9Sstevel@tonic-gate 	register struct numtab *p;
264*7c478bd9Sstevel@tonic-gate 	register h = NHASH(i);
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 	if (i == 0)
267*7c478bd9Sstevel@tonic-gate 		return(-1);
268*7c478bd9Sstevel@tonic-gate 	for (p = nhash[h]; p; p = p->link)
269*7c478bd9Sstevel@tonic-gate 		if (i == p->r)
270*7c478bd9Sstevel@tonic-gate 			return(p - numtab);
271*7c478bd9Sstevel@tonic-gate 	for (p = numtab; p < &numtab[NN]; p++) {
272*7c478bd9Sstevel@tonic-gate 		if (p->r == 0) {
273*7c478bd9Sstevel@tonic-gate 			p->r = i;
274*7c478bd9Sstevel@tonic-gate 			p->link = nhash[h];
275*7c478bd9Sstevel@tonic-gate 			nhash[h] = p;
276*7c478bd9Sstevel@tonic-gate 			regcnt++;
277*7c478bd9Sstevel@tonic-gate 			return(p - numtab);
278*7c478bd9Sstevel@tonic-gate 		}
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate 	errprint(gettext("too many number registers (%d)."), NN);
281*7c478bd9Sstevel@tonic-gate 	done2(04);
282*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
283*7c478bd9Sstevel@tonic-gate }
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate usedr(i)	/* returns -1 if nr i has never been used */
286*7c478bd9Sstevel@tonic-gate register int	i;
287*7c478bd9Sstevel@tonic-gate {
288*7c478bd9Sstevel@tonic-gate 	register struct numtab *p;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	if (i == 0)
291*7c478bd9Sstevel@tonic-gate 		return(-1);
292*7c478bd9Sstevel@tonic-gate 	for (p = nhash[NHASH(i)]; p; p = p->link)
293*7c478bd9Sstevel@tonic-gate 		if (i == p->r)
294*7c478bd9Sstevel@tonic-gate 			return(p - numtab);
295*7c478bd9Sstevel@tonic-gate 	return -1;
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate fnumb(i, f)
300*7c478bd9Sstevel@tonic-gate register int	i, (*f)();
301*7c478bd9Sstevel@tonic-gate {
302*7c478bd9Sstevel@tonic-gate 	register j;
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	j = 0;
305*7c478bd9Sstevel@tonic-gate 	if (i < 0) {
306*7c478bd9Sstevel@tonic-gate 		j = (*f)('-' | nrbits);
307*7c478bd9Sstevel@tonic-gate 		i = -i;
308*7c478bd9Sstevel@tonic-gate 	}
309*7c478bd9Sstevel@tonic-gate 	switch (nform) {
310*7c478bd9Sstevel@tonic-gate 	default:
311*7c478bd9Sstevel@tonic-gate 	case '1':
312*7c478bd9Sstevel@tonic-gate 	case 0:
313*7c478bd9Sstevel@tonic-gate 		return decml(i, f) + j;
314*7c478bd9Sstevel@tonic-gate 		break;
315*7c478bd9Sstevel@tonic-gate 	case 'i':
316*7c478bd9Sstevel@tonic-gate 	case 'I':
317*7c478bd9Sstevel@tonic-gate 		return roman(i, f) + j;
318*7c478bd9Sstevel@tonic-gate 		break;
319*7c478bd9Sstevel@tonic-gate 	case 'a':
320*7c478bd9Sstevel@tonic-gate 	case 'A':
321*7c478bd9Sstevel@tonic-gate 		return abc(i, f) + j;
322*7c478bd9Sstevel@tonic-gate 		break;
323*7c478bd9Sstevel@tonic-gate 	}
324*7c478bd9Sstevel@tonic-gate }
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate decml(i, f)
328*7c478bd9Sstevel@tonic-gate register int	i, (*f)();
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate 	register j, k;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	k = 0;
333*7c478bd9Sstevel@tonic-gate 	nform--;
334*7c478bd9Sstevel@tonic-gate 	if ((j = i / 10) || (nform > 0))
335*7c478bd9Sstevel@tonic-gate 		k = decml(j, f);
336*7c478bd9Sstevel@tonic-gate 	return(k + (*f)((i % 10 + '0') | nrbits));
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate roman(i, f)
341*7c478bd9Sstevel@tonic-gate int	i, (*f)();
342*7c478bd9Sstevel@tonic-gate {
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	if (!i)
345*7c478bd9Sstevel@tonic-gate 		return((*f)('0' | nrbits));
346*7c478bd9Sstevel@tonic-gate 	if (nform == 'i')
347*7c478bd9Sstevel@tonic-gate 		return(roman0(i, f, "ixcmz", "vldw"));
348*7c478bd9Sstevel@tonic-gate 	else
349*7c478bd9Sstevel@tonic-gate 		return(roman0(i, f, "IXCMZ", "VLDW"));
350*7c478bd9Sstevel@tonic-gate }
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate roman0(i, f, onesp, fivesp)
354*7c478bd9Sstevel@tonic-gate int	i, (*f)();
355*7c478bd9Sstevel@tonic-gate char	*onesp, *fivesp;
356*7c478bd9Sstevel@tonic-gate {
357*7c478bd9Sstevel@tonic-gate 	register q, rem, k;
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate 	k = 0;
360*7c478bd9Sstevel@tonic-gate 	if (!i)
361*7c478bd9Sstevel@tonic-gate 		return(0);
362*7c478bd9Sstevel@tonic-gate 	k = roman0(i / 10, f, onesp + 1, fivesp + 1);
363*7c478bd9Sstevel@tonic-gate 	q = (i = i % 10) / 5;
364*7c478bd9Sstevel@tonic-gate 	rem = i % 5;
365*7c478bd9Sstevel@tonic-gate 	if (rem == 4) {
366*7c478bd9Sstevel@tonic-gate 		k += (*f)(*onesp | nrbits);
367*7c478bd9Sstevel@tonic-gate 		if (q)
368*7c478bd9Sstevel@tonic-gate 			i = *(onesp + 1);
369*7c478bd9Sstevel@tonic-gate 		else
370*7c478bd9Sstevel@tonic-gate 			i = *fivesp;
371*7c478bd9Sstevel@tonic-gate 		return(k += (*f)(i | nrbits));
372*7c478bd9Sstevel@tonic-gate 	}
373*7c478bd9Sstevel@tonic-gate 	if (q)
374*7c478bd9Sstevel@tonic-gate 		k += (*f)(*fivesp | nrbits);
375*7c478bd9Sstevel@tonic-gate 	while (--rem >= 0)
376*7c478bd9Sstevel@tonic-gate 		k += (*f)(*onesp | nrbits);
377*7c478bd9Sstevel@tonic-gate 	return(k);
378*7c478bd9Sstevel@tonic-gate }
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate abc(i, f)
382*7c478bd9Sstevel@tonic-gate int	i, (*f)();
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	if (!i)
385*7c478bd9Sstevel@tonic-gate 		return((*f)('0' | nrbits));
386*7c478bd9Sstevel@tonic-gate 	else
387*7c478bd9Sstevel@tonic-gate 		return(abc0(i - 1, f));
388*7c478bd9Sstevel@tonic-gate }
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate abc0(i, f)
392*7c478bd9Sstevel@tonic-gate int	i, (*f)();
393*7c478bd9Sstevel@tonic-gate {
394*7c478bd9Sstevel@tonic-gate 	register j, k;
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 	k = 0;
397*7c478bd9Sstevel@tonic-gate 	if (j = i / 26)
398*7c478bd9Sstevel@tonic-gate 		k = abc0(j - 1, f);
399*7c478bd9Sstevel@tonic-gate 	return(k + (*f)((i % 26 + nform) | nrbits));
400*7c478bd9Sstevel@tonic-gate }
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate long	atoi0()
403*7c478bd9Sstevel@tonic-gate {
404*7c478bd9Sstevel@tonic-gate 	register c, k, cnt;
405*7c478bd9Sstevel@tonic-gate 	register tchar ii;
406*7c478bd9Sstevel@tonic-gate 	long	i, acc;
407*7c478bd9Sstevel@tonic-gate 	extern long	ckph();
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate 	i = 0;
410*7c478bd9Sstevel@tonic-gate 	acc = 0;
411*7c478bd9Sstevel@tonic-gate 	nonumb = 0;
412*7c478bd9Sstevel@tonic-gate 	cnt = -1;
413*7c478bd9Sstevel@tonic-gate a0:
414*7c478bd9Sstevel@tonic-gate 	cnt++;
415*7c478bd9Sstevel@tonic-gate 	ii = getch();
416*7c478bd9Sstevel@tonic-gate 	c = cbits(ii);
417*7c478bd9Sstevel@tonic-gate 	switch (c) {
418*7c478bd9Sstevel@tonic-gate 	default:
419*7c478bd9Sstevel@tonic-gate 		ch = ii;
420*7c478bd9Sstevel@tonic-gate 		if (cnt)
421*7c478bd9Sstevel@tonic-gate 			break;
422*7c478bd9Sstevel@tonic-gate 	case '+':
423*7c478bd9Sstevel@tonic-gate 		i = ckph();
424*7c478bd9Sstevel@tonic-gate 		if (nonumb)
425*7c478bd9Sstevel@tonic-gate 			break;
426*7c478bd9Sstevel@tonic-gate 		acc += i;
427*7c478bd9Sstevel@tonic-gate 		goto a0;
428*7c478bd9Sstevel@tonic-gate 	case '-':
429*7c478bd9Sstevel@tonic-gate 		i = ckph();
430*7c478bd9Sstevel@tonic-gate 		if (nonumb)
431*7c478bd9Sstevel@tonic-gate 			break;
432*7c478bd9Sstevel@tonic-gate 		acc -= i;
433*7c478bd9Sstevel@tonic-gate 		goto a0;
434*7c478bd9Sstevel@tonic-gate 	case '*':
435*7c478bd9Sstevel@tonic-gate 		i = ckph();
436*7c478bd9Sstevel@tonic-gate 		if (nonumb)
437*7c478bd9Sstevel@tonic-gate 			break;
438*7c478bd9Sstevel@tonic-gate 		acc *= i;
439*7c478bd9Sstevel@tonic-gate 		goto a0;
440*7c478bd9Sstevel@tonic-gate 	case '/':
441*7c478bd9Sstevel@tonic-gate 		i = ckph();
442*7c478bd9Sstevel@tonic-gate 		if (nonumb)
443*7c478bd9Sstevel@tonic-gate 			break;
444*7c478bd9Sstevel@tonic-gate 		if (i == 0) {
445*7c478bd9Sstevel@tonic-gate 			flusho();
446*7c478bd9Sstevel@tonic-gate 			errprint(gettext("divide by zero."));
447*7c478bd9Sstevel@tonic-gate 			acc = 0;
448*7c478bd9Sstevel@tonic-gate 		} else
449*7c478bd9Sstevel@tonic-gate 			acc /= i;
450*7c478bd9Sstevel@tonic-gate 		goto a0;
451*7c478bd9Sstevel@tonic-gate 	case '%':
452*7c478bd9Sstevel@tonic-gate 		i = ckph();
453*7c478bd9Sstevel@tonic-gate 		if (nonumb)
454*7c478bd9Sstevel@tonic-gate 			break;
455*7c478bd9Sstevel@tonic-gate 		acc %= i;
456*7c478bd9Sstevel@tonic-gate 		goto a0;
457*7c478bd9Sstevel@tonic-gate 	case '&':	/*and*/
458*7c478bd9Sstevel@tonic-gate 		i = ckph();
459*7c478bd9Sstevel@tonic-gate 		if (nonumb)
460*7c478bd9Sstevel@tonic-gate 			break;
461*7c478bd9Sstevel@tonic-gate 		if ((acc > 0) && (i > 0))
462*7c478bd9Sstevel@tonic-gate 			acc = 1;
463*7c478bd9Sstevel@tonic-gate 		else
464*7c478bd9Sstevel@tonic-gate 			acc = 0;
465*7c478bd9Sstevel@tonic-gate 		goto a0;
466*7c478bd9Sstevel@tonic-gate 	case ':':	/*or*/
467*7c478bd9Sstevel@tonic-gate 		i = ckph();
468*7c478bd9Sstevel@tonic-gate 		if (nonumb)
469*7c478bd9Sstevel@tonic-gate 			break;
470*7c478bd9Sstevel@tonic-gate 		if ((acc > 0) || (i > 0))
471*7c478bd9Sstevel@tonic-gate 			acc = 1;
472*7c478bd9Sstevel@tonic-gate 		else
473*7c478bd9Sstevel@tonic-gate 			acc = 0;
474*7c478bd9Sstevel@tonic-gate 		goto a0;
475*7c478bd9Sstevel@tonic-gate 	case '=':
476*7c478bd9Sstevel@tonic-gate 		if (cbits(ii = getch()) != '=')
477*7c478bd9Sstevel@tonic-gate 			ch = ii;
478*7c478bd9Sstevel@tonic-gate 		i = ckph();
479*7c478bd9Sstevel@tonic-gate 		if (nonumb) {
480*7c478bd9Sstevel@tonic-gate 			acc = 0;
481*7c478bd9Sstevel@tonic-gate 			break;
482*7c478bd9Sstevel@tonic-gate 		}
483*7c478bd9Sstevel@tonic-gate 		if (i == acc)
484*7c478bd9Sstevel@tonic-gate 			acc = 1;
485*7c478bd9Sstevel@tonic-gate 		else
486*7c478bd9Sstevel@tonic-gate 			acc = 0;
487*7c478bd9Sstevel@tonic-gate 		goto a0;
488*7c478bd9Sstevel@tonic-gate 	case '>':
489*7c478bd9Sstevel@tonic-gate 		k = 0;
490*7c478bd9Sstevel@tonic-gate 		if (cbits(ii = getch()) == '=')
491*7c478bd9Sstevel@tonic-gate 			k++;
492*7c478bd9Sstevel@tonic-gate 		else
493*7c478bd9Sstevel@tonic-gate 			ch = ii;
494*7c478bd9Sstevel@tonic-gate 		i = ckph();
495*7c478bd9Sstevel@tonic-gate 		if (nonumb) {
496*7c478bd9Sstevel@tonic-gate 			acc = 0;
497*7c478bd9Sstevel@tonic-gate 			break;
498*7c478bd9Sstevel@tonic-gate 		}
499*7c478bd9Sstevel@tonic-gate 		if (acc > (i - k))
500*7c478bd9Sstevel@tonic-gate 			acc = 1;
501*7c478bd9Sstevel@tonic-gate 		else
502*7c478bd9Sstevel@tonic-gate 			acc = 0;
503*7c478bd9Sstevel@tonic-gate 		goto a0;
504*7c478bd9Sstevel@tonic-gate 	case '<':
505*7c478bd9Sstevel@tonic-gate 		k = 0;
506*7c478bd9Sstevel@tonic-gate 		if (cbits(ii = getch()) == '=')
507*7c478bd9Sstevel@tonic-gate 			k++;
508*7c478bd9Sstevel@tonic-gate 		else
509*7c478bd9Sstevel@tonic-gate 			ch = ii;
510*7c478bd9Sstevel@tonic-gate 		i = ckph();
511*7c478bd9Sstevel@tonic-gate 		if (nonumb) {
512*7c478bd9Sstevel@tonic-gate 			acc = 0;
513*7c478bd9Sstevel@tonic-gate 			break;
514*7c478bd9Sstevel@tonic-gate 		}
515*7c478bd9Sstevel@tonic-gate 		if (acc < (i + k))
516*7c478bd9Sstevel@tonic-gate 			acc = 1;
517*7c478bd9Sstevel@tonic-gate 		else
518*7c478bd9Sstevel@tonic-gate 			acc = 0;
519*7c478bd9Sstevel@tonic-gate 		goto a0;
520*7c478bd9Sstevel@tonic-gate 	case ')':
521*7c478bd9Sstevel@tonic-gate 		break;
522*7c478bd9Sstevel@tonic-gate 	case '(':
523*7c478bd9Sstevel@tonic-gate 		acc = atoi0();
524*7c478bd9Sstevel@tonic-gate 		goto a0;
525*7c478bd9Sstevel@tonic-gate 	}
526*7c478bd9Sstevel@tonic-gate 	return(acc);
527*7c478bd9Sstevel@tonic-gate }
528*7c478bd9Sstevel@tonic-gate 
529*7c478bd9Sstevel@tonic-gate 
530*7c478bd9Sstevel@tonic-gate long	ckph()
531*7c478bd9Sstevel@tonic-gate {
532*7c478bd9Sstevel@tonic-gate 	register tchar i;
533*7c478bd9Sstevel@tonic-gate 	register long	j;
534*7c478bd9Sstevel@tonic-gate 	extern long	atoi0();
535*7c478bd9Sstevel@tonic-gate 	extern long	atoi1();
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 	if (cbits(i = getch()) == '(')
538*7c478bd9Sstevel@tonic-gate 		j = atoi0();
539*7c478bd9Sstevel@tonic-gate 	else {
540*7c478bd9Sstevel@tonic-gate 		j = atoi1(i);
541*7c478bd9Sstevel@tonic-gate 	}
542*7c478bd9Sstevel@tonic-gate 	return(j);
543*7c478bd9Sstevel@tonic-gate }
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate long	atoi1(ii)
547*7c478bd9Sstevel@tonic-gate register tchar ii;
548*7c478bd9Sstevel@tonic-gate {
549*7c478bd9Sstevel@tonic-gate 	register i, j, digits;
550*7c478bd9Sstevel@tonic-gate 	register long	acc;
551*7c478bd9Sstevel@tonic-gate 	int	neg, abs, field;
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 	neg = abs = field = digits = 0;
554*7c478bd9Sstevel@tonic-gate 	acc = 0;
555*7c478bd9Sstevel@tonic-gate 	for (;;) {
556*7c478bd9Sstevel@tonic-gate 		i = cbits(ii);
557*7c478bd9Sstevel@tonic-gate 		switch (i) {
558*7c478bd9Sstevel@tonic-gate 		default:
559*7c478bd9Sstevel@tonic-gate 			break;
560*7c478bd9Sstevel@tonic-gate 		case '+':
561*7c478bd9Sstevel@tonic-gate 			ii = getch();
562*7c478bd9Sstevel@tonic-gate 			continue;
563*7c478bd9Sstevel@tonic-gate 		case '-':
564*7c478bd9Sstevel@tonic-gate 			neg = 1;
565*7c478bd9Sstevel@tonic-gate 			ii = getch();
566*7c478bd9Sstevel@tonic-gate 			continue;
567*7c478bd9Sstevel@tonic-gate 		case '|':
568*7c478bd9Sstevel@tonic-gate 			abs = 1 + neg;
569*7c478bd9Sstevel@tonic-gate 			neg = 0;
570*7c478bd9Sstevel@tonic-gate 			ii = getch();
571*7c478bd9Sstevel@tonic-gate 			continue;
572*7c478bd9Sstevel@tonic-gate 		}
573*7c478bd9Sstevel@tonic-gate 		break;
574*7c478bd9Sstevel@tonic-gate 	}
575*7c478bd9Sstevel@tonic-gate a1:
576*7c478bd9Sstevel@tonic-gate 	while (i >= '0' && i <= '9') {
577*7c478bd9Sstevel@tonic-gate 		field++;
578*7c478bd9Sstevel@tonic-gate 		digits++;
579*7c478bd9Sstevel@tonic-gate 		acc = 10 * acc + i - '0';
580*7c478bd9Sstevel@tonic-gate 		ii = getch();
581*7c478bd9Sstevel@tonic-gate 		i = cbits(ii);
582*7c478bd9Sstevel@tonic-gate 	}
583*7c478bd9Sstevel@tonic-gate 	if (i == '.') {
584*7c478bd9Sstevel@tonic-gate 		field++;
585*7c478bd9Sstevel@tonic-gate 		digits = 0;
586*7c478bd9Sstevel@tonic-gate 		ii = getch();
587*7c478bd9Sstevel@tonic-gate 		i = cbits(ii);
588*7c478bd9Sstevel@tonic-gate 		goto a1;
589*7c478bd9Sstevel@tonic-gate 	}
590*7c478bd9Sstevel@tonic-gate 	if (!field) {
591*7c478bd9Sstevel@tonic-gate 		ch = ii;
592*7c478bd9Sstevel@tonic-gate 		goto a2;
593*7c478bd9Sstevel@tonic-gate 	}
594*7c478bd9Sstevel@tonic-gate 	switch (i) {
595*7c478bd9Sstevel@tonic-gate 	case 'u':
596*7c478bd9Sstevel@tonic-gate 		i = j = 1;	/* should this be related to HOR?? */
597*7c478bd9Sstevel@tonic-gate 		break;
598*7c478bd9Sstevel@tonic-gate 	case 'v':	/*VSs - vert spacing*/
599*7c478bd9Sstevel@tonic-gate 		j = lss;
600*7c478bd9Sstevel@tonic-gate 		i = 1;
601*7c478bd9Sstevel@tonic-gate 		break;
602*7c478bd9Sstevel@tonic-gate 	case 'm':	/*Ems*/
603*7c478bd9Sstevel@tonic-gate 		j = EM;
604*7c478bd9Sstevel@tonic-gate 		i = 1;
605*7c478bd9Sstevel@tonic-gate 		break;
606*7c478bd9Sstevel@tonic-gate 	case 'n':	/*Ens*/
607*7c478bd9Sstevel@tonic-gate 		j = EM;
608*7c478bd9Sstevel@tonic-gate #ifndef NROFF
609*7c478bd9Sstevel@tonic-gate 		i = 2;
610*7c478bd9Sstevel@tonic-gate #endif
611*7c478bd9Sstevel@tonic-gate #ifdef NROFF
612*7c478bd9Sstevel@tonic-gate 		i = 1;	/*Same as Ems in NROFF*/
613*7c478bd9Sstevel@tonic-gate #endif
614*7c478bd9Sstevel@tonic-gate 		break;
615*7c478bd9Sstevel@tonic-gate 	case 'p':	/*Points*/
616*7c478bd9Sstevel@tonic-gate 		j = INCH;
617*7c478bd9Sstevel@tonic-gate 		i = 72;
618*7c478bd9Sstevel@tonic-gate 		break;
619*7c478bd9Sstevel@tonic-gate 	case 'i':	/*Inches*/
620*7c478bd9Sstevel@tonic-gate 		j = INCH;
621*7c478bd9Sstevel@tonic-gate 		i = 1;
622*7c478bd9Sstevel@tonic-gate 		break;
623*7c478bd9Sstevel@tonic-gate 	case 'c':	/*Centimeters*/
624*7c478bd9Sstevel@tonic-gate 		/* if INCH is too big, this will overflow */
625*7c478bd9Sstevel@tonic-gate 		j = INCH * 50;
626*7c478bd9Sstevel@tonic-gate 		i = 127;
627*7c478bd9Sstevel@tonic-gate 		break;
628*7c478bd9Sstevel@tonic-gate 	case 'P':	/*Picas*/
629*7c478bd9Sstevel@tonic-gate 		j = INCH;
630*7c478bd9Sstevel@tonic-gate 		i = 6;
631*7c478bd9Sstevel@tonic-gate 		break;
632*7c478bd9Sstevel@tonic-gate 	default:
633*7c478bd9Sstevel@tonic-gate 		j = dfact;
634*7c478bd9Sstevel@tonic-gate 		ch = ii;
635*7c478bd9Sstevel@tonic-gate 		i = dfactd;
636*7c478bd9Sstevel@tonic-gate 	}
637*7c478bd9Sstevel@tonic-gate 	if (neg)
638*7c478bd9Sstevel@tonic-gate 		acc = -acc;
639*7c478bd9Sstevel@tonic-gate 	if (!noscale) {
640*7c478bd9Sstevel@tonic-gate 		acc = (acc * j) / i;
641*7c478bd9Sstevel@tonic-gate 	}
642*7c478bd9Sstevel@tonic-gate 	if ((field != digits) && (digits > 0))
643*7c478bd9Sstevel@tonic-gate 		while (digits--)
644*7c478bd9Sstevel@tonic-gate 			acc /= 10;
645*7c478bd9Sstevel@tonic-gate 	if (abs) {
646*7c478bd9Sstevel@tonic-gate 		if (dip != d)
647*7c478bd9Sstevel@tonic-gate 			j = dip->dnl;
648*7c478bd9Sstevel@tonic-gate 		else
649*7c478bd9Sstevel@tonic-gate 			j = numtab[NL].val;
650*7c478bd9Sstevel@tonic-gate 		if (!vflag) {
651*7c478bd9Sstevel@tonic-gate 			j = numtab[HP].val;
652*7c478bd9Sstevel@tonic-gate 		}
653*7c478bd9Sstevel@tonic-gate 		if (abs == 2)
654*7c478bd9Sstevel@tonic-gate 			j = -j;
655*7c478bd9Sstevel@tonic-gate 		acc -= j;
656*7c478bd9Sstevel@tonic-gate 	}
657*7c478bd9Sstevel@tonic-gate a2:
658*7c478bd9Sstevel@tonic-gate 	nonumb = !field;
659*7c478bd9Sstevel@tonic-gate 	return(acc);
660*7c478bd9Sstevel@tonic-gate }
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate caserr()
664*7c478bd9Sstevel@tonic-gate {
665*7c478bd9Sstevel@tonic-gate 	register i, j;
666*7c478bd9Sstevel@tonic-gate 	register struct numtab *p;
667*7c478bd9Sstevel@tonic-gate 
668*7c478bd9Sstevel@tonic-gate 	lgf++;
669*7c478bd9Sstevel@tonic-gate 	while (!skip() && (i = getrq()) ) {
670*7c478bd9Sstevel@tonic-gate 		j = usedr(i);
671*7c478bd9Sstevel@tonic-gate 		if (j < 0)
672*7c478bd9Sstevel@tonic-gate 			continue;
673*7c478bd9Sstevel@tonic-gate 		p = &numtab[j];
674*7c478bd9Sstevel@tonic-gate 		nunhash(p);
675*7c478bd9Sstevel@tonic-gate 		p->r = p->val = p->inc = p->fmt = 0;
676*7c478bd9Sstevel@tonic-gate 		regcnt--;
677*7c478bd9Sstevel@tonic-gate 	}
678*7c478bd9Sstevel@tonic-gate }
679*7c478bd9Sstevel@tonic-gate 
680*7c478bd9Sstevel@tonic-gate 
681*7c478bd9Sstevel@tonic-gate casenr()
682*7c478bd9Sstevel@tonic-gate {
683*7c478bd9Sstevel@tonic-gate 	register i, j;
684*7c478bd9Sstevel@tonic-gate 
685*7c478bd9Sstevel@tonic-gate 	lgf++;
686*7c478bd9Sstevel@tonic-gate 	skip();
687*7c478bd9Sstevel@tonic-gate 	if ((i = findr(getrq())) == -1)
688*7c478bd9Sstevel@tonic-gate 		goto rtn;
689*7c478bd9Sstevel@tonic-gate 	skip();
690*7c478bd9Sstevel@tonic-gate 	j = inumb(&numtab[i].val);
691*7c478bd9Sstevel@tonic-gate 	if (nonumb)
692*7c478bd9Sstevel@tonic-gate 		goto rtn;
693*7c478bd9Sstevel@tonic-gate 	numtab[i].val = j;
694*7c478bd9Sstevel@tonic-gate 	skip();
695*7c478bd9Sstevel@tonic-gate 	j = atoi();
696*7c478bd9Sstevel@tonic-gate 	if (nonumb)
697*7c478bd9Sstevel@tonic-gate 		goto rtn;
698*7c478bd9Sstevel@tonic-gate 	numtab[i].inc = j;
699*7c478bd9Sstevel@tonic-gate rtn:
700*7c478bd9Sstevel@tonic-gate 	return;
701*7c478bd9Sstevel@tonic-gate }
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate caseaf()
705*7c478bd9Sstevel@tonic-gate {
706*7c478bd9Sstevel@tonic-gate 	register i, k;
707*7c478bd9Sstevel@tonic-gate 	register tchar j, jj;
708*7c478bd9Sstevel@tonic-gate 
709*7c478bd9Sstevel@tonic-gate 	lgf++;
710*7c478bd9Sstevel@tonic-gate 	if (skip() || !(i = getrq()) || skip())
711*7c478bd9Sstevel@tonic-gate 		return;
712*7c478bd9Sstevel@tonic-gate 	k = 0;
713*7c478bd9Sstevel@tonic-gate 	j = getch();
714*7c478bd9Sstevel@tonic-gate 	if (!ischar(jj = cbits(j)) || !isalpha(jj)) {
715*7c478bd9Sstevel@tonic-gate 		ch = j;
716*7c478bd9Sstevel@tonic-gate 		while ((j = cbits(getch())) >= '0' &&  j <= '9')
717*7c478bd9Sstevel@tonic-gate 			k++;
718*7c478bd9Sstevel@tonic-gate 	}
719*7c478bd9Sstevel@tonic-gate 	if (!k)
720*7c478bd9Sstevel@tonic-gate 		k = j;
721*7c478bd9Sstevel@tonic-gate 	numtab[findr(i)].fmt = k & BYTEMASK;
722*7c478bd9Sstevel@tonic-gate }
723*7c478bd9Sstevel@tonic-gate 
724*7c478bd9Sstevel@tonic-gate setaf()	/* return format of number register */
725*7c478bd9Sstevel@tonic-gate {
726*7c478bd9Sstevel@tonic-gate 	register int i, j;
727*7c478bd9Sstevel@tonic-gate 
728*7c478bd9Sstevel@tonic-gate 	i = usedr(getsn());
729*7c478bd9Sstevel@tonic-gate 	if (i == -1)
730*7c478bd9Sstevel@tonic-gate 		return;
731*7c478bd9Sstevel@tonic-gate 	if (numtab[i].fmt > 20)	/* it was probably a, A, i or I */
732*7c478bd9Sstevel@tonic-gate 		*pbp++ = numtab[i].fmt;
733*7c478bd9Sstevel@tonic-gate 	else
734*7c478bd9Sstevel@tonic-gate 		for (j = (numtab[i].fmt ? numtab[i].fmt : 1); j; j--)
735*7c478bd9Sstevel@tonic-gate 			*pbp++ = '0';
736*7c478bd9Sstevel@tonic-gate }
737*7c478bd9Sstevel@tonic-gate 
738*7c478bd9Sstevel@tonic-gate 
739*7c478bd9Sstevel@tonic-gate vnumb(i)
740*7c478bd9Sstevel@tonic-gate int	*i;
741*7c478bd9Sstevel@tonic-gate {
742*7c478bd9Sstevel@tonic-gate 	vflag++;
743*7c478bd9Sstevel@tonic-gate 	dfact = lss;
744*7c478bd9Sstevel@tonic-gate 	res = VERT;
745*7c478bd9Sstevel@tonic-gate 	return(inumb(i));
746*7c478bd9Sstevel@tonic-gate }
747*7c478bd9Sstevel@tonic-gate 
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate hnumb(i)
750*7c478bd9Sstevel@tonic-gate int	*i;
751*7c478bd9Sstevel@tonic-gate {
752*7c478bd9Sstevel@tonic-gate 	dfact = EM;
753*7c478bd9Sstevel@tonic-gate 	res = HOR;
754*7c478bd9Sstevel@tonic-gate 	return(inumb(i));
755*7c478bd9Sstevel@tonic-gate }
756*7c478bd9Sstevel@tonic-gate 
757*7c478bd9Sstevel@tonic-gate 
758*7c478bd9Sstevel@tonic-gate inumb(n)
759*7c478bd9Sstevel@tonic-gate int	*n;
760*7c478bd9Sstevel@tonic-gate {
761*7c478bd9Sstevel@tonic-gate 	register i, j, f;
762*7c478bd9Sstevel@tonic-gate 	register tchar ii;
763*7c478bd9Sstevel@tonic-gate 
764*7c478bd9Sstevel@tonic-gate 	f = 0;
765*7c478bd9Sstevel@tonic-gate 	if (n) {
766*7c478bd9Sstevel@tonic-gate 		if ((j = cbits(ii = getch())) == '+')
767*7c478bd9Sstevel@tonic-gate 			f = 1;
768*7c478bd9Sstevel@tonic-gate 		else if (j == '-')
769*7c478bd9Sstevel@tonic-gate 			f = -1;
770*7c478bd9Sstevel@tonic-gate 		else
771*7c478bd9Sstevel@tonic-gate 			ch = ii;
772*7c478bd9Sstevel@tonic-gate 	}
773*7c478bd9Sstevel@tonic-gate 	i = atoi();
774*7c478bd9Sstevel@tonic-gate 	if (n && f)
775*7c478bd9Sstevel@tonic-gate 		i = *n + f * i;
776*7c478bd9Sstevel@tonic-gate 	i = quant(i, res);
777*7c478bd9Sstevel@tonic-gate 	vflag = 0;
778*7c478bd9Sstevel@tonic-gate 	res = dfactd = dfact = 1;
779*7c478bd9Sstevel@tonic-gate 	if (nonumb)
780*7c478bd9Sstevel@tonic-gate 		i = 0;
781*7c478bd9Sstevel@tonic-gate 	return(i);
782*7c478bd9Sstevel@tonic-gate }
783*7c478bd9Sstevel@tonic-gate 
784*7c478bd9Sstevel@tonic-gate 
785*7c478bd9Sstevel@tonic-gate quant(n, m)
786*7c478bd9Sstevel@tonic-gate int	n, m;
787*7c478bd9Sstevel@tonic-gate {
788*7c478bd9Sstevel@tonic-gate 	register i, neg;
789*7c478bd9Sstevel@tonic-gate 
790*7c478bd9Sstevel@tonic-gate 	neg = 0;
791*7c478bd9Sstevel@tonic-gate 	if (n < 0) {
792*7c478bd9Sstevel@tonic-gate 		neg++;
793*7c478bd9Sstevel@tonic-gate 		n = -n;
794*7c478bd9Sstevel@tonic-gate 	}
795*7c478bd9Sstevel@tonic-gate 	/* better as i = ((n + (m/2))/m)*m */
796*7c478bd9Sstevel@tonic-gate 	i = n / m;
797*7c478bd9Sstevel@tonic-gate 	if ((n - m * i) > (m / 2))
798*7c478bd9Sstevel@tonic-gate 		i += 1;
799*7c478bd9Sstevel@tonic-gate 	i *= m;
800*7c478bd9Sstevel@tonic-gate 	if (neg)
801*7c478bd9Sstevel@tonic-gate 		i = -i;
802*7c478bd9Sstevel@tonic-gate 	return(i);
803*7c478bd9Sstevel@tonic-gate }
804*7c478bd9Sstevel@tonic-gate 
805*7c478bd9Sstevel@tonic-gate 
806