4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
51 * number registers, conversion, arithmetic
56 int falsef
= 0; /* on if inside false branch of if */
57 #define NHASH(i) ((i>>6)^i)&0177
58 struct numtab
*nhash
[128]; /* 128 == the 0177 on line above */
68 if ((i
= cbits(ii
= getach())) == '+')
76 if ((i
= getsn()) == 0)
78 if ((i
& 0177) == '.')
145 break; /*-Tterm used in nroff*/
166 *pbp
++ = (i
>> BYTE
) & BYTEMASK
;
167 *pbp
++ = i
& BYTEMASK
;
173 cpushback(cfname
[ifi
]);
181 if ((j
= findr(i
)) == -1)
184 i
= numtab
[j
].val
= (numtab
[j
].val
+numtab
[j
].inc
*f
);
185 nform
= numtab
[j
].fmt
;
188 setn1(i
, nform
, (tchar
) 0);
200 if (numbufp
>= &numbuf
[16])
208 /* insert into input number i, in format form, with size-font bits bits */
233 for (i
=0; i
<128; i
++)
235 for (p
=numtab
; p
< &numtab
[NN
]; p
++)
237 for (p
=numtab
; p
< &numtab
[NN
]; p
++) {
257 lp
= &nhash
[NHASH(rp
->r
)];
280 for (p
= nhash
[h
]; p
; p
= p
->link
)
283 for (p
= numtab
; p
< &numtab
[NN
]; p
++) {
292 errprint(gettext("too many number registers (%d)."), NN
);
300 usedr(i
) /* returns -1 if nr i has never been used */
307 for (p
= nhash
[NHASH(i
)]; p
; p
= p
->link
)
322 j
= (*f
)('-' | nrbits
);
329 return decml(i
, f
) + j
;
333 return roman(i
, f
) + j
;
337 return abc(i
, f
) + j
;
353 if ((j
= i
/ 10) || (nform
> 0))
355 return(k
+ (*f
)((i
% 10 + '0') | nrbits
));
365 return((*f
)('0' | nrbits
));
367 return(roman0(i
, f
, "ixcmz", "vldw"));
369 return(roman0(i
, f
, "IXCMZ", "VLDW"));
374 roman0(i
, f
, onesp
, fivesp
)
376 char *onesp
, *fivesp
;
383 k
= roman0(i
/ 10, f
, onesp
+ 1, fivesp
+ 1);
384 q
= (i
= i
% 10) / 5;
387 k
+= (*f
)(*onesp
| nrbits
);
392 return(k
+= (*f
)(i
| nrbits
));
395 k
+= (*f
)(*fivesp
| nrbits
);
397 k
+= (*f
)(*onesp
| nrbits
);
407 return((*f
)('0' | nrbits
));
409 return(abc0(i
- 1, f
));
422 return(k
+ (*f
)((i
% 26 + nform
) | nrbits
));
469 errprint(gettext("divide by zero."));
484 if ((acc
> 0) && (i
> 0))
493 if ((acc
> 0) || (i
> 0))
499 if (cbits(ii
= getch()) != '=')
513 if (cbits(ii
= getch()) == '=')
529 if (cbits(ii
= getch()) == '=')
560 if (cbits(i
= getch()) == '(')
576 neg
= abs
= field
= digits
= 0;
599 while (i
>= '0' && i
<= '9') {
602 acc
= 10 * acc
+ i
- '0';
619 i
= j
= 1; /* should this be related to HOR?? */
621 case 'v': /*VSs - vert spacing*/
635 i
= 1; /*Same as Ems in NROFF*/
646 case 'c': /*Centimeters*/
647 /* if INCH is too big, this will overflow */
665 if ((field
!= digits
) && (digits
> 0))
693 while (!skip() && (i
= getrq()) ) {
699 p
->r
= p
->val
= p
->inc
= p
->fmt
= 0;
714 if ((i
= findr(getrq())) == -1)
717 j
= inumb(&numtab
[i
].val
);
738 if (skip() || !(i
= getrq()) || skip())
742 if (!ischar(jj
= cbits(j
)) || !isalpha(jj
)) {
744 while ((j
= cbits(getch())) >= '0' && j
<= '9')
749 numtab
[findr(i
)].fmt
= k
& BYTEMASK
;
755 setaf() /* return format of number register */
762 if (numtab
[i
].fmt
> 20) /* it was probably a, A, i or I */
763 *pbp
++ = numtab
[i
].fmt
;
765 for (j
= (numtab
[i
].fmt
? numtab
[i
].fmt
: 1); j
; j
--)
802 if ((j
= cbits(ii
= getch())) == '+')
814 res
= dfactd
= dfact
= 1;
832 /* better as i = ((n + (m/2))/m)*m */
834 if ((n
- m
* i
) > (m
/ 2))