|
|
1.1 ! root 1: # include <sccs.h> ! 2: ! 3: SCCSID(@(#)IIatoi.c 7.1 2/5/81) ! 4: ! 5: ! 6: /* ! 7: ** IIatoi() ! 8: ** ASCII CHARACTER STRING TO 16-BIT INTEGER CONVERSION ! 9: ** ! 10: ** `a' is a pointer to the character string, `i' is a ! 11: ** pointer to the word which is to contain the result. ! 12: ** ! 13: ** The return value of the function is: ! 14: ** zero: succesful conversion; `i' contains the integer ! 15: ** +1: numeric overflow; `i' is unchanged ! 16: ** -1: syntax error; `i' is unchanged ! 17: ** ! 18: ** A valid string is of the form: ! 19: ** <space>* [+-] <space>* <digit>* <space>* ! 20: ** ! 21: ** Eric's utility routine. ! 22: ** ! 23: */ ! 24: ! 25: IIatoi(a1, i) ! 26: char *a1; ! 27: int *i; ! 28: { ! 29: int sign; /* flag to indicate the sign */ ! 30: register int x; /* holds the integer being formed */ ! 31: register char c; ! 32: register char *a; ! 33: ! 34: a = a1; ! 35: sign = 0; ! 36: /* skip leading blanks */ ! 37: while (*a == ' ') ! 38: a++; ! 39: /* check for sign */ ! 40: switch (*a) ! 41: { ! 42: ! 43: case '-': ! 44: sign = -1; ! 45: ! 46: case '+': ! 47: while (*++a == ' '); ! 48: } ! 49: ! 50: /* at this point everything had better be numeric */ ! 51: x = 0; ! 52: while ((c = *a) <= '9' && c >= '0') ! 53: { ! 54: if (x > 3276 || (x == 3276 && c > '7')) ! 55: return (1); /* overflow */ ! 56: x = x * 10 + c - '0'; ! 57: a++; ! 58: } ! 59: ! 60: /* eaten all the numerics; better be all blanks */ ! 61: while (c = *a++) ! 62: if(c != ' ') /* syntax error */ ! 63: return (-1); ! 64: *i = sign ? -x : x; ! 65: return (0); /* successful termination */ ! 66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.