]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
Convert to local encoding before printing on console (closes #556)
[vlc] / src / misc / messages.c
index 740ec130fb281810b860479aba39927e21faa30a..3978d504af2780c86c15c4845e664cc8c3ab9b24 100644 (file)
@@ -45,6 +45,7 @@
 #endif
 
 #include "vlc_interface.h"
+#include "charset.h"
 
 /*****************************************************************************
  * Local macros
@@ -133,7 +134,7 @@ void __msg_Flush( vlc_object_t *p_this )
 void __msg_Destroy( vlc_object_t *p_this )
 {
     int i;
-    for( i =  0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
+    for( i = p_this->p_libvlc->msg_bank.i_queues -1 ; i >= 0;  i-- )
     {
         msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
         if( p_queue->i_sub )
@@ -148,6 +149,9 @@ void __msg_Destroy( vlc_object_t *p_this )
 #endif
         /* Destroy lock */
         vlc_mutex_destroy( &p_queue->lock );
+        REMOVE_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
+                     p_this->p_libvlc->msg_bank.i_queues, i );
+        free( p_queue );
     }
     vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) );
 }
@@ -302,15 +306,22 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
     msg_item_t * p_item = NULL;                        /* pointer to message */
     msg_item_t   item;                    /* message in case of a full queue */
 
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
+#if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
     int          i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
 #endif
     int i;
 
+    if( p_this->i_flags & OBJECT_FLAGS_QUIET ||
+        (p_this->i_flags & OBJECT_FLAGS_NODBG &&
+         i_type == VLC_MSG_DBG ) )
+    {
+        return;
+    }
+
     /*
      * Convert message to string
      */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined( SYS_BEOS )
+#if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined( SYS_BEOS )
     vlc_va_copy( args, _args );
     vasprintf( &psz_str, psz_format, args );
     va_end( args );
@@ -323,9 +334,10 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         fprintf( stderr, "main warning: can't store message (%s): ",
                  strerror(errno) );
         vlc_va_copy( args, _args );
+        /* We should use utf8_vfprintf - but it calls malloc()... */
         vfprintf( stderr, psz_format, args );
         va_end( args );
-        fprintf( stderr, "\n" );
+        fputs( "\n", stderr );
         return;
     }
 
@@ -356,7 +368,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         p_obj = p_obj->p_parent;
     }
 
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
+#if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
     vlc_va_copy( args, _args );
     vsnprintf( psz_str, i_size, psz_format, args );
     va_end( args );
@@ -376,6 +388,8 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
     if( p_queue == NULL )
     {
         vlc_mutex_unlock( &p_bank->lock );
+        if( psz_str ) free( psz_str );
+        if( psz_header ) free( psz_header );
         return;
     }
 
@@ -449,6 +463,8 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
             free( p_item->psz_module );
         if( p_item->psz_msg )
             free( p_item->psz_msg );
+        if( p_item->psz_header )
+            free( p_item->psz_header );
     }
 
     vlc_mutex_unlock ( &p_queue->lock );
@@ -582,7 +598,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     {
         if( p_item->psz_header )
         {
-            fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
+            utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
                               "\n",
                          p_item->i_object_id, p_item->psz_header,
                          p_item->psz_module, psz_object,
@@ -591,7 +607,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
         }
         else
         {
-             fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
+             utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
                          p_item->i_object_id, p_item->psz_module, psz_object,
                          ppsz_type[i_type], ppsz_color[i_type],
                          p_item->psz_msg );
@@ -601,13 +617,13 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     {
         if( p_item->psz_header )
         {
-            fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
+            utf8_fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
                          p_item->psz_header, p_item->psz_module,
                          psz_object, ppsz_type[i_type], p_item->psz_msg );
         }
         else
         {
-            fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
+            utf8_fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
                          p_item->psz_module, psz_object, ppsz_type[i_type],
                          p_item->psz_msg );
         }