diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-08-21 18:19:23 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-08-21 18:19:23 +0200 |
commit | de5d95e0fb849c74e05a865fa2c2e1abf7800cf9 (patch) | |
tree | e9afdb8fe38e3e6edf75014ad3e02987d02b1c60 | |
parent | 1af374e8892e97d0c2e826a5de0ad7b37fe9238f (diff) | |
download | holes-de5d95e0fb849c74e05a865fa2c2e1abf7800cf9.tar.gz holes-de5d95e0fb849c74e05a865fa2c2e1abf7800cf9.tar.xz holes-de5d95e0fb849c74e05a865fa2c2e1abf7800cf9.zip |
Add -b to change which byte is tested
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | holes.1 | 14 | ||||
-rw-r--r-- | holes.c | 22 |
3 files changed, 39 insertions, 10 deletions
diff --git a/README b/README index a5a6b5c..91f6cca 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME holes – find runs of zero bytes SYNOPSIS - holes [-n minlen] [files ...] + holes [-b byte] [-n minlen] [files ...] DESCRIPTION holes looks for runs of zero bytes (a.k.a. holes) in the specified input @@ -12,8 +12,15 @@ DESCRIPTION hexadecimal) as well as the lengths (in decimal). When multiple input files are specified, holes prefixes each line with the file name. - By default, only holes of at least 64 bytes are reported. This can be - changed using the -n option. + The options are as follows: + + -b byte + Count runs of byte, a number between 0 and 255, instead of zero + bytes. + + -n minlen + Change minimum size of holes reported. By default, only holes of + at least 64 bytes are reported. EXIT STATUS The holes utility exits 0 on success, and >0 if an error occurs. diff --git a/holes.1 b/holes.1 index 6d24b08..2edbaf9 100644 --- a/holes.1 +++ b/holes.1 @@ -6,6 +6,7 @@ .Nd find runs of zero bytes .Sh SYNOPSIS .Nm +.Op Fl b Ar byte .Op Fl n Ar minlen .Op Ar files\ ... .Sh DESCRIPTION @@ -18,11 +19,18 @@ When multiple input files are specified, .Nm prefixes each line with the file name. .Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl b Ar byte +Count runs of +.Ar byte , +a number between 0 and 255, +instead of zero bytes. +.It Fl n Ar minlen +Change minimum size of holes reported. By default, only holes of at least 64 bytes are reported. -This can be changed using the -.Fl n -option. +.El .Sh EXIT STATUS .Ex -std .Sh SEE ALSO diff --git a/holes.c b/holes.c index c618a8e..41fc50c 100644 --- a/holes.c +++ b/holes.c @@ -7,7 +7,8 @@ #include <unistd.h> ssize_t minlen = 64; -int ret; +char byte = 0; +int ret = 0; char *argv0; void @@ -18,7 +19,7 @@ holes(FILE *input, char *filename) int ch; while ((ch = getc_unlocked(input)) != EOF) { - if (ch == 0) { + if (ch == byte) { run++; } else { if (run >= minlen) { @@ -49,12 +50,24 @@ int main(int argc, char *argv[]) { int c, i; + long b; char *e; argv0 = argv[0]; - while ((c = getopt(argc, argv, "n:")) != -1) + while ((c = getopt(argc, argv, "b:n:")) != -1) switch(c) { + case 'b': + errno = 0; + b = strtol(optarg, &e, 0); + if (errno != 0 || *e || b < 0 || b > 256) { + fprintf(stderr, + "%s: can't parse byte '%s'.\n", + argv0, optarg); + exit(2); + } + byte = b; + break; case 'n': errno = 0; minlen = strtoll(optarg, &e, 0); @@ -73,7 +86,8 @@ main(int argc, char *argv[]) break; default: fprintf(stderr, - "Usage: %s [-n MINLEN] [FILES...]\n", argv0); + "Usage: %s [-b BYTE] [-n MINLEN] [FILES...]\n", + argv0); exit(2); } |