461 |
if (found) |
if (found) |
462 |
print_line(gl->pattern, strlen(gl->pattern), linenum, ':'); |
print_line(gl->pattern, strlen(gl->pattern), linenum, ':'); |
463 |
} else while (1) { |
} else while (1) { |
464 |
|
unsigned start = gl->matched_range.rm_so; |
465 |
unsigned end = gl->matched_range.rm_eo; |
unsigned end = gl->matched_range.rm_eo; |
466 |
|
unsigned len = end - start; |
467 |
char old = line[end]; |
char old = line[end]; |
468 |
line[end] = '\0'; |
line[end] = '\0'; |
469 |
print_line(line + gl->matched_range.rm_so, |
/* Empty match is not printed: try "echo test | grep -o ''" */ |
470 |
end - gl->matched_range.rm_so, |
if (len != 0) |
471 |
linenum, ':'); |
print_line(line + start, len, linenum, ':'); |
472 |
if (old == '\0') |
if (old == '\0') |
473 |
break; |
break; |
474 |
line[end] = old; |
line[end] = old; |
475 |
|
if (len == 0) |
476 |
|
end++; |
477 |
#if !ENABLE_EXTRA_COMPAT |
#if !ENABLE_EXTRA_COMPAT |
478 |
if (regexec(&gl->compiled_regex, line + end, |
if (regexec(&gl->compiled_regex, line + end, |
479 |
1, &gl->matched_range, REG_NOTBOL) != 0) |
1, &gl->matched_range, REG_NOTBOL) != 0) |