17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
40*e5190c10Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*e5190c10Smuffin
427c478bd9Sstevel@tonic-gate #include <ctype.h>
437c478bd9Sstevel@tonic-gate #include "tdef.h"
447c478bd9Sstevel@tonic-gate #ifdef NROFF
457c478bd9Sstevel@tonic-gate #include "tw.h"
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate #include "ext.h"
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate * troff4.c
507c478bd9Sstevel@tonic-gate *
517c478bd9Sstevel@tonic-gate * number registers, conversion, arithmetic
527c478bd9Sstevel@tonic-gate */
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate int regcnt = NNAMES;
567c478bd9Sstevel@tonic-gate int falsef = 0; /* on if inside false branch of if */
577c478bd9Sstevel@tonic-gate #define NHASH(i) ((i>>6)^i)&0177
587c478bd9Sstevel@tonic-gate struct numtab *nhash[128]; /* 128 == the 0177 on line above */
597c478bd9Sstevel@tonic-gate
60*e5190c10Smuffin int
setn()617c478bd9Sstevel@tonic-gate setn()
627c478bd9Sstevel@tonic-gate {
63*e5190c10Smuffin int i, j;
64*e5190c10Smuffin tchar ii;
657c478bd9Sstevel@tonic-gate int f;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate f = nform = 0;
687c478bd9Sstevel@tonic-gate if ((i = cbits(ii = getach())) == '+')
697c478bd9Sstevel@tonic-gate f = 1;
707c478bd9Sstevel@tonic-gate else if (i == '-')
717c478bd9Sstevel@tonic-gate f = -1;
727c478bd9Sstevel@tonic-gate else
737c478bd9Sstevel@tonic-gate ch = ii;
747c478bd9Sstevel@tonic-gate if (falsef)
757c478bd9Sstevel@tonic-gate f = 0;
767c478bd9Sstevel@tonic-gate if ((i = getsn()) == 0)
77*e5190c10Smuffin return (0);
787c478bd9Sstevel@tonic-gate if ((i & 0177) == '.')
797c478bd9Sstevel@tonic-gate switch (i >> BYTE) {
807c478bd9Sstevel@tonic-gate case 's':
817c478bd9Sstevel@tonic-gate i = pts;
827c478bd9Sstevel@tonic-gate break;
837c478bd9Sstevel@tonic-gate case 'v':
847c478bd9Sstevel@tonic-gate i = lss;
857c478bd9Sstevel@tonic-gate break;
867c478bd9Sstevel@tonic-gate case 'f':
877c478bd9Sstevel@tonic-gate i = font;
887c478bd9Sstevel@tonic-gate break;
897c478bd9Sstevel@tonic-gate case 'p':
907c478bd9Sstevel@tonic-gate i = pl;
917c478bd9Sstevel@tonic-gate break;
927c478bd9Sstevel@tonic-gate case 't':
937c478bd9Sstevel@tonic-gate i = findt1();
947c478bd9Sstevel@tonic-gate break;
957c478bd9Sstevel@tonic-gate case 'o':
967c478bd9Sstevel@tonic-gate i = po;
977c478bd9Sstevel@tonic-gate break;
987c478bd9Sstevel@tonic-gate case 'l':
997c478bd9Sstevel@tonic-gate i = ll;
1007c478bd9Sstevel@tonic-gate break;
1017c478bd9Sstevel@tonic-gate case 'i':
1027c478bd9Sstevel@tonic-gate i = in;
1037c478bd9Sstevel@tonic-gate break;
1047c478bd9Sstevel@tonic-gate case '$':
1057c478bd9Sstevel@tonic-gate i = frame->nargs;
1067c478bd9Sstevel@tonic-gate break;
1077c478bd9Sstevel@tonic-gate case 'A':
1087c478bd9Sstevel@tonic-gate i = ascii;
1097c478bd9Sstevel@tonic-gate break;
1107c478bd9Sstevel@tonic-gate case 'c':
1117c478bd9Sstevel@tonic-gate i = numtab[CD].val;
1127c478bd9Sstevel@tonic-gate break;
1137c478bd9Sstevel@tonic-gate case 'n':
1147c478bd9Sstevel@tonic-gate i = lastl;
1157c478bd9Sstevel@tonic-gate break;
1167c478bd9Sstevel@tonic-gate case 'a':
1177c478bd9Sstevel@tonic-gate i = ralss;
1187c478bd9Sstevel@tonic-gate break;
1197c478bd9Sstevel@tonic-gate case 'h':
1207c478bd9Sstevel@tonic-gate i = dip->hnl;
1217c478bd9Sstevel@tonic-gate break;
1227c478bd9Sstevel@tonic-gate case 'd':
1237c478bd9Sstevel@tonic-gate if (dip != d)
1247c478bd9Sstevel@tonic-gate i = dip->dnl;
1257c478bd9Sstevel@tonic-gate else
1267c478bd9Sstevel@tonic-gate i = numtab[NL].val;
1277c478bd9Sstevel@tonic-gate break;
1287c478bd9Sstevel@tonic-gate case 'u':
1297c478bd9Sstevel@tonic-gate i = fi;
1307c478bd9Sstevel@tonic-gate break;
1317c478bd9Sstevel@tonic-gate case 'j':
1327c478bd9Sstevel@tonic-gate i = ad + 2 * admod;
1337c478bd9Sstevel@tonic-gate break;
1347c478bd9Sstevel@tonic-gate case 'w':
1357c478bd9Sstevel@tonic-gate i = widthp;
1367c478bd9Sstevel@tonic-gate break;
1377c478bd9Sstevel@tonic-gate case 'x':
1387c478bd9Sstevel@tonic-gate i = nel;
1397c478bd9Sstevel@tonic-gate break;
1407c478bd9Sstevel@tonic-gate case 'y':
1417c478bd9Sstevel@tonic-gate i = un;
1427c478bd9Sstevel@tonic-gate break;
1437c478bd9Sstevel@tonic-gate case 'T':
1447c478bd9Sstevel@tonic-gate i = dotT;
1457c478bd9Sstevel@tonic-gate break; /*-Tterm used in nroff*/
1467c478bd9Sstevel@tonic-gate case 'V':
1477c478bd9Sstevel@tonic-gate i = VERT;
1487c478bd9Sstevel@tonic-gate break;
1497c478bd9Sstevel@tonic-gate case 'H':
1507c478bd9Sstevel@tonic-gate i = HOR;
1517c478bd9Sstevel@tonic-gate break;
1527c478bd9Sstevel@tonic-gate case 'k':
1537c478bd9Sstevel@tonic-gate i = ne;
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate case 'P':
1567c478bd9Sstevel@tonic-gate i = print;
1577c478bd9Sstevel@tonic-gate break;
1587c478bd9Sstevel@tonic-gate case 'L':
1597c478bd9Sstevel@tonic-gate i = ls;
1607c478bd9Sstevel@tonic-gate break;
1617c478bd9Sstevel@tonic-gate case 'R':
1627c478bd9Sstevel@tonic-gate i = NN - regcnt;
1637c478bd9Sstevel@tonic-gate break;
1647c478bd9Sstevel@tonic-gate case 'z':
1657c478bd9Sstevel@tonic-gate i = dip->curd;
1667c478bd9Sstevel@tonic-gate *pbp++ = (i >> BYTE) & BYTEMASK;
1677c478bd9Sstevel@tonic-gate *pbp++ = i & BYTEMASK;
168*e5190c10Smuffin return (0);
1697c478bd9Sstevel@tonic-gate case 'b':
1707c478bd9Sstevel@tonic-gate i = bdtab[font];
1717c478bd9Sstevel@tonic-gate break;
1727c478bd9Sstevel@tonic-gate case 'F':
1737c478bd9Sstevel@tonic-gate cpushback(cfname[ifi]);
174*e5190c10Smuffin return (0);
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate default:
1777c478bd9Sstevel@tonic-gate goto s0;
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate else {
1807c478bd9Sstevel@tonic-gate s0:
1817c478bd9Sstevel@tonic-gate if ((j = findr(i)) == -1)
1827c478bd9Sstevel@tonic-gate i = 0;
1837c478bd9Sstevel@tonic-gate else {
1847c478bd9Sstevel@tonic-gate i = numtab[j].val = (numtab[j].val+numtab[j].inc*f);
1857c478bd9Sstevel@tonic-gate nform = numtab[j].fmt;
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate setn1(i, nform, (tchar) 0);
189*e5190c10Smuffin
190*e5190c10Smuffin return (0);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate tchar numbuf[17];
1947c478bd9Sstevel@tonic-gate tchar *numbufp;
1957c478bd9Sstevel@tonic-gate
196*e5190c10Smuffin int
wrc(i)1977c478bd9Sstevel@tonic-gate wrc(i)
1987c478bd9Sstevel@tonic-gate tchar i;
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate if (numbufp >= &numbuf[16])
2017c478bd9Sstevel@tonic-gate return(0);
2027c478bd9Sstevel@tonic-gate *numbufp++ = i;
2037c478bd9Sstevel@tonic-gate return(1);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate /* insert into input number i, in format form, with size-font bits bits */
209*e5190c10Smuffin int
setn1(i,form,bits)2107c478bd9Sstevel@tonic-gate setn1(i, form, bits)
2117c478bd9Sstevel@tonic-gate int i;
2127c478bd9Sstevel@tonic-gate tchar bits;
2137c478bd9Sstevel@tonic-gate {
2147c478bd9Sstevel@tonic-gate extern int wrc();
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate numbufp = numbuf;
2177c478bd9Sstevel@tonic-gate nrbits = bits;
2187c478bd9Sstevel@tonic-gate nform = form;
2197c478bd9Sstevel@tonic-gate fnumb(i, wrc);
2207c478bd9Sstevel@tonic-gate *numbufp = 0;
2217c478bd9Sstevel@tonic-gate pushback(numbuf);
222*e5190c10Smuffin
223*e5190c10Smuffin return (0);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate
227*e5190c10Smuffin int
nrehash()2287c478bd9Sstevel@tonic-gate nrehash()
2297c478bd9Sstevel@tonic-gate {
230*e5190c10Smuffin struct numtab *p;
231*e5190c10Smuffin int i;
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate for (i=0; i<128; i++)
2347c478bd9Sstevel@tonic-gate nhash[i] = 0;
2357c478bd9Sstevel@tonic-gate for (p=numtab; p < &numtab[NN]; p++)
2367c478bd9Sstevel@tonic-gate p->link = 0;
2377c478bd9Sstevel@tonic-gate for (p=numtab; p < &numtab[NN]; p++) {
2387c478bd9Sstevel@tonic-gate if (p->r == 0)
2397c478bd9Sstevel@tonic-gate continue;
2407c478bd9Sstevel@tonic-gate i = NHASH(p->r);
2417c478bd9Sstevel@tonic-gate p->link = nhash[i];
2427c478bd9Sstevel@tonic-gate nhash[i] = p;
2437c478bd9Sstevel@tonic-gate }
244*e5190c10Smuffin
245*e5190c10Smuffin return (0);
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate
248*e5190c10Smuffin int
nunhash(rp)2497c478bd9Sstevel@tonic-gate nunhash(rp)
250*e5190c10Smuffin struct numtab *rp;
2517c478bd9Sstevel@tonic-gate {
252*e5190c10Smuffin struct numtab *p;
253*e5190c10Smuffin struct numtab **lp;
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate if (rp->r == 0)
256*e5190c10Smuffin return (0);
2577c478bd9Sstevel@tonic-gate lp = &nhash[NHASH(rp->r)];
2587c478bd9Sstevel@tonic-gate p = *lp;
2597c478bd9Sstevel@tonic-gate while (p) {
2607c478bd9Sstevel@tonic-gate if (p == rp) {
2617c478bd9Sstevel@tonic-gate *lp = p->link;
2627c478bd9Sstevel@tonic-gate p->link = 0;
263*e5190c10Smuffin return (0);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate lp = &p->link;
2667c478bd9Sstevel@tonic-gate p = p->link;
2677c478bd9Sstevel@tonic-gate }
268*e5190c10Smuffin return (0);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
271*e5190c10Smuffin int
findr(i)2727c478bd9Sstevel@tonic-gate findr(i)
273*e5190c10Smuffin int i;
2747c478bd9Sstevel@tonic-gate {
275*e5190c10Smuffin struct numtab *p;
276*e5190c10Smuffin int h = NHASH(i);
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if (i == 0)
2797c478bd9Sstevel@tonic-gate return(-1);
2807c478bd9Sstevel@tonic-gate for (p = nhash[h]; p; p = p->link)
2817c478bd9Sstevel@tonic-gate if (i == p->r)
2827c478bd9Sstevel@tonic-gate return(p - numtab);
2837c478bd9Sstevel@tonic-gate for (p = numtab; p < &numtab[NN]; p++) {
2847c478bd9Sstevel@tonic-gate if (p->r == 0) {
2857c478bd9Sstevel@tonic-gate p->r = i;
2867c478bd9Sstevel@tonic-gate p->link = nhash[h];
2877c478bd9Sstevel@tonic-gate nhash[h] = p;
2887c478bd9Sstevel@tonic-gate regcnt++;
2897c478bd9Sstevel@tonic-gate return(p - numtab);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate errprint(gettext("too many number registers (%d)."), NN);
2937c478bd9Sstevel@tonic-gate done2(04);
2947c478bd9Sstevel@tonic-gate /* NOTREACHED */
295*e5190c10Smuffin
296*e5190c10Smuffin return (0);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate
299*e5190c10Smuffin int
usedr(i)3007c478bd9Sstevel@tonic-gate usedr(i) /* returns -1 if nr i has never been used */
301*e5190c10Smuffin int i;
3027c478bd9Sstevel@tonic-gate {
303*e5190c10Smuffin struct numtab *p;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate if (i == 0)
3067c478bd9Sstevel@tonic-gate return(-1);
3077c478bd9Sstevel@tonic-gate for (p = nhash[NHASH(i)]; p; p = p->link)
3087c478bd9Sstevel@tonic-gate if (i == p->r)
3097c478bd9Sstevel@tonic-gate return(p - numtab);
3107c478bd9Sstevel@tonic-gate return -1;
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate
314*e5190c10Smuffin int
3157c478bd9Sstevel@tonic-gate fnumb(i, f)
316*e5190c10Smuffin int i, (*f)();
3177c478bd9Sstevel@tonic-gate {
318*e5190c10Smuffin int j;
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate j = 0;
3217c478bd9Sstevel@tonic-gate if (i < 0) {
3227c478bd9Sstevel@tonic-gate j = (*f)('-' | nrbits);
3237c478bd9Sstevel@tonic-gate i = -i;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate switch (nform) {
3267c478bd9Sstevel@tonic-gate default:
3277c478bd9Sstevel@tonic-gate case '1':
3287c478bd9Sstevel@tonic-gate case 0:
3297c478bd9Sstevel@tonic-gate return decml(i, f) + j;
3307c478bd9Sstevel@tonic-gate break;
3317c478bd9Sstevel@tonic-gate case 'i':
3327c478bd9Sstevel@tonic-gate case 'I':
3337c478bd9Sstevel@tonic-gate return roman(i, f) + j;
3347c478bd9Sstevel@tonic-gate break;
3357c478bd9Sstevel@tonic-gate case 'a':
3367c478bd9Sstevel@tonic-gate case 'A':
3377c478bd9Sstevel@tonic-gate return abc(i, f) + j;
3387c478bd9Sstevel@tonic-gate break;
3397c478bd9Sstevel@tonic-gate }
340*e5190c10Smuffin
341*e5190c10Smuffin return (0);
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate
345*e5190c10Smuffin int
3467c478bd9Sstevel@tonic-gate decml(i, f)
347*e5190c10Smuffin int i, (*f)();
3487c478bd9Sstevel@tonic-gate {
349*e5190c10Smuffin int j, k;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate k = 0;
3527c478bd9Sstevel@tonic-gate nform--;
3537c478bd9Sstevel@tonic-gate if ((j = i / 10) || (nform > 0))
3547c478bd9Sstevel@tonic-gate k = decml(j, f);
3557c478bd9Sstevel@tonic-gate return(k + (*f)((i % 10 + '0') | nrbits));
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate
359*e5190c10Smuffin int
3607c478bd9Sstevel@tonic-gate roman(i, f)
3617c478bd9Sstevel@tonic-gate int i, (*f)();
3627c478bd9Sstevel@tonic-gate {
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate if (!i)
3657c478bd9Sstevel@tonic-gate return((*f)('0' | nrbits));
3667c478bd9Sstevel@tonic-gate if (nform == 'i')
3677c478bd9Sstevel@tonic-gate return(roman0(i, f, "ixcmz", "vldw"));
3687c478bd9Sstevel@tonic-gate else
3697c478bd9Sstevel@tonic-gate return(roman0(i, f, "IXCMZ", "VLDW"));
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate
373*e5190c10Smuffin int
3747c478bd9Sstevel@tonic-gate roman0(i, f, onesp, fivesp)
3757c478bd9Sstevel@tonic-gate int i, (*f)();
3767c478bd9Sstevel@tonic-gate char *onesp, *fivesp;
3777c478bd9Sstevel@tonic-gate {
378*e5190c10Smuffin int q, rem, k;
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate k = 0;
3817c478bd9Sstevel@tonic-gate if (!i)
3827c478bd9Sstevel@tonic-gate return(0);
3837c478bd9Sstevel@tonic-gate k = roman0(i / 10, f, onesp + 1, fivesp + 1);
3847c478bd9Sstevel@tonic-gate q = (i = i % 10) / 5;
3857c478bd9Sstevel@tonic-gate rem = i % 5;
3867c478bd9Sstevel@tonic-gate if (rem == 4) {
3877c478bd9Sstevel@tonic-gate k += (*f)(*onesp | nrbits);
3887c478bd9Sstevel@tonic-gate if (q)
3897c478bd9Sstevel@tonic-gate i = *(onesp + 1);
3907c478bd9Sstevel@tonic-gate else
3917c478bd9Sstevel@tonic-gate i = *fivesp;
3927c478bd9Sstevel@tonic-gate return(k += (*f)(i | nrbits));
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate if (q)
3957c478bd9Sstevel@tonic-gate k += (*f)(*fivesp | nrbits);
3967c478bd9Sstevel@tonic-gate while (--rem >= 0)
3977c478bd9Sstevel@tonic-gate k += (*f)(*onesp | nrbits);
3987c478bd9Sstevel@tonic-gate return(k);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate
402*e5190c10Smuffin int
4037c478bd9Sstevel@tonic-gate abc(i, f)
4047c478bd9Sstevel@tonic-gate int i, (*f)();
4057c478bd9Sstevel@tonic-gate {
4067c478bd9Sstevel@tonic-gate if (!i)
4077c478bd9Sstevel@tonic-gate return((*f)('0' | nrbits));
4087c478bd9Sstevel@tonic-gate else
4097c478bd9Sstevel@tonic-gate return(abc0(i - 1, f));
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate
413*e5190c10Smuffin int
4147c478bd9Sstevel@tonic-gate abc0(i, f)
4157c478bd9Sstevel@tonic-gate int i, (*f)();
4167c478bd9Sstevel@tonic-gate {
417*e5190c10Smuffin int j, k;
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate k = 0;
4207c478bd9Sstevel@tonic-gate if (j = i / 26)
4217c478bd9Sstevel@tonic-gate k = abc0(j - 1, f);
4227c478bd9Sstevel@tonic-gate return(k + (*f)((i % 26 + nform) | nrbits));
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
atoi0()4257c478bd9Sstevel@tonic-gate long atoi0()
4267c478bd9Sstevel@tonic-gate {
427*e5190c10Smuffin int c, k, cnt;
428*e5190c10Smuffin tchar ii;
4297c478bd9Sstevel@tonic-gate long i, acc;
4307c478bd9Sstevel@tonic-gate extern long ckph();
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate i = 0;
4337c478bd9Sstevel@tonic-gate acc = 0;
4347c478bd9Sstevel@tonic-gate nonumb = 0;
4357c478bd9Sstevel@tonic-gate cnt = -1;
4367c478bd9Sstevel@tonic-gate a0:
4377c478bd9Sstevel@tonic-gate cnt++;
4387c478bd9Sstevel@tonic-gate ii = getch();
4397c478bd9Sstevel@tonic-gate c = cbits(ii);
4407c478bd9Sstevel@tonic-gate switch (c) {
4417c478bd9Sstevel@tonic-gate default:
4427c478bd9Sstevel@tonic-gate ch = ii;
4437c478bd9Sstevel@tonic-gate if (cnt)
4447c478bd9Sstevel@tonic-gate break;
4457c478bd9Sstevel@tonic-gate case '+':
4467c478bd9Sstevel@tonic-gate i = ckph();
4477c478bd9Sstevel@tonic-gate if (nonumb)
4487c478bd9Sstevel@tonic-gate break;
4497c478bd9Sstevel@tonic-gate acc += i;
4507c478bd9Sstevel@tonic-gate goto a0;
4517c478bd9Sstevel@tonic-gate case '-':
4527c478bd9Sstevel@tonic-gate i = ckph();
4537c478bd9Sstevel@tonic-gate if (nonumb)
4547c478bd9Sstevel@tonic-gate break;
4557c478bd9Sstevel@tonic-gate acc -= i;
4567c478bd9Sstevel@tonic-gate goto a0;
4577c478bd9Sstevel@tonic-gate case '*':
4587c478bd9Sstevel@tonic-gate i = ckph();
4597c478bd9Sstevel@tonic-gate if (nonumb)
4607c478bd9Sstevel@tonic-gate break;
4617c478bd9Sstevel@tonic-gate acc *= i;
4627c478bd9Sstevel@tonic-gate goto a0;
4637c478bd9Sstevel@tonic-gate case '/':
4647c478bd9Sstevel@tonic-gate i = ckph();
4657c478bd9Sstevel@tonic-gate if (nonumb)
4667c478bd9Sstevel@tonic-gate break;
4677c478bd9Sstevel@tonic-gate if (i == 0) {
4687c478bd9Sstevel@tonic-gate flusho();
4697c478bd9Sstevel@tonic-gate errprint(gettext("divide by zero."));
4707c478bd9Sstevel@tonic-gate acc = 0;
4717c478bd9Sstevel@tonic-gate } else
4727c478bd9Sstevel@tonic-gate acc /= i;
4737c478bd9Sstevel@tonic-gate goto a0;
4747c478bd9Sstevel@tonic-gate case '%':
4757c478bd9Sstevel@tonic-gate i = ckph();
4767c478bd9Sstevel@tonic-gate if (nonumb)
4777c478bd9Sstevel@tonic-gate break;
4787c478bd9Sstevel@tonic-gate acc %= i;
4797c478bd9Sstevel@tonic-gate goto a0;
4807c478bd9Sstevel@tonic-gate case '&': /*and*/
4817c478bd9Sstevel@tonic-gate i = ckph();
4827c478bd9Sstevel@tonic-gate if (nonumb)
4837c478bd9Sstevel@tonic-gate break;
4847c478bd9Sstevel@tonic-gate if ((acc > 0) && (i > 0))
4857c478bd9Sstevel@tonic-gate acc = 1;
4867c478bd9Sstevel@tonic-gate else
4877c478bd9Sstevel@tonic-gate acc = 0;
4887c478bd9Sstevel@tonic-gate goto a0;
4897c478bd9Sstevel@tonic-gate case ':': /*or*/
4907c478bd9Sstevel@tonic-gate i = ckph();
4917c478bd9Sstevel@tonic-gate if (nonumb)
4927c478bd9Sstevel@tonic-gate break;
4937c478bd9Sstevel@tonic-gate if ((acc > 0) || (i > 0))
4947c478bd9Sstevel@tonic-gate acc = 1;
4957c478bd9Sstevel@tonic-gate else
4967c478bd9Sstevel@tonic-gate acc = 0;
4977c478bd9Sstevel@tonic-gate goto a0;
4987c478bd9Sstevel@tonic-gate case '=':
4997c478bd9Sstevel@tonic-gate if (cbits(ii = getch()) != '=')
5007c478bd9Sstevel@tonic-gate ch = ii;
5017c478bd9Sstevel@tonic-gate i = ckph();
5027c478bd9Sstevel@tonic-gate if (nonumb) {
5037c478bd9Sstevel@tonic-gate acc = 0;
5047c478bd9Sstevel@tonic-gate break;
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate if (i == acc)
5077c478bd9Sstevel@tonic-gate acc = 1;
5087c478bd9Sstevel@tonic-gate else
5097c478bd9Sstevel@tonic-gate acc = 0;
5107c478bd9Sstevel@tonic-gate goto a0;
5117c478bd9Sstevel@tonic-gate case '>':
5127c478bd9Sstevel@tonic-gate k = 0;
5137c478bd9Sstevel@tonic-gate if (cbits(ii = getch()) == '=')
5147c478bd9Sstevel@tonic-gate k++;
5157c478bd9Sstevel@tonic-gate else
5167c478bd9Sstevel@tonic-gate ch = ii;
5177c478bd9Sstevel@tonic-gate i = ckph();
5187c478bd9Sstevel@tonic-gate if (nonumb) {
5197c478bd9Sstevel@tonic-gate acc = 0;
5207c478bd9Sstevel@tonic-gate break;
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate if (acc > (i - k))
5237c478bd9Sstevel@tonic-gate acc = 1;
5247c478bd9Sstevel@tonic-gate else
5257c478bd9Sstevel@tonic-gate acc = 0;
5267c478bd9Sstevel@tonic-gate goto a0;
5277c478bd9Sstevel@tonic-gate case '<':
5287c478bd9Sstevel@tonic-gate k = 0;
5297c478bd9Sstevel@tonic-gate if (cbits(ii = getch()) == '=')
5307c478bd9Sstevel@tonic-gate k++;
5317c478bd9Sstevel@tonic-gate else
5327c478bd9Sstevel@tonic-gate ch = ii;
5337c478bd9Sstevel@tonic-gate i = ckph();
5347c478bd9Sstevel@tonic-gate if (nonumb) {
5357c478bd9Sstevel@tonic-gate acc = 0;
5367c478bd9Sstevel@tonic-gate break;
5377c478bd9Sstevel@tonic-gate }
5387c478bd9Sstevel@tonic-gate if (acc < (i + k))
5397c478bd9Sstevel@tonic-gate acc = 1;
5407c478bd9Sstevel@tonic-gate else
5417c478bd9Sstevel@tonic-gate acc = 0;
5427c478bd9Sstevel@tonic-gate goto a0;
5437c478bd9Sstevel@tonic-gate case ')':
5447c478bd9Sstevel@tonic-gate break;
5457c478bd9Sstevel@tonic-gate case '(':
5467c478bd9Sstevel@tonic-gate acc = atoi0();
5477c478bd9Sstevel@tonic-gate goto a0;
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate return(acc);
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate
ckph()5537c478bd9Sstevel@tonic-gate long ckph()
5547c478bd9Sstevel@tonic-gate {
555*e5190c10Smuffin tchar i;
556*e5190c10Smuffin long j;
5577c478bd9Sstevel@tonic-gate extern long atoi0();
5587c478bd9Sstevel@tonic-gate extern long atoi1();
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate if (cbits(i = getch()) == '(')
5617c478bd9Sstevel@tonic-gate j = atoi0();
5627c478bd9Sstevel@tonic-gate else {
5637c478bd9Sstevel@tonic-gate j = atoi1(i);
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate return(j);
5667c478bd9Sstevel@tonic-gate }
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate
atoi1(ii)5697c478bd9Sstevel@tonic-gate long atoi1(ii)
570*e5190c10Smuffin tchar ii;
5717c478bd9Sstevel@tonic-gate {
572*e5190c10Smuffin int i, j, digits;
573*e5190c10Smuffin long acc;
5747c478bd9Sstevel@tonic-gate int neg, abs, field;
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate neg = abs = field = digits = 0;
5777c478bd9Sstevel@tonic-gate acc = 0;
5787c478bd9Sstevel@tonic-gate for (;;) {
5797c478bd9Sstevel@tonic-gate i = cbits(ii);
5807c478bd9Sstevel@tonic-gate switch (i) {
5817c478bd9Sstevel@tonic-gate default:
5827c478bd9Sstevel@tonic-gate break;
5837c478bd9Sstevel@tonic-gate case '+':
5847c478bd9Sstevel@tonic-gate ii = getch();
5857c478bd9Sstevel@tonic-gate continue;
5867c478bd9Sstevel@tonic-gate case '-':
5877c478bd9Sstevel@tonic-gate neg = 1;
5887c478bd9Sstevel@tonic-gate ii = getch();
5897c478bd9Sstevel@tonic-gate continue;
5907c478bd9Sstevel@tonic-gate case '|':
5917c478bd9Sstevel@tonic-gate abs = 1 + neg;
5927c478bd9Sstevel@tonic-gate neg = 0;
5937c478bd9Sstevel@tonic-gate ii = getch();
5947c478bd9Sstevel@tonic-gate continue;
5957c478bd9Sstevel@tonic-gate }
5967c478bd9Sstevel@tonic-gate break;
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate a1:
5997c478bd9Sstevel@tonic-gate while (i >= '0' && i <= '9') {
6007c478bd9Sstevel@tonic-gate field++;
6017c478bd9Sstevel@tonic-gate digits++;
6027c478bd9Sstevel@tonic-gate acc = 10 * acc + i - '0';
6037c478bd9Sstevel@tonic-gate ii = getch();
6047c478bd9Sstevel@tonic-gate i = cbits(ii);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate if (i == '.') {
6077c478bd9Sstevel@tonic-gate field++;
6087c478bd9Sstevel@tonic-gate digits = 0;
6097c478bd9Sstevel@tonic-gate ii = getch();
6107c478bd9Sstevel@tonic-gate i = cbits(ii);
6117c478bd9Sstevel@tonic-gate goto a1;
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate if (!field) {
6147c478bd9Sstevel@tonic-gate ch = ii;
6157c478bd9Sstevel@tonic-gate goto a2;
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate switch (i) {
6187c478bd9Sstevel@tonic-gate case 'u':
6197c478bd9Sstevel@tonic-gate i = j = 1; /* should this be related to HOR?? */
6207c478bd9Sstevel@tonic-gate break;
6217c478bd9Sstevel@tonic-gate case 'v': /*VSs - vert spacing*/
6227c478bd9Sstevel@tonic-gate j = lss;
6237c478bd9Sstevel@tonic-gate i = 1;
6247c478bd9Sstevel@tonic-gate break;
6257c478bd9Sstevel@tonic-gate case 'm': /*Ems*/
6267c478bd9Sstevel@tonic-gate j = EM;
6277c478bd9Sstevel@tonic-gate i = 1;
6287c478bd9Sstevel@tonic-gate break;
6297c478bd9Sstevel@tonic-gate case 'n': /*Ens*/
6307c478bd9Sstevel@tonic-gate j = EM;
6317c478bd9Sstevel@tonic-gate #ifndef NROFF
6327c478bd9Sstevel@tonic-gate i = 2;
6337c478bd9Sstevel@tonic-gate #endif
6347c478bd9Sstevel@tonic-gate #ifdef NROFF
6357c478bd9Sstevel@tonic-gate i = 1; /*Same as Ems in NROFF*/
6367c478bd9Sstevel@tonic-gate #endif
6377c478bd9Sstevel@tonic-gate break;
6387c478bd9Sstevel@tonic-gate case 'p': /*Points*/
6397c478bd9Sstevel@tonic-gate j = INCH;
6407c478bd9Sstevel@tonic-gate i = 72;
6417c478bd9Sstevel@tonic-gate break;
6427c478bd9Sstevel@tonic-gate case 'i': /*Inches*/
6437c478bd9Sstevel@tonic-gate j = INCH;
6447c478bd9Sstevel@tonic-gate i = 1;
6457c478bd9Sstevel@tonic-gate break;
6467c478bd9Sstevel@tonic-gate case 'c': /*Centimeters*/
6477c478bd9Sstevel@tonic-gate /* if INCH is too big, this will overflow */
6487c478bd9Sstevel@tonic-gate j = INCH * 50;
6497c478bd9Sstevel@tonic-gate i = 127;
6507c478bd9Sstevel@tonic-gate break;
6517c478bd9Sstevel@tonic-gate case 'P': /*Picas*/
6527c478bd9Sstevel@tonic-gate j = INCH;
6537c478bd9Sstevel@tonic-gate i = 6;
6547c478bd9Sstevel@tonic-gate break;
6557c478bd9Sstevel@tonic-gate default:
6567c478bd9Sstevel@tonic-gate j = dfact;
6577c478bd9Sstevel@tonic-gate ch = ii;
6587c478bd9Sstevel@tonic-gate i = dfactd;
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate if (neg)
6617c478bd9Sstevel@tonic-gate acc = -acc;
6627c478bd9Sstevel@tonic-gate if (!noscale) {
6637c478bd9Sstevel@tonic-gate acc = (acc * j) / i;
6647c478bd9Sstevel@tonic-gate }
6657c478bd9Sstevel@tonic-gate if ((field != digits) && (digits > 0))
6667c478bd9Sstevel@tonic-gate while (digits--)
6677c478bd9Sstevel@tonic-gate acc /= 10;
6687c478bd9Sstevel@tonic-gate if (abs) {
6697c478bd9Sstevel@tonic-gate if (dip != d)
6707c478bd9Sstevel@tonic-gate j = dip->dnl;
6717c478bd9Sstevel@tonic-gate else
6727c478bd9Sstevel@tonic-gate j = numtab[NL].val;
6737c478bd9Sstevel@tonic-gate if (!vflag) {
6747c478bd9Sstevel@tonic-gate j = numtab[HP].val;
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate if (abs == 2)
6777c478bd9Sstevel@tonic-gate j = -j;
6787c478bd9Sstevel@tonic-gate acc -= j;
6797c478bd9Sstevel@tonic-gate }
6807c478bd9Sstevel@tonic-gate a2:
6817c478bd9Sstevel@tonic-gate nonumb = !field;
6827c478bd9Sstevel@tonic-gate return(acc);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate
686*e5190c10Smuffin int
caserr()6877c478bd9Sstevel@tonic-gate caserr()
6887c478bd9Sstevel@tonic-gate {
689*e5190c10Smuffin int i, j;
690*e5190c10Smuffin struct numtab *p;
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate lgf++;
6937c478bd9Sstevel@tonic-gate while (!skip() && (i = getrq()) ) {
6947c478bd9Sstevel@tonic-gate j = usedr(i);
6957c478bd9Sstevel@tonic-gate if (j < 0)
6967c478bd9Sstevel@tonic-gate continue;
6977c478bd9Sstevel@tonic-gate p = &numtab[j];
6987c478bd9Sstevel@tonic-gate nunhash(p);
6997c478bd9Sstevel@tonic-gate p->r = p->val = p->inc = p->fmt = 0;
7007c478bd9Sstevel@tonic-gate regcnt--;
7017c478bd9Sstevel@tonic-gate }
702*e5190c10Smuffin
703*e5190c10Smuffin return (0);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate
707*e5190c10Smuffin int
casenr()7087c478bd9Sstevel@tonic-gate casenr()
7097c478bd9Sstevel@tonic-gate {
710*e5190c10Smuffin int i, j;
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate lgf++;
7137c478bd9Sstevel@tonic-gate skip();
7147c478bd9Sstevel@tonic-gate if ((i = findr(getrq())) == -1)
7157c478bd9Sstevel@tonic-gate goto rtn;
7167c478bd9Sstevel@tonic-gate skip();
7177c478bd9Sstevel@tonic-gate j = inumb(&numtab[i].val);
7187c478bd9Sstevel@tonic-gate if (nonumb)
7197c478bd9Sstevel@tonic-gate goto rtn;
7207c478bd9Sstevel@tonic-gate numtab[i].val = j;
7217c478bd9Sstevel@tonic-gate skip();
7227c478bd9Sstevel@tonic-gate j = atoi();
7237c478bd9Sstevel@tonic-gate if (nonumb)
7247c478bd9Sstevel@tonic-gate goto rtn;
7257c478bd9Sstevel@tonic-gate numtab[i].inc = j;
7267c478bd9Sstevel@tonic-gate rtn:
727*e5190c10Smuffin return (0);
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate
7307c478bd9Sstevel@tonic-gate
731*e5190c10Smuffin int
caseaf()7327c478bd9Sstevel@tonic-gate caseaf()
7337c478bd9Sstevel@tonic-gate {
734*e5190c10Smuffin int i, k;
735*e5190c10Smuffin tchar j, jj;
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate lgf++;
7387c478bd9Sstevel@tonic-gate if (skip() || !(i = getrq()) || skip())
739*e5190c10Smuffin return (0);
7407c478bd9Sstevel@tonic-gate k = 0;
7417c478bd9Sstevel@tonic-gate j = getch();
7427c478bd9Sstevel@tonic-gate if (!ischar(jj = cbits(j)) || !isalpha(jj)) {
7437c478bd9Sstevel@tonic-gate ch = j;
7447c478bd9Sstevel@tonic-gate while ((j = cbits(getch())) >= '0' && j <= '9')
7457c478bd9Sstevel@tonic-gate k++;
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate if (!k)
7487c478bd9Sstevel@tonic-gate k = j;
7497c478bd9Sstevel@tonic-gate numtab[findr(i)].fmt = k & BYTEMASK;
750*e5190c10Smuffin
751*e5190c10Smuffin return (0);
7527c478bd9Sstevel@tonic-gate }
7537c478bd9Sstevel@tonic-gate
754*e5190c10Smuffin int
setaf()7557c478bd9Sstevel@tonic-gate setaf() /* return format of number register */
7567c478bd9Sstevel@tonic-gate {
757*e5190c10Smuffin int i, j;
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate i = usedr(getsn());
7607c478bd9Sstevel@tonic-gate if (i == -1)
761*e5190c10Smuffin return (0);
7627c478bd9Sstevel@tonic-gate if (numtab[i].fmt > 20) /* it was probably a, A, i or I */
7637c478bd9Sstevel@tonic-gate *pbp++ = numtab[i].fmt;
7647c478bd9Sstevel@tonic-gate else
7657c478bd9Sstevel@tonic-gate for (j = (numtab[i].fmt ? numtab[i].fmt : 1); j; j--)
7667c478bd9Sstevel@tonic-gate *pbp++ = '0';
767*e5190c10Smuffin
768*e5190c10Smuffin return (0);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate
772*e5190c10Smuffin int
vnumb(i)7737c478bd9Sstevel@tonic-gate vnumb(i)
7747c478bd9Sstevel@tonic-gate int *i;
7757c478bd9Sstevel@tonic-gate {
7767c478bd9Sstevel@tonic-gate vflag++;
7777c478bd9Sstevel@tonic-gate dfact = lss;
7787c478bd9Sstevel@tonic-gate res = VERT;
7797c478bd9Sstevel@tonic-gate return(inumb(i));
7807c478bd9Sstevel@tonic-gate }
7817c478bd9Sstevel@tonic-gate
7827c478bd9Sstevel@tonic-gate
783*e5190c10Smuffin int
hnumb(i)7847c478bd9Sstevel@tonic-gate hnumb(i)
7857c478bd9Sstevel@tonic-gate int *i;
7867c478bd9Sstevel@tonic-gate {
7877c478bd9Sstevel@tonic-gate dfact = EM;
7887c478bd9Sstevel@tonic-gate res = HOR;
7897c478bd9Sstevel@tonic-gate return(inumb(i));
7907c478bd9Sstevel@tonic-gate }
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate
793*e5190c10Smuffin int
inumb(n)7947c478bd9Sstevel@tonic-gate inumb(n)
7957c478bd9Sstevel@tonic-gate int *n;
7967c478bd9Sstevel@tonic-gate {
797*e5190c10Smuffin int i, j, f;
798*e5190c10Smuffin tchar ii;
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate f = 0;
8017c478bd9Sstevel@tonic-gate if (n) {
8027c478bd9Sstevel@tonic-gate if ((j = cbits(ii = getch())) == '+')
8037c478bd9Sstevel@tonic-gate f = 1;
8047c478bd9Sstevel@tonic-gate else if (j == '-')
8057c478bd9Sstevel@tonic-gate f = -1;
8067c478bd9Sstevel@tonic-gate else
8077c478bd9Sstevel@tonic-gate ch = ii;
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate i = atoi();
8107c478bd9Sstevel@tonic-gate if (n && f)
8117c478bd9Sstevel@tonic-gate i = *n + f * i;
8127c478bd9Sstevel@tonic-gate i = quant(i, res);
8137c478bd9Sstevel@tonic-gate vflag = 0;
8147c478bd9Sstevel@tonic-gate res = dfactd = dfact = 1;
8157c478bd9Sstevel@tonic-gate if (nonumb)
8167c478bd9Sstevel@tonic-gate i = 0;
8177c478bd9Sstevel@tonic-gate return(i);
8187c478bd9Sstevel@tonic-gate }
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate
821*e5190c10Smuffin int
quant(n,m)8227c478bd9Sstevel@tonic-gate quant(n, m)
8237c478bd9Sstevel@tonic-gate int n, m;
8247c478bd9Sstevel@tonic-gate {
825*e5190c10Smuffin int i, neg;
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate neg = 0;
8287c478bd9Sstevel@tonic-gate if (n < 0) {
8297c478bd9Sstevel@tonic-gate neg++;
8307c478bd9Sstevel@tonic-gate n = -n;
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate /* better as i = ((n + (m/2))/m)*m */
8337c478bd9Sstevel@tonic-gate i = n / m;
8347c478bd9Sstevel@tonic-gate if ((n - m * i) > (m / 2))
8357c478bd9Sstevel@tonic-gate i += 1;
8367c478bd9Sstevel@tonic-gate i *= m;
8377c478bd9Sstevel@tonic-gate if (neg)
8387c478bd9Sstevel@tonic-gate i = -i;
8397c478bd9Sstevel@tonic-gate return(i);
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate
8427c478bd9Sstevel@tonic-gate
843