diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-25 17:39:28 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-25 17:40:20 +0200 |
commit | e2287f99fe6f21fd6435ad04340170ad4ba5f6b3 (patch) | |
tree | 09224d93a16e18c0f4e31ada2375d7ca9cfab03e /coreutils/od.c | |
parent | 64bdd7566c21cb53cb4c384ed52845106529e55f (diff) | |
download | busybox-w32-e2287f99fe6f21fd6435ad04340170ad4ba5f6b3.tar.gz busybox-w32-e2287f99fe6f21fd6435ad04340170ad4ba5f6b3.tar.bz2 busybox-w32-e2287f99fe6f21fd6435ad04340170ad4ba5f6b3.zip |
od: for !DESKTOP, match output more closely to GNU coreutils 9.1, implement -s
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/od.c')
-rw-r--r-- | coreutils/od.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/coreutils/od.c b/coreutils/od.c index dcf1bd6f6..6d562ea91 100644 --- a/coreutils/od.c +++ b/coreutils/od.c | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | //usage:#if !ENABLE_DESKTOP | 23 | //usage:#if !ENABLE_DESKTOP |
24 | //usage:#define od_trivial_usage | 24 | //usage:#define od_trivial_usage |
25 | //usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]" | 25 | //usage: "[-aBbcDdeFfHhIiLlOoXxsv] [FILE]" |
26 | //usage:#define od_full_usage "\n\n" | 26 | //usage:#define od_full_usage "\n\n" |
27 | //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" | 27 | //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" |
28 | //usage:#endif | 28 | //usage:#endif |
@@ -144,29 +144,42 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) | |||
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | // A format string contains format units separated by whitespace. | ||
148 | // A format unit contains up to three items: an iteration count, a byte count, | ||
149 | // and a format. | ||
150 | // The iteration count is an optional integer (default 1) | ||
151 | // Each format is applied iteration count times. | ||
152 | // The byte count is an optional integer. It defines the number | ||
153 | // 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 | // placed after the iteration count and/or before the byte count | ||
156 | // to disambiguate them. | ||
157 | // The format is required and must be surrounded by " "s. | ||
158 | // It is a printf-style format. | ||
147 | static const char *const add_strings[] ALIGN_PTR = { | 159 | static const char *const add_strings[] ALIGN_PTR = { |
148 | "16/1 \"%3_u \" \"\\n\"", /* a */ | 160 | "16/1 \"%3_u \" \"\\n\"", /* 0: a */ |
149 | "8/2 \" %06o \" \"\\n\"", /* B, o */ | 161 | "8/2 \"%06o \" \"\\n\"", /* 1: B (undocumented in od), o */ |
150 | "16/1 \"%03o \" \"\\n\"", /* b */ | 162 | "16/1 \"%03o \" \"\\n\"", /* 2: b */ |
151 | "16/1 \"%3_c \" \"\\n\"", /* c */ | 163 | "16/1 \"%3_c \" \"\\n\"", /* 3: c */ |
152 | "8/2 \" %05u \" \"\\n\"", /* d */ | 164 | "8/2 \"%5u \" \"\\n\"", /* 4: d */ |
153 | "4/4 \" %010u \" \"\\n\"", /* D */ | 165 | "4/4 \"%10u \" \"\\n\"", /* 5: D */ |
154 | "2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */ | 166 | "2/8 \"%24.14e \" \"\\n\"", /* 6: e (undocumented in od), F */ |
155 | "4/4 \" %14.7e \" \"\\n\"", /* f */ | 167 | "4/4 \"%15.7e \" \"\\n\"", /* 7: f */ |
156 | "4/4 \" %08x \" \"\\n\"", /* H, X */ | 168 | "4/4 \"%08x \" \"\\n\"", /* 8: H, X */ |
157 | "8/2 \" %04x \" \"\\n\"", /* h, x */ | 169 | "8/2 \"%04x \" \"\\n\"", /* 9: h, x */ |
158 | "4/4 \" %11d \" \"\\n\"", /* I, L, l */ | 170 | "2/8 \"%20lld \" \"\\n\"", /* 10: I, L, l */ |
159 | "8/2 \" %6d \" \"\\n\"", /* i */ | 171 | "4/4 \"%11d \" \"\\n\"", /* 11: i */ |
160 | "4/4 \" %011o \" \"\\n\"", /* O */ | 172 | "4/4 \"%011o \" \"\\n\"", /* 12: O */ |
173 | "8/2 \"%6d \" \"\\n\"", /* 13: s */ | ||
161 | }; | 174 | }; |
162 | 175 | ||
163 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv"; | 176 | static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; |
164 | 177 | ||
165 | static const char od_o2si[] ALIGN1 = { | 178 | static const char od_o2si[] ALIGN1 = { |
166 | 0, 1, 2, 3, 5, | 179 | 0, 1, 2, 3, 5, /* aBbcD */ |
167 | 4, 6, 6, 7, 8, | 180 | 4, 6, 6, 7, 8, /* deFfH */ |
168 | 9, 0xa, 0xb, 0xa, 0xa, | 181 | 9, 10, 11, 10, 10, /* hIiLl */ |
169 | 0xc, 1, 8, 9, | 182 | 12, 1, 8, 9, 13 /* OoXxs */ |
170 | }; | 183 | }; |
171 | 184 | ||
172 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 185 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -184,9 +197,9 @@ int od_main(int argc, char **argv) | |||
184 | if (first) { | 197 | if (first) { |
185 | first = 0; | 198 | first = 0; |
186 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); | 199 | bb_dump_add(dumper, "\"%07.7_Ao\n\""); |
187 | bb_dump_add(dumper, "\"%07.7_ao \""); | 200 | bb_dump_add(dumper, "\"%07.7_ao \""); |
188 | } else { | 201 | } else { |
189 | bb_dump_add(dumper, "\" \""); | 202 | bb_dump_add(dumper, "\" \""); |
190 | } | 203 | } |
191 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); | 204 | bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); |
192 | } else { /* P, p, s, w, or other unhandled */ | 205 | } else { /* P, p, s, w, or other unhandled */ |