diff options
author | Denys Vlasenko | 2023-05-25 17:39:28 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-05-25 17:40:20 +0200 |
commit | e2287f99fe6f21fd6435ad04340170ad4ba5f6b3 (patch) | |
tree | 09224d93a16e18c0f4e31ada2375d7ca9cfab03e /coreutils/od.c | |
parent | 64bdd7566c21cb53cb4c384ed52845106529e55f (diff) | |
download | busybox-e2287f99fe6f21fd6435ad04340170ad4ba5f6b3.zip busybox-e2287f99fe6f21fd6435ad04340170ad4ba5f6b3.tar.gz |
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 dcf1bd6..6d562ea 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -22,7 +22,7 @@ //usage:#if !ENABLE_DESKTOP //usage:#define od_trivial_usage -//usage: "[-aBbcDdeFfHhIiLlOovXx] [FILE]" +//usage: "[-aBbcDdeFfHhIiLlOoXxsv] [FILE]" //usage:#define od_full_usage "\n\n" //usage: "Print FILE (or stdin) unambiguously, as octal bytes by default" //usage:#endif @@ -144,29 +144,42 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) } } +// A format string contains format units separated by whitespace. +// A format unit contains up to three items: an iteration count, a byte count, +// and a format. +// The iteration count is an optional integer (default 1) +// Each format is applied iteration count times. +// The byte count is an optional integer. It defines the number +// of bytes to be interpreted by each iteration of the format. +// If an iteration count and/or a byte count is specified, a slash must be +// placed after the iteration count and/or before the byte count +// to disambiguate them. +// The format is required and must be surrounded by " "s. +// It is a printf-style format. static const char *const add_strings[] ALIGN_PTR = { - "16/1 \"%3_u \" \"\\n\"", /* a */ - "8/2 \" %06o \" \"\\n\"", /* B, o */ - "16/1 \"%03o \" \"\\n\"", /* b */ - "16/1 \"%3_c \" \"\\n\"", /* c */ - "8/2 \" %05u \" \"\\n\"", /* d */ - "4/4 \" %010u \" \"\\n\"", /* D */ - "2/8 \" %21.14e \" \"\\n\"", /* e (undocumented in od), F */ - "4/4 \" %14.7e \" \"\\n\"", /* f */ - "4/4 \" %08x \" \"\\n\"", /* H, X */ - "8/2 \" %04x \" \"\\n\"", /* h, x */ - "4/4 \" %11d \" \"\\n\"", /* I, L, l */ - "8/2 \" %6d \" \"\\n\"", /* i */ - "4/4 \" %011o \" \"\\n\"", /* O */ + "16/1 \"%3_u \" \"\\n\"", /* 0: a */ + "8/2 \"%06o \" \"\\n\"", /* 1: B (undocumented in od), o */ + "16/1 \"%03o \" \"\\n\"", /* 2: b */ + "16/1 \"%3_c \" \"\\n\"", /* 3: c */ + "8/2 \"%5u \" \"\\n\"", /* 4: d */ + "4/4 \"%10u \" \"\\n\"", /* 5: D */ + "2/8 \"%24.14e \" \"\\n\"", /* 6: e (undocumented in od), F */ + "4/4 \"%15.7e \" \"\\n\"", /* 7: f */ + "4/4 \"%08x \" \"\\n\"", /* 8: H, X */ + "8/2 \"%04x \" \"\\n\"", /* 9: h, x */ + "2/8 \"%20lld \" \"\\n\"", /* 10: I, L, l */ + "4/4 \"%11d \" \"\\n\"", /* 11: i */ + "4/4 \"%011o \" \"\\n\"", /* 12: O */ + "8/2 \"%6d \" \"\\n\"", /* 13: s */ }; -static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv"; +static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; static const char od_o2si[] ALIGN1 = { - 0, 1, 2, 3, 5, - 4, 6, 6, 7, 8, - 9, 0xa, 0xb, 0xa, 0xa, - 0xc, 1, 8, 9, + 0, 1, 2, 3, 5, /* aBbcD */ + 4, 6, 6, 7, 8, /* deFfH */ + 9, 10, 11, 10, 10, /* hIiLl */ + 12, 1, 8, 9, 13 /* OoXxs */ }; int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -184,9 +197,9 @@ int od_main(int argc, char **argv) if (first) { first = 0; bb_dump_add(dumper, "\"%07.7_Ao\n\""); - bb_dump_add(dumper, "\"%07.7_ao \""); + bb_dump_add(dumper, "\"%07.7_ao \""); } else { - bb_dump_add(dumper, "\" \""); + bb_dump_add(dumper, "\" \""); } bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); } else { /* P, p, s, w, or other unhandled */ |