diff mp_msg.c @ 22002:ebd2d5efb11b

filename double-conversion, especially usefull for CJK users :-) Patch by Zuxy Meng <zuxy.meng@gmail.com> date: Oct 25, 2006 2:20 AM subject: [MPlayer-dev-eng] [PATCH] Filename double-conversion
author gpoirier
date Fri, 26 Jan 2007 09:57:09 +0000
parents 04cea12cd324
children 77c4ad229db6
line wrap: on
line diff
--- a/mp_msg.c	Fri Jan 26 09:21:22 2007 +0000
+++ b/mp_msg.c	Fri Jan 26 09:57:09 2007 +0000
@@ -14,6 +14,7 @@
 #endif
 #ifdef USE_ICONV
 #include <iconv.h>
+#include <errno.h>
 #endif
 
 #if	defined(FOR_MENCODER) || defined(CODECS2HTML)
@@ -38,6 +39,36 @@
 static iconv_t msgiconv;
 #endif
 
+const char* filename_recode(const char* filename)
+{
+#if !defined(USE_ICONV) || !defined(MSG_CHARSET)
+    return filename;
+#else
+    static iconv_t inv_msgiconv = (iconv_t)(-1);
+    static char recoded_filename[MSGSIZE_MAX];
+    size_t filename_len, max_path;
+    char* precoded;
+    if (!strcasecmp(mp_msg_charset, MSG_CHARSET) ||
+	    !strcasecmp(mp_msg_charset, "noconv"))
+       return filename;	
+    if (inv_msgiconv == (iconv_t)(-1)) {
+	inv_msgiconv = iconv_open(MSG_CHARSET, mp_msg_charset);
+	if (inv_msgiconv == (iconv_t)(-1))
+	    return filename;
+    }
+    filename_len = strlen(filename);
+    max_path = MSGSIZE_MAX - 4;
+    precoded = recoded_filename;
+    if (iconv(inv_msgiconv, &filename, &filename_len,
+	    &precoded, &max_path) == (size_t)(-1) && errno == E2BIG) {
+	precoded[0] = precoded[1] = precoded[2] = '.';
+	precoded += 3;
+    }
+    *precoded = '\0';
+    return recoded_filename;
+#endif
+}
+
 void mp_msg_init(void){
     int i;
     char *env = getenv("MPLAYER_VERBOSE");