ref: face54aefe11b61cc95b2859d8c5c5396f868b25
parent: b66196c7ba0254fbda7ade0f2c3233dfbbf6215b
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jul 2 09:49:24 EDT 2021
add -s option to section the printout
--- a/README.md
+++ b/README.md
@@ -21,3 +21,4 @@
# Notes
* hx will print data as soon as it is available (if used on pipes), without buffering.
+ * it provides an option `-s` ("section") to print data read separating it into sections.
--- a/hx.c
+++ b/hx.c
@@ -25,6 +25,7 @@
Linesz = 87,
};
+static int section = 0;
static unsigned char *buf;
static const char b2h[] = (
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
@@ -46,6 +47,7 @@
unsigned char line[16];
int wroff, off, eof, lineoff, r;
+again:
#ifdef __linux__
readahead(fd, 0, Bufsz);
#endif
@@ -113,6 +115,8 @@
off = 0;
}
}
+ if (section)
+ break;
if (sz == 0)
continue;
@@ -147,6 +151,11 @@
}
}
+ if (section) {
+ write(1, "\n", 1);
+ goto again;
+ }
+
return sz != 0;
}
@@ -165,6 +174,12 @@
}
res = 0;
+ if (argc > 1 && strcmp(argv[1], "-s") == 0) {
+ section = 1;
+ argv++;
+ argc--;
+ }
+
if (argc == 1) {
i = 1;
fd = 0;