From: Alan Cox Date: Mon, 20 Jun 2016 18:58:17 +0000 (+0100) Subject: a64l: some of the crap in a libc is amazing X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=170f019f1387d97b57b8f2881c06ceb3d4cf99b5;p=FUZIX.git a64l: some of the crap in a libc is amazing --- diff --git a/Library/libs/a64l.c b/Library/libs/a64l.c new file mode 100644 index 00000000..a75c0158 --- /dev/null +++ b/Library/libs/a64l.c @@ -0,0 +1,20 @@ +#include + +long a64l(const char *s) +{ + uint32_t n = 0; + const char *se = s + 6; + while(*s && s < se) { + n <<= 6; + if (*s == '.') + n++; + if (*s >= '0' && *s <= '9') + n += *s - '0' + 2; + else if (*s >= 'A' && *s <= 'Z') + n += *s - 'A' + 12; + else + n += *s - 'a' + 38; + s++; + } + return n; +} diff --git a/Library/libs/l64a.c b/Library/libs/l64a.c new file mode 100644 index 00000000..d7f7b3b1 --- /dev/null +++ b/Library/libs/l64a.c @@ -0,0 +1,20 @@ +#include + +static char buf[7]; + +static char str[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +char *l64a(long l) +{ + uint32_t n = l; + char *p = buf; + + while(n && p < buf + 6) { + *p++ = str[n & 63]; + n >>= 6; + } + *p = 0; + return buf; +} + + \ No newline at end of file