diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-26 16:43:40 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-26 16:43:40 +0200 |
commit | d7814f572725f224fcef8870a75c2483043d3681 (patch) | |
tree | 45ff64e890baa569c1ff9110205605d4f48282a0 | |
parent | 283cba78f2c9ea8478ef58ba616197df31640353 (diff) | |
download | busybox-w32-d7814f572725f224fcef8870a75c2483043d3681.tar.gz busybox-w32-d7814f572725f224fcef8870a75c2483043d3681.tar.bz2 busybox-w32-d7814f572725f224fcef8870a75c2483043d3681.zip |
hexdump: code shrink
function old new delta
add_format - 50 +50
add_first 10 - -10
hexdump_main 401 366 -35
.rodata 105306 105255 -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 50/-96) Total: -46 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/hexdump.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index 421fe025d..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 | ||
74 | static const char *const add_strings[] ALIGN_PTR = { | 74 | static const char *const add_strings[] ALIGN_PTR = { |
75 | "\"%07_ax\"16/1 \" %03o\"" "\"\n\"", /* b */ | 75 | "16/1 \" %03o" , /* b */ |
76 | "\"%07_ax\"16/1 \" %3_c\"" "\"\n\"", /* c */ | 76 | "16/1 \" %3_c" , /* c */ |
77 | "\"%07_ax\"8/2 \" %05u\"" "\"\n\"", /* d */ | 77 | "8/2 \" %05u" , /* d */ |
78 | "\"%07_ax\"8/2 \" %06o\"" "\"\n\"", /* o */ | 78 | "8/2 \" %06o" , /* o */ |
79 | "\"%07_ax\"8/2 \" %04x\"" "\"\n\"", /* x */ | 79 | "8/2 \" %04x", /* x */ |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static const char add_first[] ALIGN1 = "\"%07_Ax\n\""; | 82 | static 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 | ||
84 | static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; | 90 | static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; |
85 | 91 | ||
@@ -104,8 +110,7 @@ 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') { |
@@ -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_ax\"8/2 \" %04x\"\"\n\""); | ||
144 | } | 148 | } |
145 | 149 | ||
146 | argv += optind; | 150 | argv += optind; |