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
abtol (char const **p, int base)
{
char const *s = *p;
char const *s = p[0];
int i = 0;
int sign_p = 0;
if (!base)
if (base == 0)
base = 10;
while (isspace (*s))
s++;
if (*s && *s == '+')
s++;
if (*s && *s == '-')
while (isspace (s[0]) != 0)
s = s + 1;
if (s[0] != 0 && s[0] == '+')
s = s + 1;
if (s[0] != 0 && s[0] == '-')
{
sign_p = 1;
s++;
s = s + 1;
}
while (isnumber (*s, base))
while (isnumber (s[0], base) != 0)
{
i *= base;
int m = *s > '9' ? 'a' - 10 : '0';
i += *s - m;
s++;
i = i * base;
int m = '0';
if (s[0] > '9')
m = 'a' - 10;
i = i + s[0] - m;
s = s + 1;
}
*p = s;
return sign_p ? -i : i;
p[0] = s;
if (sign_p != 0)
return -i;
return i;
}