git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Gryazin <dosagc@gmail.com>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] grep: fix word-regexp colouring
Date: Thu, 21 May 2009 08:29:03 +0400	[thread overview]
Message-ID: <4A14D88F.8010105@gmail.com> (raw)
In-Reply-To: <4A1476C9.8060900@lsrfire.ath.cx>

René Scharfe wrote:
> 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;
>  }
>  
>   
Thanks.

ACK

      reply	other threads:[~2009-05-21  4:31 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 ` [PATCH] grep: fix word-regexp colouring René Scharfe
2009-05-21  4:29   ` Dmitry Gryazin [this message]

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=4A14D88F.8010105@gmail.com \
    --to=dosagc@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /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).