From 65feadc0658d8422f30c0cce7bd9af0fb183a2fa Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 29 May 2019 17:55:10 -0400 Subject: Add xx -p option --- bin/man1/xx.1 | 9 +++++++++ bin/xx.c | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/man1/xx.1 b/bin/man1/xx.1 index 3fbcbd70..d38789a7 100644 --- a/bin/man1/xx.1 +++ b/bin/man1/xx.1 @@ -11,6 +11,7 @@ .Op Fl arsz .Op Fl c Ar cols .Op Fl g Ar group +.Op Fl p Ar count .Op Ar file . .Sh DESCRIPTION @@ -42,6 +43,14 @@ The default .Ar group is 8. . +.It Fl p Ar count +Output a blank line after every +.Ar count +bytes. +.Ar count +must be a multiple of +.Ar cols . +. .It Fl r Reverse hexdump. Read hexadecimal input diff --git a/bin/xx.c b/bin/xx.c index 3a314c1b..6d04f2f5 100644 --- a/bin/xx.c +++ b/bin/xx.c @@ -34,10 +34,11 @@ static bool zero(const byte *ptr, size_t size) { static struct { size_t cols; size_t group; + size_t blank; bool ascii; bool offset; bool skip; -} options = { 16, 8, true, true, false }; +} options = { 16, 8, 0, true, true, false }; static void dump(FILE *file) { bool skip = false; @@ -59,6 +60,12 @@ static void dump(FILE *file) { } } + if (options.blank) { + if (offset && offset % options.blank == 0) { + printf("\n"); + } + } + if (options.offset) { printf("%08zX: ", offset); } @@ -106,11 +113,12 @@ int main(int argc, char *argv[]) { const char *path = NULL; int opt; - while (0 < (opt = getopt(argc, argv, "ac:g:rsz"))) { + while (0 < (opt = getopt(argc, argv, "ac:g:p:rsz"))) { switch (opt) { break; case 'a': options.ascii ^= true; break; case 'c': options.cols = strtoul(optarg, NULL, 0); break; case 'g': options.group = strtoul(optarg, NULL, 0); + break; case 'p': options.blank = strtoul(optarg, NULL, 0); break; case 'r': reverse = true; break; case 's': options.offset ^= true; break; case 'z': options.skip ^= true; -- cgit 1.4.1