Am 19.06.2018 um 19:44 schrieb Taylor Blau:
> diff --git a/grep.c b/grep.c
> index f3329d82ed..a09935d8c5 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1257,8 +1257,8 @@ static int match_one_pattern(struct grep_pat *p, char 
> *bol, char *eol,
>       return hit;
>   }
> 
> -static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
> -                        enum grep_context ctx, ssize_t *col,
> +static int match_expr_eval(struct grep_opt *opt, struct grep_expr *x, char 
> *bol,
> +                        char *eol, enum grep_context ctx, ssize_t *col,
>                          ssize_t *icol, int collect_hits)

Passing opt in is one way.  Piggy-backing on collect_hits and making it
a flags parameter for two bits might be easier.  At least it wouldn't
increase the number of function arguments any further.  Not sure.

Anyway, something like this would be needed as well; or we could
force opt->columnnum to switch opt->extended on:

diff --git a/grep.c b/grep.c
index 8ffa94c791..a724ca3010 100644
--- a/grep.c
+++ b/grep.c
@@ -1325,6 +1321,7 @@ static int match_line(struct grep_opt *opt, char *bol, 
char *eol,
                      enum grep_context ctx, int collect_hits)
 {
        struct grep_pat *p;
+       int hit = 0;
 
        if (opt->extended)
                return match_expr(opt, bol, eol, ctx, col, icol,
@@ -1334,11 +1331,14 @@ static int match_line(struct grep_opt *opt, char *bol, 
char *eol,
        for (p = opt->pattern_list; p; p = p->next) {
                regmatch_t tmp;
                if (match_one_pattern(p, bol, eol, ctx, &tmp, 0)) {
-                       *col = tmp.rm_so;
-                       return 1;
+                       hit |= 1;
+                       if (!opt->columnnum)
+                               break;
+                       if (*col < 0 || tmp.rm_so < *col)
+                               *col = tmp.rm_so;
                }
        }
-       return 0;
+       return hit;
 }
 
 static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,

Reply via email to