mescc: Mes C Library: Prepare for M2-Planet: abtol.

* lib/mes/abtol.c: Rewrite C-constructs not supported by M2-Planet.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-05-17 19:27:53 +02:00
parent 902ed2524a
commit 11d6a9679d
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -24,27 +24,32 @@
long long
abtol (char const **p, int base) abtol (char const **p, int base)
{ {
char const *s = *p; char const *s = p[0];
int i = 0; int i = 0;
int sign_p = 0; int sign_p = 0;
if (!base) if (base == 0)
base = 10; base = 10;
while (isspace (*s)) while (isspace (s[0]) != 0)
s++; s = s + 1;
if (*s && *s == '+') if (s[0] != 0 && s[0] == '+')
s++; s = s + 1;
if (*s && *s == '-') if (s[0] != 0 && s[0] == '-')
{ {
sign_p = 1; sign_p = 1;
s++; s = s + 1;
} }
while (isnumber (*s, base)) while (isnumber (s[0], base) != 0)
{ {
i *= base; i = i * base;
int m = *s > '9' ? 'a' - 10 : '0'; int m = '0';
i += *s - m; if (s[0] > '9')
s++; m = 'a' - 10;
i = i + s[0] - m;
s = s + 1;
} }
*p = s; p[0] = s;
return sign_p ? -i : i; if (sign_p != 0)
return -i;
return i;
} }