[git commit] od: support -DOHXIL

Denys Vlasenko vda.linux at googlemail.com
Fri May 26 10:56:17 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=60d4d55b870757089cdae96920cf6c416ba2de37
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
od_main                                             1866    1917     +51
.rodata                                           105306  105321     +15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 66/0)               Total: 66 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/od.c        |  4 +++-
 coreutils/od_bloaty.c | 43 +++++++++++++++++++++++++++----------------
 testsuite/od.tests    | 44 ++++++++++++++++----------------------------
 3 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/coreutils/od.c b/coreutils/od.c
index 46aba5a7c..98ae06ba7 100644
--- a/coreutils/od.c
+++ b/coreutils/od.c
@@ -22,7 +22,9 @@
 
 //usage:#if !ENABLE_DESKTOP
 //usage:#define od_trivial_usage
-//usage:       "[-aBbcDdeFfHhIiLlOoXxsv] [FILE]"
+//usage:       "[-abcdeFfhIiLloxsv] [FILE]"
+// We also support -BDOHXIL, but they are not documented in coreutils 9.1
+// manpage/help, so don't show them either.
 //usage:#define od_full_usage "\n\n"
 //usage:       "Print FILE (or stdin) unambiguously, as octal bytes by default"
 //usage:#endif
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 57a4fe163..2782adbf6 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -27,6 +27,8 @@
 //usage:#if ENABLE_DESKTOP
 //usage:#define od_trivial_usage
 //usage:       "[-abcdfhilovxs] [-t TYPE] [-A RADIX] [-N SIZE] [-j SKIP] [-S MINSTR] [-w WIDTH] [FILE]..."
+// We also support -BDOHXIL, but they are not documented in coreutils 9.1
+// manpage/help, so don't show them either.
 // We don't support:
 // ... [FILE] [[+]OFFSET[.][b]]
 // Support is buggy for:
@@ -43,27 +45,33 @@ enum {
 	OPT_b = 1 << 3,
 	OPT_c = 1 << 4,
 	OPT_d = 1 << 5,
-	OPT_f = 1 << 6,
-	OPT_h = 1 << 7,
-	OPT_i = 1 << 8,
-	OPT_j = 1 << 9,
-	OPT_l = 1 << 10,
-	OPT_o = 1 << 11,
-	OPT_B = 1 << 12, /* undocumented synonym to -o */
-	OPT_t = 1 << 13,
+	OPT_D = 1 << 6, /* undocumented in coreutils 9.1 */
+	OPT_f = 1 << 7,
+	OPT_h = 1 << 8,
+	OPT_H = 1 << 9, /* undocumented in coreutils 9.1 */
+	OPT_i = 1 << 10,
+	OPT_I = 1 << 11, /* undocumented in coreutils 9.1 */
+	OPT_j = 1 << 12,
+	OPT_l = 1 << 13,
+	OPT_L = 1 << 14, /* undocumented in coreutils 9.1 */
+	OPT_o = 1 << 15,
+	OPT_O = 1 << 16, /* undocumented in coreutils 9.1 */
+	OPT_B = 1 << 17, /* undocumented synonym to -o */
+	OPT_t = 1 << 18,
 	/* When zero and two or more consecutive blocks are equal, format
 	   only the first block and output an asterisk alone on the following
 	   line to indicate that identical blocks have been elided: */
-	OPT_v = 1 << 14,
-	OPT_x = 1 << 15,
-	OPT_s = 1 << 16,
-	OPT_S = 1 << 17,
-	OPT_w = 1 << 18,
-	OPT_traditional = (1 << 19) * ENABLE_LONG_OPTS,
+	OPT_v = 1 << 19,
+	OPT_x = 1 << 20,
+	OPT_X = 1 << 21, /* undocumented in coreutils 9.1 */
+	OPT_s = 1 << 22,
+	OPT_S = 1 << 23,
+	OPT_w = 1 << 24,
+	OPT_traditional = (1 << 25) * ENABLE_LONG_OPTS,
 };
 
 #define OD_GETOPT32() getopt32long(argv, \
-	"A:N:abcdfhij:loBt:*vxsS:w:+:", od_longopts, \
+	"A:N:abcdDfhHiIj:lLoOBt:*vxXsS:w:+:", od_longopts, \
 	/* -w with optional param */ \
 	/* -S was -s and also had optional parameter */ \
 	/* but in coreutils 6.3 it was renamed and now has */ \
@@ -1245,14 +1253,17 @@ int od_main(int argc UNUSED_PARAM, char **argv)
 	if (opt & OPT_b) decode_format_string("oC");
 	if (opt & OPT_c) decode_format_string("c");
 	if (opt & OPT_d) decode_format_string("u2");
+	if (opt & OPT_D) decode_format_string("uI");
 	if (opt & OPT_f) decode_format_string("fF");
 	if (opt & (OPT_h|OPT_x)) decode_format_string("x2");
+	if (opt & (OPT_H|OPT_X)) decode_format_string("xI");
 	if (opt & OPT_i) decode_format_string("dI");
 	if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
 	/* This probably also depends on word width of the arch (what is "long"?) */
 	/* should be "d4" or "d8" depending on sizeof(long)? */
-	if (opt & OPT_l) decode_format_string("d8");
+	if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("d8");
 	if (opt & (OPT_o|OPT_B)) decode_format_string("o2");
+	if (opt & OPT_O) decode_format_string("oI");
 	while (lst_t) {
 		decode_format_string(llist_pop(&lst_t));
 	}
diff --git a/testsuite/od.tests b/testsuite/od.tests
index d6f50a206..677968967 100755
--- a/testsuite/od.tests
+++ b/testsuite/od.tests
@@ -90,9 +90,8 @@ testing "od -d (little-endian)" \
 	"" "$input"
 SKIP=
 
-optional !DESKTOP  #DESKTOP: unrecognized option: D
 $le || SKIP=1
-testing "od -D (!DESKTOP little-endian)" \
+testing "od -D (little-endian)" \
         "od -D" \
 "\
 0000000  167969281 4265820737
@@ -133,9 +132,8 @@ testing "od -f (little-endian)" \
 	"" "$input"
 SKIP=
 
-optional !DESKTOP  #DESKTOP: unrecognized option: H
 $le || SKIP=1
-testing "od -H (!DESKTOP little-endian)" \
+testing "od -H (little-endian)" \
         "od -H" \
 "\
 0000000 0a030201 fe434241
@@ -144,9 +142,8 @@ testing "od -H (!DESKTOP little-endian)" \
 	"" "$input"
 SKIP=
 
-optional !DESKTOP  #DESKTOP: unrecognized option: X
 $le || SKIP=1
-testing "od -X (!DESKTOP little-endian)" \
+testing "od -X (little-endian)" \
         "od -X" \
 "\
 0000000 0a030201 fe434241
@@ -175,51 +172,42 @@ testing "od -x (little-endian)" \
 	"" "$input"
 SKIP=
 
-optional !DESKTOP  #DESKTOP: unrecognized option: I
 $le || SKIP=1
-testing "od -I (!DESKTOP little-endian)" \
-        "od -I" \
+testing "od -i (little-endian)" \
+        "od -i" \
 "\
-0000000  -125183517527965183
+0000000   167969281   -29146559
 0000010
 " \
 	"" "$input"
 SKIP=
 
-optional !DESKTOP  #DESKTOP: unrecognized option: L
 $le || SKIP=1
-testing "od -L (!DESKTOP little-endian)" \
-        "od -L" \
+testing "od -O (little-endian)" \
+        "od -O" \
 "\
-0000000  -125183517527965183
+0000000 01200601001 37620641101
 0000010
 " \
 	"" "$input"
 SKIP=
 
+# This probably also depends on word width of the arch (what is "long"?)
 $le || SKIP=1
-testing "od -i (little-endian)" \
-        "od -i" \
+testing "od -I (little-endian)" \
+        "od -I" \
 "\
-0000000   167969281   -29146559
+0000000  -125183517527965183
 0000010
 " \
 	"" "$input"
-SKIP=
-
-optional !DESKTOP  #DESKTOP: unrecognized option: O
-$le || SKIP=1
-testing "od -O (!DESKTOP little-endian)" \
-        "od -O" \
+testing "od -L (little-endian)" \
+        "od -L" \
 "\
-0000000 01200601001 37620641101
+0000000  -125183517527965183
 0000010
 " \
 	"" "$input"
-SKIP=
-
-# This probably also depends on word width of the arch (what is "long"?)
-$le || SKIP=1
 testing "od -l (little-endian)" \
         "od -l" \
 "\


More information about the busybox-cvs mailing list