]> git.sesse.net Git - vlc/blobdiff - src/interface/intf_msg.c
* DirectX plugin by Gildas Bazin <gbazin@netcourrier.com>.
[vlc] / src / interface / intf_msg.c
index e5e65d4bd0f9363f57e5576718c54a20f6c58c8b..62e2cc101d9dc87aca42a8532863535015b49c2c 100644 (file)
@@ -4,7 +4,7 @@
  * interface, such as message output. See config.h for output configuration.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: intf_msg.c,v 1.28 2001/03/21 13:42:34 sam Exp $
+ * $Id: intf_msg.c,v 1.36 2001/06/02 01:09:03 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *
 #include <stdarg.h>                                       /* va_list for BSD */
 #include <stdlib.h>                                              /* malloc() */
 #include <string.h>                                            /* strerror() */
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>                                      /* close(), write() */
+#endif
 
 #include "config.h"
 #include "common.h"
 
 #include "intf_msg.h"
 #include "interface.h"
-#include "intf_console.h"
 
 #include "main.h"
 
+#ifdef WIN32
+#ifndef snprintf
+#define snprintf _snprintf         /* snprintf not defined in mingw32 (bug?) */
+#endif
+#endif
+
 /*****************************************************************************
  * intf_msg_item_t
  *****************************************************************************
  * Store a single message. Messages have a maximal size of INTF_MSG_MSGSIZE.
- * If DEBUG is defined, messages have a date field and debug messages are
+ * If TRACE is defined, messages have a date field and debug messages are
  * printed with a date to allow more precise profiling.
  *****************************************************************************/
 typedef struct
@@ -59,8 +67,8 @@ typedef struct
     int     i_type;                               /* message type, see below */
     char *  psz_msg;                                   /* the message itself */
 
-#ifdef DEBUG
-    /* Debugging informations - in DEBUG mode, debug messages have calling
+#ifdef TRACE
+    /* Debugging informations - in TRACE mode, debug messages have calling
      * location informations printed */
     mtime_t date;                                     /* date of the message */
     char *  psz_file;               /* file in which the function was called */
@@ -72,7 +80,6 @@ typedef struct
 /* Message types */
 #define INTF_MSG_STD    0                                /* standard message */
 #define INTF_MSG_ERR    1                                   /* error message */
-#define INTF_MSG_INTF   2                               /* interface message */
 #define INTF_MSG_DBG    3                                   /* debug message */
 #define INTF_MSG_WARN   4                                  /* warning message*/
 
@@ -92,12 +99,12 @@ typedef struct intf_msg_s
     intf_msg_item_t         msg[INTF_MSG_QSIZE];            /* message queue */
 #endif
 
-#ifdef DEBUG_LOG
+#ifdef TRACE_LOG
     /* Log file */
     FILE *                  p_log_file;                          /* log file */
 #endif
 
-#if !defined(INTF_MSG_QUEUE) && !defined(DEBUG_LOG)
+#if !defined(INTF_MSG_QUEUE) && !defined(TRACE_LOG)
     /* If neither messages queue, neither log file is used, then the structure
      * is empty. However, empty structures are not allowed in C. Therefore, a
      * dummy integer is used to fill it. */
@@ -112,7 +119,7 @@ typedef struct intf_msg_s
 static void QueueMsg        ( intf_msg_t *p_msg, int i_type,
                               char *psz_format, va_list ap );
 static void PrintMsg        ( intf_msg_item_t *p_msg );
-#ifdef DEBUG
+#ifdef TRACE
 static void QueueDbgMsg     ( intf_msg_t *p_msg, char *psz_file,
                               char *psz_function, int i_line,
                               char *psz_format, va_list ap );
@@ -147,11 +154,11 @@ p_intf_msg_t intf_MsgCreate( void )
 #endif
 
     
-#ifdef DEBUG_LOG
+#ifdef TRACE_LOG
         /* Log file initialization - on failure, file pointer will be null,
          * and no log will be issued, but this is not considered as an
          * error */
-        p_msg->p_log_file = fopen( DEBUG_LOG, "w" );
+        p_msg->p_log_file = fopen( TRACE_LOG, "w" );
 #endif
     }
     return( p_msg );
@@ -168,7 +175,7 @@ void intf_MsgDestroy( void )
 {
     intf_FlushMsg();                         /* print all remaining messages */
 
-#ifdef DEBUG_LOG
+#ifdef TRACE_LOG
     /* Close log file if any */
     if( p_main->p_msg->p_log_file != NULL )
     {
@@ -225,7 +232,7 @@ void intf_WarnMsg( int i_level, char *psz_format, ... )
 {
     va_list ap;
     
-    if( i_level >= p_main->i_warning_level )
+    if( i_level <= p_main->i_warning_level )
     {
         va_start( ap, psz_format );
         QueueMsg( p_main->p_msg, INTF_MSG_WARN, psz_format, ap );
@@ -234,35 +241,15 @@ void intf_WarnMsg( int i_level, char *psz_format, ... )
 }
 
 
-/*****************************************************************************
- * intf_IntfMsg : print an interface message                             (ok ?)
- *****************************************************************************
- * In opposition to all other intf_*Msg function, this function does not print
- * it's message on default terminal (stdout or stderr), but send it to
- * interface (in fact to the X11 console). This means that the interface MUST
- * be initialized and a X11 console openned before this function is used, and
- * that once the console is closed, this call is vorbidden.
- * Practically, only the interface thread itself should call this function, and
- * flush all messages before intf_CloseX11Console() is called.
- *****************************************************************************/
-void intf_IntfMsg(char *psz_format, ...)
-{
-    va_list ap;
-
-    va_start( ap, psz_format );
-    QueueMsg( p_main->p_msg, INTF_MSG_INTF, psz_format, ap );
-    va_end( ap );
-}
-
 /*****************************************************************************
  * _intf_DbgMsg: print a debugging message                               (ok ?)
  *****************************************************************************
  * This function prints a debugging message. Compared to other intf_*Msg
- * functions, it is only defined if DEBUG is defined and require a file name,
+ * functions, it is only defined if TRACE is defined and require a file name,
  * a function name and a line number as additionnal debugging informations. It
  * also prints a debugging header for each received line.
  *****************************************************************************/
-#ifdef DEBUG
+#ifdef TRACE
 void _intf_DbgMsg( char *psz_file, char *psz_function, int i_line,
                    char *psz_format, ...)
 {
@@ -317,7 +304,7 @@ void intf_WarnMsgImm( int i_level, char *psz_format, ... )
 {
     va_list ap;
 
-    if( i_level >= p_main->i_warning_level )
+    if( i_level <= p_main->i_warning_level )
     {
         va_start( ap, psz_format );
         QueueMsg( p_main->p_msg, INTF_MSG_WARN, psz_format, ap );
@@ -335,7 +322,7 @@ void intf_WarnMsgImm( int i_level, char *psz_format, ... )
  * message immediately. It should only be called through the macro
  * intf_DbgMsgImm().
  *****************************************************************************/
-#ifdef DEBUG
+#ifdef TRACE
 void _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line,
                       char *psz_format, ...)
 {
@@ -461,7 +448,7 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a
      */
     p_msg_item->i_type =     i_type;
     p_msg_item->psz_msg =    psz_str;
-#ifdef DEBUG    
+#ifdef TRACE    
     p_msg_item->date =       mdate();
 #endif
 
@@ -477,9 +464,9 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a
  * QueueDbgMsg: add a message to a queue with debugging informations
  *****************************************************************************
  * This function is the same as QueueMsg, except that it is only defined when
- * DEBUG is define, and require additionnal debugging informations.
+ * TRACE is define, and require additionnal debugging informations.
  *****************************************************************************/
-#ifdef DEBUG
+#ifdef TRACE
 static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function,
                         int i_line, char *psz_format, va_list ap)
 {
@@ -566,16 +553,27 @@ static void FlushLockedMsg ( intf_msg_t *p_msg )
  * PrintMsg: print a message                                             (ok ?)
  *****************************************************************************
  * Print a single message. The message data is not freed. This function exists
- * in two version. The DEBUG version prints a date with each message, and is
- * able to log messages (if DEBUG_LOG is defined).
+ * in two version. The TRACE version prints a date with each message, and is
+ * able to log messages (if TRACE_LOG is defined).
  * The normal one just prints messages to the screen.
  *****************************************************************************/
-#ifdef DEBUG
+#ifdef TRACE
 
 static void PrintMsg( intf_msg_item_t *p_msg )
 {
     char    psz_date[MSTRTIME_MAX_SIZE];            /* formatted time buffer */
-    char *  psz_msg;                                       /* message buffer */
+    int     i_msg_len = MSTRTIME_MAX_SIZE + strlen(p_msg->psz_msg) + 200;
+    char   *psz_msg;                                       /* message buffer */
+
+    psz_msg = malloc( sizeof( char ) * i_msg_len );
+
+    /* Check if allocation succeeded */
+    if( psz_msg == NULL )
+    {
+        fprintf( stderr, "error: not enough memory for message %s\n",
+                 p_msg->psz_msg );
+        return;
+    }
 
     /* Format message - the message is formatted here because in case the log
      * file is used, it avoids another format string parsing */
@@ -583,36 +581,24 @@ static void PrintMsg( intf_msg_item_t *p_msg )
     {
     case INTF_MSG_STD:                                   /* regular messages */
     case INTF_MSG_ERR:
-        asprintf( &psz_msg, "%s", p_msg->psz_msg );
+        snprintf( psz_msg, i_msg_len, "%s", p_msg->psz_msg );
         break;
 
     case INTF_MSG_WARN:                                   /* Warning message */
         mstrtime( psz_date, p_msg->date );
-        asprintf( &psz_msg, "(%s) %s",
+        snprintf( psz_msg, i_msg_len, "(%s) %s",
                   psz_date, p_msg->psz_msg );
 
         break;
         
-    case INTF_MSG_INTF:                                /* interface messages */
-        asprintf( &psz_msg, "%s", p_msg->psz_msg );
-        break;
-
     case INTF_MSG_DBG:                                     /* debug messages */
         mstrtime( psz_date, p_msg->date );
-        asprintf( &psz_msg, "(%s) " INTF_MSG_DBG_FORMAT "%s",
+        snprintf( psz_msg, i_msg_len, "(%s) " INTF_MSG_DBG_FORMAT "%s",
                   psz_date, p_msg->psz_file, p_msg->psz_function, p_msg->i_line,
                   p_msg->psz_msg );
         break;
     }
 
-    /* Check if formatting function succeeded */
-    if( psz_msg == NULL )
-    {
-        fprintf( stderr, "error: can not format message (%s): %s\n",
-                 strerror( errno ), p_msg->psz_msg );
-        return;
-    }
-
     /*
      * Print messages
      */
@@ -623,17 +609,14 @@ static void PrintMsg( intf_msg_item_t *p_msg )
         break;
     case INTF_MSG_ERR:                                     /* error messages */
     case INTF_MSG_WARN:
-#ifndef DEBUG_LOG_ONLY
+#ifndef TRACE_LOG_ONLY
     case INTF_MSG_DBG:                                 /* debugging messages */
 #endif
         fprintf( stderr, "%s\n", psz_msg );
         break;
-    case INTF_MSG_INTF:                                /* interface messages */
-        intf_ConsolePrint( p_main->p_intf->p_console, psz_msg );
-        break;
     }
 
-#ifdef DEBUG_LOG
+#ifdef TRACE_LOG
     /* Append all messages to log file */
     if( p_main->p_msg->p_log_file != NULL )
     {
@@ -642,7 +625,7 @@ static void PrintMsg( intf_msg_item_t *p_msg )
     }
 #endif
 
-    /* Free formatted message */
+    /* Free the message */
     free( psz_msg );
 }
 
@@ -663,9 +646,6 @@ static void PrintMsg( intf_msg_item_t *p_msg )
     case INTF_MSG_WARN:
         fprintf( stderr, "%s\n", p_msg->psz_msg );        /* warning message */
         break;
-    case INTF_MSG_INTF:                                /* interface messages */
-        intf_ConsolePrint( p_main->p_intf->p_console, p_msg->psz_msg );
-        break;
     }
 }