From ef2bd77ebda12fbbfd11a9c15de6eee2c2a3f20b Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sun, 29 Apr 2012 09:05:21 +0400 Subject: [PATCH] show: Beautify output of the -c data dump Calculate the best width for address and print them all with it. Signed-off-by: Pavel Emelyanov --- cr-show.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cr-show.c b/cr-show.c index c0193f46f..6d4e0ec7c 100644 --- a/cr-show.c +++ b/cr-show.c @@ -254,12 +254,26 @@ void show_vmas(int fd_vma, struct cr_options *o) pr_img_tail(CR_FD_VMAS); } +static int nice_width_for(unsigned long addr) +{ + int ret = 3; + + while (addr) { + addr >>= 4; + ret++; + } + + return ret; +} + void print_data(unsigned long addr, unsigned char *data, size_t size) { - int i, j; + int i, j, addr_len; + + addr_len = nice_width_for(addr + size); for (i = 0; i < size; i+= 16) { - pr_msg("0x%16lx: ", addr + i); + pr_msg("%#0*lx: ", addr_len, addr + i); for (j = 0; j < 8; j++) pr_msg("0x%02x ", data[i + j]); pr_msg(" ");