--- tgif-QPL-4.1.45/text.c.org	2009-09-08 21:01:51.000000000 +0900
+++ tgif-QPL-4.1.45/text.c	2009-09-08 21:11:44.000000000 +0900
@@ -18,6 +18,9 @@
  * @(#)$Header: /mm2/home/cvs/bc-src/tgif/text.c,v 1.9 2006/06/06 16:38:51 william Exp $
  */
 
+#include <iconv.h>
+#include <string.h>
+
 #define _INCLUDE_FROM_TEXT_C_
 
 #include "tgifdefs.h"
@@ -3420,6 +3423,9 @@
 
 static XComposeStatus c_stat;
 
+static char *locale = NULL;
+static iconv_t convd = NULL;
+
 void DrawText(input)
    XEvent *input;
 {
@@ -3487,6 +3493,31 @@
       if (HandleFunctionKey(key_sym)) {
          return;
       }
+      if(locale == NULL){
+         locale = setlocale(LC_CTYPE, NULL);
+         if(locale == NULL) locale = "C";
+         if(strncmp(locale, "ja_JP.", 6) == 0 &&
+            (strncasecmp(locale+6, "utf8", 4) == 0 ||
+             strncasecmp(locale+6, "utf-8", 5) == 0)){
+            convd = iconv_open("EUC-JP", "utf-8");
+         }
+      }
+      if(convd != NULL){
+         int ret;
+         char s2[80];
+         char *in_buf, *out_buf;
+         int in_size, out_size;
+         iconv(convd, NULL, NULL, NULL, NULL);
+         in_buf = s;
+         in_size = strlen(s);
+         out_buf = s2;
+         out_size = sizeof(s2) - 1;
+         ret = iconv(convd, &in_buf, &in_size, &out_buf, &out_size);
+         if(ret >= 0){
+            memcpy(s, s2, sizeof(s2)-1 - out_size);
+            s[sizeof(s2)-1 - out_size] = 0;
+         }
+      }
       HandleTextFromBuffer(key_ev, s, key_sym, has_ch);
    }
 }
