improve GFX2_LogHexDump() : dont print consecutive 00's lines

This commit is contained in:
Thomas Bernard 2019-12-06 00:10:45 +01:00
parent fea7ac6a3c
commit 06d69ac90a
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -87,9 +87,27 @@ extern void GFX2_LogHexDump(GFX2_Log_priority_T priority, const char * header, c
{ {
char line[128]; char line[128];
long i; long i;
int previous_allzero_count = 0;
while (count > 0) while (count > 0)
{ {
int p = 0, r; int p = 0, r;
int allzero = 1;
for (i = 0; i < count && i < 16; i++)
{
if (data[offset+i] != 0)
{
allzero = 0;
break;
}
}
if (previous_allzero_count && allzero)
{
// prints a single "*" for multiple line of 00's
if (previous_allzero_count == 1)
GFX2_Log(priority, "*\n");
}
else
{
r = snprintf(line + p, sizeof(line) - p, "%s%06lX:", header, offset); r = snprintf(line + p, sizeof(line) - p, "%s%06lX:", header, offset);
if (r < 0) if (r < 0)
return; return;
@ -116,7 +134,15 @@ extern void GFX2_LogHexDump(GFX2_Log_priority_T priority, const char * header, c
line[p++] = data[offset+i]>=32 && data[offset+i]<127 ? data[offset+i] : '.'; line[p++] = data[offset+i]>=32 && data[offset+i]<127 ? data[offset+i] : '.';
line[p++] = '\0'; line[p++] = '\0';
GFX2_Log(priority, "%s\n", line); GFX2_Log(priority, "%s\n", line);
}
if (allzero)
previous_allzero_count++;
else
previous_allzero_count = 0;
count -= i; count -= i;
offset += i; offset += i;
} }
// print the ending offset if there was "*"
if (previous_allzero_count > 1)
GFX2_Log(priority, "%s%06lX\n", header, offset);
} }