X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finterface%2Fintf_msg.c;h=e5e65d4bd0f9363f57e5576718c54a20f6c58c8b;hb=c7df0042b11981873106e33d3ec9a6c2dc4137bb;hp=adea21ee71f9fcdb779a6614cf7f9d3ab78a3420;hpb=b9079557cb5224754886ea04d95df124552fb73d;p=vlc diff --git a/src/interface/intf_msg.c b/src/interface/intf_msg.c index adea21ee71..e5e65d4bd0 100644 --- a/src/interface/intf_msg.c +++ b/src/interface/intf_msg.c @@ -4,8 +4,9 @@ * 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 $ * - * Authors: + * Authors: Vincent Seguin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +40,7 @@ #include "common.h" #include "threads.h" #include "mtime.h" -#include "plugins.h" + #include "intf_msg.h" #include "interface.h" #include "intf_console.h" @@ -93,17 +94,15 @@ typedef struct intf_msg_s #ifdef DEBUG_LOG /* Log file */ - int i_log_file; /* log file */ + FILE * p_log_file; /* log file */ #endif -//#if 0 #if !defined(INTF_MSG_QUEUE) && !defined(DEBUG_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. */ int i_dummy; /* unused filler */ #endif -// int i_warning_level; } intf_msg_t; /***************************************************************************** @@ -152,14 +151,7 @@ p_intf_msg_t intf_MsgCreate( void ) /* 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->i_log_file = open( DEBUG_LOG, O_CREAT | O_TRUNC | -#ifndef SYS_BSD - O_SYNC | -#else - O_ASYNC | -#endif /* SYS_BSD */ - O_WRONLY, 0666 ); - + p_msg->p_log_file = fopen( DEBUG_LOG, "w" ); #endif } return( p_msg ); @@ -178,12 +170,17 @@ void intf_MsgDestroy( void ) #ifdef DEBUG_LOG /* Close log file if any */ - if( p_main->p_msg->i_log_file >= 0 ) + if( p_main->p_msg->p_log_file != NULL ) { - close( p_main->p_msg->i_log_file ); + fclose( p_main->p_msg->p_log_file ); } #endif +#ifdef INTF_MSG_QUEUE + /* destroy lock */ + vlc_mutex_destroy( &p_main->p_msg->lock ); +#endif + /* Free structure */ free( p_main->p_msg ); } @@ -228,7 +225,7 @@ void intf_WarnMsg( int i_level, char *psz_format, ... ) { va_list ap; - if( i_level >= p_main->p_intf->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 ); @@ -320,7 +317,7 @@ void intf_WarnMsgImm( int i_level, char *psz_format, ... ) { va_list ap; - if( i_level >= p_main->p_intf->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 ); @@ -352,6 +349,43 @@ void _intf_DbgMsgImm( char *psz_file, char *psz_function, int i_line, } #endif +/***************************************************************************** + * intf_WarnHexDump : print a hexadecimal dump of a memory area + ***************************************************************************** + * This is convenient for debugging purposes. + *****************************************************************************/ +void intf_WarnHexDump( int i_level, void *p_data, int i_size ) +{ + int i_index = 0; + int i_subindex; + char p_string[75]; + u8 *p_area = (u8 *)p_data; + + intf_WarnMsg( i_level, "hexdump: dumping %i bytes at address %p", + i_size, p_data ); + + while( i_index < i_size ) + { + i_subindex = 0; + + while( ( i_subindex < 24 ) && ( i_index + i_subindex < i_size ) ) + { + sprintf( p_string + 3 * i_subindex, "%.2x ", + p_area[ i_index + i_subindex ] ); + + i_subindex++; + } + + /* -1 here is safe because we know we printed at least one */ + p_string[ 3 * i_subindex - 1 ] = '\0'; + intf_WarnMsg( i_level, "0x%.4x: %s", i_index, p_string ); + + i_index += 24; + } + + intf_WarnMsg( i_level, "hexdump: %i bytes dumped", i_size ); +} + /***************************************************************************** * intf_FlushMsg (ok ?) ***************************************************************************** @@ -392,19 +426,23 @@ static void QueueMsg( intf_msg_t *p_msg, int i_type, char *psz_format, va_list a /* * Convert message to string */ -#ifdef SYS_BEOS - psz_str = (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE ); - vsprintf( psz_str, psz_format, ap ); -#else +#ifdef HAVE_VASPRINTF vasprintf( &psz_str, psz_format, ap ); +#else + psz_str = (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE ); #endif if( psz_str == NULL ) { fprintf(stderr, "warning: can't store following message (%s): ", strerror(errno) ); vfprintf(stderr, psz_format, ap ); + fprintf(stderr, "\n" ); exit( errno ); } +#ifdef HAVE_VASPRINTF +#else + vsprintf( psz_str, psz_format, ap ); +#endif #ifdef INTF_MSG_QUEUE /*...................................... queue mode ...*/ vlc_mutex_lock( &p_msg->lock ); /* get lock */ @@ -423,6 +461,9 @@ 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 + p_msg_item->date = mdate(); +#endif #ifdef INTF_MSG_QUEUE /*......................................... queue mode */ vlc_mutex_unlock( &p_msg->lock ); /* give lock back */ @@ -453,11 +494,11 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, /* * Convert message to string */ -#ifdef SYS_BEOS +#ifdef HAVE_VASPRINTF + vasprintf( &psz_str, psz_format, ap ); +#else psz_str = (char*) malloc( INTF_MAX_MSG_SIZE ); vsprintf( psz_str, psz_format, ap ); -#else - vasprintf( &psz_str, psz_format, ap ); #endif if( psz_str == NULL ) { @@ -465,6 +506,7 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, strerror(errno) ); fprintf(stderr, INTF_MSG_DBG_FORMAT, psz_file, psz_function, i_line ); vfprintf(stderr, psz_format, ap ); + fprintf(stderr, "\n" ); exit( errno ); } @@ -472,9 +514,7 @@ static void QueueDbgMsg(intf_msg_t *p_msg, char *psz_file, char *psz_function, vlc_mutex_lock( &p_msg->lock ); /* get lock */ if( p_msg->i_count == INTF_MSG_QSIZE ) /* flush queue if needed */ { -#ifdef DEBUG /* in debug mode, queue overflow causes a warning */ fprintf(stderr, "warning: message queue overflow\n" ); -#endif FlushLockedMsg( p_msg ); } p_msg_item = p_msg->msg + p_msg->i_count++; /* select message */ @@ -547,7 +587,10 @@ static void PrintMsg( intf_msg_item_t *p_msg ) break; case INTF_MSG_WARN: /* Warning message */ - asprintf( &psz_msg, "%s", p_msg->psz_msg ); + mstrtime( psz_date, p_msg->date ); + asprintf( &psz_msg, "(%s) %s", + psz_date, p_msg->psz_msg ); + break; case INTF_MSG_INTF: /* interface messages */ @@ -576,14 +619,14 @@ static void PrintMsg( intf_msg_item_t *p_msg ) switch( p_msg->i_type ) { case INTF_MSG_STD: /* standard messages */ - fprintf( stdout, psz_msg ); + fprintf( stdout, "%s\n", psz_msg ); break; case INTF_MSG_ERR: /* error messages */ case INTF_MSG_WARN: #ifndef DEBUG_LOG_ONLY case INTF_MSG_DBG: /* debugging messages */ #endif - fprintf( stderr, psz_msg ); + fprintf( stderr, "%s\n", psz_msg ); break; case INTF_MSG_INTF: /* interface messages */ intf_ConsolePrint( p_main->p_intf->p_console, psz_msg ); @@ -592,9 +635,10 @@ static void PrintMsg( intf_msg_item_t *p_msg ) #ifdef DEBUG_LOG /* Append all messages to log file */ - if( p_main->p_msg->i_log_file >= 0 ) + if( p_main->p_msg->p_log_file != NULL ) { - write( p_main->p_msg->i_log_file, psz_msg, strlen( psz_msg ) ); + fwrite( psz_msg, strlen( psz_msg ), 1, p_main->p_msg->p_log_file ); + fwrite( "\n", 1, 1, p_main->p_msg->p_log_file ); } #endif @@ -613,11 +657,11 @@ static void PrintMsg( intf_msg_item_t *p_msg ) { case INTF_MSG_STD: /* standard messages */ case INTF_MSG_DBG: /* debug messages */ - fprintf( stdout, p_msg->psz_msg ); + fprintf( stdout, "%s\n", p_msg->psz_msg ); break; case INTF_MSG_ERR: /* error messages */ case INTF_MSG_WARN: - fprintf( stderr, p_msg->psz_msg ); /* warning message */ + 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 ); @@ -626,3 +670,4 @@ static void PrintMsg( intf_msg_item_t *p_msg ) } #endif +