summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-05-10 19:03:10 +0100
committerGitHub <noreply@github.com>2020-05-10 19:03:10 +0100
commit898caead46faa50985c0de009eeec497f617165a (patch)
tree944a0a0f361d5b56a79a127950da8e3f38eed8e1
parent66137ff6ea9e516e0fa840134393d5a81d5b86e9 (diff)
parent5d37128db155d0688d7e8391a9eb5fe1d32a844f (diff)
downloadlibgit2-898caead46faa50985c0de009eeec497f617165a.tar.gz
Merge pull request #5431 from libgit2/ethomson/hexdump
git__hexdump: better mimic `hexdump -C`
-rw-r--r--src/util.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/util.c b/src/util.c
index 859e0a82b..745f840c0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -424,35 +424,48 @@ void git__hexdump(const char *buffer, size_t len)
last_line = (len % LINE_WIDTH);
for (i = 0; i < line_count; ++i) {
+ printf("%08" PRIxZ " ", (i * LINE_WIDTH));
+
line = buffer + (i * LINE_WIDTH);
- for (j = 0; j < LINE_WIDTH; ++j, ++line)
- printf("%02X ", (unsigned char)*line & 0xFF);
+ for (j = 0; j < LINE_WIDTH; ++j, ++line) {
+ printf("%02x ", (unsigned char)*line & 0xFF);
+
+ if (j == (LINE_WIDTH / 2))
+ printf(" ");
+ }
- printf("| ");
+ printf(" |");
line = buffer + (i * LINE_WIDTH);
for (j = 0; j < LINE_WIDTH; ++j, ++line)
printf("%c", (*line >= 32 && *line <= 126) ? *line : '.');
- printf("\n");
+ printf("|\n");
}
if (last_line > 0) {
+ printf("%08" PRIxZ " ", (line_count * LINE_WIDTH));
line = buffer + (line_count * LINE_WIDTH);
- for (j = 0; j < last_line; ++j, ++line)
- printf("%02X ", (unsigned char)*line & 0xFF);
+ for (j = 0; j < last_line; ++j, ++line) {
+ printf("%02x ", (unsigned char)*line & 0xFF);
+
+ if (j == (LINE_WIDTH / 2))
+ printf(" ");
+ }
+ if (j < (LINE_WIDTH / 2))
+ printf(" ");
for (j = 0; j < (LINE_WIDTH - last_line); ++j)
- printf(" ");
+ printf(" ");
- printf("| ");
+ printf(" |");
line = buffer + (line_count * LINE_WIDTH);
for (j = 0; j < last_line; ++j, ++line)
printf("%c", (*line >= 32 && *line <= 126) ? *line : '.');
- printf("\n");
+ printf("|\n");
}
printf("\n");