From 6778323dcdcfac399be811e4e6c45072f7aa4526 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Thu, 29 Sep 2011 18:18:13 +0000 Subject: log printable ascii with hexdumps Provides similar output to 'hexdump -C' *nix command. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4262 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/common.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'libhb/common.c') diff --git a/libhb/common.c b/libhb/common.c index 01884f02b..5abc9b950 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -6,6 +6,7 @@ #include #include +#include #include #include "common.h" @@ -1643,8 +1644,12 @@ 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; + char line[80], ascii[19], *p; + ascii[18] = 0; + ascii[0] = '|'; + ascii[17] = '|'; + memset(&ascii[1], '.', 16); p = line; if( label ) hb_deep_log(level, "++++ %s ++++", label); @@ -1655,7 +1660,8 @@ void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * dat if( ( ii & 0x0f ) == 0x0f ) { p += sprintf( p, "%02x", data[ii] ); - hb_deep_log( level, " %s", line ); + hb_deep_log( level, " %-50s%20s", line, ascii ); + memset(&ascii[1], '.', 16); p = line; } else if( ( ii & 0x07 ) == 0x07 ) @@ -1666,10 +1672,15 @@ void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * dat { p += sprintf( p, "%02x ", data[ii] ); } + if( isgraph( data[ii] ) ) + ascii[(ii & 0x0f) + 1] = data[ii]; + else + ascii[(ii & 0x0f) + 1] = '.'; } + ascii[ii] = 0; if( p != line ) { - hb_deep_log( level, " %s", line ); + hb_deep_log( level, " %-50s%20s", line, ascii ); } } -- cgit v1.2.3