From b48327d357e0818d1a6ae2a064cfa7d1567e1242 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 5 Dec 2021 15:17:44 -0800 Subject: feat(huge): huge refactor (in progress). Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions. --- src/base/fmt/buffer.c | 2 +- src/base/fmt/do.c | 10 +++++----- src/base/fmt/float.c | 14 +++++++------- src/base/fmt/open.c | 2 +- src/base/fmt/test.c | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/base/fmt') diff --git a/src/base/fmt/buffer.c b/src/base/fmt/buffer.c index e039577..3018ccc 100644 --- a/src/base/fmt/buffer.c +++ b/src/base/fmt/buffer.c @@ -33,7 +33,7 @@ fmt·make(mem·Allocator mem, void *heap, fmt·State *io) { int n; - memset(io, 0, sizeof(*io)); + mem·set(io, sizeof(*io), 0); n = 32; io->buffer.beg = io->buffer.cur = mem.alloc(heap, n, 1); diff --git a/src/base/fmt/do.c b/src/base/fmt/do.c index a990ab0..581ab1b 100644 --- a/src/base/fmt/do.c +++ b/src/base/fmt/do.c @@ -291,7 +291,7 @@ copystring(fmt·State *io, char *s) return copy(io, s, i, j); } - return copy(io, s, strlen(s), utf8·len(s)); + return copy(io, s, str·len(s), utf8·len(s)); } static int @@ -495,7 +495,7 @@ fmtint(fmt·State *io) digits = 0; excess = 0; runes = utf8·len(thousands); - bytes = strlen(thousands); + bytes = str·len(thousands); #define PARSE(VALUE) \ while((VALUE)){ \ @@ -509,7 +509,7 @@ fmtint(fmt·State *io) n += runes; \ excess += bytes - runes; \ p -= bytes; \ - memmove(p+1, thousands, bytes); \ + mem·move(p+1, bytes, thousands); \ } \ *p-- = conv[i]; \ n++; \ @@ -537,7 +537,7 @@ fmtint(fmt·State *io) n += runes; excess += bytes - runes; p -= bytes; - memmove(p+1, thousands, bytes); + mem·move(p+1, bytes, thousands); } *p-- = '0'; } @@ -565,7 +565,7 @@ fmtint(fmt·State *io) n += runes; excess += bytes - runes; p -= bytes; - memmove(p+1, thousands, bytes); + mem·move(p+1, bytes, thousands); } *p-- = '0'; } diff --git a/src/base/fmt/float.c b/src/base/fmt/float.c index 8a42dfc..ba2637e 100644 --- a/src/base/fmt/float.c +++ b/src/base/fmt/float.c @@ -154,7 +154,7 @@ sub1(char *a, int n) * can't get here. the number a is always normalized * so that it has a nonzero first digit. */ - abort(); + rt·exit(1); } // ----------------------------------------------------------------------- @@ -322,7 +322,7 @@ divascii(char *a, int *na, int *dp, int *bp) d = (int)(arrlen(tab1))-1; t = tab1 + d; b = t->bp; - if(memcmp(a, t->cmp, t->siz) > 0) + if(mem·compare(a, t->siz, t->cmp) > 0) d--; *dp -= d; *bp += b; @@ -382,7 +382,7 @@ mulascii(char *a, int *na, int *dp, int *bp) d = (int)(arrlen(tab2))-1; t = tab2 + d; b = t->bp; - if(memcmp(a, t->cmp, t->siz) < 0) + if(mem·compare(a, t->siz, t->cmp) < 0) d--; p = a + *na; *bp -= b; @@ -398,8 +398,8 @@ cmp(char *a, char *b) while((c1 = *b++) != '\0') { c2 = *a++; - if(isupper(c2)) - c2 = tolower(c2); + if(utf8·isupper(c2)) + c2 = utf8·tolower(c2); if(c1 != c2) return 1; } @@ -824,7 +824,7 @@ fmtfloat(fmt·State *io) end = special[0+ucase]; special: io->flag = f & (fmt·Width|fmt·Left); - return copy(io, end, strlen(end), strlen(end)); + return copy(io, end, str·len(end), str·len(end)); } if(isInf(val, 1)) { end = special[2+ucase]; @@ -910,7 +910,7 @@ fmtfloat(fmt·State *io) z2 = 0; } fmtexp(suf, e, ucase); - nsuf = strlen(suf); + nsuf = str·len(suf); break; casef: diff --git a/src/base/fmt/open.c b/src/base/fmt/open.c index 2020a2a..58c5ccc 100644 --- a/src/base/fmt/open.c +++ b/src/base/fmt/open.c @@ -8,7 +8,7 @@ flush(fmt·State *io) fd = (uintptr)io->file; n = io->buffer.cur - io->buffer.beg; - if(n && sys·write(fd, n, io->buffer.beg, &n)) + if(n && sys·write(fd, io->buffer.beg, n, &n)) return -1; io->buffer.cur = io->buffer.beg; diff --git a/src/base/fmt/test.c b/src/base/fmt/test.c index 3f7f070..0d46980 100644 --- a/src/base/fmt/test.c +++ b/src/base/fmt/test.c @@ -19,7 +19,7 @@ static void saygoodbye(void *arg) { intptr n; - sys·write(1, 9, "goodbye\n", &n); + sys·write(1, "goodbye\n", 9, &n); } int -- cgit v1.2.1