Index: configh.in
===================================================================
--- configh.in	(revision 6655)
+++ configh.in	(working copy)
@@ -285,6 +285,12 @@
 #undef HAVE_PTHREAD_H
 
 /*
+ * Do we have iconv?
+ */
+
+#undef HAVE_LIBC_ICONV
+
+/*
  * Do we have the ALSA library?
  */
 
Index: src/xutf8/test2.c
===================================================================
--- src/xutf8/test2.c	(revision 6655)
+++ src/xutf8/test2.c	(working copy)
@@ -62,7 +62,7 @@
 export LANG=ja_JP; export XMODIFIERS="@im=htt"
 export LANG=ko_KR; export XMODIFIERS="@im=ami"
 export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_TW"
-export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_CN"
+export LANG=zh_CN; export XMODIFIERS="@im=xcin-zh_CN"
 export LANG=fr_FR.UTF-8; export XMODIFIERS="@im=interxim"
 
 export LD_PRELOAD="/usr/src/x11/xc/exports/lib/libX11.so /usr/src/x11/xc/exports/lib/libxlcDef.so.2 /usr/src/x11/xc/exports/lib/libxlibi18n.so.2 /usr/src/x11/xc/exports/lib/libxlocale.so.2 /usr/src/x11/xc/exports/lib/libxomGeneric.so.2 /usr/src/x11/xc/exports/lib/libximcp.so.2"
Index: src/xutf8/ucs2fontmap.c
===================================================================
--- src/xutf8/ucs2fontmap.c	(revision 6655)
+++ src/xutf8/ucs2fontmap.c	(working copy)
@@ -49,6 +49,33 @@
 } Summary16;
 
 
+#if HAVE_LIBC_ICONV
+#include <iconv.h>
+static int
+iconv_wctomb(const char* enc, char* r, ucs4_t ucs, int n)
+{
+  iconv_t ic;
+  char*   i_ptr;
+  size_t  i_left;
+  char*   o_ptr;
+  size_t  o_left;
+
+  // Setup parameters for iconv()
+  i_left = sizeof(ucs);
+  i_ptr  = (char*)&ucs;
+  o_left = n;
+  o_ptr  = r;
+
+  // Perform conversion now
+  ic = iconv_open("UCS-4", enc);
+  if (!ic) return 0;
+  iconv(ic, &i_ptr, &i_left, &o_ptr, &o_left);
+  iconv_close(ic);
+
+  // Return how many bytes resulted from conversion
+  return n - o_left;
+}
+#else
 #include "lcUniConv/big5.h"
 #include "lcUniConv/gb2312.h"
 #include "lcUniConv/iso8859_10.h"
@@ -71,6 +98,7 @@
 #include "lcUniConv/koi8_u.h"
 #include "lcUniConv/ksc5601.h"
 #include "lcUniConv/cp1251.h"
+#endif
 #include "headers/symbol_.h"
 #include "headers/dingbats_.h"
   
@@ -94,6 +123,11 @@
     }
     break;
   case 2:	//iso8859-2
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-2", s, ucs, 2) > 0) {
+      return 2;
+    }
+#else
     if (ucs <= 0x00a0) {
       s[0] = 0;
       s[1] = (char) ucs;
@@ -111,99 +145,176 @@
         if (s[1]) return 2;
       }	
     }
+#endif
     break;
   case 3:	//iso8859-3
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-3", s, ucs, 2) > 0) {
+#else
     if (iso8859_3_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 3;
     } 
     break;
   case 4:	//iso8859-4
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-4", s, ucs, 2) > 0) {
+#else
     if (iso8859_4_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 4;
     } 
     break;
   case 5:	//iso8859-5
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-5", s, ucs, 2) > 0) {
+#else
     if (iso8859_5_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 5;
     } 
     break;
   case 6:	//iso8859-6
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-6", s, ucs, 2) > 0) {
+#else
     if (iso8859_6_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 6;
     } 
     break;
   case 7:	//iso8859-7
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-7", s, ucs, 2) > 0) {
+#else
     if (iso8859_7_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 7;
     } 
     break;
   case 8:	//iso8859-8
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-8", s, ucs, 2) > 0) {
+#else
     if (iso8859_8_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 8;
     } 
     break;
   case 9:	//iso8859-9
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-9", s, ucs, 2) > 0) {
+#else
     if (iso8859_9_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 9;
     } 
     break;
   case 10:	//iso8859-10
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-10", s, ucs, 2) > 0) {
+#else
     if (iso8859_10_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 10;
     } 
     break;
   case 25:	//iso8859-11
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-11", s, ucs, 2) > 0) {
+#else
     if (iso8859_11_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 25;
     } 
     break;
   case 11:	//iso8859-13
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-13", s, ucs, 2) > 0) {
+#else
     if (iso8859_13_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 11;
     } 
     break;
   case 12:	//iso8859-14
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-14", s, ucs, 2) > 0) {
+#else
     if (iso8859_14_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 12;
     } 
     break;
   case 13:	//iso8859-15
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("ISO8859-15", s, ucs, 2) > 0) {
+#else
     if (iso8859_15_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 13;
     } 
     break;
   case 14:	//koi8-r
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("KOI8-R", s, ucs, 2) > 0) {
+#else
     if (koi8_r_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 14;
     } 
     break;
   case 15:	//big5
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("BIG5", s, ucs, 2) > 0) {
+#else
     if (big5_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 15;
     } 
     break;
   case 16:	//ksc5601.1987-0
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("CP949", s, ucs, 2) > 0) {
+#else
     if (ksc5601_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 16;
     } 
     break;
   case 17:	//gb2312.1980-0
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("GB2312", s, ucs, 2) > 0) {
+#else
     if (gb2312_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 17;
     } 
     break;
   case 18:	//jisx0201.1976-0
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("EUC-JP", s, ucs, 2) > 0) {
+#else
     if (jisx0201_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 18;
     } 
     break;
   case 19:	//jisx0208.1983-0
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("EUC-JP", s, ucs, 2) > 0) {
+#else
     if (jisx0208_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 19;
     } 
     break;
   case 20:	//jisx0212.1990-0
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("EUC-JP", s, ucs, 2) > 0) {
+#else
     if (jisx0212_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 20;
     } 
     break;
@@ -298,12 +409,20 @@
     }
     break;
   case 23:	//koi8-u
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("KOI8-U", s, ucs, 2) > 0) {
+#else
     if (koi8_u_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 23;
     } 
     break;
   case 24:	//microsoft-cp1251
+#if HAVE_LIBC_ICONV
+    if (iconv_wctomb("CP1251", s, ucs, 2) > 0) {
+#else
     if (cp1251_wctomb(NULL, (unsigned char*)s, ucs, 2) > 0) {
+#endif
       return 24;
     } 
     break;
Index: src/xutf8/utf8Input.c
===================================================================
--- src/xutf8/utf8Input.c	(revision 6655)
+++ src/xutf8/utf8Input.c	(working copy)
@@ -43,15 +43,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#if HAVE_LIBC_ICONV
-#include <iconv.h>
-#endif
-/*
-  I haven't found much doc on the web about EUC encodings, so I've used
-  GNU libiconv source code as a reference.
-  http://clisp.cons.org/~haible/packages-libiconv.html
-*/
-
 #define RET_ILSEQ -1
 #define RET_TOOFEW(x) (-10 - x)
 #define RET_TOOSMALL -2
@@ -62,6 +53,48 @@
         unsigned short used;
 } Summary16;
 
+#if HAVE_LIBC_ICONV
+#  include <iconv.h>
+static int
+convert_to_utf8(
+	const char*	encoding_name,
+	char*		buffer_return,
+	int		len,
+	int		bytes_buffer)
+{
+	iconv_t ic;
+	char*   buf;
+	char*   i_ptr;
+	size_t  i_left;
+	char*   o_ptr;
+	size_t  o_left;
+
+	if (len < 1)  return 0;
+
+	// Setup parameters for iconv()
+	i_left = len;
+	i_ptr = buf = (char*)malloc(i_left);
+        if (!buf)  return 0;
+	memcpy(buf, buffer_return, i_left);
+	o_left = bytes_buffer;
+	o_ptr = (char*)buffer_return;
+
+	// Perform conversion now
+	ic = iconv_open(encoding_name, "UTF-8");
+        if (!ic) {
+                free(buf);
+                return 0;
+        }
+	iconv(ic, &i_ptr, &i_left, &o_ptr, &o_left);
+	iconv_close(ic);
+
+	// Clean up and return how many bytes resulted from conversion
+	free(buf);
+	return bytes_buffer - o_left;
+}
+
+#else
+
 #include "lcUniConv/big5.h"
 #include "lcUniConv/gb2312.h"
 #include "lcUniConv/jisx0201.h"
@@ -75,12 +108,7 @@
 	int		len)
 {
  /* FIXME */
-#if HAVE_LIBC_ICONV
-	iconv_t cd;
-	int cdl;
-#else
 	int i = 0;
-#endif
 	int l = 0;
 	char *buf, *b;
 
@@ -88,13 +116,6 @@
 	b = buf = (char*) malloc((unsigned)len);
 	memcpy(buf, buffer_return, (unsigned) len);
 
-#if HAVE_LIBC_ICONV
-	l = cdl = len;
-	cd = iconv_open("EUC-TW", "UTF-8");
-	iconv(cd, &b, &len, &buffer_return, &cdl);
-	iconv_close(cd);
-	l -= cdl;	
-#else
 	while (i < len) {
 		unsigned int ucs;
 		unsigned char c; 
@@ -131,7 +152,6 @@
 		}
 		l += XConvertUcsToUtf8(ucs, buffer_return + l);
 	}
-#endif
 	free(buf);
 	return l;
 }
@@ -363,6 +383,9 @@
 	free(buf);
 	return l;
 }
+#endif
+
+
 
 int
 XConvertEucToUtf8(
@@ -376,24 +399,59 @@
 	}
 
 	if (strstr(locale, "ja")) {	
+#if HAVE_LIBC_ICONV
+		return convert_to_utf8("EUC-JP",
+			buffer_return, len, bytes_buffer);
+#else
 		return XConvertEucJpToUtf8(buffer_return, len);
+#endif
 	} else if (strstr(locale, "Big5") || strstr(locale, "big5")) { // BIG5
+#if HAVE_LIBC_ICONV
+		return convert_to_utf8("BIG5",
+			buffer_return, len, bytes_buffer);
+#else
 		return XConvertBig5ToUtf8(buffer_return, len);
+#endif
 	} else if (strstr(locale, "zh") || strstr(locale, "chinese-")) {
 		if (strstr(locale, "TW") || strstr(locale, "chinese-t")) {
 			if (strstr(locale, "EUC") || strstr(locale, "euc") ||
 				strstr(locale, "chinese-t")) 
 			{
+#if HAVE_LIBC_ICONV
+				return convert_to_utf8("EUC-TW",
+					buffer_return, len, bytes_buffer);
+#else
 				return XConvertEucTwToUtf8(buffer_return, len);
+#endif
 			}
+#if HAVE_LIBC_ICONV
+			return convert_to_utf8("BIG5",
+				buffer_return, len, bytes_buffer);
+#else
 			return XConvertBig5ToUtf8(buffer_return, len);
+#endif
 		}
 		if (strstr(locale, "EUC") || strstr(locale, "euc")) {
+#if HAVE_LIBC_ICONV
+			return convert_to_utf8("EUC-CN",
+				buffer_return, len, bytes_buffer);
+#else
 			return XConvertEucCnToUtf8(buffer_return, len);
+#endif
 		}
+#if HAVE_LIBC_ICONV
+		return convert_to_utf8("GB2312",
+			buffer_return, len, bytes_buffer);
+#else
 		return XConvertGb2312ToUtf8(buffer_return, len);
+#endif
 	} else if (strstr(locale, "ko")) { 
+#if HAVE_LIBC_ICONV
+		return convert_to_utf8("EUC-KR",
+			buffer_return, len, bytes_buffer);
+#else
 		return XConvertEucKrToUtf8(buffer_return, len);
+#endif
 	}
 	return len;
 }
Index: src/xutf8/test.c
===================================================================
--- src/xutf8/test.c	(revision 6655)
+++ src/xutf8/test.c	(working copy)
@@ -62,7 +62,7 @@
 export LANG=ja_JP; export XMODIFIERS="@im=htt"
 export LANG=ko_KR; export XMODIFIERS="@im=Ami"
 export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_TW"
-export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_CN"
+export LANG=zh_CN; export XMODIFIERS="@im=xcin-zh_CN"
 export LANG=C; export XMODIFIERS="@im=interxim"
 */
 
Index: src/xutf8/utf8Wrap.c
===================================================================
--- src/xutf8/utf8Wrap.c	(revision 6655)
+++ src/xutf8/utf8Wrap.c	(working copy)
@@ -40,6 +40,7 @@
 
 #if !defined(WIN32) && !defined(__APPLE__)
 
+#include "config.h"
 #include "../../FL/Xutf8.h"
 #include <X11/Xlib.h>
 #include <ctype.h>
Index: configure.in
===================================================================
--- configure.in	(revision 6655)
+++ configure.in	(working copy)
@@ -545,6 +545,13 @@
 
 AC_SUBST(AUDIOLIBS)
 
+HAVE_LIBC_ICONV=0
+AC_CHECK_LIB(c, iconv, 
+	AC_DEFINE(HAVE_LIBC_ICONV)
+        HAVE_LIBC_ICONV=1 
+        )
+AC_SUBST(HAVE_LIBC_ICONV)
+
 dnl Check for image libraries...
 SAVELIBS="$LIBS"
 IMAGELIBS=""
