ongrep

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

commit ebb4be69e99ab8f89058405c70ec6a4089f03674
parent c93238c8e574351f90aa5351b28329228ce25dae
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Wed, 24 Jun 2020 20:29:47 +1000

Fix printing the "0x" prefix when using regexes

Only print the prefix if -X is given and the string has no prefix.

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

diff --git a/ngrep.c b/ngrep.c @@ -66,7 +66,7 @@ pcre *pattern = NULL; pcre_extra *pattern_extra = NULL; char *match_data = NULL, *bin_data = NULL; -int hex_exp_pfx = 0; +int hex_exp_pfx = 1; uint16_t match_len = 0; match_func matcher = blank_match_func; @@ -305,7 +305,7 @@ main(int argc, char **argv) if (quiet < 2) printf("%smatch: %s%s\n", invert_match ? "don't " : "", - hex_exp_pfx ? "" : "0x", + (bin_match && hex_exp_pfx) ? "0x" : "", match_data); if (re_match_word) @@ -487,7 +487,7 @@ setup_hex_match(void) } if (str[0] == '0' && (str[1] == 'X' || str[1] == 'x')) { - hex_exp_pfx = 1; + hex_exp_pfx = 0; str += 2; len -= 2; }