[MPlayer-dev-eng] [PATCH] automatic charset conversion for output

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Feb 20 21:00:47 CET 2006


Hi,
the attached patch would change the format of the message strings to
UTF8 (thus they will work properly with GTK2, someone should test GTK1
though) and convert them as required in mp_msg.
This is more lika a draft, so feel free to add suggestions...

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.1135
diff -u -r1.1135 configure
--- configure	18 Feb 2006 20:04:42 -0000	1.1135
+++ configure	20 Feb 2006 19:50:26 -0000
@@ -1584,7 +1584,7 @@
 #_language=en
 _shm=auto
 _linux_devfs=no
-#_charset=utf8
+_charset=utf8
 _i18n=auto
 _dynamic_plugins=no
 _crash_debug=auto
Index: mp_msg.c
===================================================================
RCS file: /cvsroot/mplayer/main/mp_msg.c,v
retrieving revision 1.33
diff -u -r1.33 mp_msg.c
--- mp_msg.c	9 Feb 2006 14:07:52 -0000	1.33
+++ mp_msg.c	20 Feb 2006 19:50:27 -0000
@@ -7,6 +7,13 @@
 
 #include "config.h"
 
+#ifdef USE_LANGINFO
+#include <langinfo.h>
+#endif
+#ifdef USE_ICONV
+#include <iconv.h>
+#endif
+
 #if	defined(FOR_MENCODER) || defined(CODECS2HTML)
 #undef HAVE_NEW_GUI
 #endif
@@ -23,6 +30,12 @@
 int mp_msg_levels[MSGT_MAX]; // verbose level of this module. inited to 2
 int mp_msg_level_all = MSGL_STATUS;
 int verbose = 0;
+#ifdef USE_ICONV
+char *mp_msg_charset = NULL;
+#endif
+
+static char *old_charset = NULL;
+static iconv_t msgiconv;
 
 void mp_msg_init(void){
     int i;
@@ -43,6 +56,14 @@
 #endif
 #endif
     for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
+    mp_msg_charset = getenv("MPLAYER_CHARSET");
+#ifdef USE_LANGINFO
+    if (!mp_msg_charset) {
+      setlocale(LC_CTYPE, "");
+      mp_msg_charset = nl_langinfo(CODESET);
+      setlocale(LC_CTYPE, "C");
+    }
+#endif
 }
 
 int mp_msg_test(int mod, int lev)
@@ -66,6 +87,27 @@
         guiMessageBox(lev, tmp);
 #endif
 
+#ifdef USE_ICONV
+    if (mp_msg_charset && strcasecmp(mp_msg_charset, "noconv")) {
+      char tmp2[MSGSIZE_MAX];
+      size_t inlen = strlen(tmp), outlen = MSGSIZE_MAX;
+      char *in = tmp, *out = tmp2;
+      if (!old_charset || strcmp(old_charset, mp_msg_charset)) {
+        if (old_charset) {
+          free(old_charset);
+          iconv_close(msgiconv);
+        }
+        msgiconv = iconv_open(mp_msg_charset, "utf8");
+        old_charset = strdup(mp_msg_charset);
+      }
+      memset(tmp2, 0, MSGSIZE_MAX);
+      iconv(msgiconv, &in, &inlen, &out, &outlen);
+      strncpy(tmp, tmp2, MSGSIZE_MAX);
+      tmp[MSGSIZE_MAX-1] = 0;
+      tmp[MSGSIZE_MAX-2] = '\n';
+    }
+#endif
+
 #ifdef MSG_USE_COLORS
 /* that's only a silly color test */
 #ifdef MP_ANNOY_ME
Index: cfg-common.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-common.h,v
retrieving revision 1.154
diff -u -r1.154 cfg-common.h
--- cfg-common.h	4 Feb 2006 00:08:54 -0000	1.154
+++ cfg-common.h	20 Feb 2006 19:50:29 -0000
@@ -6,6 +6,9 @@
 	{"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL, 0, -10, NULL},
 	{"v", cfg_inc_verbose, CONF_TYPE_FUNC, CONF_GLOBAL|CONF_NOSAVE, 0, 0, NULL},
 	{"msglevel", msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
+#ifdef USE_ICONV
+	{"msgcharset", &mp_msg_charset, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
+#endif
 	{"include", cfg_include, CONF_TYPE_FUNC_PARAM, CONF_NOSAVE, 0, 0, NULL},
 #ifdef WIN32
 	{"priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL},
@@ -298,6 +301,7 @@
 
 extern int quiet;
 extern int verbose;
+extern char *mp_msg_charset;
 
 // codec/filter opts: (defined at libmpcodecs/vd.c)
 extern float screen_size_xy;


More information about the MPlayer-dev-eng mailing list