- mbtowc(NULL, NULL, 0);
-
- charlen = mbtowc(&c, (char *) string, strlen((char *) string));
-
- if (charlen != 1) {
- fprintf(stderr, "We expected a beginning character length "
- "of 1, got %d instead\n", charlen);
- exit(1);
- }
-
- p = (char *) (string + charlen);
-
- charlen = mbtowc(&c, p, strlen(p));
-
- if (charlen != 2) {
- fprintf(stderr, "We expected a multibyte character length "
- "of 2, got %d instead\n", charlen);
- fprintf(stderr, "Are you using a UTF-8 locale?\n");
- exit(1);
+ for (i = 1; i < argc; i++) {
+ if (strncmp(argv[i], "U+", 2) == 0) {
+ /*
+ * We're making a big assumption here that
+ * wchar_t represents a Unicode codepoint.
+ * That technically isn't valid unless the
+ * C compiler defines __STDC_ISO_10646__, but
+ * we're going to assume now that it works.
+ */
+ errno = 0;
+ c = strtoul(argv[i] + 2, NULL, 16);
+ if (errno) {
+ fprintf(stderr, "Codepoint %s invalid\n",
+ argv[i]);
+ continue;
+ }
+ printf("%d\n", wcwidth(c));
+ } else {
+ getwidth(argv[i]);
+ }