diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:31:46 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:31:46 -0800 |
commit | da8ac7ebf766051245a14da1542634c6ab788457 (patch) | |
tree | 85566a20e7525d4d343f432d4282cd09f95de487 | |
parent | d584897456ef419f066be962f2c2628eeaef75bc (diff) |
chore: updated old copy of mkrunewidth
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | sys/libutf/runetype-14.0.0.c | 111 | ||||
-rw-r--r-- | sys/libutf/runewidth-14.0.0.c | 71 | ||||
-rw-r--r-- | sys/libutf/vendor/mkrunewidth.c | 71 |
4 files changed, 60 insertions, 197 deletions
@@ -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 <u.h> -#include <libutf.h> - -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 <u.h> -#include <libutf.h> - -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 @@ -91,12 +91,27 @@ parse_category(char *path) 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) { 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 */ @@ -138,6 +147,43 @@ parse_eawidths(char *path) 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) { int r, p=0, s=0; @@ -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 <UnicodeData.txt> <EastAsianWidth.txt>\n"); + fprintf(stderr, "usage: mkrunewidth <UnicodeData.txt> <EastAsianWidth.txt> <EmojiData.txt>\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); |