X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/93b377a7af2842316c5bf42108437da0327ff55f..a3970d298495e0b6358541b2c8dd0ce6c32fe43c:/test/getcwidth.c?ds=sidebyside diff --git a/test/getcwidth.c b/test/getcwidth.c index d389cb48..165f12ab 100644 --- a/test/getcwidth.c +++ b/test/getcwidth.c @@ -1,5 +1,4 @@ -/* - * getcwidth - Get the OS's idea of the width of Unicode codepoints +/* getcwidth - Get the OS's idea of the width of Unicode codepoints * * This code is Copyright (c) 2013, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -103,11 +102,13 @@ static void usage(char *argv0) { fprintf(stderr, "Usage: %s [--dump]\n", argv0); + fprintf(stderr, " %s [--ctype]\n", argv0); fprintf(stderr, " %s U+XXXX [...]\n", argv0); fprintf(stderr, " %s utf-8-sequence [...]\n", argv0); fprintf(stderr, "Returns the column width of a Unicode codepoint " "or UTF-8 character sequence\n"); fprintf(stderr, "\t--dump\tDump complete width table\n"); + fprintf(stderr, "\t--ctype\tPrint wctype(3) table.\n"); exit(1); } @@ -161,13 +162,18 @@ typedef struct { static unicode_range range[] = { /* https://en.wikipedia.org/wiki/Unicode#Code_point_planes_and_blocks */ - { L'\x0000', L'\xffff' }, + { L'\x0000', L'\xff' }, +#if WCHAR_MAX >= 0xffff + { L'\x0100', L'\xffff' }, +#if WCHAR_MAX >= 0xfffff { L'\x10000', L'\x14fff' }, { L'\x16000', L'\x18fff' }, { L'\x1b000', L'\x1bfff' }, { L'\x1d000', L'\x1ffff' }, { L'\x20000', L'\x2ffff' }, { L'\xe0000', L'\xe0fff' }, +#endif +#endif { L'\0', L'\0' }, /* Terminates list. */ }; @@ -195,9 +201,12 @@ dumpwidth(void) start = wc; lastwidth = width; } - if (wc == r->max) + if (wc == r->max) { printf("%04lX - %04lX = %d\n", (unsigned long)start, (unsigned long int)wc, lastwidth); + /* wchar_t can be a 16-bit unsigned short. */ + break; + } } } } @@ -224,6 +233,10 @@ dumpctype(void) iswpunct(wc) ? '@' : '-', iswspace(wc) ? 's' : '-', iswblank(wc) ? 'b' : '-'); + + if (wc == r->max) + /* wchar_t can be a 16-bit unsigned short. */ + break; } } #endif /* MULTIBYTE_SUPPORT */