Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] hexdump: automatically use -C when called as hd
@ 2020-06-23  0:14 Chris Hofstaedtler
  2020-06-23 11:17 ` Sami Kerola
  2020-06-24 14:41 ` Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Chris Hofstaedtler @ 2020-06-23  0:14 UTC (permalink / raw)
  To: util-linux

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.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
---
 text-utils/hexdump.1 | 3 +++
 text-utils/hexdump.c | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/text-utils/hexdump.1 b/text-utils/hexdump.1
index eb508f6d4..80a7c0f0d 100644
--- a/text-utils/hexdump.1
+++ b/text-utils/hexdump.1
@@ -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,
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index cbd593e5f..ce83c9d83 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -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':
-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hexdump: automatically use -C when called as hd
  2020-06-23  0:14 [PATCH] hexdump: automatically use -C when called as hd Chris Hofstaedtler
@ 2020-06-23 11:17 ` Sami Kerola
  2020-06-23 17:06   ` Chris Hofstaedtler
  2020-06-24 14:41 ` Karel Zak
  1 sibling, 1 reply; 4+ messages in thread
From: Sami Kerola @ 2020-06-23 11:17 UTC (permalink / raw)
  To: Chris Hofstaedtler; +Cc: util-linux

On Tue, 23 Jun 2020 at 01:15, Chris Hofstaedtler <zeha@debian.org> wrote:
>
> 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hexdump: automatically use -C when called as hd
  2020-06-23 11:17 ` Sami Kerola
@ 2020-06-23 17:06   ` Chris Hofstaedtler
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Hofstaedtler @ 2020-06-23 17:06 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux

* Sami Kerola <kerolasa@iki.fi> [200623 13:17]:
> On Tue, 23 Jun 2020 at 01:15, Chris Hofstaedtler <zeha@debian.org> wrote:
> >
> > 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'

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hexdump: automatically use -C when called as hd
  2020-06-23  0:14 [PATCH] hexdump: automatically use -C when called as hd Chris Hofstaedtler
  2020-06-23 11:17 ` Sami Kerola
@ 2020-06-24 14:41 ` Karel Zak
  1 sibling, 0 replies; 4+ messages in thread
From: Karel Zak @ 2020-06-24 14:41 UTC (permalink / raw)
  To: Chris Hofstaedtler; +Cc: util-linux

On Tue, Jun 23, 2020 at 12:14:30AM +0000, Chris Hofstaedtler wrote:
> When invoking hexdump as hd enable the "Canonical" format to by
> default, implying the -C option.

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

> 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

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23  0:14 [PATCH] hexdump: automatically use -C when called as hd Chris Hofstaedtler
2020-06-23 11:17 ` Sami Kerola
2020-06-23 17:06   ` Chris Hofstaedtler
2020-06-24 14:41 ` Karel Zak

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org
	public-inbox-index util-linux

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git