From 11d6a9679df1ecb5581d07d2cb0b82e70d6ba0a6 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Sun, 17 May 2020 19:27:53 +0200 Subject: [PATCH] mescc: Mes C Library: Prepare for M2-Planet: abtol. * lib/mes/abtol.c: Rewrite C-constructs not supported by M2-Planet. --- lib/mes/abtol.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/mes/abtol.c b/lib/mes/abtol.c index 44a474b1..df868225 100644 --- a/lib/mes/abtol.c +++ b/lib/mes/abtol.c @@ -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; }