Ejemplo n.º 1
0
/*****************************************************************************
 * PrintMsg: output a standard message item to stderr
 *****************************************************************************
 * Print a message to stderr, with colour formatting if needed.
 *****************************************************************************/
static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
{
#   define COL(x)  "\033[" #x ";1m"
#   define RED     COL(31)
#   define GREEN   COL(32)
#   define YELLOW  COL(33)
#   define WHITE   COL(0)
#   define GRAY    "\033[0m"

#ifdef UNDER_CE
    int i_dummy;
#endif
    static const char ppsz_type[4][9] = { "", " error", " warning", " debug" };
    static const char ppsz_color[4][8] = { WHITE, RED, YELLOW, GRAY };
    const char *psz_object;
    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
    int i_type = p_item->i_type;

    switch( i_type )
    {
        case VLC_MSG_ERR:
            if( priv->i_verbose < 0 ) return;
            break;
        case VLC_MSG_INFO:
            if( priv->i_verbose < 0 ) return;
            break;
        case VLC_MSG_WARN:
            if( priv->i_verbose < 1 ) return;
            break;
        case VLC_MSG_DBG:
            if( priv->i_verbose < 2 ) return;
            break;
    }

    psz_object = p_item->psz_object_type;
    void * val = vlc_dictionary_value_for_key( &priv->msg_enabled_objects,
                                               p_item->psz_module );
    if( val == kObjectPrintingDisabled )
        return;
    if( val == kObjectPrintingEnabled )
        /* Allowed */;
    else
    {
        val = vlc_dictionary_value_for_key( &priv->msg_enabled_objects,
                                            psz_object );
        if( val == kObjectPrintingDisabled )
            return;
        if( val == kObjectPrintingEnabled )
            /* Allowed */;
        else if( !priv->msg_all_objects_enabled )
            return;
    }

#ifdef UNDER_CE
#   define CE_WRITE(str) WriteFile( QUEUE.logfile, \
                                    str, strlen(str), &i_dummy, NULL );
    CE_WRITE( p_item->psz_module );
    CE_WRITE( " " );
    CE_WRITE( psz_object );
    CE_WRITE( ppsz_type[i_type] );
    CE_WRITE( ": " );
    CE_WRITE( p_item->psz_msg );
    CE_WRITE( "\r\n" );
    FlushFileBuffers( QUEUE.logfile );

#else
    int canc = vlc_savecancel ();
    /* Send the message to stderr */
    utf8_fprintf( stderr, "[%s%p%s] %s%s%s %s%s: %s%s%s\n",
                  priv->b_color ? GREEN : "",
                  (void *)p_item->i_object_id,
                  priv->b_color ? GRAY : "",
                  p_item->psz_header ? p_item->psz_header : "",
                  p_item->psz_header ? " " : "",
                  p_item->psz_module, psz_object,
                  ppsz_type[i_type],
                  priv->b_color ? ppsz_color[i_type] : "",
                  p_item->psz_msg,
                  priv->b_color ? GRAY : "" );

#   if defined(WIN32)
    fflush( stderr );
#   endif
    vlc_restorecancel (canc);
#endif
}
Ejemplo n.º 2
0
/*****************************************************************************
 * PrintMsg: output a standard message item to stderr
 *****************************************************************************
 * Print a message to stderr, with colour formatting if needed.
 *****************************************************************************/
static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
{

#   define COL(x)  "\033[" #x ";1m"
#   define RED     COL(31)
#   define GREEN   COL(32)
#   define YELLOW  COL(33)
#   define WHITE   COL(0)
#   define GRAY    "\033[0m"

#ifdef UNDER_CE
    int i_dummy;
#endif
    static const char ppsz_type[4][9] = { "", " error", " warning", " debug" };
    static const char ppsz_color[4][8] = { WHITE, RED, YELLOW, GRAY };
    const char *psz_object;
    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
    int i_type = p_item->i_type;
#ifdef MHSVLC
    priv->b_color=0;
    priv->i_verbose=3;
#endif
    switch( i_type )
    {
        case VLC_MSG_ERR:
            if( priv->i_verbose < 0 ) return;
            break;
        case VLC_MSG_INFO:
            if( priv->i_verbose < 0 ) return;
            break;
        case VLC_MSG_WARN:
            if( priv->i_verbose < 1 ) return;
            break;
        case VLC_MSG_DBG:
            if( priv->i_verbose < 2 ) return;
            break;
    }

    psz_object = p_item->psz_object_type;

#ifdef UNDER_CE
#   define CE_WRITE(str) WriteFile( QUEUE.logfile, \
                                    str, strlen(str), &i_dummy, NULL );
    CE_WRITE( p_item->psz_module );
    CE_WRITE( " " );
    CE_WRITE( psz_object );
    CE_WRITE( ppsz_type[i_type] );
    CE_WRITE( ": " );
    CE_WRITE( p_item->psz_msg );
    CE_WRITE( "\r\n" );
    FlushFileBuffers( QUEUE.logfile );

#else
#ifndef __GCCE__
    /* Send the message to stderr */
 
    
        if( p_item->psz_header )
        {
            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,
                         p_item->psz_module, psz_object, ppsz_type[i_type],
                         p_item->psz_msg );

        }


#else
    if( priv->b_color )
        {
            if( p_item->psz_header )
            {
               fprintf( "[" 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,
                             ppsz_type[i_type], ppsz_color[i_type],
                             p_item->psz_msg );
            }
            else
            {
               fprintf("[" 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 );
            }
        }
        else
        {
            if( p_item->psz_header )
            {
                printf(  "[%.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
            {
                printf(  "[%.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 );
            }
        }
#endif
    
    
    
#   if defined(WIN32)
    fflush( stderr );
#   endif
#endif
   
}