From: Alexander Müller Date: Mon, 24 Apr 2023 13:08:42 +0000 (+0200) Subject: hexdump: fix ability to use given format when invoked as hd X-Git-Tag: v2.39~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1da142635acb9f044dfd98a49e15b37559a76d8;p=thirdparty%2Futil-linux.git hexdump: fix ability to use given format when invoked as hd Fixes: https://github.com/util-linux/util-linux/issues/2177 Signed-off-by: Karel Zak --- diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index 4068fb8d10..73b3a94a0b 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -82,13 +82,6 @@ parse_args(int argc, char **argv, struct hexdump *hex) {NULL, no_argument, NULL, 0} }; - if (!strcmp(program_invocation_short_name, "hd")) { - /* Canonical format */ - add_fmt("\"%08.8_Ax\n\"", hex); - add_fmt("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ", hex); - add_fmt("\" |\" 16/1 \"%_p\" \"|\\n\"", hex); - } - while ((ch = getopt_long(argc, argv, "bcCde:f:L::n:os:vxhV", longopts, NULL)) != -1) { switch (ch) { case 'b': @@ -148,8 +141,15 @@ parse_args(int argc, char **argv, struct hexdump *hex) } if (list_empty(&hex->fshead)) { - add_fmt(hex_offt, hex); - add_fmt("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"", hex); + if (!strcmp(program_invocation_short_name, "hd")) { + /* Canonical format */ + add_fmt("\"%08.8_Ax\n\"", hex); + add_fmt("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ", hex); + add_fmt("\" |\" 16/1 \"%_p\" \"|\\n\"", hex); + } else { + add_fmt(hex_offt, hex); + add_fmt("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"", hex); + } } colors_init (colormode, "hexdump"); return optind;