Skip to contentSkip to conversation

hexdump: automatically use -C when called as hd

PATCH Applied Chris Hofstaedtler 3 participants 4 messages Jun 23, 2020 – Jun 24, 2020 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hexdump: automatically use -C when called as hd

When invoking hexdump as hd enable the "Canonical" format to by default, implying the -C option.

This is historic behaviour on Debian and apparently also on FreeBSD. Some Debian users have asked for this to be restored, after Debian switched to util-linux' hexdump and hd.

---
 text-utils/hexdump.1 | 3 +++
 text-utils/hexdump.c | 7 +++++++
 2 files changed, 10 insertions(+)
text-utils/hexdump.1 +3 -0
index eb508f6d4..80a7c0f0d 100644
@@ -67,6 +67,9 @@ by the same sixteen bytes in
 format enclosed in
 .RB ' | '
 characters.
+Invoking the program as
+.B hd
+implies this option.
 .TP
 \fB\-d\fR, \fB\-\-two\-bytes\-decimal\fR
 \fITwo-byte decimal display\fR.  Display the input offset in hexadecimal,
text-utils/hexdump.c +7 -0
index cbd593e5f..ce83c9d83 100644
@@ -82,6 +82,13 @@ 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':
Signature · 1 line
2.27.0
#1 lore raw
Quoted 7 lines · Chris Hofstaedtler

When invoking hexdump as hd enable the "Canonical" format to by default, implying the -C option.

This is historic behaviour on Debian and apparently also on FreeBSD. Some Debian users have asked for this to be restored, after Debian switched to util-linux' hexdump and hd.

Wouldn't it make more sense to add an alias to a global profile?

alias hd='hexdump -C'

--
Sami Kerola
http://www.iki.fi/kerolasa/

#2 lore raw
Quoted 5 lines · Sami Kerola
Quoted 4 lines · Chris Hofstaedtler

When invoking hexdump as hd enable the "Canonical" format to by default, implying the -C option.

Quoted 7 lines
Quoted 3 lines

This is historic behaviour on Debian and apparently also on FreeBSD. Some Debian users have asked for this to be restored, after Debian switched to util-linux' hexdump and hd.

Wouldn't it make more sense to add an alias to a global profile?

alias hd='hexdump -C'

That's not scalable on Debian given the number of shells we ship. Also, util-linux already has a number of binaries that modify their behaviour depending on the name they are invoked as.

FreeBSD has this here:
https://github.com/freebsd/freebsd/blame/master/usr.bin/hexdump/hexsyntax.c#L59
And supports it for over 24 years; I believe Debian shipped with this support since basically forever, too.

Chris

maintainer Applied
#3 lore raw
In reply to Chris Hofstaedtler
Quoted 2 lines · Chris Hofstaedtler

When invoking hexdump as hd enable the "Canonical" format to by default, implying the -C option.

Well, I personally prefer aliases too, but ...

Quoted 3 lines

This is historic behaviour on Debian and apparently also on FreeBSD. Some Debian users have asked for this to be restored, after Debian switched to util-linux' hexdump and hd.

if BSD implements it 24 years ago than it's probably good idea to follow this manner to make util-linux more portable.

Merged to the "next" branch (it's too late for v2.36).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com