+typedef struct {
+ wchar_t min, max;
+} unicode_range;
+
+static unicode_range range[] = {
+ /* https://en.wikipedia.org/wiki/Unicode#Code_point_planes_and_blocks */
+ { 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. */
+};
+
+static void
+dumpwidth(void)
+{
+ unicode_range *r;
+ int first;
+ wchar_t wc, start;
+ int width, lastwidth;
+
+ for (r = range; r->max; r++) {
+ first = 1;
+ for (wc = r->min; wc <= r->max; wc++) {
+ width = wcwidth(wc);
+ if (first) {
+ start = wc;
+ lastwidth = width;
+ first = 0;
+ continue;
+ }
+ if (width != lastwidth) {
+ printf("%04lX - %04lX = %d\n", (unsigned long)start,
+ (unsigned long int)wc - 1, lastwidth);
+ start = wc;
+ lastwidth = width;
+ }
+ 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;
+ }
+ }
+ }
+}
+
+static void
+dumpctype(void)
+{
+ unicode_range *r;
+ wchar_t wc;
+
+ for (r = range; r->max; r++) {
+ for (wc = r->min; wc <= r->max; wc++) {
+ printf("%6x %2d %c%c%c%c%c%c%c%c%c%c%c%c\n",
+ wc, wcwidth(wc),
+ iswcntrl(wc) ? 'c' : '-',
+ iswprint(wc) ? 'p' : '-',
+ iswgraph(wc) ? 'g' : '-',
+ iswalpha(wc) ? 'a' : '-',
+ iswupper(wc) ? 'u' : '-',
+ iswlower(wc) ? 'l' : '-',
+ iswdigit(wc) ? 'd' : '-',
+ iswxdigit(wc) ? 'x' : '-',
+ iswalnum(wc) ? 'N' : '-',
+ iswpunct(wc) ? '@' : '-',
+ iswspace(wc) ? 's' : '-',
+ iswblank(wc) ? 'b' : '-');
+
+ if (wc == r->max)
+ /* wchar_t can be a 16-bit unsigned short. */
+ break;
+ }
+ }