ongrep

A cleaned up fork of ngrep for OpenBSD
git clone git://git.sgregoratto.me/ongrep
Log | Files | Refs | README | LICENSE

commit 8cd98b64eb51beb718d3ae21c2d53524097baf2c
parent e609c03de6cf48b2948d3cd05dcd5b363e78d859
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Sun, 14 Jun 2020 22:33:16 +1000

sort option handling alphabetically

Diffstat:
Mngrep.c | 140++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/ngrep.c b/ngrep.c @@ -92,7 +92,7 @@ void (*print_time)() = NULL, (*dump_delay)() = dump_delay_proc_init; */ uint32_t ws_row, ws_col = 80, ws_col_forced = 0; -const char *optstring = "nhXiwqpevxlDtTRMCs:n:c:d:A:I:O:S:P:F:W:"; +const char *optstring = "A:c:d:DeF:hiI:lMn:NO:pP:qRs:S:tTvwW:xX"; int main(int argc, char **argv) @@ -108,38 +108,6 @@ main(int argc, char **argv) while ((c = getopt(argc, argv, optstring)) != EOF) { switch (c) { - case 'W': - if (!strcasecmp(optarg, "normal")) - dump_func = &dump_formatted; - else if (!strcasecmp(optarg, "byline")) - dump_func = &dump_byline; - else if (!strcasecmp(optarg, "none")) - dump_func = &dump_unwrapped; - else if (!strcasecmp(optarg, "single")) { - dump_func = &dump_unwrapped; - dump_single = 1; - } else { - warnx("invalid wrap method: %s", optarg); - usage(); - } - break; - case 'F': - filter_file = optarg; - break; - case 'P': - nonprint_char = *optarg; - break; - case 'S': - limitlen = strtonum(optarg, 1, UINT32_MAX, &errstr); - if (errstr != NULL) - errx(2, "limitlen is %s: %s", errstr, optarg); - break; - case 'O': - dump_file = optarg; - break; - case 'I': - read_file = optarg; - break; case 'A': match_after = strtonum(optarg, 1, UINT32_MAX, &errstr); if (errstr != NULL) @@ -147,31 +115,75 @@ main(int argc, char **argv) if (match_after < UINT32_MAX) match_after++; break; - case 'd': - usedev = optarg; - break; case 'c': ws_col_forced = strtonum(optarg, 1, UINT32_MAX, &errstr); if (errstr != NULL) errx(2, "cols is %s: %s", errstr, optarg); break; + case 'C': + enable_hilite = 1; + break; + case 'd': + usedev = optarg; + break; + case 'D': + want_delay = 1; + break; + case 'e': + show_empty++; + break; + case 'F': + filter_file = optarg; + break; + case 'i': + re_ignore_case++; + break; + case 'I': + read_file = optarg; + break; + case 'l': + setvbuf(stdout, NULL, _IOLBF, 0); + break; + case 'M': + re_multiline_match = 0; + break; case 'n': max_matches = strtonum(optarg, 1, UINT32_MAX, &errstr); if (errstr != NULL) errx(2, "num is %s: %s", errstr, optarg); break; + case 'N': + show_proto++; + break; + case 'O': + dump_file = optarg; + break; + case 'p': + promisc = 0; + break; + case 'P': + nonprint_char = *optarg; + break; + case 'q': + quiet++; + break; + case 'R': + dont_dropprivs = 1; + break; case 's': snaplen = strtonum(optarg, 1, UINT32_MAX, &errstr); if (errstr != NULL) errx(2, "snaplen is %s: %s", errstr, optarg); - case 'C': - enable_hilite = 1; + case 'S': + limitlen = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "limitlen is %s: %s", errstr, optarg); break; - case 'M': - re_multiline_match = 0; + case 't': + print_time = &print_time_absolute; break; - case 'R': - dont_dropprivs = 1; + case 'v': + invert_match++; break; case 'T': if (print_time == &print_time_diff) { @@ -182,42 +194,30 @@ main(int argc, char **argv) gettimeofday(&prev_ts, NULL); } break; - case 't': - print_time = &print_time_absolute; - break; - case 'D': - want_delay = 1; + case 'w': + re_match_word++; break; - case 'l': - setvbuf(stdout, NULL, _IOLBF, 0); + case 'W': + if (!strcasecmp(optarg, "normal")) + dump_func = &dump_formatted; + else if (!strcasecmp(optarg, "byline")) + dump_func = &dump_byline; + else if (!strcasecmp(optarg, "none")) + dump_func = &dump_unwrapped; + else if (!strcasecmp(optarg, "single")) { + dump_func = &dump_unwrapped; + dump_single = 1; + } else { + warnx("invalid wrap method: %s", optarg); + usage(); + } break; case 'x': show_hex++; break; - case 'v': - invert_match++; - break; - case 'e': - show_empty++; - break; - case 'p': - promisc = 0; - break; - case 'q': - quiet++; - break; - case 'w': - re_match_word++; - break; - case 'i': - re_ignore_case++; - break; case 'X': bin_match++; break; - case 'N': - show_proto++; - break; case 'h': /* FALLTHROUGH */ default: