git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] grep: fix word-regexp colouring

From
DGDmitry Gryazin <dosagc@gmail.com>
Date
May 21, 2009, 04:29 UTC
Message-ID
<4A14D88F.8010105@gmail.com>
In-Reply-To
<4A1476C9.8060900@lsrfire.ath.cx>
René Scharfe wrote:
Show 38 quoted lines
> 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
Previous: René Scharfe
Message 3 of 3 in “git-grep colouring bug with -w option.”
  1. Dmitry GryazinMay 20, 2009
  2. grep: fix word-regexp colouringRené Scharfe, May 20, 2009
  3. Dmitry GryazinMay 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.