From cb9b4c40d87480bc794b90c2a36ed0f4c3240d8a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 30 Jul 2021 20:46:50 -0700 Subject: Added -w/--word flag --- bp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'bp.c') diff --git a/bp.c b/bp.c index b36607e..c9eb009 100644 --- a/bp.c +++ b/bp.c @@ -48,6 +48,7 @@ static const char *usage = ( " -C --confirm ask for confirmation on each replacement\n" " -l --list-files list filenames only\n" " -p --pattern provide a pattern (equivalent to bp '\\()')\n" + " -w --word find words matching the given string pattern\n" " -r --replace replace the input pattern with the given replacement\n" " -s --skip skip over the given pattern when looking for matches\n" " -c --context set number of lines of context to print (all: the whole file, 0: only the match, 1: the line, N: N lines of context)\n" @@ -559,6 +560,13 @@ int main(int argc, char *argv[]) str = after_spaces(p->end); } } + } else if (FLAG("-w") || FLAG("--word")) { + check_nonnegative(asprintf(&flag, "\\|%s\\|", flag), "Could not allocate memory"); + file_t *arg_file = spoof_file(&loaded_files, "", flag, -1); + delete(&flag); + pat_t *p = bp_stringpattern(arg_file, arg_file->start); + if (!p) errx(EXIT_FAILURE, "Pattern failed to compile: %s", flag); + pattern = chain_together(arg_file, pattern, p); } else if (FLAG("-s") || FLAG("--skip")) { file_t *arg_file = spoof_file(&loaded_files, "", flag, -1); pat_t *s = bp_pattern(arg_file, arg_file->start); @@ -588,8 +596,7 @@ int main(int argc, char *argv[]) if (pattern != NULL) break; file_t *arg_file = spoof_file(&loaded_files, "", argv[0], -1); pat_t *p = bp_stringpattern(arg_file, arg_file->start); - if (!p) - errx(EXIT_FAILURE, "Pattern failed to compile: %s", argv[0]); + if (!p) errx(EXIT_FAILURE, "Pattern failed to compile: %s", argv[0]); pattern = chain_together(arg_file, pattern, p); ++argv; } else { -- cgit v1.2.3