/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include "tdef.h"
#ifdef NROFF
#include "tw.h"
#endif
#include "ext.h"
/*
* troff4.c
*
* number registers, conversion, arithmetic
*/
int
setn()
{
int i, j;
int f;
f = nform = 0;
f = 1;
else if (i == '-')
f = -1;
else
if (falsef)
f = 0;
if ((i = getsn()) == 0)
return (0);
if ((i & 0177) == '.')
switch (i >> BYTE) {
case 's':
i = pts;
break;
case 'v':
i = lss;
break;
case 'f':
i = font;
break;
case 'p':
i = pl;
break;
case 't':
i = findt1();
break;
case 'o':
i = po;
break;
case 'l':
i = ll;
break;
case 'i':
i = in;
break;
case '$':
break;
case 'A':
i = ascii;
break;
case 'c':
break;
case 'n':
i = lastl;
break;
case 'a':
i = ralss;
break;
case 'h':
break;
case 'd':
if (dip != d)
else
break;
case 'u':
i = fi;
break;
case 'j':
break;
case 'w':
i = widthp;
break;
case 'x':
i = nel;
break;
case 'y':
i = un;
break;
case 'T':
i = dotT;
break; /*-Tterm used in nroff*/
case 'V':
i = VERT;
break;
case 'H':
i = HOR;
break;
case 'k':
i = ne;
break;
case 'P':
i = print;
break;
case 'L':
i = ls;
break;
case 'R':
break;
case 'z':
return (0);
case 'b':
break;
case 'F':
return (0);
default:
goto s0;
}
else {
s0:
if ((j = findr(i)) == -1)
i = 0;
else {
}
}
return (0);
}
int
wrc(i)
tchar i;
{
return(0);
*numbufp++ = i;
return(1);
}
/* insert into input number i, in format form, with size-font bits bits */
int
int i;
{
extern int wrc();
*numbufp = 0;
return (0);
}
int
nrehash()
{
struct numtab *p;
int i;
for (i=0; i<128; i++)
nhash[i] = 0;
p->link = 0;
if (p->r == 0)
continue;
i = NHASH(p->r);
nhash[i] = p;
}
return (0);
}
int
{
struct numtab *p;
if (rp->r == 0)
return (0);
p = *lp;
while (p) {
if (p == rp) {
p->link = 0;
return (0);
}
p = p->link;
}
return (0);
}
int
findr(i)
int i;
{
struct numtab *p;
int h = NHASH(i);
if (i == 0)
return(-1);
if (i == p->r)
return(p - numtab);
if (p->r == 0) {
p->r = i;
nhash[h] = p;
regcnt++;
return(p - numtab);
}
}
done2(04);
/* NOTREACHED */
return (0);
}
int
int i;
{
struct numtab *p;
if (i == 0)
return(-1);
if (i == p->r)
return(p - numtab);
return -1;
}
int
fnumb(i, f)
int i, (*f)();
{
int j;
j = 0;
if (i < 0) {
j = (*f)('-' | nrbits);
i = -i;
}
switch (nform) {
default:
case '1':
case 0:
return decml(i, f) + j;
break;
case 'i':
case 'I':
return roman(i, f) + j;
break;
case 'a':
case 'A':
return abc(i, f) + j;
break;
}
return (0);
}
int
decml(i, f)
int i, (*f)();
{
int j, k;
k = 0;
nform--;
if ((j = i / 10) || (nform > 0))
k = decml(j, f);
}
int
roman(i, f)
int i, (*f)();
{
if (!i)
return((*f)('0' | nrbits));
if (nform == 'i')
else
}
int
int i, (*f)();
{
int q, rem, k;
k = 0;
if (!i)
return(0);
q = (i = i % 10) / 5;
rem = i % 5;
if (rem == 4) {
if (q)
i = *(onesp + 1);
else
i = *fivesp;
return(k += (*f)(i | nrbits));
}
if (q)
while (--rem >= 0)
return(k);
}
int
abc(i, f)
int i, (*f)();
{
if (!i)
return((*f)('0' | nrbits));
else
return(abc0(i - 1, f));
}
int
abc0(i, f)
int i, (*f)();
{
int j, k;
k = 0;
if (j = i / 26)
k = abc0(j - 1, f);
}
long atoi0()
{
int c, k, cnt;
long i, acc;
extern long ckph();
i = 0;
acc = 0;
nonumb = 0;
cnt = -1;
a0:
cnt++;
switch (c) {
default:
if (cnt)
break;
case '+':
i = ckph();
if (nonumb)
break;
acc += i;
goto a0;
case '-':
i = ckph();
if (nonumb)
break;
acc -= i;
goto a0;
case '*':
i = ckph();
if (nonumb)
break;
acc *= i;
goto a0;
case '/':
i = ckph();
if (nonumb)
break;
if (i == 0) {
flusho();
acc = 0;
} else
acc /= i;
goto a0;
case '%':
i = ckph();
if (nonumb)
break;
acc %= i;
goto a0;
case '&': /*and*/
i = ckph();
if (nonumb)
break;
if ((acc > 0) && (i > 0))
acc = 1;
else
acc = 0;
goto a0;
case ':': /*or*/
i = ckph();
if (nonumb)
break;
if ((acc > 0) || (i > 0))
acc = 1;
else
acc = 0;
goto a0;
case '=':
i = ckph();
if (nonumb) {
acc = 0;
break;
}
if (i == acc)
acc = 1;
else
acc = 0;
goto a0;
case '>':
k = 0;
k++;
else
i = ckph();
if (nonumb) {
acc = 0;
break;
}
if (acc > (i - k))
acc = 1;
else
acc = 0;
goto a0;
case '<':
k = 0;
k++;
else
i = ckph();
if (nonumb) {
acc = 0;
break;
}
if (acc < (i + k))
acc = 1;
else
acc = 0;
goto a0;
case ')':
break;
case '(':
goto a0;
}
return(acc);
}
long ckph()
{
tchar i;
long j;
extern long atoi0();
extern long atoi1();
j = atoi0();
else {
j = atoi1(i);
}
return(j);
}
{
int i, j, digits;
long acc;
acc = 0;
for (;;) {
switch (i) {
default:
break;
case '+':
continue;
case '-':
neg = 1;
continue;
case '|':
neg = 0;
continue;
}
break;
}
a1:
while (i >= '0' && i <= '9') {
field++;
digits++;
}
if (i == '.') {
field++;
digits = 0;
goto a1;
}
if (!field) {
goto a2;
}
switch (i) {
case 'u':
i = j = 1; /* should this be related to HOR?? */
break;
case 'v': /*VSs - vert spacing*/
j = lss;
i = 1;
break;
case 'm': /*Ems*/
j = EM;
i = 1;
break;
case 'n': /*Ens*/
j = EM;
#ifndef NROFF
i = 2;
#endif
#ifdef NROFF
i = 1; /*Same as Ems in NROFF*/
#endif
break;
case 'p': /*Points*/
j = INCH;
i = 72;
break;
case 'i': /*Inches*/
j = INCH;
i = 1;
break;
case 'c': /*Centimeters*/
/* if INCH is too big, this will overflow */
j = INCH * 50;
i = 127;
break;
case 'P': /*Picas*/
j = INCH;
i = 6;
break;
default:
j = dfact;
i = dfactd;
}
if (neg)
if (!noscale) {
}
while (digits--)
acc /= 10;
if (abs) {
if (dip != d)
else
if (!vflag) {
}
if (abs == 2)
j = -j;
acc -= j;
}
a2:
return(acc);
}
int
caserr()
{
int i, j;
struct numtab *p;
lgf++;
j = usedr(i);
if (j < 0)
continue;
p = &numtab[j];
nunhash(p);
regcnt--;
}
return (0);
}
int
casenr()
{
int i, j;
lgf++;
skip();
goto rtn;
skip();
if (nonumb)
goto rtn;
skip();
j = atoi();
if (nonumb)
goto rtn;
rtn:
return (0);
}
int
caseaf()
{
int i, k;
lgf++;
return (0);
k = 0;
j = getch();
ch = j;
k++;
}
if (!k)
k = j;
return (0);
}
int
{
int i, j;
if (i == -1)
return (0);
else
*pbp++ = '0';
return (0);
}
int
vnumb(i)
int *i;
{
vflag++;
return(inumb(i));
}
int
hnumb(i)
int *i;
{
return(inumb(i));
}
int
inumb(n)
int *n;
{
int i, j, f;
f = 0;
if (n) {
f = 1;
else if (j == '-')
f = -1;
else
}
i = atoi();
if (n && f)
i = *n + f * i;
vflag = 0;
if (nonumb)
i = 0;
return(i);
}
int
quant(n, m)
int n, m;
{
int i, neg;
neg = 0;
if (n < 0) {
neg++;
n = -n;
}
/* better as i = ((n + (m/2))/m)*m */
i = n / m;
if ((n - m * i) > (m / 2))
i += 1;
i *= m;
if (neg)
i = -i;
return(i);
}