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 /sys/libutf/vendor/mkrunewidth.c | |
parent | d584897456ef419f066be962f2c2628eeaef75bc (diff) |
chore: updated old copy of mkrunewidth
Diffstat (limited to 'sys/libutf/vendor/mkrunewidth.c')
-rw-r--r-- | sys/libutf/vendor/mkrunewidth.c | 71 |
1 files changed, 58 insertions, 13 deletions
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); |