diff options
author | Natanael Copa | 2012-02-23 14:20:22 +0000 |
---|---|---|
committer | Denys Vlasenko | 2012-02-28 03:44:08 +0100 |
commit | cd09e81520b7917adebcffd7c361671f913325eb (patch) | |
tree | 8b9bca5890d22a116511c5b098d08c6bbcd294d4 /findutils/grep.c | |
parent | 0b170e6a096b0d5010e29a39f3b270c3a7bc4945 (diff) | |
download | busybox-cd09e81520b7917adebcffd7c361671f913325eb.zip busybox-cd09e81520b7917adebcffd7c361671f913325eb.tar.gz |
grep: support for -x, match whole line
Specified in POSIX.
http://pubs.opengroup.org/onlinepubs/009604499/utilities/grep.html
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 5f42242..f14d6e6 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -85,6 +85,7 @@ //usage: "\n -r Recurse" //usage: "\n -i Ignore case" //usage: "\n -w Match whole words only" +//usage: "\n -x Match whole lines only" //usage: "\n -F PATTERN is a literal (not regexp)" //usage: IF_FEATURE_GREP_EGREP_ALIAS( //usage: "\n -E PATTERN is an extended regexp" @@ -113,7 +114,7 @@ //usage:#define fgrep_full_usage "" #define OPTSTR_GREP \ - "lnqvscFiHhe:f:Lorm:w" \ + "lnqvscFiHhe:f:Lorm:wx" \ IF_FEATURE_GREP_CONTEXT("A:B:C:") \ IF_FEATURE_GREP_EGREP_ALIAS("E") \ IF_EXTRA_COMPAT("z") \ @@ -138,6 +139,7 @@ enum { OPTBIT_r, /* recurse dirs */ OPTBIT_m, /* -m MAX_MATCHES */ OPTBIT_w, /* -w whole word match */ + OPTBIT_x, /* -x whole line match */ IF_FEATURE_GREP_CONTEXT( OPTBIT_A ,) /* -A NUM: after-match context */ IF_FEATURE_GREP_CONTEXT( OPTBIT_B ,) /* -B NUM: before-match context */ IF_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ @@ -160,6 +162,7 @@ enum { OPT_r = 1 << OPTBIT_r, OPT_m = 1 << OPTBIT_m, OPT_w = 1 << OPTBIT_w, + OPT_x = 1 << OPTBIT_x, OPT_A = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_A)) + 0, OPT_B = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_B)) + 0, OPT_C = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, @@ -370,9 +373,12 @@ static int grep_file(FILE *file) &gl->matched_range) >= 0 #endif ) { - if (!(option_mask32 & OPT_w)) + if (option_mask32 & OPT_x) { + found = (gl->matched_range.rm_so == 0 + && line[gl->matched_range.rm_eo] == '\0'); + } else if (!(option_mask32 & OPT_w)) { found = 1; - else { + } else { char c = ' '; if (gl->matched_range.rm_so) c = line[gl->matched_range.rm_so - 1]; |