aboutsummaryrefslogtreecommitdiff
path: root/printmatch.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-06-07 14:45:03 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-06-07 14:45:03 -0400
commit31e414af503cbbc29f40ab6127073be939ffada1 (patch)
tree24737c23ef248468c43e0cdeac5a151a462c8f09 /printmatch.c
parent0e9f324955f5ce30e6eb7e735aadea0852547ca4 (diff)
Fix issue with replacement text printing before its line number
Diffstat (limited to 'printmatch.c')
-rw-r--r--printmatch.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/printmatch.c b/printmatch.c
index ee45a22..a3197f1 100644
--- a/printmatch.c
+++ b/printmatch.c
@@ -232,6 +232,16 @@ public int fprint_match(FILE *out, const char *file_start, bp_match_t *m, print_
}
}
+ // Bugfix: if pattern matches at the start of a line and first printed character is from
+ // the replacement string, we need to be sure that the line number gets printed.
+ // Regression test: `seq 3 | bp '{..$}' -r '#@0'` (should not print "#" before line numbers)
+ if (r == text) {
+ if (opts && opts->fprint_between) {
+ printed += opts->fprint_between(out, m->start, m->start, opts->match_color);
+ if (opts->replace_color) printed += fprintf(out, "%s", opts->replace_color);
+ }
+ }
+
if (*r == '\\') {
++r;
if (*r == 'N') { // \N (nodent)