grep: fix 'echo aaa | grep -o a' + ENABLE_EXTRA_COMPAT case
by Natanael Copa
This commit is contained in:
parent
df6b3ad6ba
commit
f60719cd49
@ -363,11 +363,21 @@ static int grep_file(FILE *file)
|
|||||||
* (unless -v: -Fov doesnt print anything at all) */
|
* (unless -v: -Fov doesnt print anything at all) */
|
||||||
if (found)
|
if (found)
|
||||||
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
|
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
|
||||||
} else {
|
} else while (1) {
|
||||||
|
char old = line[gl->matched_range.rm_eo];
|
||||||
line[gl->matched_range.rm_eo] = '\0';
|
line[gl->matched_range.rm_eo] = '\0';
|
||||||
print_line(line + gl->matched_range.rm_so,
|
print_line(line + gl->matched_range.rm_so,
|
||||||
gl->matched_range.rm_eo - gl->matched_range.rm_so,
|
gl->matched_range.rm_eo - gl->matched_range.rm_so,
|
||||||
linenum, ':');
|
linenum, ':');
|
||||||
|
line[gl->matched_range.rm_eo] = old;
|
||||||
|
#if !ENABLE_EXTRA_COMPAT
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
if (re_search(&gl->compiled_regex, line, line_len,
|
||||||
|
gl->matched_range.rm_eo, line_len - gl->matched_range.rm_eo,
|
||||||
|
&gl->matched_range) < 0)
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print_line(line, line_len, linenum, ':');
|
print_line(line, line_len, linenum, ':');
|
||||||
|
Loading…
Reference in New Issue
Block a user