USG_PG3/usr/source/portc2/scan2.c
_Iint (iptr, length, numbase, longf)
int *iptr, length;
{
int minus, numdig;
int n, *lptr;
extern int _Isfil, (*_Iungc)(), (*_Igetc)();
int c, dval;
n = minus = numdig = 0;
switch ((c=_Inxch()))
{
case '-': minus = 1;
case '+': numdig++;
if (_Idigt( (*_Iungc)((*_Igetc)(_Isfil),_Isfil), numbase) < 0)
{
(*_Iungc)(c, _Isfil);
return(0);
}
break;
case -1: /* eof */ return(-2);
default: (*_Iungc)(c,_Isfil);
}
while ((dval=_Idigt(c=((*_Igetc)(_Isfil)), numbase ) ) >= 0 && numdig++ < length)
{
switch(numbase)
{
case 8:
n = (n<<3) | dval; break;
case 16:
n = (n<<4) | dval; break;
default:
n = n*numbase + dval;
}
}
(*_Iungc)(c,_Isfil);
if (numdig == 0)
return (0);
if (iptr == 0)
return (-1);
if (minus) n = -n;
if (longf)
{
lptr= iptr;
*lptr = n;
}
else
*iptr = n;
return (1);
}
_Idigt (x, base)
{
switch (x)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
return(x-'0');
case '8':
case '9':
if (base > 8)
return(x - '0');
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base >10)
return(x - 'a' + 10);
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
if (base > 10)
return(x-'A' + 10);
}
return(-1);
}
_Ilong (dptr, length)
double *dptr;
int length;
{
char temp[75];
int _Inodg(), kk;
double x;
double atof();
extern int (*_Iungc)(), _Isfil;
extern int _Isfil, (*_Iungc)();
if ((kk = _Inxch()) < 0)
return (-2);
(*_Iungc)(kk,_Isfil);
if ((kk = _Isstr(temp, length, _Inodg)) <= 0)
return (kk);
x = atof(temp);
if (dptr == 0)
return (-1);
*dptr = x;
return (1);
}
_Isstr (sptr, length, stopf)
char *sptr;
int length, (*stopf)();
{
int ch, initlen, _Inxch();
extern int _Isfil, (*_Igetc)(), (*_Iungc)(), _Iestr();
initlen = length;
if (stopf == _Iestr)
{
if ((ch=_Inxch()) < 0)
return (-2);
(*_Iungc)(ch,_Isfil);
}
while (!((*stopf)(ch=(*_Igetc)(_Isfil))) && length-- > 0)
if (sptr != 0)
*(sptr++) = ch;
if (ch >= 0)
(*_Iungc)(ch,_Isfil);
if (length == initlen)
return (0);
if (sptr == 0)
return (-1);
*sptr = '\0';
return (1);
}
_Iestr (c)
char c;
{
if (_Ispce(c)) return (1);
if (c == '\0') return (1);
return (0);
}