]> granicus.if.org Git - handbrake/commitdiff
add utility function for doing hexdumps to log
authorjstebbins <jstebbins.hb@gmail.com>
Tue, 27 Sep 2011 00:48:35 +0000 (00:48 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Tue, 27 Sep 2011 00:48:35 +0000 (00:48 +0000)
I find myself re-writing a quick and dirty hexdump function far too
often when debugging.  This will save some time in the future.

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

libhb/common.c
libhb/internal.h

index ce0f1a7f65c3b67e1790de6f0a3ba5958f7d931c..51a5139fe70c99141638b038aabbc89a673b4707 100644 (file)
@@ -1634,3 +1634,36 @@ const char * hb_subsource_name( int source )
     }
 }
 
+void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * data, int len )
+{
+    int ii;
+    char line[80], *p;
+
+    p = line;
+    if( label )
+        hb_deep_log(level, "++++ %s ++++", label);
+    else
+        hb_deep_log(level, "++++++++++++");
+    for( ii = 0; ii < len; ii++ )
+    {
+        if( ( ii & 0x0f ) == 0x0f )
+        {
+            p += sprintf( p, "%02x", data[ii] );
+            hb_deep_log( level, "    %s", line );
+            p = line;
+        }
+        else if( ( ii & 0x07 ) == 0x07 )
+        {
+            p += sprintf( p, "%02x  ", data[ii] );
+        }
+        else
+        {
+            p += sprintf( p, "%02x ", data[ii] );
+        }
+    }
+    if( p != line )
+    {
+        hb_deep_log( level, "    %s", line );
+    }
+}
+
index 77ead967ca3d3c57b3d138f37389ed261977e432..63220f5cb497f0a4198f5580bb851f07deea353e 100644 (file)
@@ -18,6 +18,7 @@ typedef enum hb_debug_level_s
 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);
+void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * data, int len );
 
 int  hb_list_bytes( hb_list_t * );
 void hb_list_seebytes( hb_list_t * l, uint8_t * dst, int size );