Re: [PATCH v4 2/7] grep.c: expose matched column in match_line()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 05.05.2018 um 04:42 schrieb Taylor Blau:
> When calling match_line(), callers presently cannot determine the
> relative offset of the match because match_line() discards the
> 'regmatch_t' that contains this information.
> 
> Instead, teach match_line() to take in a 'regmatch_t *' so that callers
> can inspect the match's starting and ending offset from the beginning of
> the line. This additional argument has no effect when opt->extended is
> non-zero.
> 
> We will later pass the starting offset from 'regmatch_t *' to
> show_line() in order to display the column number of the first match.
> 
> Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx>
> ---
>   grep.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/grep.c b/grep.c
> index 65b90c10a3..1c25782355 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,
>   }
>   
>   static int match_line(struct grep_opt *opt, char *bol, char *eol,
> -		      enum grep_context ctx, int collect_hits)
> +		      regmatch_t *match, enum grep_context ctx,
> +		      int collect_hits)
>   {
>   	struct grep_pat *p;
> -	regmatch_t match;
>   
>   	if (opt->extended)
>   		return match_expr(opt, bol, eol, ctx, collect_hits);

If ->extended is set then match won't be touched...

>   
>   	/* we do not call with collect_hits without being extended */
>   	for (p = opt->pattern_list; p; p = p->next) {
> -		if (match_one_pattern(p, bol, eol, ctx, &match, 0))
> +		if (match_one_pattern(p, bol, eol, ctx, match, 0))
>   			return 1;
>   	}
>   	return 0;
> @@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
>   	int try_lookahead = 0;
>   	int show_function = 0;
>   	struct userdiff_driver *textconv = NULL;
> +	regmatch_t match;
>   	enum grep_context ctx = GREP_CONTEXT_HEAD;
>   	xdemitconf_t xecfg;
>   
> @@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
>   		if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
>   			ctx = GREP_CONTEXT_BODY;
>   
> -		hit = match_line(opt, bol, eol, ctx, collect_hits);
> +		hit = match_line(opt, bol, eol, &match, ctx, collect_hits);
>   		*eol = ch;
>   
>   		if (collect_hits)
> 

... which leaves it uninitialized.

So at least the combination of extended matches and --column should error
out.  Supporting it would be better, of course.  That could get tricky for
negations, though (e.g. git grep --not -e foo).

René



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux