From 4d1616179745ee3883a726aaf13468e9c44dff9e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jun 2021 23:53:30 +0200 Subject: xxd: implement -o DISPLAYOFFSET function old new delta xxd_main 680 710 +30 xstrtoll - 30 +30 bb_dump_dump 1511 1531 +20 rewrite 941 951 +10 packed_usage 33629 33639 +10 .rodata 103250 103252 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/0 up/down: 102/0) Total: 102 bytes Signed-off-by: Denys Vlasenko --- libbb/dump.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'libbb') diff --git a/libbb/dump.c b/libbb/dump.c index e83633c..8c2a370 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -228,7 +228,8 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) if ((p1[2] != 'd') && (p1[2] != 'o') && (p1[2] != 'x')) { goto DO_BAD_CONV_CHAR; } - *p1 = p1[2]; + *p1++ = 'l'; + *p1++ = 'l'; break; case 'c': /* %_c: chars, \ooo, \n \r \t etc */ pr->flags = F_C; @@ -558,9 +559,9 @@ static void display(priv_dumper_t* dumper) if (dumper->eaddress && dumper->address >= dumper->eaddress ) { - if (dumper->pub.eofstring) { + if (dumper->pub.xxd_eofstring) { /* xxd support: requested to not pad incomplete blocks */ - fputs_stdout(dumper->pub.eofstring); + fputs_stdout(dumper->pub.xxd_eofstring); return; } if (!(pr->flags & (F_TEXT | F_BPAD))) @@ -572,7 +573,7 @@ static void display(priv_dumper_t* dumper) } switch (pr->flags) { case F_ADDRESS: - printf(pr->fmt, (unsigned) dumper->address); + printf(pr->fmt, (unsigned long long) dumper->address + dumper->pub.xxd_displayoff); break; case F_BPAD: printf(pr->fmt, ""); @@ -674,7 +675,7 @@ static void display(priv_dumper_t* dumper) for (pr = dumper->endfu->nextpr; pr; pr = pr->nextpr) { switch (pr->flags) { case F_ADDRESS: - printf(pr->fmt, (unsigned) dumper->eaddress); + printf(pr->fmt, (unsigned long long) dumper->eaddress + dumper->pub.xxd_displayoff); break; case F_TEXT: printf(pr->fmt); -- cgit v1.1