[rtmpdump] r131 - in trunk: log.c log.h

hyc subversion at mplayerhq.hu
Tue Dec 29 23:23:07 CET 2009


Author: hyc
Date: Tue Dec 29 23:23:05 2009
New Revision: 131

Log:
Make LogHexString() more usable, add DEBUG2 level

Modified:
   trunk/log.c
   trunk/log.h

Modified: trunk/log.c
==============================================================================
--- trunk/log.c	Tue Dec 29 11:59:24 2009	(r130)
+++ trunk/log.c	Tue Dec 29 23:23:05 2009	(r131)
@@ -22,6 +22,8 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
+#include <assert.h>
+#include <ctype.h>
 
 #include "log.h"
 
@@ -121,18 +123,53 @@ void LogHex(int level, const char *data,
 	LogPrintf("\n");
 }
 
-void LogHexString(const char *data, unsigned long len)
+void LogHexString(int level, const char *data, unsigned long len)
 {
+	static const char hexdig[] = "0123456789abcdef";
+#define BP_OFFSET 9
+#define BP_GRAPH 60
+#define BP_LEN	80
+	char	line[BP_LEN];
 	unsigned long i;
-	if ( debuglevel==LOGCRIT )
+
+	if ( !data || level > debuglevel )
 		return;
-	for(i=0; i<len; i++) {
-		LogPrintf("%02X ", (unsigned char)data[i]);
-	}
-	LogPrintf("\n");
 
-	for(i=0; i<len; i++) {
-		LogPrintf("%c", (unsigned char)data[i]);
+	/* in case len is zero */
+	line[0] = '\n';
+	line[1] = '\0';
+
+	for ( i = 0 ; i < len ; i++ ) {
+		int n = i % 16;
+		unsigned off;
+
+		if( !n ) {
+			if( i ) LogPrintf( "%s", line );
+			memset( line, ' ', sizeof(line)-2 );
+			line[sizeof(line)-2] = '\n';
+			line[sizeof(line)-1] = '\0';
+
+			off = i % 0x0ffffU;
+
+			line[2] = hexdig[0x0f & (off >> 12)];
+			line[3] = hexdig[0x0f & (off >>  8)];
+			line[4] = hexdig[0x0f & (off >>  4)];
+			line[5] = hexdig[0x0f & off];
+			line[6] = ':';
+		}
+
+		off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
+		line[off] = hexdig[0x0f & ( data[i] >> 4 )];
+		line[off+1] = hexdig[0x0f & data[i]];
+
+		off = BP_GRAPH + n + ((n >= 8)?1:0);
+
+		if ( isprint( (unsigned char) data[i] )) {
+			line[BP_GRAPH + n] = data[i];
+		} else {
+			line[BP_GRAPH + n] = '.';
+		}
 	}
-	LogPrintf("\n");
+
+	LogPrintf( "%s", line );
 }

Modified: trunk/log.h
==============================================================================
--- trunk/log.h	Tue Dec 29 11:59:24 2009	(r130)
+++ trunk/log.h	Tue Dec 29 23:23:05 2009	(r131)
@@ -39,8 +39,9 @@ extern "C" {
 #define LOGERROR        1
 #define LOGWARNING	2
 #define LOGINFO		3
-#define LOGDEBUG		4
-#define LOGALL		5
+#define LOGDEBUG	4
+#define LOGDEBUG2	5
+#define LOGALL		6
 
 #define Log	AMF_Log
 #define LogHex	AMF_LogHex
@@ -57,7 +58,7 @@ void LogPrintf(const char *format, ...);
 void LogStatus(const char *format, ...);
 void Log(int level, const char *format, ...);
 void LogHex(int level, const char *data, unsigned long len);
-void LogHexString(const char *data, unsigned long len);
+void LogHexString(int level, const char *data, unsigned long len);
 
 #ifdef __cplusplus
 }


More information about the rtmpdump mailing list