bug-gnu-utils
[Top][All Lists]
Advanced

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

[Fwd: Re: (Another?) Grep patch]


From: Ed Smith
Subject: [Fwd: Re: (Another?) Grep patch]
Date: Mon, 07 Jul 2003 17:17:57 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225



-------- Original Message --------
Message-ID: <address@hidden>
Date: Sun, 04 May 2003 15:35:12 +0100
From: Ed Smith <address@hidden>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: address@hidden
Subject: Re: (Another?) Grep patch
References: <address@hidden>
In-Reply-To: <address@hidden>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi again,

I also noticed that

echo "hi" | grep -i -o "HI"

doesn't work. This is because the compiled regular expression contains
uppercase characters and no translation table. So I patched search.c
with this diff:

212a213,220
 >       if(match_icase){
 >       static char trans[NCHAR];
 >       int i;
 >       for (i = 0; i < NCHAR; ++i)
 >         trans[i] = TOLOWER (i);
 >       patterns[pcount].regexbuf.translate = trans;
 >      }
 >
295a304,311
 >       if(match_icase){
 >       static char trans[NCHAR];
 >       int i;
 >       for (i = 0; i < NCHAR; ++i)
 >         trans[i] = TOLOWER (i);
 >       patterns[pcount].regexbuf.translate = trans;
 >       }
 >

This fixes the problem:

address@hidden src]$ echo PQ | ./grep -i -o pq
PQ
address@hidden src]$ echo pq | ./grep -i -o pq
pq
address@hidden src]$ echo pq | ./grep -i -o PQ
pq
address@hidden src]$ echo PQ | ./grep -i -o PQ
PQ

And notice that  now the origional case of the matching part is printed,
not the lowercase version (same behaviour as without -o).

Futher still, this makes the last patch I sent and (some of) the diff
from 1.80 to 1.81 redundant. In other words, you can also apply the
following diff to grep.c (1.81) as well. This removes the faulty code
which I corrected in my last email.

Hope this is clear, else feel free to ask me to clarify any points,

Ed

536,566d535
<       if(match_icase)
<         {
<           char *buf = (char*) xmalloc (lim - beg);
<         char *ibeg = buf;
<         char *ilim = ibeg + (lim - beg);
<         int i;
<         for (i = 0; i < lim - beg; i++)
<           ibeg[i] = tolower (beg[i]);
<
<         while ((match_offset = (*execute) (ibeg, lim - beg,
&match_size, 1))
<                != (size_t) -1)
<           {
<             char const *b = ibeg + match_offset;
<             if (b == lim)
<               break;
<             if (match_size == 0)
<               break;
<             if(color_option)
<               printf("\33[%sm", grep_color);
<             fwrite(b, sizeof (char), match_size, stdout);
<             if(color_option)
<               fputs("\33[00m", stdout);
<             fputs("\n", stdout);
<             ibeg = b + match_size;
<           }
<         free (buf);
<         lastout = lim;
<         if(line_buffered)
<           fflush(stdout);
<         return;
<       }

Ed

Ed Smith wrote:
Hi,

Got a seg fault using latest CVS version of grep. Tracked it down and here's a diff of grep.c:

545c545
< while ((match_offset = (*execute) (ibeg, ilim - ibeg, &match_size, 1))
---
> while ((match_offset = (*execute) (ibeg, lim - beg, &match_size, 1))

It was failing because ibeg was being increased in the while loop when a match was found, thus reporting the wrong size to GExecute.

Thanks,

Ed








reply via email to

[Prev in Thread] Current Thread [Next in Thread]