]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: fix ability to use given format when invoked as hd
authorAlexander Müller <ddondy@gmail.com>
Mon, 24 Apr 2023 13:08:42 +0000 (15:08 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 24 Apr 2023 13:10:57 +0000 (15:10 +0200)
Fixes: https://github.com/util-linux/util-linux/issues/2177
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/hexdump.c

index 4068fb8d10ae4603d140646724f6459e952d1409..73b3a94a0b42664d3dae0be4a36a2f4f5a182ca0 100644 (file)
@@ -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;