diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-12-05 15:17:44 -0800 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-12-05 15:17:44 -0800 |
commit | b48327d357e0818d1a6ae2a064cfa7d1567e1242 (patch) | |
tree | 4677f228a9846937a7ec71c72a1ab63ab69d68ab /src/base/utf/vendor | |
parent | c200dd832789afa298ba45e0b9efdec96c0e92cc (diff) |
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.
Diffstat (limited to 'src/base/utf/vendor')
-rw-r--r-- | src/base/utf/vendor/common.c | 30 | ||||
-rw-r--r-- | src/base/utf/vendor/common.h | 6 | ||||
-rw-r--r-- | src/base/utf/vendor/mkrunetype.c | 18 | ||||
-rw-r--r-- | src/base/utf/vendor/mkrunewidth.c | 21 |
4 files changed, 47 insertions, 28 deletions
diff --git a/src/base/utf/vendor/common.c b/src/base/utf/vendor/common.c index c35d022..37ccca3 100644 --- a/src/base/utf/vendor/common.c +++ b/src/base/utf/vendor/common.c @@ -1,5 +1,19 @@ #include "common.h" +int +fatal(char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + + fprintf(stderr,"panic: "); + vfprintf(stderr, fmt, args); + fprintf(stderr,"\n"); + + va_end(args); + rt·exit(1); +} + // ----------------------------------------------------------------------- // input functions @@ -29,7 +43,7 @@ parse(io·Buffer *io, int nfield, char field[][FieldLen]) strcpy(field[n++], b); if(n != nfield) - panicf("expected %d number of fields, got %d: %s", nfield, n, b); + fatal("expected %d number of fields, got %d: %s", nfield, n, b); return ParseOK; } @@ -47,7 +61,7 @@ codepoint(char *s) else if(b >= 'A' && b <= 'F') c += b - 'A' + 10; else - panicf("bad codepoint char '%c'", b); + fatal("bad codepoint char '%c'", b); } return c; @@ -64,23 +78,23 @@ codepointrange(io·Buffer *utf8, char field[NumFields][FieldLen], int *start, i c = codepoint(field[Fcode]); if(c >= NumRunes) - panicf("unexpected large codepoint %x", c); + fatal("unexpected large codepoint %x", c); if(c <= e) - panicf("bad code sequence: %x then %x", e, c); + fatal("bad code sequence: %x then %x", e, c); e = c; if(strstr(field[Fname], ", First>") != nil){ if(!parse(utf8, arrlen(other), other)) - panicf("range start at end of file"); + fatal("range start at end of file"); if(strstr(other[Fname], ", Last>") == nil) - panicf("range start not followed by range end"); + fatal("range start not followed by range end"); e = codepoint(other[Fcode]); if(e <= c) - panicf("bad code sequence: %x then %x", c, e); + fatal("bad code sequence: %x then %x", c, e); if(strcmp(field[Fcategory], other[Fcategory]) != 0) - panicf("range with mismatched category"); + fatal("range with mismatched category"); } *start = c; diff --git a/src/base/utf/vendor/common.h b/src/base/utf/vendor/common.h index 95d7eaf..566fe68 100644 --- a/src/base/utf/vendor/common.h +++ b/src/base/utf/vendor/common.h @@ -3,6 +3,10 @@ #include <u.h> #include <base.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> + enum { // Fields inside UnicodeData.txt @@ -44,3 +48,5 @@ void putsearch(void); int putrange(char *ident, char *prop, int force); int putpair(char *ident, char *prop); int putsingle(char *ident, char *prop); + +int fatal(char *fmt, ...); diff --git a/src/base/utf/vendor/mkrunetype.c b/src/base/utf/vendor/mkrunetype.c index 3d75ce8..dd6e2c7 100644 --- a/src/base/utf/vendor/mkrunetype.c +++ b/src/base/utf/vendor/mkrunetype.c @@ -39,7 +39,7 @@ isrange(char *label, char *prop, int force) { char ident[128]; if(snprintf(ident, arrlen(ident), "is%s_range", label) == arrlen(ident)) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); return putrange(ident, prop, force); } @@ -49,7 +49,7 @@ ispair(char *label, char *prop) { char ident[128]; if(snprintf(ident, arrlen(ident), "is%s_pair", label) == arrlen(ident)) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); return putpair(ident, prop); } @@ -59,7 +59,7 @@ issingle(char *label, char *prop) { char ident[128]; if(snprintf(ident, arrlen(ident), "is%s_single", label) == arrlen(ident)) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); return putsingle(ident, prop); } @@ -125,7 +125,7 @@ torange(char *label, int *index, int force) d = DELTA(index[l], l); if(d != (rune)d) - panicf("bad map delta %d", d); + fatal("bad map delta %d", d); for(r = l+1; r < NumRunes; r++){ if(DELTA(index[r], r) != d) @@ -162,7 +162,7 @@ topair(char *label, int *index) d = DELTA(index[l], l); if(d != (rune)d) - panicf("bad delta %d", d); + fatal("bad delta %d", d); for(r = l+2; r < NumRunes; r += 2){ if(DELTA(index[r], r) != d) @@ -198,7 +198,7 @@ tosingle(char *label, int *index) d = DELTA(index[i], i); if(d != (rune)d) - panicf("bad map delta %d", d); + fatal("bad map delta %d", d); if(!start){ printf("static rune to%s_single[] = {\n", label); @@ -268,7 +268,7 @@ static void usage(void) { fprintf(stderr, "usage: mkrunetype <UnicodeData.txt>\n"); - exit(1); + rt·exit(1); } int @@ -285,7 +285,7 @@ main(int argc, char *argv[]) usage(); if((err=io·open(argv[0], sys·ORead, &utf8))) - panicf("can't open %s: %d: %s\n", argv[0], err, strerror(err)); + fatal("can't open %s: %d: %s\n", argv[0], err, strerror(err)); /* by default each character maps to itself */ for(i = 0; i < NumRunes; i++) { @@ -350,7 +350,7 @@ main(int argc, char *argv[]) break; default: badproperty: - panicf("unrecognized category '%s'", prop); + fatal("unrecognized category '%s'", prop); } /* grab transformations */ if(*field[Fupper]) diff --git a/src/base/utf/vendor/mkrunewidth.c b/src/base/utf/vendor/mkrunewidth.c index c911b66..7025744 100644 --- a/src/base/utf/vendor/mkrunewidth.c +++ b/src/base/utf/vendor/mkrunewidth.c @@ -38,7 +38,7 @@ parse_category(char *path) char *prop, field[NumFields][FieldLen]; if(io·open(path, sys·ORead, &utf8)) - panicf("can't open %s\n", path); + fatal("can't open %s\n", path); // NOTE: we don't check for comments here ec = -1; @@ -111,7 +111,7 @@ parse_eawidths(char *path) char field[2][FieldLen]; if(io·open(path, sys·ORead, &utf8)) - panicf("can't open %s\n", path); + fatal("can't open %s\n", path); while((at=parse(&utf8, arrlen(field), field)) != ParseEOF){ if(at == ParseSkip) @@ -129,7 +129,7 @@ parse_eawidths(char *path) case 'F': w = 2; break; default: - panicf("malformed east asian width class: %s\n", field[1]); + fatal("malformed east asian width class: %s\n", field[1]); } coderange(field[0], &l, &r); @@ -153,7 +153,7 @@ parse_emoji(char *path) char *s, field[2][FieldLen]; if(io·open(path, sys·ORead, &utf8)) - panicf("can't open %s\n", path); + fatal("can't open %s\n", path); while((at=parse(&utf8, arrlen(field), field)) != ParseEOF){ if(at == ParseSkip) @@ -198,17 +198,17 @@ maketable(char *label, char *table, int pairs, int onlyranges) /* ranges */ if(snprintf(ident[Irange], arrlen(ident[Irange]), "%s_range", label) == arrlen(ident[Irange])) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); r = putrange(ident[Irange], table, onlyranges); if(!onlyranges && pairs){ if(snprintf(ident[Ipair], arrlen(ident[Ipair]), "%s_pair", label) == arrlen(ident[Ipair])) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); p = putpair(ident[Ipair], table); } if(!onlyranges){ if(snprintf(ident[Isingle], arrlen(ident[Isingle]), "%s_single", label) == arrlen(ident[Isingle])) - panicf("out of identifier space\n"); + fatal("out of identifier space\n"); s = putsingle(ident[Isingle], table); } @@ -253,12 +253,11 @@ maketable(char *label, char *table, int pairs, int onlyranges) // ----------------------------------------------------------------------- // main point of entry -static -void +static void usage(void) { fprintf(stderr, "usage: mkrunewidth <UnicodeData.txt> <EastAsianWidth.txt> <EmojiData.txt>\n"); - exit(1); + rt·exit(1); } #define SETW0(c) \ @@ -301,7 +300,7 @@ main(int argc, char *argv[]) /* simple checking */ for(c=0; c<NumRunes; c++){ if(table.width[0][c] + table.width[1][c] + table.width[2][c] > 1) - panicf("improper table state"); + fatal("improper table state"); } putsearch(); |