summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-05-29 17:55:10 -0400
committerJune McEnroe <june@causal.agency>2019-05-29 17:55:10 -0400
commit4093cb550d4c7acdef1314ebe255eba07ef1f3d1 (patch)
tree72845e517920ca8b2ba8d70fbf4ae7d0872b9fa0
parentAdd Frontier (diff)
downloadsrc-4093cb550d4c7acdef1314ebe255eba07ef1f3d1.tar.gz
src-4093cb550d4c7acdef1314ebe255eba07ef1f3d1.zip
Add xx -p option
-rw-r--r--bin/man1/xx.19
-rw-r--r--bin/xx.c12
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 1dd7ce5e..39d7ec07 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;