]> granicus.if.org Git - handbrake/commitdiff
libhb: fix a warning in decssasub.c by adding new hb_valog function
authorjstebbins <jstebbins.hb@gmail.com>
Wed, 15 Jun 2011 16:38:13 +0000 (16:38 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Wed, 15 Jun 2011 16:38:13 +0000 (16:38 +0000)
And consolidate logging code in hb_valog.  hb_log and hb_deep_log
call hb_valog.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4060 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/decssasub.c
libhb/internal.h

index 5f3ce49f8bc23c5a412349e19f6ed44595f94fbd..2b2917e5d1ddfe8066effc864375578caa41476c 100644 (file)
@@ -852,18 +852,18 @@ void hb_list_close( hb_list_t ** _l )
     *_l = NULL;
 }
 
+int global_verbosity_level; //Necessary for hb_deep_log
 /**********************************************************************
- * hb_log
+ * hb_valog
  **********************************************************************
  * If verbose mode is one, print message with timestamp. Messages
  * longer than 180 characters are stripped ;p
  *********************************************************************/
-void hb_log( char * log, ... )
+void hb_valog( hb_debug_level_t level, const char * prefix, const char * log, va_list args)
 {
     char        string[362]; /* 360 chars + \n + \0 */
     time_t      _now;
     struct tm * now;
-    va_list     args;
 
     if( !getenv( "HB_DEBUG" ) )
     {
@@ -871,16 +871,30 @@ void hb_log( char * log, ... )
         return;
     }
 
+    if( global_verbosity_level < level )
+    {
+        /* Hiding message */
+        return;
+    }
+
     /* Get the time */
     _now = time( NULL );
     now  = localtime( &_now );
-    sprintf( string, "[%02d:%02d:%02d] ",
-             now->tm_hour, now->tm_min, now->tm_sec );
+    if ( prefix && *prefix )
+    {
+        // limit the prefix length
+        snprintf( string, 40, "[%02d:%02d:%02d] %s ",
+                 now->tm_hour, now->tm_min, now->tm_sec, prefix );
+    }
+    else
+    {
+        sprintf( string, "[%02d:%02d:%02d] ",
+                 now->tm_hour, now->tm_min, now->tm_sec );
+    }
+    int end = strlen( string );
 
     /* Convert the message to a string */
-    va_start( args, log );
-    vsnprintf( string + 11, 349, log, args );
-    va_end( args );
+    vsnprintf( string + end, 361 - end, log, args );
 
     /* Add the end of line */
     strcat( string, "\n" );
@@ -889,7 +903,21 @@ void hb_log( char * log, ... )
     fprintf( stderr, "%s", string );
 }
 
-int global_verbosity_level; //Necessary for hb_deep_log
+/**********************************************************************
+ * hb_log
+ **********************************************************************
+ * If verbose mode is one, print message with timestamp. Messages
+ * longer than 180 characters are stripped ;p
+ *********************************************************************/
+void hb_log( char * log, ... )
+{
+    va_list     args;
+
+    va_start( args, log );
+    hb_valog( 0, NULL, log, args );
+    va_end( args );
+}
+
 /**********************************************************************
  * hb_deep_log
  **********************************************************************
@@ -898,33 +926,11 @@ int global_verbosity_level; //Necessary for hb_deep_log
  *********************************************************************/
 void hb_deep_log( hb_debug_level_t level, char * log, ... )
 {
-    char        string[362]; /* 360 chars + \n + \0 */
-    time_t      _now;
-    struct tm * now;
     va_list     args;
 
-    if( global_verbosity_level < level )
-    {
-        /* Hiding message */
-        return;
-    }
-
-    /* Get the time */
-    _now = time( NULL );
-    now  = localtime( &_now );
-    sprintf( string, "[%02d:%02d:%02d] ",
-             now->tm_hour, now->tm_min, now->tm_sec );
-
-    /* Convert the message to a string */
     va_start( args, log );
-    vsnprintf( string + 11, 349, log, args );
+    hb_valog( level, NULL, log, args );
     va_end( args );
-
-    /* Add the end of line */
-    strcat( string, "\n" );
-
-    /* Print it */
-    fprintf( stderr, "%s", string );
 }
 
 /**********************************************************************
index 460a8ddc05f240a052bc38b4f01a1bf33be33b6b..2d2ec3d2b5494f890d04fe7ad6897e3fb0c46544 100644 (file)
@@ -19,7 +19,6 @@
  * 
  * @author David Foster (davidfstr)
  */
-
 #include <stdlib.h>
 #include <stdio.h>
 #include "hb.h"
@@ -574,15 +573,7 @@ static void ssa_log(int level, const char *fmt, va_list args, void *data)
 {
     if ( level < 5 )      // same as default verbosity when no callback is set
     {
-        char *msg;
-        if ( vasprintf( &msg, fmt, args ) < 0 )
-        {
-            hb_log( "decssasub: could not report libass message\n" );
-            return;
-        }
-        hb_log( "[ass] %s", msg );  // no need for extra '\n' because libass sends it
-        
-        free( msg );
+        hb_valog( 1, "[ass]", fmt, args );
     }
 }
 
index f92ce263a8bed2255abdda0d7f53339b3bea4728..b78072ad869fb74120161da79f580a4da42c90f1 100644 (file)
@@ -15,6 +15,7 @@ typedef enum hb_debug_level_s
     HB_HOUSEKEEPING_LOG = 2, // stuff we hate scrolling through  
     HB_GRANULAR_LOG     = 3  // sample-by-sample
 } hb_debug_level_t;
+void hb_valog( hb_debug_level_t level, const char * prefix, const char * log, va_list args) HB_WPRINTF(3,0);
 void hb_deep_log( hb_debug_level_t level, char * log, ... ) HB_WPRINTF(2,3);
 void hb_error( char * fmt, ...) HB_WPRINTF(1,2);