From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Dmitry Gryazin <dosagc@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH] grep: fix word-regexp colouring
Date: Wed, 20 May 2009 23:31:53 +0200 [thread overview]
Message-ID: <4A1476C9.8060900@lsrfire.ath.cx> (raw)
In-Reply-To: <4A144E41.4010303@gmail.com>
As noticed by Dmitry Gryazin: When a pattern is found but it doesn't
start and end at word boundaries, bol is forwarded to after the match and
the pattern is searched again. When a pattern is finally found between
word boundaries, the match offsets are off by the number of characters
that have been skipped.
This patch corrects the offsets to be relative to the value of bol as
passed to match_one_pattern() by its caller.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
grep.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/grep.c b/grep.c
index 04c777a..a649f06 100644
--- a/grep.c
+++ b/grep.c
@@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
{
int hit = 0;
int saved_ch = 0;
+ const char *start = bol;
if ((p->token != GREP_PATTERN) &&
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
@@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
}
if (p->token == GREP_PATTERN_HEAD && saved_ch)
*eol = saved_ch;
+ if (hit) {
+ pmatch[0].rm_so += bol - start;
+ pmatch[0].rm_eo += bol - start;
+ }
return hit;
}
--
1.6.3.1
next prev parent reply other threads:[~2009-05-20 21:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-20 18:38 git-grep colouring bug with -w option Dmitry Gryazin
2009-05-20 21:31 ` René Scharfe [this message]
2009-05-21 4:29 ` [PATCH] grep: fix word-regexp colouring Dmitry Gryazin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A1476C9.8060900@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=dosagc@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).