From da8ac7ebf766051245a14da1542634c6ab788457 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 11 Nov 2021 08:31:46 -0800 Subject: chore: updated old copy of mkrunewidth --- .gitignore | 4 +- sys/libutf/runetype-14.0.0.c | 111 ---------------------------------------- sys/libutf/runewidth-14.0.0.c | 71 ------------------------- sys/libutf/vendor/mkrunewidth.c | 71 ++++++++++++++++++++----- 4 files changed, 60 insertions(+), 197 deletions(-) delete mode 100644 sys/libutf/runetype-14.0.0.c delete mode 100644 sys/libutf/runewidth-14.0.0.c diff --git a/.gitignore b/.gitignore index fd958fb..8fb80bc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,10 +17,10 @@ include/libimage.h sys/cc sys/nixos sys/libdraw -sys/libfont sys/libimage sys/libterm -sys/libutf8 + +sys/libutf/*-14.0.0.c sys/cmd/muc sys/cmd/wm diff --git a/sys/libutf/runetype-14.0.0.c b/sys/libutf/runetype-14.0.0.c deleted file mode 100644 index 6f4469d..0000000 --- a/sys/libutf/runetype-14.0.0.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include - -static -rune* -rangesearch(rune c, rune *t, int n, int ne) -{ - rune *p; - int m; - while(n > 1) { - m = n >> 1; - p = t + m*ne; - if(c >= p[0]){ - t = p; - n = n-m; - }else - n = m; - } - if(n && c >= t[0]) - return t; - return 0; -} - -static rune isspace_range[] = { - 0x0009, 0x000d, - 0x0085, 0x0085, -}; - -int -utf8·isspace(rune c) -{ - rune *p; - - p = rangesearch(c, isspace_range, arrlen(isspace_range)/2, 2); - if(p && c >= p[0] && c <= p[1]) - return 1; - return 0; -} - -int -utf8·isdigit(rune c) -{ - rune *p; - - return 0; -} - -int -utf8·isalpha(rune c) -{ - rune *p; - - return 0; -} - -int -utf8·isupper(rune c) -{ - rune *p; - - return 0; -} - -int -utf8·islower(rune c) -{ - rune *p; - - return 0; -} - -int -utf8·istitle(rune c) -{ - rune *p; - - return 0; -} - -int -utf8·ispunct(rune c) -{ - rune *p; - - return 0; -} - -rune -utf8·toupper(rune c) -{ - rune *p; - - return c; -} - -rune -utf8·tolower(rune c) -{ - rune *p; - - return c; -} - -rune -utf8·totitle(rune c) -{ - rune *p; - - return c; -} - diff --git a/sys/libutf/runewidth-14.0.0.c b/sys/libutf/runewidth-14.0.0.c deleted file mode 100644 index 113c35e..0000000 --- a/sys/libutf/runewidth-14.0.0.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include - -static -rune* -rangesearch(rune c, rune *t, int n, int ne) -{ - rune *p; - int m; - while(n > 1) { - m = n >> 1; - p = t + m*ne; - if(c >= p[0]){ - t = p; - n = n-m; - }else - n = m; - } - if(n && c >= t[0]) - return t; - return 0; -} - -static rune width0_range[] = { - 0x2028, 0x2029, -}; - -static int -iswidth0(rune c) -{ - rune *p; - - p = rangesearch(c, width0_range, arrlen(width0_range)/2, 2); - if(p && c >= p[0] && c <= p[1]) - return 1; - return 0; -} - -static rune width1_single[] = { - 0x00ad, -}; - -static int -iswidth1(rune c) -{ - rune *p; - - p = rangesearch(c, width1_single, arrlen(width1_single), 1); - if(p && c == p[0]) - return 1; - return 0; -} - -static int -iswidth2(rune c) -{ - rune *p; - - return 0; -} - - -int -utf8·runewidth(rune c) -{ - if(iswidth1(c)) - return 1; - if(iswidth2(c)) - return 2; - return 0; -} diff --git a/sys/libutf/vendor/mkrunewidth.c b/sys/libutf/vendor/mkrunewidth.c index 43feb5e..14e6973 100644 --- a/sys/libutf/vendor/mkrunewidth.c +++ b/sys/libutf/vendor/mkrunewidth.c @@ -89,6 +89,21 @@ parse_category(char *path) io·close(utf8); } +static +void +coderange(char *field, int *l, int *r) +{ + char *s; + + if(!(s = strstr(field, ".."))) + *l=*r=codepoint(field); + else{ + *s++ = 0, *s++ = 0; + *l=codepoint(field); + *r=codepoint(s); + } +} + static void parse_eawidths(char *path) @@ -96,7 +111,7 @@ parse_eawidths(char *path) int at, w; int l, c, r; io·Stream *utf8; - char *s, *field[2], line[1024]; + char *field[2], line[1024]; utf8 = io·open(path, "r"); while((at=parse(utf8, arrlen(field), field, arrlen(line), line)) != ParseEOF){ @@ -118,13 +133,7 @@ parse_eawidths(char *path) panicf("malformed east asian width class: %s\n", field[1]); } - if(!(s = strstr(field[0], ".."))) - l=codepoint(field[0]), r=l; - else{ - *s++ = 0, *s++ = 0; - l=codepoint(field[0]); - r=codepoint(s); - } + coderange(field[0], &l, &r); for(c=l; c <= r; c++){ /* ensure it only exists in one table */ @@ -136,6 +145,43 @@ parse_eawidths(char *path) io·close(utf8); } +static +void +parse_emoji(char *path) +{ + int at, w; + int l, c, r; + io·Stream *utf8; + char *s, *field[2], line[1024]; + + utf8 = io·open(path, "r"); + while((at=parse(utf8, arrlen(field), field, arrlen(line), line)) != ParseEOF){ + if(at == ParseSkip) + continue; + + /* only override emoji presentation */ + if(!strstr(field[1], "Emoji_Presentation")) + continue; + + /* trim trailing space */ + for(s=field[0]; *s; s++){ + if(*s == ' ') + *s = 0; + } + + coderange(field[0], &l, &r); + + for(c=l; c <= r; c++){ + table.width[0][c] = 0; + table.width[1][c] = 0; + table.width[2][c] = 1; + } + } + + io·close(utf8); +} + +/* output functions */ static void maketable(char *label, char *table, int pairs, int onlyranges) @@ -204,8 +250,6 @@ maketable(char *label, char *table, int pairs, int onlyranges) "\n"); } - - // ----------------------------------------------------------------------- // main point of entry @@ -213,7 +257,7 @@ static void usage(void) { - fprintf(stderr, "usage: mkrunewidth \n"); + fprintf(stderr, "usage: mkrunewidth \n"); exit(1); } @@ -241,11 +285,12 @@ main(int argc, char *argv[]) ARGBEGIN{ }ARGEND; - if(argc != 2) + if(argc != 3) usage(); parse_category(*argv++); - parse_eawidths(*argv); + parse_eawidths(*argv++); + parse_emoji(*argv); /* overrides */ SETW0(0x2028); -- cgit v1.2.1