aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Wojdat <tpwojdat@gmail.com>2023-05-16 20:10:13 +0200
committerTomasz Wojdat <tpwojdat@gmail.com>2023-05-16 20:24:21 +0200
commitbbf5bf8a881f17d5ed9ac6c92a1793163ce47f7e (patch)
tree23e5577c858d5a1cf4ed5fe95069e504707a7717
parente27b9ed2c0ab93779938f2a770aeab8033489ab0 (diff)
downloadutil-linux-bbf5bf8a881f17d5ed9ac6c92a1793163ce47f7e.tar.gz
hexdump: add '--one-byte-hex' format option
Signed-off-by: Tomasz Wojdat <tpwojdat@gmail.com>
-rw-r--r--bash-completion/hexdump1
-rw-r--r--text-utils/hexdump.1.adoc3
-rw-r--r--text-utils/hexdump.c8
3 files changed, 11 insertions, 1 deletions
diff --git a/bash-completion/hexdump b/bash-completion/hexdump
index 80b1ab6285..981d535d2e 100644
--- a/bash-completion/hexdump
+++ b/bash-completion/hexdump
@@ -28,6 +28,7 @@ _hexdump_module()
case $cur in
-*)
OPTS=" --one-byte-octal
+ --one-byte-hex
--one-byte-char
--canonical
--two-bytes-decimal
diff --git a/text-utils/hexdump.1.adoc b/text-utils/hexdump.1.adoc
index 82c1e606cf..3516e0405c 100644
--- a/text-utils/hexdump.1.adoc
+++ b/text-utils/hexdump.1.adoc
@@ -61,6 +61,9 @@ Below, the _length_ and _offset_ arguments may be followed by the multiplicative
*-b*, *--one-byte-octal*::
_One-byte octal display_. Display the input offset in hexadecimal, followed by sixteen space-separated, three-column, zero-filled bytes of input data, in octal, per line.
+*-X*, *--one-byte-hex*::
+_One-byte hexadecimal display_. Display the input offset in hexadecimal, followed by sixteen space-separated, two-column, zero-filled bytes of input data, in hexadecimal, per line.
+
*-c*, *--one-byte-char*::
_One-byte character display_. Display the input offset in hexadecimal, followed by sixteen space-separated, three-column, space-filled characters of input data per line.
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 73b3a94a0b..5b92b16371 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -66,6 +66,7 @@ parse_args(int argc, char **argv, struct hexdump *hex)
static const struct option longopts[] = {
{"one-byte-octal", no_argument, NULL, 'b'},
+ {"one-byte-hex", no_argument, NULL, 'X'},
{"one-byte-char", no_argument, NULL, 'c'},
{"canonical", no_argument, NULL, 'C'},
{"two-bytes-decimal", no_argument, NULL, 'd'},
@@ -82,12 +83,16 @@ parse_args(int argc, char **argv, struct hexdump *hex)
{NULL, no_argument, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "bcCde:f:L::n:os:vxhV", longopts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "bXcCde:f:L::n:os:vxhV", longopts, NULL)) != -1) {
switch (ch) {
case 'b':
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"", hex);
break;
+ case 'X':
+ add_fmt("\"%07.7_Ax\n\"", hex);
+ add_fmt("\"%07.7_ax \" 16/1 \" %02x \" \"\\n\"", hex);
+ break;
case 'c':
add_fmt(hex_offt, hex);
add_fmt("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"", hex);
@@ -166,6 +171,7 @@ void __attribute__((__noreturn__)) usage(void)
fputs(USAGE_OPTIONS, out);
fputs(_(" -b, --one-byte-octal one-byte octal display\n"), out);
+ fputs(_(" -X, --one-byte-hex one-byte hexadecimal display\n"), out);
fputs(_(" -c, --one-byte-char one-byte character display\n"), out);
fputs(_(" -C, --canonical canonical hex+ASCII display\n"), out);
fputs(_(" -d, --two-bytes-decimal two-byte decimal display\n"), out);