1*308Srobbin /*
2*308Srobbin * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*308Srobbin * Use is subject to license terms.
4*308Srobbin */
5*308Srobbin
60Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
70Sstevel@tonic-gate /* All Rights Reserved */
80Sstevel@tonic-gate
90Sstevel@tonic-gate /*
100Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
110Sstevel@tonic-gate * All rights reserved. The Berkeley Software License Agreement
120Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
150Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
160Sstevel@tonic-gate
170Sstevel@tonic-gate #include <stdio.h>
180Sstevel@tonic-gate #include <locale.h>
19*308Srobbin #include <signal.h>
200Sstevel@tonic-gate
210Sstevel@tonic-gate #define NDIM 10
220Sstevel@tonic-gate #define NTAB 1009
230Sstevel@tonic-gate char *dfile = "/usr/share/lib/unittab";
240Sstevel@tonic-gate char *unames[NDIM];
250Sstevel@tonic-gate struct unit
260Sstevel@tonic-gate {
270Sstevel@tonic-gate double factor;
280Sstevel@tonic-gate char dim[NDIM];
290Sstevel@tonic-gate };
300Sstevel@tonic-gate
310Sstevel@tonic-gate struct table
320Sstevel@tonic-gate {
330Sstevel@tonic-gate double factor;
340Sstevel@tonic-gate char dim[NDIM];
350Sstevel@tonic-gate char *name;
360Sstevel@tonic-gate } table[NTAB];
370Sstevel@tonic-gate char names[NTAB*10];
380Sstevel@tonic-gate struct prefix
390Sstevel@tonic-gate {
400Sstevel@tonic-gate double factor;
410Sstevel@tonic-gate char *pname;
420Sstevel@tonic-gate } prefix[] =
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 1e-21, "zepto",
450Sstevel@tonic-gate 1e-24, "yocto",
460Sstevel@tonic-gate 1e-18, "atto",
470Sstevel@tonic-gate 1e-15, "femto",
480Sstevel@tonic-gate 1e-12, "pico",
490Sstevel@tonic-gate 1e-9, "nano",
500Sstevel@tonic-gate 1e-6, "micro",
510Sstevel@tonic-gate 1e-3, "milli",
520Sstevel@tonic-gate 1e-2, "centi",
530Sstevel@tonic-gate 1e-1, "deci",
540Sstevel@tonic-gate 1e1, "deka",
550Sstevel@tonic-gate 1e1, "deca",
560Sstevel@tonic-gate 1e2, "hecta",
570Sstevel@tonic-gate 1e2, "hecto",
580Sstevel@tonic-gate 1e3, "kilo",
590Sstevel@tonic-gate 1e6, "mega",
600Sstevel@tonic-gate 1e6, "meg",
610Sstevel@tonic-gate 1e9, "giga",
620Sstevel@tonic-gate 1e12, "tera",
630Sstevel@tonic-gate 1e15, "peta",
640Sstevel@tonic-gate 1e18, "exa",
650Sstevel@tonic-gate 1e21, "zetta",
660Sstevel@tonic-gate 1e24, "yotta",
670Sstevel@tonic-gate 1<<10, "kibi",
680Sstevel@tonic-gate 1L<<20, "mebi",
690Sstevel@tonic-gate 1L<<30, "gibi",
700Sstevel@tonic-gate 1LL<<40,"tebi",
710Sstevel@tonic-gate 0.0, 0
720Sstevel@tonic-gate };
730Sstevel@tonic-gate FILE *inp;
740Sstevel@tonic-gate int fperrc;
750Sstevel@tonic-gate int peekc;
760Sstevel@tonic-gate int dumpflg;
770Sstevel@tonic-gate
78*308Srobbin void fperr(int sig);
79*308Srobbin double getflt(void);
80*308Srobbin struct table *hash(char *name);
81*308Srobbin int get(void);
82*308Srobbin void init(void);
83*308Srobbin int equal(char *s1, char *s2);
84*308Srobbin int lookup(char *name, struct unit *up, int den, int c);
85*308Srobbin int convr(struct unit *up);
86*308Srobbin int pu(int u, int i, int f);
87*308Srobbin void units(struct unit *up);
88*308Srobbin
89*308Srobbin int
main(int argc,char * argv[])90*308Srobbin main(int argc, char *argv[])
910Sstevel@tonic-gate {
92*308Srobbin int i;
93*308Srobbin char *file;
940Sstevel@tonic-gate struct unit u1, u2;
950Sstevel@tonic-gate double f;
960Sstevel@tonic-gate
970Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
980Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
990Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1000Sstevel@tonic-gate #endif
1010Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate if(argc>1 && *argv[1]=='-') {
1040Sstevel@tonic-gate argc--;
1050Sstevel@tonic-gate argv++;
1060Sstevel@tonic-gate dumpflg++;
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate file = dfile;
1090Sstevel@tonic-gate if(argc > 1)
1100Sstevel@tonic-gate file = argv[1];
1110Sstevel@tonic-gate if ((inp = fopen(file, "r")) == NULL) {
1120Sstevel@tonic-gate printf(gettext("no table\n"));
1130Sstevel@tonic-gate exit(1);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate signal(8, fperr);
1160Sstevel@tonic-gate init();
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate loop:
1190Sstevel@tonic-gate fperrc = 0;
1200Sstevel@tonic-gate printf(gettext("you have: "));
1210Sstevel@tonic-gate if(convr(&u1))
1220Sstevel@tonic-gate goto loop;
1230Sstevel@tonic-gate if(fperrc)
1240Sstevel@tonic-gate goto fp;
1250Sstevel@tonic-gate loop1:
1260Sstevel@tonic-gate printf(gettext("you want: "));
1270Sstevel@tonic-gate if(convr(&u2))
1280Sstevel@tonic-gate goto loop1;
1290Sstevel@tonic-gate for(i=0; i<NDIM; i++)
1300Sstevel@tonic-gate if(u1.dim[i] != u2.dim[i])
1310Sstevel@tonic-gate goto conform;
1320Sstevel@tonic-gate f = u1.factor/u2.factor;
1330Sstevel@tonic-gate if(fperrc || f == 0.0)
1340Sstevel@tonic-gate goto fp;
1350Sstevel@tonic-gate printf("\t* %e\n", f);
1360Sstevel@tonic-gate printf("\t/ %e\n", 1./f);
1370Sstevel@tonic-gate goto loop;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate conform:
1400Sstevel@tonic-gate if(fperrc)
1410Sstevel@tonic-gate goto fp;
1420Sstevel@tonic-gate printf(gettext("conformability\n"));
1430Sstevel@tonic-gate units(&u1);
1440Sstevel@tonic-gate units(&u2);
1450Sstevel@tonic-gate goto loop;
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate fp:
1480Sstevel@tonic-gate printf(gettext("underflow or overflow\n"));
1490Sstevel@tonic-gate goto loop;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate
152*308Srobbin void
units(struct unit * up)153*308Srobbin units(struct unit *up)
1540Sstevel@tonic-gate {
155*308Srobbin struct unit *p;
156*308Srobbin int f, i;
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate p = up;
1590Sstevel@tonic-gate printf("\t%e ", p->factor);
1600Sstevel@tonic-gate f = 0;
1610Sstevel@tonic-gate for(i=0; i<NDIM; i++)
1620Sstevel@tonic-gate f |= pu(p->dim[i], i, f);
1630Sstevel@tonic-gate if(f&1) {
1640Sstevel@tonic-gate putchar('/');
1650Sstevel@tonic-gate f = 0;
1660Sstevel@tonic-gate for(i=0; i<NDIM; i++)
1670Sstevel@tonic-gate f |= pu(-p->dim[i], i, f);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate putchar('\n');
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate
172*308Srobbin int
pu(int u,int i,int f)173*308Srobbin pu(int u, int i, int f)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate if(u > 0) {
1770Sstevel@tonic-gate if(f&2)
1780Sstevel@tonic-gate putchar('-');
1790Sstevel@tonic-gate if(unames[i])
1800Sstevel@tonic-gate printf("%s", unames[i]); else
1810Sstevel@tonic-gate printf(gettext("*%c*"), i+'a');
1820Sstevel@tonic-gate if(u > 1)
1830Sstevel@tonic-gate putchar(u+'0');
1840Sstevel@tonic-gate return(2);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate if(u < 0)
1870Sstevel@tonic-gate return(1);
1880Sstevel@tonic-gate return(0);
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate
191*308Srobbin int
convr(struct unit * up)192*308Srobbin convr(struct unit *up)
1930Sstevel@tonic-gate {
194*308Srobbin struct unit *p;
195*308Srobbin int c;
196*308Srobbin char *cp;
1970Sstevel@tonic-gate char name[20];
1980Sstevel@tonic-gate int den, err;
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate p = up;
2010Sstevel@tonic-gate for(c=0; c<NDIM; c++)
2020Sstevel@tonic-gate p->dim[c] = 0;
2030Sstevel@tonic-gate p->factor = getflt();
2040Sstevel@tonic-gate if(p->factor == 0.)
2050Sstevel@tonic-gate p->factor = 1.0;
2060Sstevel@tonic-gate err = 0;
2070Sstevel@tonic-gate den = 0;
2080Sstevel@tonic-gate cp = name;
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate loop:
2110Sstevel@tonic-gate switch(c=get()) {
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate case '1':
2140Sstevel@tonic-gate case '2':
2150Sstevel@tonic-gate case '3':
2160Sstevel@tonic-gate case '4':
2170Sstevel@tonic-gate case '5':
2180Sstevel@tonic-gate case '6':
2190Sstevel@tonic-gate case '7':
2200Sstevel@tonic-gate case '8':
2210Sstevel@tonic-gate case '9':
2220Sstevel@tonic-gate case '-':
2230Sstevel@tonic-gate case '/':
2240Sstevel@tonic-gate case ' ':
2250Sstevel@tonic-gate case '\t':
2260Sstevel@tonic-gate case '\n':
2270Sstevel@tonic-gate if(cp != name) {
2280Sstevel@tonic-gate *cp++ = 0;
2290Sstevel@tonic-gate cp = name;
2300Sstevel@tonic-gate err |= lookup(cp, p, den, c);
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate if(c == '/')
2330Sstevel@tonic-gate den++;
2340Sstevel@tonic-gate if(c == '\n')
2350Sstevel@tonic-gate return(err);
2360Sstevel@tonic-gate goto loop;
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate *cp++ = c;
2390Sstevel@tonic-gate goto loop;
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
242*308Srobbin int
lookup(char * name,struct unit * up,int den,int c)243*308Srobbin lookup(char *name, struct unit *up, int den, int c)
2440Sstevel@tonic-gate {
245*308Srobbin struct unit *p;
246*308Srobbin struct table *q;
247*308Srobbin int i;
2480Sstevel@tonic-gate char *cp1, *cp2;
2490Sstevel@tonic-gate double e;
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate p = up;
2520Sstevel@tonic-gate e = 1.0;
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate loop:
2550Sstevel@tonic-gate q = hash(name);
2560Sstevel@tonic-gate if(q->name) {
2570Sstevel@tonic-gate l1:
2580Sstevel@tonic-gate if(den) {
2590Sstevel@tonic-gate p->factor /= q->factor*e;
2600Sstevel@tonic-gate for(i=0; i<NDIM; i++)
2610Sstevel@tonic-gate p->dim[i] -= q->dim[i];
2620Sstevel@tonic-gate } else {
2630Sstevel@tonic-gate p->factor *= q->factor*e;
2640Sstevel@tonic-gate for(i=0; i<NDIM; i++)
2650Sstevel@tonic-gate p->dim[i] += q->dim[i];
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate if(c >= '2' && c <= '9') {
2680Sstevel@tonic-gate c--;
2690Sstevel@tonic-gate goto l1;
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate return(0);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate for(i=0; cp1 = prefix[i].pname; i++) {
2740Sstevel@tonic-gate cp2 = name;
2750Sstevel@tonic-gate while(*cp1 == *cp2++)
2760Sstevel@tonic-gate if(*cp1++ == 0) {
2770Sstevel@tonic-gate cp1--;
2780Sstevel@tonic-gate break;
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate if(*cp1 == 0) {
2810Sstevel@tonic-gate e *= prefix[i].factor;
2820Sstevel@tonic-gate name = cp2-1;
2830Sstevel@tonic-gate goto loop;
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate for(cp1 = name; *cp1; cp1++);
2870Sstevel@tonic-gate if(cp1 > name+1 && *--cp1 == 's') {
2880Sstevel@tonic-gate *cp1 = 0;
2890Sstevel@tonic-gate goto loop;
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate printf(gettext("cannot recognize %s\n"), name);
2920Sstevel@tonic-gate return(1);
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate
295*308Srobbin int
equal(char * s1,char * s2)296*308Srobbin equal(char *s1, char *s2)
2970Sstevel@tonic-gate {
298*308Srobbin char *c1, *c2;
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate c1 = s1;
3010Sstevel@tonic-gate c2 = s2;
3020Sstevel@tonic-gate while(*c1++ == *c2)
3030Sstevel@tonic-gate if(*c2++ == 0)
3040Sstevel@tonic-gate return(1);
3050Sstevel@tonic-gate return(0);
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate
308*308Srobbin void
init(void)309*308Srobbin init(void)
3100Sstevel@tonic-gate {
311*308Srobbin char *cp;
312*308Srobbin struct table *tp, *lp;
3130Sstevel@tonic-gate int c, i, f, t;
3140Sstevel@tonic-gate char *np;
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate cp = names;
3170Sstevel@tonic-gate for(i=0; i<NDIM; i++) {
3180Sstevel@tonic-gate np = cp;
3190Sstevel@tonic-gate *cp++ = '*';
3200Sstevel@tonic-gate *cp++ = i+'a';
3210Sstevel@tonic-gate *cp++ = '*';
3220Sstevel@tonic-gate *cp++ = 0;
3230Sstevel@tonic-gate lp = hash(np);
3240Sstevel@tonic-gate lp->name = np;
3250Sstevel@tonic-gate lp->factor = 1.0;
3260Sstevel@tonic-gate lp->dim[i] = 1;
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate lp = hash("");
3290Sstevel@tonic-gate lp->name = cp-1;
3300Sstevel@tonic-gate lp->factor = 1.0;
3310Sstevel@tonic-gate
3320Sstevel@tonic-gate l0:
3330Sstevel@tonic-gate c = get();
3340Sstevel@tonic-gate if(c == 0) {
3350Sstevel@tonic-gate if(dumpflg) {
3360Sstevel@tonic-gate printf(gettext("%d units; %d bytes\n\n"), i, cp-names);
3370Sstevel@tonic-gate for(tp = &table[0]; tp < &table[NTAB]; tp++) {
3380Sstevel@tonic-gate if(tp->name == 0)
3390Sstevel@tonic-gate continue;
3400Sstevel@tonic-gate printf("%s", tp->name);
3410Sstevel@tonic-gate units((struct unit *)tp);
3420Sstevel@tonic-gate } }
3430Sstevel@tonic-gate fclose(inp);
3440Sstevel@tonic-gate inp = stdin;
3450Sstevel@tonic-gate return;
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate if(c == '/') {
3480Sstevel@tonic-gate while(c != '\n' && c != 0)
3490Sstevel@tonic-gate c = get();
3500Sstevel@tonic-gate goto l0;
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate if(c == '\n')
3530Sstevel@tonic-gate goto l0;
3540Sstevel@tonic-gate np = cp;
3550Sstevel@tonic-gate while(c != ' ' && c != '\t') {
3560Sstevel@tonic-gate *cp++ = c;
3570Sstevel@tonic-gate c = get();
3580Sstevel@tonic-gate if (c==0)
3590Sstevel@tonic-gate goto l0;
3600Sstevel@tonic-gate if(c == '\n') {
3610Sstevel@tonic-gate *cp++ = 0;
3620Sstevel@tonic-gate tp = hash(np);
3630Sstevel@tonic-gate if(tp->name)
3640Sstevel@tonic-gate goto redef;
3650Sstevel@tonic-gate tp->name = np;
3660Sstevel@tonic-gate tp->factor = lp->factor;
3670Sstevel@tonic-gate for(c=0; c<NDIM; c++)
3680Sstevel@tonic-gate tp->dim[c] = lp->dim[c];
3690Sstevel@tonic-gate i++;
3700Sstevel@tonic-gate goto l0;
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate *cp++ = 0;
3740Sstevel@tonic-gate lp = hash(np);
3750Sstevel@tonic-gate if(lp->name)
3760Sstevel@tonic-gate goto redef;
3770Sstevel@tonic-gate convr((struct unit *)lp);
3780Sstevel@tonic-gate lp->name = np;
3790Sstevel@tonic-gate f = 0;
3800Sstevel@tonic-gate i++;
3810Sstevel@tonic-gate if(lp->factor != 1.0)
3820Sstevel@tonic-gate goto l0;
3830Sstevel@tonic-gate for(c=0; c<NDIM; c++) {
3840Sstevel@tonic-gate t = lp->dim[c];
3850Sstevel@tonic-gate if(t>1 || (f>0 && t!=0))
3860Sstevel@tonic-gate goto l0;
3870Sstevel@tonic-gate if(f==0 && t==1) {
3880Sstevel@tonic-gate if(unames[c])
3890Sstevel@tonic-gate goto l0;
3900Sstevel@tonic-gate f = c+1;
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate if(f>0)
3940Sstevel@tonic-gate unames[f-1] = np;
3950Sstevel@tonic-gate goto l0;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate redef:
3980Sstevel@tonic-gate printf(gettext("redefinition %s\n"), np);
3990Sstevel@tonic-gate goto l0;
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate double
getflt(void)403*308Srobbin getflt(void)
4040Sstevel@tonic-gate {
405*308Srobbin int c, i, dp;
4060Sstevel@tonic-gate double d, e;
4070Sstevel@tonic-gate int f;
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate d = 0.;
4100Sstevel@tonic-gate dp = 0;
4110Sstevel@tonic-gate do
4120Sstevel@tonic-gate c = get();
4130Sstevel@tonic-gate while(c == ' ' || c == '\t');
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate l1:
4160Sstevel@tonic-gate if(c >= '0' && c <= '9') {
4170Sstevel@tonic-gate d = d*10. + c-'0';
4180Sstevel@tonic-gate if(dp)
4190Sstevel@tonic-gate dp++;
4200Sstevel@tonic-gate c = get();
4210Sstevel@tonic-gate goto l1;
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate if(c == '.') {
4240Sstevel@tonic-gate dp++;
4250Sstevel@tonic-gate c = get();
4260Sstevel@tonic-gate goto l1;
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate if(dp)
4290Sstevel@tonic-gate dp--;
4300Sstevel@tonic-gate if(c == '+' || c == '-') {
4310Sstevel@tonic-gate f = 0;
4320Sstevel@tonic-gate if(c == '-')
4330Sstevel@tonic-gate f++;
4340Sstevel@tonic-gate i = 0;
4350Sstevel@tonic-gate c = get();
4360Sstevel@tonic-gate while(c >= '0' && c <= '9') {
4370Sstevel@tonic-gate i = i*10 + c-'0';
4380Sstevel@tonic-gate c = get();
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate if(f)
4410Sstevel@tonic-gate i = -i;
4420Sstevel@tonic-gate dp -= i;
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate e = 1.;
4450Sstevel@tonic-gate i = dp;
4460Sstevel@tonic-gate if(i < 0)
4470Sstevel@tonic-gate i = -i;
4480Sstevel@tonic-gate while(i--)
4490Sstevel@tonic-gate e *= 10.;
4500Sstevel@tonic-gate if(dp < 0)
4510Sstevel@tonic-gate d *= e; else
4520Sstevel@tonic-gate d /= e;
4530Sstevel@tonic-gate if(c == '|')
4540Sstevel@tonic-gate return(d/getflt());
4550Sstevel@tonic-gate peekc = c;
4560Sstevel@tonic-gate return(d);
4570Sstevel@tonic-gate }
4580Sstevel@tonic-gate
459*308Srobbin int
get(void)460*308Srobbin get(void)
4610Sstevel@tonic-gate {
462*308Srobbin int c;
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate if(c=peekc) {
4650Sstevel@tonic-gate peekc = 0;
4660Sstevel@tonic-gate return(c);
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate c = getc(inp);
4690Sstevel@tonic-gate if (c == EOF) {
4700Sstevel@tonic-gate if (inp == stdin) {
4710Sstevel@tonic-gate printf("\n");
4720Sstevel@tonic-gate exit(0);
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate return(0);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate return(c);
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate struct table *
hash(char * name)480*308Srobbin hash(char *name)
4810Sstevel@tonic-gate {
482*308Srobbin struct table *tp;
483*308Srobbin char *np;
484*308Srobbin unsigned int h;
4850Sstevel@tonic-gate
4860Sstevel@tonic-gate h = 0;
4870Sstevel@tonic-gate np = name;
4880Sstevel@tonic-gate while(*np)
4890Sstevel@tonic-gate h = h*57 + *np++ - '0';
4900Sstevel@tonic-gate if( ((int)h)<0) h= -(int)h;
4910Sstevel@tonic-gate h %= NTAB;
4920Sstevel@tonic-gate tp = &table[h];
4930Sstevel@tonic-gate l0:
4940Sstevel@tonic-gate if(tp->name == 0)
4950Sstevel@tonic-gate return(tp);
4960Sstevel@tonic-gate if(equal(name, tp->name))
4970Sstevel@tonic-gate return(tp);
4980Sstevel@tonic-gate tp++;
4990Sstevel@tonic-gate if(tp >= &table[NTAB])
5000Sstevel@tonic-gate tp = table;
5010Sstevel@tonic-gate goto l0;
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate
504*308Srobbin void
fperr(int sig)505*308Srobbin fperr(int sig)
5060Sstevel@tonic-gate {
5070Sstevel@tonic-gate
5080Sstevel@tonic-gate signal(8, fperr);
5090Sstevel@tonic-gate fperrc++;
5100Sstevel@tonic-gate }
511