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

Zuxy Meng zuxy.meng at gmail.com
Thu Nov 16 09:29:58 CET 2006


Hi,

2006/11/16, Torinthiel <torinthiel at megapolis.pl>:
> On Thu, Nov 16, 2006 at 02:44:41PM +0800, Zuxy Meng wrote:
> > Index: mp_msg.h
> > ===================================================================
> > --- mp_msg.h  ???????? 20426??
> > +++ mp_msg.h  ????????????
> > @@ -14,6 +14,7 @@
> >  #endif
> >  #ifdef USE_ICONV
> >  #include <iconv.h>
> > +#include <limits.h>
> >  #endif
> >
> >  #if  defined(FOR_MENCODER) || defined(CODECS2HTML)
>
> patching file mp_msg.h
> Hunk #1 FAILED at 14.
> Hunk #2 succeeded at 130 (offset 2 lines).
>
> grep -i iconv mp_msg.h returns nothing. Where should it go?

Sorry, my mistake. This one should be OK.
-- 
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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(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_recode(const char* filename);
 
 #endif
 #endif
Index: mp_msg.c
===================================================================
--- mp_msg.c	???????? 20547??
+++ mp_msg.c	????????????
@@ -14,6 +14,7 @@
 #endif
 #ifdef USE_ICONV
 #include <iconv.h>
+#include <limits.h>
 #endif
 
 #if	defined(FOR_MENCODER) || defined(CODECS2HTML)
@@ -38,6 +42,33 @@
 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[PATH_MAX];
+    size_t filename_len, max_path;
+    char* precoded_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 = PATH_MAX - 1;
+    precoded_filename = recoded_filename;
+    iconv(inv_msgiconv, &filename, &filename_len,
+	    &precoded_filename, &max_path);
+    *precoded_filename = '\0';
+    return recoded_filename;
+#endif
+}
+
 void mp_msg_init(void){
     int i;
     char *env = getenv("MPLAYER_VERBOSE");


More information about the MPlayer-dev-eng mailing list