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

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Feb 20 22:15:02 CET 2006


Hi,
On Mon, Feb 20, 2006 at 09:00:47PM +0100, Reimar Döffinger wrote:
> 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...

This one should work a bit better, esp. with gtk1 (though gtk1 is quite
broken in many ways, so I guess we don't have to support it too much
anyway...).

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 21:09:41 -0000
@@ -6957,6 +6962,20 @@
 fi
 # --------------- GUI specific tests end -------------------
 
+if test "$_charset" = "noconv" ; then
+  _charset=""
+elif test -z "$_charset" ; then
+  if test "$_gtk1" = yes ; then
+    _charset=`cat ${_mp_help}.charset`
+  else
+    _charset=utf8
+  fi
+fi
+if test "$_charset" ; then
+  _def_charset="#define MSG_CHARSET \"$_charset\""
+else
+  _def_charset="#undef MSG_CHARSET"
+fi
 
 
 #############################################################################
@@ -7404,6 +7423,9 @@
 /* use GNU internationalization */
 $_def_i18n
 
+/* name of messages charset */
+$_def_charset
+
 /* Runtime CPU detection */
 $_def_runtime_cpudetection
 
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 21:09:42 -0000
@@ -7,6 +7,14 @@
 
 #include "config.h"
 
+#ifdef USE_LANGINFO
+#include <locale.h>
+#include <langinfo.h>
+#endif
+#ifdef USE_ICONV
+#include <iconv.h>
+#endif
+
 #if	defined(FOR_MENCODER) || defined(CODECS2HTML)
 #undef HAVE_NEW_GUI
 #endif
@@ -23,6 +31,11 @@
 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;
+static char *old_charset = NULL;
+static iconv_t msgiconv;
+#endif
 
 void mp_msg_init(void){
     int i;
@@ -43,6 +56,16 @@
 #endif
 #endif
     for(i=0;i<MSGT_MAX;i++) mp_msg_levels[i] = -2;
+#ifdef USE_ICONV
+    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
+#endif
 }
 
 int mp_msg_test(int mod, int lev)
@@ -66,6 +89,32 @@
         guiMessageBox(lev, tmp);
 #endif
 
+#if defined(USE_ICONV) && defined(MSG_CHARSET)
+    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, MSG_CHARSET);
+        old_charset = strdup(mp_msg_charset);
+      }
+      memset(tmp2, 0, MSGSIZE_MAX);
+      while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) {
+        if (!inlen || !outlen)
+          break;
+        *out++ = *in++;
+        outlen--; inlen--;
+      }
+      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 21:09:45 -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;
Index: Gui/mplayer/widgets.c
===================================================================
RCS file: /cvsroot/mplayer/main/Gui/mplayer/widgets.c,v
retrieving revision 1.47
diff -u -r1.47 widgets.c
--- Gui/mplayer/widgets.c	8 Dec 2005 22:12:56 -0000	1.47
+++ Gui/mplayer/widgets.c	20 Feb 2006 21:09:45 -0000
@@ -61,7 +61,6 @@
 void gtkInit( void )
 {
  mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[widget] init GTK ...\n" );
- gtk_set_locale();
  gtk_init( 0,NULL );
 // gdk_set_use_xshm( TRUE );
 


More information about the MPlayer-dev-eng mailing list