On Mon, May 2, 2011 at 8:39 AM, Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> wrote: > Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> > --- > Âgrep.c |  33 +++++++++++++++++++++++++++++++++ > Âgrep.h |  Â7 +++++-- > Â2 files changed, 38 insertions(+), 2 deletions(-) > > diff --git a/grep.c b/grep.c > index f21b022..cbb3757 100644 > --- a/grep.c > +++ b/grep.c > @@ -87,6 +87,15 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) >    Â} > Â} > > +static void parse_lno(struct grep_pat *p, struct grep_opt *opt) Maybe parse_line_number? > +{ > +    char *eon; > + > +    p->u.lno = strtoul(p->pattern, &eon, 10); > +    if (*eon || p->u.lno == 0) > +        die("'%s': Invalid number for line match", p->pattern); > +} > + > Âstatic struct grep_expr *compile_pattern_or(struct grep_pat **); > Âstatic struct grep_expr *compile_pattern_atom(struct grep_pat **list) > Â{ > @@ -100,6 +109,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list) >    Âcase GREP_PATTERN: /* atom */ >    Âcase GREP_PATTERN_HEAD: >    Âcase GREP_PATTERN_BODY: > +    case GREP_LNO: >        Âx = xcalloc(1, sizeof (struct grep_expr)); >        Âx->node = GREP_NODE_ATOM; >        Âx->u.atom = p; > @@ -264,6 +274,9 @@ void compile_grep_patterns(struct grep_opt *opt) >        Âcase GREP_PATTERN_BODY: >            Âcompile_regexp(p, opt); >            Âbreak; > +        case GREP_LNO: > +            parse_lno(p, opt); > +            break; >        Âdefault: >            Âopt->extended = 1; >            Âbreak; > @@ -297,6 +310,7 @@ static void free_pattern_expr(struct grep_expr *x) >    Âswitch (x->node) { >    Âcase GREP_NODE_TRUE: >    Âcase GREP_NODE_ATOM: > +    case GREP_NODE_LNO: >        Âbreak; >    Âcase GREP_NODE_NOT: >        Âfree_pattern_expr(x->u.unary); > @@ -436,6 +450,21 @@ static struct { >    Â{ "committer ", 10 }, > Â}; > > +static int match_lno(struct grep_pat *p, char *bol, char *eol, unsigned lno, > +          Âregmatch_t *pmatch) > +{ > +    if (p->u.lno == lno) { > +        /* > +        Â* because coloring will stop at so == eo, match at the end > +        Â* of line, so that the whole line can be colored > +        Â*/ > +        pmatch->rm_so = eol - bol; > +        pmatch->rm_eo = eol - bol; > +        return 1; > +    } > +    return 0; > +} > + > Âstatic int match_one_pattern(struct grep_pat *p, char *bol, char *eol, >               unsigned lno, enum grep_context ctx, >               regmatch_t *pmatch, int eflags) > @@ -444,6 +473,9 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, >    Âint saved_ch = 0; >    Âconst char *start = bol; > > +    if (p->token == GREP_LNO) > +        return match_lno(p, bol, eol, lno, pmatch); > + >    Âif ((p->token != GREP_PATTERN) && >      Â((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD))) >        Âreturn 0; > @@ -614,6 +646,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol, unsigned lno, >            Âcase GREP_PATTERN: /* atom */ >            Âcase GREP_PATTERN_HEAD: >            Âcase GREP_PATTERN_BODY: > +            case GREP_LNO: >                Âhit |= match_next_pattern(p, bol, eol, lno, ctx, >                             Âpmatch, eflags); >                Âbreak; > diff --git a/grep.h b/grep.h > index 9912c11..41821f3 100644 > --- a/grep.h > +++ b/grep.h > @@ -10,7 +10,8 @@ enum grep_pat_token { >    ÂGREP_OPEN_PAREN, >    ÂGREP_CLOSE_PAREN, >    ÂGREP_NOT, > -    GREP_OR > +    GREP_OR, > +    GREP_LNO Maybe GREP_LINE_NR? > Â}; > > Âenum grep_context { > @@ -34,6 +35,7 @@ struct grep_pat { >    Âenum grep_header_field field; >    Âunion { >        Âregex_t regexp; > +        unsigned lno; >    Â} u; >    Âunsigned fixed:1; >    Âunsigned ignore_case:1; > @@ -45,7 +47,8 @@ enum grep_expr_node { >    ÂGREP_NODE_NOT, >    ÂGREP_NODE_AND, >    ÂGREP_NODE_TRUE, > -    GREP_NODE_OR > +    GREP_NODE_OR, > +    GREP_NODE_LNO > Â}; > > Âstruct grep_expr { > -- > 1.7.5.349.gfeb1a > > -- > To unsubscribe from this list: send the line "unsubscribe git" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html > ÿô.nÇ·®+%˱é¥wÿº{.nÇ· ßØnr¡öë¨è&£ûz¹Þúzf£¢·h§~Ûÿÿïÿê_èæ+v¨þ)ßø