diff options
| author | Karel Zak <kzak@redhat.com> | 2023-05-22 12:36:45 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2023-05-22 12:36:45 +0200 |
| commit | cc665f33f47345fe5df50d998f1d857c53463ac0 (patch) | |
| tree | 99621ff3e8a550e5508589fead2a49c8d7f74222 | |
| parent | 8a53082787f2c4bdce253a4af0896929e7373710 (diff) | |
| parent | 42de8aba286a1a1e11625e77d82187528792638d (diff) | |
| download | util-linux-cc665f33f47345fe5df50d998f1d857c53463ac0.tar.gz | |
Merge branch 'hexdump-one-byte-hex' of https://github.com/tpwo/util-linux
* 'hexdump-one-byte-hex' of https://github.com/tpwo/util-linux:
hexdump: add new format-strings test case
hexdump: add '--one-byte-hex' format option
| -rw-r--r-- | bash-completion/hexdump | 1 | ||||
| -rw-r--r-- | tests/expected/hexdump/format-strings-1b_hex | 41 | ||||
| -rwxr-xr-x | tests/ts/hexdump/format-strings | 4 | ||||
| -rw-r--r-- | text-utils/hexdump.1.adoc | 3 | ||||
| -rw-r--r-- | text-utils/hexdump.c | 8 |
5 files changed, 56 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/tests/expected/hexdump/format-strings-1b_hex b/tests/expected/hexdump/format-strings-1b_hex new file mode 100644 index 0000000000..ecd49603ae --- /dev/null +++ b/tests/expected/hexdump/format-strings-1b_hex @@ -0,0 +1,41 @@ +0000000 00 20 01 20 02 20 03 20 04 20 05 20 06 20 07 20 +0000010 08 20 09 20 0a 20 0b 20 0c 20 0d 20 0e 20 0f 20 +0000020 10 20 11 20 12 20 13 20 14 20 15 20 16 20 17 20 +0000030 18 20 19 20 1a 20 1b 20 1c 20 1d 20 1e 20 1f 20 +0000040 20 20 21 20 22 20 23 20 24 20 25 20 26 20 27 20 +0000050 28 20 29 20 2a 20 2b 20 2c 20 2d 20 2e 20 2f 20 +0000060 30 20 31 20 32 20 33 20 34 20 35 20 36 20 37 20 +0000070 38 20 39 20 3a 20 3b 20 3c 20 3d 20 3e 20 3f 20 +0000080 40 20 41 20 42 20 43 20 44 20 45 20 46 20 47 20 +0000090 48 20 49 20 4a 20 4b 20 4c 20 4d 20 4e 20 4f 20 +00000a0 50 20 51 20 52 20 53 20 54 20 55 20 56 20 57 20 +00000b0 58 20 59 20 5a 20 5b 20 5c 20 5d 20 5e 20 5f 20 +00000c0 60 20 61 20 62 20 63 20 64 20 65 20 66 20 67 20 +00000d0 68 20 69 20 6a 20 6b 20 6c 20 6d 20 6e 20 6f 20 +00000e0 70 20 71 20 72 20 73 20 74 20 75 20 76 20 77 20 +00000f0 78 20 79 20 7a 20 7b 20 7c 20 7d 20 7e 20 7f 20 +0000100 c2 80 20 c2 81 20 c2 82 20 c2 83 20 c2 84 20 c2 +0000110 85 20 c2 86 20 c2 87 20 c2 88 20 c2 89 20 c2 8a +0000120 20 c2 8b 20 c2 8c 20 c2 8d 20 c2 8e 20 c2 8f 20 +0000130 c2 90 20 c2 91 20 c2 92 20 c2 93 20 c2 94 20 c2 +0000140 95 20 c2 96 20 c2 97 20 c2 98 20 c2 99 20 c2 9a +0000150 20 c2 9b 20 c2 9c 20 c2 9d 20 c2 9e 20 c2 9f 20 +0000160 c2 a0 20 c2 a1 20 c2 a2 20 c2 a3 20 c2 a4 20 c2 +0000170 a5 20 c2 a6 20 c2 a7 20 c2 a8 20 c2 a9 20 c2 aa +0000180 20 c2 ab 20 c2 ac 20 c2 ad 20 c2 ae 20 c2 af 20 +0000190 c2 b0 20 c2 b1 20 c2 b2 20 c2 b3 20 c2 b4 20 c2 +00001a0 b5 20 c2 b6 20 c2 b7 20 c2 b8 20 c2 b9 20 c2 ba +00001b0 20 c2 bb 20 c2 bc 20 c2 bd 20 c2 be 20 c2 bf 20 +00001c0 c3 80 20 c3 81 20 c3 82 20 c3 83 20 c3 84 20 c3 +00001d0 85 20 c3 86 20 c3 87 20 c3 88 20 c3 89 20 c3 8a +00001e0 20 c3 8b 20 c3 8c 20 c3 8d 20 c3 8e 20 c3 8f 20 +00001f0 c3 90 20 c3 91 20 c3 92 20 c3 93 20 c3 94 20 c3 +0000200 95 20 c3 96 20 c3 97 20 c3 98 20 c3 99 20 c3 9a +0000210 20 c3 9b 20 c3 9c 20 c3 9d 20 c3 9e 20 c3 9f 20 +0000220 c3 a0 20 c3 a1 20 c3 a2 20 c3 a3 20 c3 a4 20 c3 +0000230 a5 20 c3 a6 20 c3 a7 20 c3 a8 20 c3 a9 20 c3 aa +0000240 20 c3 ab 20 c3 ac 20 c3 ad 20 c3 ae 20 c3 af 20 +0000250 c3 b0 20 c3 b1 20 c3 b2 20 c3 b3 20 c3 b4 20 c3 +0000260 b5 20 c3 b6 20 c3 b7 20 c3 b8 20 c3 b9 20 c3 ba +0000270 20 c3 bb 20 c3 bc 20 c3 bd 20 c3 be 20 c3 bf 20 +0000280 diff --git a/tests/ts/hexdump/format-strings b/tests/ts/hexdump/format-strings index 9f055ba145..b971538e64 100755 --- a/tests/ts/hexdump/format-strings +++ b/tests/ts/hexdump/format-strings @@ -43,6 +43,10 @@ ts_init_subtest "1b_octal" $TS_CMD_HEXDUMP -b $FILES/ascii.in &> $TS_OUTPUT ts_finalize_subtest +ts_init_subtest "1b_hex" +$TS_CMD_HEXDUMP -X $FILES/ascii.in &> $TS_OUTPUT +ts_finalize_subtest + ts_init_subtest "1b_char" $TS_CMD_HEXDUMP -c $FILES/ascii.in &> $TS_OUTPUT ts_finalize_subtest 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); |
