Silly of me to overlook it: another obvious way you might like to master git-svn
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 19 Jul 2012 17:03:15 +0000 (17:03 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 19 Jul 2012 17:03:15 +0000 (17:03 +0000)
specify characters to 'confuse' is to just put them on the command
line in the system multibyte encoding! In a UTF-8 terminal environment
this may very well be the easiest thing.

git-svn-id: svn://svn.tartarus.org/sgt/charset@9584 cda61777-01e9-0310-a592-d414129be87e

confuse.c

index 207c5b9..21005cf 100644 (file)
--- a/confuse.c
+++ b/confuse.c
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <locale.h>
 
 #include "charset.h"
 
@@ -24,6 +25,8 @@ int main(int argc, char **argv)
     int i, j, k, cs;
     const char *sep;
 
+    setlocale(LC_ALL, "");
+
     chars = malloc(argc * sizeof(wchar_t));
     if (!chars) {
         fprintf(stderr, "out of memory\n");
@@ -37,6 +40,7 @@ int main(int argc, char **argv)
         char *orig = p;
         char *end;
         int base = 16, semi_ok = 0;
+        wchar_t ch;
 
         if ((p[0] == 'U' || p[0] == 'u') &&
             (p[1] == '-' || p[1] == '+')) {
@@ -50,6 +54,9 @@ int main(int argc, char **argv)
             else
                 base = 10;
             semi_ok = 1;
+        } else if (mbtowc(&ch, p, strlen(p)) == strlen(p)) {
+            chars[nchars++] = ch;
+            continue;
         }
 
         chars[nchars++] = strtoul(p, &end, base);