[git commit] hexdump, xxd: shrink strings

Denys Vlasenko vda.linux at googlemail.com
Fri May 26 12:46:29 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=283cba78f2c9ea8478ef58ba616197df31640353
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
add_first                                             12      10      -2
.rodata                                           105321  105306     -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 util-linux/hexdump.c     | 20 ++++++++++----------
 util-linux/hexdump_xxd.c |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c
index 307a84803..421fe025d 100644
--- a/util-linux/hexdump.c
+++ b/util-linux/hexdump.c
@@ -72,14 +72,14 @@ static void bb_dump_addfile(dumper_t *dumper, char *name)
 }
 
 static const char *const add_strings[] ALIGN_PTR = {
-	"\"%07.7_ax \"16/1 \"%03o \"\"\n\"",   /* b */
-	"\"%07.7_ax \"16/1 \"%3_c \"\"\n\"",   /* c */
-	"\"%07.7_ax \"8/2 \"  %05u \"\"\n\"",  /* d */
-	"\"%07.7_ax \"8/2 \" %06o \"\"\n\"",   /* o */
-	"\"%07.7_ax \"8/2 \"   %04x \"\"\n\"", /* x */
+	"\"%07_ax\"16/1 \" %03o\""   "\"\n\"", /* b */
+	"\"%07_ax\"16/1 \" %3_c\""   "\"\n\"", /* c */
+	"\"%07_ax\"8/2 \"   %05u\""  "\"\n\"", /* d */
+	"\"%07_ax\"8/2 \"  %06o\""   "\"\n\"", /* o */
+	"\"%07_ax\"8/2 \"    %04x\"" "\"\n\"", /* x */
 };
 
-static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\"";
+static const char add_first[] ALIGN1 = "\"%07_Ax\n\"";
 
 static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v";
 
@@ -110,9 +110,9 @@ int hexdump_main(int argc, char **argv)
 		/* Save a little bit of space below by omitting the 'else's. */
 		if (ch == 'C') {
  hd_applet:
-			bb_dump_add(dumper, "\"%08.8_Ax\n\""); // final address line after dump
-			//------------------- "address  "   8 * "xx "    "  "  8 * "xx "
-			bb_dump_add(dumper, "\"%08.8_ax  \"8/1 \"%02x \"\"  \"8/1 \"%02x \"");
+			bb_dump_add(dumper, "\"%08_Ax\n\""); // final address line after dump
+			//------------------- "address "   8 * " xx"  " "  8 * " xx"
+			bb_dump_add(dumper, "\"%08_ax \"8/1 \" %02x\"\" \"8/1 \" %02x\"");
 			//------------------- "  |ASCII...........|\n"
 			bb_dump_add(dumper, "\"  |\"16/1 \"%_p\"\"|\n\"");
 		}
@@ -140,7 +140,7 @@ int hexdump_main(int argc, char **argv)
 
 	if (!dumper->fshead) {
 		bb_dump_add(dumper, add_first);
-		bb_dump_add(dumper, "\"%07.7_ax \"8/2 \"%04x \"\"\n\"");
+		bb_dump_add(dumper, "\"%07_ax\"8/2 \" %04x\"\"\n\"");
 	}
 
 	argv += optind;
diff --git a/util-linux/hexdump_xxd.c b/util-linux/hexdump_xxd.c
index 9738a76ad..636cbfeec 100644
--- a/util-linux/hexdump_xxd.c
+++ b/util-linux/hexdump_xxd.c
@@ -285,7 +285,7 @@ int xxd_main(int argc UNUSED_PARAM, char **argv)
 			// output is "  0xXX, 0xXX, 0xXX...", add leading space
 			bb_dump_add(dumper, "\" \"");
 		} else
-			bb_dump_add(dumper, "\"%08.8_ax: \""); // "address: "
+			bb_dump_add(dumper, "\"%08_ax: \""); // "address: "
 	}
 
 	if (bytes < 1 || bytes >= cols) {


More information about the busybox-cvs mailing list