From: Thiago Farina <tfransosi@gmail.com>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC 2/4] grep: pass current line number down to match_one_pattern
Date: Mon, 2 May 2011 10:30:16 -0300 [thread overview]
Message-ID: <BANLkTi=HtStcEFezT9sEeRFzsGw1mMyg7Q@mail.gmail.com> (raw)
In-Reply-To: <2681b60988c7c4d059f83df368395eca0520012c.1304321122.git.bert.wesarg@googlemail.com>
On Mon, May 2, 2011 at 8:39 AM, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
> grep.c | 42 +++++++++++++++++++++---------------------
> 1 files changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index b8eda9e..f21b022 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -437,7 +437,7 @@ static struct {
> };
>
> static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
> - enum grep_context ctx,
> + unsigned lno, enum grep_context ctx,
I'd rename lno to line_nr, so it's more clearer. Also, I'd add the new
paramenter at the end, not in some random position (or was there some
particular reason to put here but not in the end?).
> regmatch_t *pmatch, int eflags)
> {
> int hit = 0;
> @@ -516,7 +516,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
> }
>
> static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
> - enum grep_context ctx, int collect_hits)
> + unsigned lno, enum grep_context ctx, int collect_hits)
> {
> int h = 0;
> regmatch_t match;
> @@ -528,25 +528,25 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
> h = 1;
> break;
> case GREP_NODE_ATOM:
> - h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
> + h = match_one_pattern(x->u.atom, bol, eol, lno, ctx, &match, 0);
> break;
> case GREP_NODE_NOT:
> - h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
> + h = !match_expr_eval(x->u.unary, bol, eol, lno, ctx, 0);
> break;
> case GREP_NODE_AND:
> - if (!match_expr_eval(x->u.binary.left, bol, eol, ctx, 0))
> + if (!match_expr_eval(x->u.binary.left, bol, eol, lno, ctx, 0))
> return 0;
> - h = match_expr_eval(x->u.binary.right, bol, eol, ctx, 0);
> + h = match_expr_eval(x->u.binary.right, bol, eol, lno, ctx, 0);
> break;
> case GREP_NODE_OR:
> if (!collect_hits)
> return (match_expr_eval(x->u.binary.left,
> - bol, eol, ctx, 0) ||
> + bol, eol, lno, ctx, 0) ||
> match_expr_eval(x->u.binary.right,
> - bol, eol, ctx, 0));
> - h = match_expr_eval(x->u.binary.left, bol, eol, ctx, 0);
> + bol, eol, lno, ctx, 0));
> + h = match_expr_eval(x->u.binary.left, bol, eol, lno, ctx, 0);
> x->u.binary.left->hit |= h;
> - h |= match_expr_eval(x->u.binary.right, bol, eol, ctx, 1);
> + h |= match_expr_eval(x->u.binary.right, bol, eol, lno, ctx, 1);
> break;
> default:
> die("Unexpected node type (internal error) %d", x->node);
> @@ -557,36 +557,36 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
> }
>
> static int match_expr(struct grep_opt *opt, char *bol, char *eol,
> - enum grep_context ctx, int collect_hits)
> + unsigned lno, enum grep_context ctx, int collect_hits)
> {
> struct grep_expr *x = opt->pattern_expression;
> - return match_expr_eval(x, bol, eol, ctx, collect_hits);
> + return match_expr_eval(x, bol, eol, lno, ctx, collect_hits);
> }
>
> static int match_line(struct grep_opt *opt, char *bol, char *eol,
> - enum grep_context ctx, int collect_hits)
> + unsigned lno, 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);
> + return match_expr(opt, bol, eol, lno, ctx, collect_hits);
>
> /* 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, lno, ctx, &match, 0))
> return 1;
> }
> return 0;
> }
>
> static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,
> - enum grep_context ctx,
> + unsigned lno, enum grep_context ctx,
> regmatch_t *pmatch, int eflags)
> {
> regmatch_t match;
>
> - if (!match_one_pattern(p, bol, eol, ctx, &match, eflags))
> + if (!match_one_pattern(p, bol, eol, lno, ctx, &match, eflags))
> return 0;
> if (match.rm_so < 0 || match.rm_eo < 0)
> return 0;
> @@ -601,7 +601,7 @@ static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,
> return 1;
> }
>
> -static int next_match(struct grep_opt *opt, char *bol, char *eol,
> +static int next_match(struct grep_opt *opt, char *bol, char *eol, unsigned lno,
> enum grep_context ctx, regmatch_t *pmatch, int eflags)
> {
> struct grep_pat *p;
> @@ -614,7 +614,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,
> case GREP_PATTERN: /* atom */
> case GREP_PATTERN_HEAD:
> case GREP_PATTERN_BODY:
> - hit |= match_next_pattern(p, bol, eol, ctx,
> + hit |= match_next_pattern(p, bol, eol, lno, ctx,
> pmatch, eflags);
> break;
> default:
> @@ -667,7 +667,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
> else if (sign == '=')
> line_color = opt->color_function;
> *eol = '\0';
> - while (next_match(opt, bol, eol, ctx, &match, eflags)) {
> + while (next_match(opt, bol, eol, lno, ctx, &match, eflags)) {
> if (match.rm_so == match.rm_eo)
> break;
>
> @@ -911,7 +911,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
> 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, lno, ctx, collect_hits);
> *eol = ch;
>
> if (collect_hits)
> --
> 1.7.5.349.gfeb1a
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2011-05-02 13:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 11:39 [PATCH/RFC 0/4] grep: support to match by line number Bert Wesarg
[not found] ` <cover.1304321122.git.bert.wesarg@googlemail.com>
2011-05-02 11:39 ` [PATCH/RFC 1/4] grep: prepare for re-using the space of the regexp member in struct grep_pat Bert Wesarg
2011-05-02 13:27 ` Thiago Farina
2011-05-02 14:25 ` Bert Wesarg
2011-05-02 11:39 ` [PATCH/RFC 2/4] grep: pass current line number down to match_one_pattern Bert Wesarg
2011-05-02 13:30 ` Thiago Farina [this message]
2011-05-02 14:29 ` Bert Wesarg
2011-05-02 16:40 ` Junio C Hamano
2011-05-02 11:39 ` [PATCH/RFC 3/4] grep: introduce pattern which matches at line number Bert Wesarg
2011-05-02 13:33 ` Thiago Farina
2011-05-02 14:32 ` Bert Wesarg
2011-05-02 11:39 ` [PATCH/RFC 4/4] grep: provide option to match " Bert Wesarg
2011-05-02 11:54 ` [PATCH/RFC 0/4] grep: support to match by " Sverre Rabbelier
2011-05-02 12:20 ` Bert Wesarg
2011-05-02 16:46 ` Junio C Hamano
2011-05-02 19:14 ` Bert Wesarg
2011-05-02 19:30 ` Junio C Hamano
2011-05-02 16:38 ` Junio C Hamano
2011-05-02 17:11 ` Jakub Narebski
2011-05-02 18:54 ` Bert Wesarg
2011-05-02 19:08 ` Junio C Hamano
2011-05-02 19:33 ` Bert Wesarg
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='BANLkTi=HtStcEFezT9sEeRFzsGw1mMyg7Q@mail.gmail.com' \
--to=tfransosi@gmail.com \
--cc=bert.wesarg@googlemail.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).