From f84276e918f3f70bce10d1bae923ce48bc600985 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 16 Sep 1996 21:18:48 +0000 Subject: [PATCH] Add '-C' "Canonical" format to hexdump: $ hexdump -C /etc/resolv.conf 00000000 64 6f 6d 61 69 6e 20 64 6b 2e 74 66 73 2e 63 6f |domain dk.tfs.co| 00000010 6d 0a 6e 61 6d 65 73 65 72 76 65 72 20 31 34 30 |m.nameserver 140| 00000020 2e 31 34 35 2e 32 33 30 2e 31 30 0a |.145.230.10.| --- usr.bin/hexdump/hexdump.1 | 7 ++++++- usr.bin/hexdump/hexsyntax.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/usr.bin/hexdump/hexdump.1 b/usr.bin/hexdump/hexdump.1 index 321151e4d6b..563edac0fcd 100644 --- a/usr.bin/hexdump/hexdump.1 +++ b/usr.bin/hexdump/hexdump.1 @@ -39,7 +39,7 @@ .Nd ascii, decimal, hexadecimal, octal dump .Sh SYNOPSIS .Nm hexdump -.Op Fl bcdovx +.Op Fl bcCdovx .Op Fl e Ar format_string .Op Fl f Ar format_file .Op Fl n Ar length @@ -64,6 +64,11 @@ in octal, per line. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line. +.It Fl C +.Em Canonical hex+ASCII display. +Display the input offset in hexadecimal, followed by sixteen +space-separated, two column, hexadecimal bytes, followed by the +same sixteen bytes in %_p format enclosed in ``|'' characters. .It Fl d .Em Two-byte decimal display. Display the input offset in hexadecimal, followed by eight diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c index 68abbe6137c..829a6303f24 100644 --- a/usr.bin/hexdump/hexsyntax.c +++ b/usr.bin/hexdump/hexsyntax.c @@ -56,7 +56,7 @@ newsyntax(argc, argvp) char *p, **argv; argv = *argvp; - while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF) + while ((ch = getopt(argc, argv, "bcCde:f:n:os:vx")) != EOF) switch (ch) { case 'b': add("\"%07.7_Ax\n\""); @@ -66,6 +66,11 @@ newsyntax(argc, argvp) add("\"%07.7_Ax\n\""); add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\""); break; + case 'C': + add("\"%08.8_Ax\n\""); + add("\"%08.8_ax \" 16/1 \"%02x \" "); + add("\" |\" 16/1 \"%_p\" \"|\\n\""); + break; case 'd': add("\"%07.7_Ax\n\""); add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");