diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-26 04:27:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-26 04:27:43 +0200 |
commit | aa4d303a3139107919f73cece4eaf85a7dc75db6 (patch) | |
tree | 53aa8df516e1f4783ddc6d020c7e200587359356 | |
parent | 0c3270f7e55e0ca7b8d664851468511d2c8995cf (diff) | |
download | busybox-w32-aa4d303a3139107919f73cece4eaf85a7dc75db6.tar.gz busybox-w32-aa4d303a3139107919f73cece4eaf85a7dc75db6.tar.bz2 busybox-w32-aa4d303a3139107919f73cece4eaf85a7dc75db6.zip |
od: fix default format, shrink
function old new delta
od_main 556 568 +12
.rodata 104613 104555 -58
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 12/-58) Total: -46 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/od.c | 42 | ||||
-rwxr-xr-x | testsuite/od.tests | 10 |
2 files changed, 32 insertions, 20 deletions
diff --git a/coreutils/od.c b/coreutils/od.c index abedb40a7..3fd241d51 100644 --- a/coreutils/od.c +++ b/coreutils/od.c | |||
@@ -144,35 +144,36 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) | |||
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | // A format string contains format units separated by whitespace. | 147 | // bb_dump_add(): |
148 | // A format string contains format units separated by [optional] whitespace. | ||
148 | // A format unit contains up to three items: an iteration count, a byte count, | 149 | // A format unit contains up to three items: an iteration count, a byte count, |
149 | // and a format. | 150 | // and a format. |
150 | // The iteration count is an optional integer (default 1) | 151 | // The iteration count is an optional integer (default 1). |
151 | // Each format is applied iteration count times. | 152 | // Each format is applied iteration count times. |
152 | // The byte count is an optional integer. It defines the number | 153 | // The byte count is an optional integer. It defines the number |
153 | // of bytes to be interpreted by each iteration of the format. | 154 | // of bytes to be interpreted by each iteration of the format. |
154 | // If an iteration count and/or a byte count is specified, a slash must be | 155 | // If an iteration count and/or a byte count is specified, a slash must be |
155 | // placed after the iteration count and/or before the byte count | 156 | // placed after the iteration count and/or before the byte count |
156 | // to disambiguate them. | 157 | // to disambiguate them. |
157 | // The format is required and must be surrounded by " "s. | 158 | // The printf-style format is required and must be surrounded by " "s. |
158 | // It is a printf-style format. | 159 | // (Below, each string contains two format units) |
159 | static const char *const add_strings[] ALIGN_PTR = { | 160 | static const char *const add_strings[] ALIGN_PTR = { |
160 | "16/1 \" %3_u\" \"\\n\"", /* 0: a */ | 161 | "16/1 \" %3_u\"" "\"\n\"", /* 0: a */ |
161 | "8/2 \" %06o\" \"\\n\"", /* 1: B (undocumented in od), o */ | 162 | "8/2 \" %06o\"" "\"\n\"", /* 1: B (undocumented in od), o */ |
162 | "16/1 \" %03o\" \"\\n\"", /* 2: b */ | 163 | "16/1 \" %03o\"" "\"\n\"", /* 2: b */ |
163 | "16/1 \" %3_c\" \"\\n\"", /* 3: c */ | 164 | "16/1 \" %3_c\"" "\"\n\"", /* 3: c */ |
164 | "8/2 \" %5u\" \"\\n\"", /* 4: d */ | 165 | "8/2 \" %5u\"" "\"\n\"", /* 4: d */ |
165 | "4/4 \" %10u\" \"\\n\"", /* 5: D */ | 166 | "4/4 \" %10u\"" "\"\n\"", /* 5: D */ |
166 | "2/8 \" %24.14e\" \"\\n\"", /* 6: e (undocumented in od), F */ | 167 | "2/8 \" %24.14e\"" "\"\n\"", /* 6: e (undocumented in od), F */ |
167 | "4/4 \" %15.7e\" \"\\n\"", /* 7: f */ | 168 | "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */ |
168 | "4/4 \" %08x\" \"\\n\"", /* 8: H, X */ | 169 | "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */ |
169 | "8/2 \" %04x\" \"\\n\"", /* 9: h, x */ | 170 | "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */ |
170 | /* This probably also depends on word width of the arch (what is "long"?) */ | 171 | /* This probably also depends on word width of the arch (what is "long"?) */ |
171 | /* should be "2/8" or "4/4" depending on sizeof(long)? */ | 172 | /* should be "2/8" or "4/4" depending on sizeof(long)? */ |
172 | "2/8 \" %20lld\" \"\\n\"", /* 10: I, L, l */ | 173 | "2/8 \" %20lld\"" "\"\n\"", /* 10: I, L, l */ |
173 | "4/4 \" %11d\" \"\\n\"", /* 11: i */ | 174 | "4/4 \" %11d\"" "\"\n\"", /* 11: i */ |
174 | "4/4 \" %011o\" \"\\n\"", /* 12: O */ | 175 | "4/4 \" %011o\"" "\"\n\"", /* 12: O */ |
175 | "8/2 \" %6d\" \"\\n\"", /* 13: s */ | 176 | "8/2 \" %6d\"" "\"\n\"", /* 13: s */ |
176 | }; | 177 | }; |
177 | 178 | ||
178 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; | 179 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; |
@@ -204,13 +205,14 @@ int od_main(int argc, char **argv) | |||
204 | bb_dump_add(dumper, "\" \""); | 205 | bb_dump_add(dumper, "\" \""); |
205 | } | 206 | } |
206 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); | 207 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); |
207 | } else { /* P, p, s, w, or other unhandled */ | 208 | } else { /* P, p, w, or other unhandled */ |
208 | bb_show_usage(); | 209 | bb_show_usage(); |
209 | } | 210 | } |
210 | } | 211 | } |
211 | if (!dumper->fshead) { | 212 | if (!dumper->fshead) { |
212 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); | 213 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); |
213 | bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); | 214 | bb_dump_add(dumper, "\"%07.7_ao\""); |
215 | bb_dump_add(dumper, add_strings[1]); /* -o format is default */ | ||
214 | } | 216 | } |
215 | dumper->od_eofstring = "\n"; | 217 | dumper->od_eofstring = "\n"; |
216 | 218 | ||
diff --git a/testsuite/od.tests b/testsuite/od.tests index 4b1525620..d6f50a206 100755 --- a/testsuite/od.tests +++ b/testsuite/od.tests | |||
@@ -12,6 +12,16 @@ le=false | |||
12 | { printf '\0\1' | od -s | grep -q 256; } && le=true | 12 | { printf '\0\1' | od -s | grep -q 256; } && le=true |
13 | readonly le | 13 | readonly le |
14 | 14 | ||
15 | $le || SKIP=1 | ||
16 | testing "od (little-endian)" \ | ||
17 | "od" \ | ||
18 | "\ | ||
19 | 0000000 001001 005003 041101 177103 | ||
20 | 0000010 | ||
21 | " \ | ||
22 | "" "$input" | ||
23 | SKIP= | ||
24 | |||
15 | optional !DESKTOP | 25 | optional !DESKTOP |
16 | testing "od -a (!DESKTOP)" \ | 26 | testing "od -a (!DESKTOP)" \ |
17 | "od -a" \ | 27 | "od -a" \ |