diff --git a/bp.1 b/bp.1 index 9a60593..8a9be7f 100644 --- a/bp.1 +++ b/bp.1 @@ -15,8 +15,13 @@ bp - Bruce\[aq]s Parsing Expression Grammar tool custom syntax. .SH OPTIONS .TP -\f[B]-v\f[R], \f[B]--verbose\f[R] -Print debugging information. +\f[B]-p\f[R], \f[B]--pattern\f[R] \f[I]pat\f[R] +Give a pattern in BP syntax instead of string syntax (equivalent to +\f[B]bp \[aq]\[rs](pat)\[aq]\f[R] +.TP +\f[B]-w\f[R], \f[B]--word\f[R] \f[I]word\f[R] +Surround a string pattern with word boundaries (equivalent to +\f[B]bp \[aq]\[rs]|word\[rs]|\[aq]\f[R]) .TP \f[B]-e\f[R], \f[B]--explain\f[R] Print a visual explanation of the matches. @@ -73,7 +78,7 @@ Set the output format. includes neither, and \f[I]auto\f[R] (the default) uses \f[I]fancy\f[R] formatting only when the output is a TTY. .TP -\f[B]--help\f[R] +\f[B]-h\f[R], \f[B]--help\f[R] Print the usage and exit. .TP \f[I]pattern\f[R] diff --git a/bp.1.md b/bp.1.md index 8e9482d..13f98e7 100644 --- a/bp.1.md +++ b/bp.1.md @@ -17,8 +17,13 @@ syntax. # OPTIONS -`-v`, `--verbose` -: Print debugging information. +`-p`, `--pattern` *pat* +: Give a pattern in BP syntax instead of string syntax (equivalent to `bp +'\(pat)'` + +`-w`, `--word` *word* +: Surround a string pattern with word boundaries (equivalent to `bp +'\|word\|'`) `-e`, `--explain` : Print a visual explanation of the matches. @@ -69,7 +74,7 @@ occur). includes neither, and *auto* (the default) uses *fancy* formatting only when the output is a TTY. -`--help` +`-h`, `--help` : Print the usage and exit. *pattern* 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 {