Re: [PATCH/RFC 3/4] grep: introduce pattern which matches at line number
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- May 2, 2011, 14:32 UTC
- Message-ID
- <BANLkTi=qKGdZpU+-aG3tuM8mssb6FnmpHw@mail.gmail.com>
- In-Reply-To
- <BANLkTinUWbhCKyfpimUuvCsxnCmRi3E=dg@mail.gmail.com>
On Mon, May 2, 2011 at 15:33, Thiago Farina <tfransosi@gmail.com> wrote:
Show 47 quoted lines
> 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 | 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)
>> {
>> 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 {Yeah, I must admit that these symbols should probably get a more descriptive name.
Bert