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:
parent
902ed2524a
commit
11d6a9679d
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue