From 333436a8aa5c3f6038a0ce46ea66f7fa4f512ac0 Mon Sep 17 00:00:00 2001 From: gpoirier Date: Fri, 26 Jan 2007 09:57:09 +0000 Subject: filename double-conversion, especially usefull for CJK users :-) Patch by Zuxy Meng 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 --- mp_msg.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'mp_msg.c') 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 +#include #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"); -- cgit v1.2.3