summaryrefslogtreecommitdiffstats
path: root/mp_msg.c
diff options
context:
space:
mode:
authorgpoirier <gpoirier@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-01-26 09:57:09 +0000
committergpoirier <gpoirier@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-01-26 09:57:09 +0000
commit333436a8aa5c3f6038a0ce46ea66f7fa4f512ac0 (patch)
tree5f184a98fa4f25af96ef0eed550f810f0df94b39 /mp_msg.c
parentb74e51f49ce31afe00dc292a94d683d944d27cd2 (diff)
downloadmpv-333436a8aa5c3f6038a0ce46ea66f7fa4f512ac0.tar.bz2
mpv-333436a8aa5c3f6038a0ce46ea66f7fa4f512ac0.tar.xz
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 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22020 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mp_msg.c')
-rw-r--r--mp_msg.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/mp_msg.c b/mp_msg.c
index c3d8db22a5..241f0c9997 100644
--- a/mp_msg.c
+++ b/mp_msg.c
@@ -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 char *old_charset = NULL;
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");