aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-06-16 13:02:47 +0100
committerRon Yorston <rmy@pobox.com>2023-06-16 13:02:47 +0100
commit4b3d7e62cff6015e1c4b856165efd90cf9182a5c (patch)
tree0a59c6a94a47c3e8f1a47b0a3218f9591b842385 /util-linux
parent0627e352656effac8d8e617378e7a68edfce41df (diff)
parent2ca39ffd447ca874fcea933194829717d5573247 (diff)
downloadbusybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.tar.gz
busybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.tar.bz2
busybox-w32-4b3d7e62cff6015e1c4b856165efd90cf9182a5c.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/hexdump.c30
-rw-r--r--util-linux/hexdump_xxd.c2
2 files changed, 18 insertions, 14 deletions
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c
index 307a84803..be4c1964f 100644
--- a/util-linux/hexdump.c
+++ b/util-linux/hexdump.c
@@ -72,14 +72,20 @@ static void bb_dump_addfile(dumper_t *dumper, char *name)
72} 72}
73 73
74static const char *const add_strings[] ALIGN_PTR = { 74static const char *const add_strings[] ALIGN_PTR = {
75 "\"%07.7_ax \"16/1 \"%03o \"\"\n\"", /* b */ 75 "16/1 \" %03o" , /* b */
76 "\"%07.7_ax \"16/1 \"%3_c \"\"\n\"", /* c */ 76 "16/1 \" %3_c" , /* c */
77 "\"%07.7_ax \"8/2 \" %05u \"\"\n\"", /* d */ 77 "8/2 \" %05u" , /* d */
78 "\"%07.7_ax \"8/2 \" %06o \"\"\n\"", /* o */ 78 "8/2 \" %06o" , /* o */
79 "\"%07.7_ax \"8/2 \" %04x \"\"\n\"", /* x */ 79 "8/2 \" %04x", /* x */
80}; 80};
81 81
82static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\""; 82static void add_format(dumper_t *dumper, const char *fmt)
83{
84 char fmtbuf[sizeof("\"%07_ax\"" "%s\"" "\"\n\"") + 16];
85 sprintf(fmtbuf, "\"%%07_ax\"" "%s\"" "\"\n\"", fmt);
86 bb_dump_add(dumper, "\"%07_Ax\n\"");
87 bb_dump_add(dumper, fmtbuf);
88}
83 89
84static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; 90static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v";
85 91
@@ -104,15 +110,14 @@ int hexdump_main(int argc, char **argv)
104 if (!p) 110 if (!p)
105 bb_show_usage(); 111 bb_show_usage();
106 if ((p - hexdump_opts) < 5) { 112 if ((p - hexdump_opts) < 5) {
107 bb_dump_add(dumper, add_first); 113 add_format(dumper, add_strings[(int)(p - hexdump_opts)]);
108 bb_dump_add(dumper, add_strings[(int)(p - hexdump_opts)]);
109 } 114 }
110 /* Save a little bit of space below by omitting the 'else's. */ 115 /* Save a little bit of space below by omitting the 'else's. */
111 if (ch == 'C') { 116 if (ch == 'C') {
112 hd_applet: 117 hd_applet:
113 bb_dump_add(dumper, "\"%08.8_Ax\n\""); // final address line after dump 118 bb_dump_add(dumper, "\"%08_Ax\n\""); // final address line after dump
114 //------------------- "address " 8 * "xx " " " 8 * "xx " 119 //------------------- "address " 8 * " xx" " " 8 * " xx"
115 bb_dump_add(dumper, "\"%08.8_ax \"8/1 \"%02x \"\" \"8/1 \"%02x \""); 120 bb_dump_add(dumper, "\"%08_ax \"8/1 \" %02x\"\" \"8/1 \" %02x\"");
116 //------------------- " |ASCII...........|\n" 121 //------------------- " |ASCII...........|\n"
117 bb_dump_add(dumper, "\" |\"16/1 \"%_p\"\"|\n\""); 122 bb_dump_add(dumper, "\" |\"16/1 \"%_p\"\"|\n\"");
118 } 123 }
@@ -139,8 +144,7 @@ int hexdump_main(int argc, char **argv)
139 } 144 }
140 145
141 if (!dumper->fshead) { 146 if (!dumper->fshead) {
142 bb_dump_add(dumper, add_first); 147 add_format(dumper, "8/2 \" %04x");
143 bb_dump_add(dumper, "\"%07.7_ax \"8/2 \"%04x \"\"\n\"");
144 } 148 }
145 149
146 argv += optind; 150 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)
285 // output is " 0xXX, 0xXX, 0xXX...", add leading space 285 // output is " 0xXX, 0xXX, 0xXX...", add leading space
286 bb_dump_add(dumper, "\" \""); 286 bb_dump_add(dumper, "\" \"");
287 } else 287 } else
288 bb_dump_add(dumper, "\"%08.8_ax: \""); // "address: " 288 bb_dump_add(dumper, "\"%08_ax: \""); // "address: "
289 } 289 }
290 290
291 if (bytes < 1 || bytes >= cols) { 291 if (bytes < 1 || bytes >= cols) {