-gettext (char *str, int lim)
-{
- int c, i;
-
- while ((c = pol_inchar()) == BLANK || c == TAB)
- ;
- pol_ungetch (c);
-
- for (i = 0; i < lim && (c = pol_inchar()) != EOF && c != NEWLINE; i++)
- str[i] = c;
- pol_ungetch (c);
- str[i] = EOS;
-}
-
-/*----------------------------------------------*/
-/* Get a number for gettok() */
-/*----------------------------------------------*/
-
-static int
-getnumber (
- char str[], /* string to return token in */
- int strsize, /* maximum length of token string */
- double *fnum, /* floating point value of number read */
- int *inum /* integer value of number read */
-)
-{
- int c, sp, isSigned;
- double sign, whole, frac, powerof10, exp, expsign;
-
- sp = 0;
- sign = 1.0;
- isSigned = FALSE; /* TRUE if number prefixed by '+' or '-' */
- *fnum = 0.0;
- *inum = 0;
- str[0] = EOS;
-
- c = pol_inchar();
- if (c == HYPHEN) {
- str[sp++] = c;
- isSigned = TRUE;
- sign = -1.0;
- } else if (c == PLUS) {
- str[sp++] = c;
- isSigned = TRUE;
- sign = 1.0;
- } else if (c == PERIOD) {
- if (type(pol_lookchar()) != DIGIT) {
- str[0] = PERIOD;
- str[1] = EOS;
- return (TT_SPECLCHAR);
- } else
- pol_ungetch (PERIOD);
- } else if (type(c) != DIGIT) {
- pol_ungetch (c);
- return (TT_ERROR);
- } else
- pol_ungetch (c);
-
- if (isSigned == TRUE) {
- c = pol_lookchar();
- if (c == PERIOD) {
- pol_inchar(); /* get period */
- c = pol_lookchar(); /* look at character past period */
- pol_ungetch (PERIOD); /* put back period */
- if (type(c) != DIGIT) {
- str[sp] = EOS;
- return (TT_SPECLCHAR);
- }
- } else if (type (c) != DIGIT) {
- str[sp] = EOS;
- return (TT_SPECLCHAR);
- }
- }
-
- whole = 0.0;
- while (type(c = pol_inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- whole = 10.0 * whole + (c - '0');
- }
- pol_ungetch (c); /* put back non-numeric character */
-
- if (c != PERIOD && tolower(c) != 'e') {
- str[sp] = EOS;
- *fnum = whole * sign;
- if (*fnum < MIN_INT)
- *inum = MIN_INT;
- else if (*fnum > MAX_INT)
- *inum = MAX_INT;
- else
- *inum = (int) *fnum;
- return (TT_INT);
- }
-
- if (pol_lookchar() == PERIOD) {
- pol_inchar();
- if (sp < strsize)
- str[sp++] = PERIOD;
- }
-
- frac = 0.0;
- powerof10 = 10.0;
-
- while (type(c = pol_inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- frac += (double) (c - '0') / powerof10;
- powerof10 *= 10.0;
- }
- pol_ungetch (c);
-
- exp = 0.0;
- expsign = 1.0;
- c = pol_inchar();
- if (tolower(c) != 'e')
- pol_ungetch (c);
- else {
- if (sp < strsize)
- str[sp++] = c;
- if ((c = pol_inchar()) == PLUS) {
- if (sp < strsize)
- str[sp++] = c;
- expsign = 1.0;
- } else if (c == HYPHEN) {
- if (sp < strsize)
- str[sp++] = c;
- expsign = -1.0;
- } else if (type(c) != DIGIT) {
- --sp; /* erase 'e' */
- pol_ungetch (c);
- pol_ungetch ('e');
- goto getnumexit;
- } else
- pol_ungetch(c);
-
- exp = 0;
- while (type(c = pol_inchar()) == DIGIT) {
- if (sp < strsize)
- str[sp++] = c;
- exp = 10 * exp + (c - '0');
- }
- pol_ungetch (c);
- }
-
-getnumexit:
- str[sp] = EOS;
- *fnum = sign * (whole + frac) * pow (10.0, expsign * exp);
- if (*fnum < MIN_INT)
- *inum = MIN_INT;
- else if (*fnum > MAX_INT)
- *inum = MAX_INT;
- else
- *inum = (int) *fnum;
- return (TT_REAL);
-}
-
-static void
-eatline (void)