Added -w/--word flag
This commit is contained in:
parent
9c05f880b0
commit
cb9b4c40d8
11
bp.1
11
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]
|
||||
|
11
bp.1.md
11
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*
|
||||
|
11
bp.c
11
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 <pat> provide a pattern (equivalent to bp '\\(<pat>)')\n"
|
||||
" -w --word <string-pat> find words matching the given string pattern\n"
|
||||
" -r --replace <replacement> replace the input pattern with the given replacement\n"
|
||||
" -s --skip <skip-pattern> skip over the given pattern when looking for matches\n"
|
||||
" -c --context <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, "<word pattern>", 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, "<skip argument>", 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, "<pattern argument>", 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user