From e1da142635acb9f044dfd98a49e15b37559a76d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20M=C3=BCller?= Date: Mon, 24 Apr 2023 15:08:42 +0200 Subject: [PATCH] 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 --- text-utils/hexdump.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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; -- 2.47.3