grep: properly handle grep -w "^str" in !EXTRA_COMPAT case too
function old new delta grep_file 1267 1288 +21 Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
07f417b6ab
commit
3ba2df874c
@ -375,6 +375,8 @@ static int grep_file(FILE *file)
|
|||||||
} else {
|
} else {
|
||||||
#if ENABLE_EXTRA_COMPAT
|
#if ENABLE_EXTRA_COMPAT
|
||||||
unsigned start_pos;
|
unsigned start_pos;
|
||||||
|
#else
|
||||||
|
int match_flg;
|
||||||
#endif
|
#endif
|
||||||
char *match_at;
|
char *match_at;
|
||||||
|
|
||||||
@ -392,6 +394,7 @@ static int grep_file(FILE *file)
|
|||||||
#if !ENABLE_EXTRA_COMPAT
|
#if !ENABLE_EXTRA_COMPAT
|
||||||
gl->matched_range.rm_so = 0;
|
gl->matched_range.rm_so = 0;
|
||||||
gl->matched_range.rm_eo = 0;
|
gl->matched_range.rm_eo = 0;
|
||||||
|
match_flg = 0;
|
||||||
#else
|
#else
|
||||||
start_pos = 0;
|
start_pos = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -400,7 +403,7 @@ static int grep_file(FILE *file)
|
|||||||
//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
|
//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
|
||||||
if (
|
if (
|
||||||
#if !ENABLE_EXTRA_COMPAT
|
#if !ENABLE_EXTRA_COMPAT
|
||||||
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
|
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0
|
||||||
#else
|
#else
|
||||||
re_search(&gl->compiled_regex, match_at, line_len,
|
re_search(&gl->compiled_regex, match_at, line_len,
|
||||||
start_pos, /*range:*/ line_len,
|
start_pos, /*range:*/ line_len,
|
||||||
@ -415,7 +418,7 @@ static int grep_file(FILE *file)
|
|||||||
found = 1;
|
found = 1;
|
||||||
} else {
|
} else {
|
||||||
char c = ' ';
|
char c = ' ';
|
||||||
if (gl->matched_range.rm_so)
|
if (match_at > line || gl->matched_range.rm_so != 0)
|
||||||
c = match_at[gl->matched_range.rm_so - 1];
|
c = match_at[gl->matched_range.rm_so - 1];
|
||||||
if (!isalnum(c) && c != '_') {
|
if (!isalnum(c) && c != '_') {
|
||||||
c = match_at[gl->matched_range.rm_eo];
|
c = match_at[gl->matched_range.rm_eo];
|
||||||
@ -432,6 +435,7 @@ static int grep_file(FILE *file)
|
|||||||
#if !ENABLE_EXTRA_COMPAT
|
#if !ENABLE_EXTRA_COMPAT
|
||||||
if (gl->matched_range.rm_eo != 0) {
|
if (gl->matched_range.rm_eo != 0) {
|
||||||
match_at += gl->matched_range.rm_eo;
|
match_at += gl->matched_range.rm_eo;
|
||||||
|
match_flg |= REG_NOTBOL;
|
||||||
goto opt_w_again;
|
goto opt_w_again;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -159,6 +159,12 @@ testing "grep -w ^ doesn't hang" \
|
|||||||
"anything\n" \
|
"anything\n" \
|
||||||
""
|
""
|
||||||
|
|
||||||
|
testing "grep -w word doesn't match wordword" \
|
||||||
|
"grep -w word input" \
|
||||||
|
"" \
|
||||||
|
"wordword\n" \
|
||||||
|
""
|
||||||
|
|
||||||
# testing "test name" "commands" "expected result" "file input" "stdin"
|
# testing "test name" "commands" "expected result" "file input" "stdin"
|
||||||
# file input will be file called "input"
|
# file input will be file called "input"
|
||||||
# test can create a file "actual" instead of writing to stdout
|
# test can create a file "actual" instead of writing to stdout
|
||||||
|
Loading…
Reference in New Issue
Block a user