[MPlayer-dev-eng] [PATCH] Filename double-conversion

Zuxy Meng zuxy.meng at gmail.com
Wed Oct 25 12:00:30 CEST 2006


2006/10/25, Zuxy Meng <zuxy.meng at gmail.com>:
>
> You remind me: mplayer still support MSG_CHARSET != UTF-8

Revised patch attached.

-- 
Zuxy
Beauty is truth,
While truth is beauty.
PGP KeyID: E8555ED6
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	???????? 20426??
+++ mplayer.c	????????????
@@ -986,7 +987,8 @@
 #else
     if(!subd && !silent) 
 #endif
-        mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename);
+        mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub,
+		filename_to_utf8(filename));
     
 #ifdef USE_ASS
     if (!asst && !subd) return;
@@ -996,9 +998,11 @@
 #endif
     set_of_subtitles[set_of_sub_size] = subd;
     mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size);
-    mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename);
+    mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n",
+	   filename_to_utf8(filename));
     ++set_of_sub_size;
-    mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);
+    mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size,
+	    filename_to_utf8(filename));
 }
 
 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.
@@ -3084,7 +3088,8 @@
 #ifdef HAVE_BITMAP_FONT
   if(font_name){
        vo_font=read_font_desc(font_name,font_factor,verbose>1);
-       if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
+       if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,
+		filename_to_utf8(font_name));
   } else {
       // try default:
        vo_font=read_font_desc( mem_ptr=get_path("font/font.desc"),font_factor,verbose>1);
@@ -3332,7 +3337,9 @@
 }
 //---------------------------------------------------------------------------
 
-    if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
+    if(filename)
+	mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing,
+		filename_to_utf8(filename));
 
 if (edl_filename) {
     if (edl_records) free_edl(edl_records);
@@ -3343,7 +3350,7 @@
     if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
     {
         mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
-               edl_output_filename);
+		filename_to_utf8(edl_output_filename));
     }
 }
 
@@ -3353,7 +3360,8 @@
     if (vobsub_name){
       vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
       if(vo_vobsub==NULL)
-        mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
+        mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,
+		filename_to_utf8(vobsub_name));
     }else if(sub_auto && filename && (strlen(filename)>=5)){
       /* try to autodetect vobsub from movie filename ::atmos */
       char *buf = malloc((strlen(filename)-3)),*psub;
@@ -3420,7 +3428,8 @@
     play_tree_t* entry;
     // Handle playlist
     current_module="handle_playlist";
-    mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
+    mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",
+	    filename_to_utf8(filename));
     entry = parse_playtree(stream,0);
     eof=playtree_add_playlist(entry);
     goto goto_next_file;
@@ -3500,7 +3509,8 @@
   {	 
     char *temp, *bname;
     
-    mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);
+    mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",
+	    filename_to_utf8(playlist_entry));
 
     bname=mp_basename(playlist_entry);
     if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
@@ -3796,7 +3806,8 @@
     }
 }
 
-  mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", filename);
+  mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n",
+	  filename_to_utf8(filename));
   mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", demuxer->desc->name);
   if (sh_video) {
     /* Assume FOURCC if all bytes >= 0x20 (' ') */
@@ -4993,7 +5004,8 @@
         if (v < 0) {
           for (v = 0; v < set_of_sub_size; ++v) {
             subd = set_of_subtitles[v];
-            mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
+            mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1,
+		    filename_to_utf8(subd->filename));
             sub_free(subd);
             set_of_subtitles[v] = NULL;
           }
@@ -5010,7 +5022,8 @@
         }
         else if (v < set_of_sub_size) {
           subd = set_of_subtitles[v];
-          mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1, subd->filename);
+          mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_RemovedSubtitleFile, v + 1,
+		  filename_to_utf8(subd->filename));
           sub_free(subd);
           if (set_of_sub_pos == v) {
             global_sub_pos = -2;
Index: mp_msg.h
===================================================================
--- mp_msg.h	???????? 20426??
+++ mp_msg.h	????????????
@@ -128,6 +128,7 @@
 #   endif
 #endif
 
+const char* filename_to_utf8(char* filename);
 
 #endif
 #endif
Index: mp_msg.c
===================================================================
--- mp_msg.c	???????? 20440??
+++ mp_msg.c	????????????
@@ -36,11 +36,64 @@
 char *mp_msg_charset = NULL;
 static char *old_charset = NULL;
 static iconv_t msgiconv;
+static iconv_t inv_msgiconv = (iconv_t)(-1);
+static char utf8_filename[MAX_PATH];
 #endif
 
+const char* filename_to_utf8(char* filename)
+{
+#if !defined(USE_ICONV) || !defined(MSG_CHARSET)
+    return filename;
+#else
+    size_t filename_len, max_path;
+    char* putf8_filename;
+    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 = MAX_PATH - 1;
+    putf8_filename = utf8_filename;
+    iconv(inv_msgiconv, (const char**)&filename, &filename_len,
+	    &putf8_filename, &max_path);
+    *putf8_filename = '\0';
+    return utf8_filename;
+#endif
+}
+
 void mp_msg_init(void){
     int i;
     char *env = getenv("MPLAYER_VERBOSE");


More information about the MPlayer-dev-eng mailing list