diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-02-04 14:57:16 +0200 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-02-10 13:15:58 +0200 |
commit | 044ff5e4cda4e0cfddd0363389ea9824d211b2bf (patch) | |
tree | 8231c929deab216772ca86ba8d57c1d4f622ae3d /client/display.c | |
parent | cfe7f0a6134d6d01b91c502bf3b7e770901bdefd (diff) | |
download | bluez-044ff5e4cda4e0cfddd0363389ea9824d211b2bf.tar.gz |
client/display: Add rl_hexdump
Diffstat (limited to 'client/display.c')
-rw-r--r-- | client/display.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/client/display.c b/client/display.c index 0f212b68e..619973cfa 100644 --- a/client/display.c +++ b/client/display.c @@ -62,3 +62,44 @@ void rl_printf(const char *fmt, ...) free(saved_line); } } + +void rl_hexdump(const unsigned char *buf, size_t len) +{ + static const char hexdigits[] = "0123456789abcdef"; + char str[68]; + size_t i; + + if (!len) + return; + + str[0] = ' '; + + for (i = 0; i < len; i++) { + str[((i % 16) * 3) + 1] = ' '; + str[((i % 16) * 3) + 2] = hexdigits[buf[i] >> 4]; + str[((i % 16) * 3) + 3] = hexdigits[buf[i] & 0xf]; + str[(i % 16) + 51] = isprint(buf[i]) ? buf[i] : '.'; + + if ((i + 1) % 16 == 0) { + str[49] = ' '; + str[50] = ' '; + str[67] = '\0'; + rl_printf("%s\n", str); + str[0] = ' '; + } + } + + if (i % 16 > 0) { + size_t j; + for (j = (i % 16); j < 16; j++) { + str[(j * 3) + 1] = ' '; + str[(j * 3) + 2] = ' '; + str[(j * 3) + 3] = ' '; + str[j + 51] = ' '; + } + str[49] = ' '; + str[50] = ' '; + str[67] = '\0'; + rl_printf("%s\n", str); + } +} |