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

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

Re: grep bug


From: Stepan Kasal
Subject: Re: grep bug
Date: Sat, 12 Apr 2003 00:16:13 +0200
User-agent: Mutt/1.2.5.1i

Hello,

On Fri, Apr 11, 2003 at 01:14:55PM -0700, Michael J. Bailey wrote:
> echo 'COM' | grep -io 'com'

Please try the attached patch.
But the pattern has to be specified in lowercase to get correct results.

The problem will be fixed in the next release.

Sorry for the inconvenience.

Stepan Kasal


--- grep-2.5.1.orig/src/grep.c  Tue Mar 26 16:54:12 2002
+++ grep-2.5.1/src/grep.c       Wed Feb  5 11:00:59 2003
@@ -533,6 +533,37 @@ prline (char const *beg, char const *lim
     {
       size_t match_size;
       size_t match_offset;
+      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 = beg + 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 = ibeg + match_offset + match_size;
+           }
+         free (buf);
+         lastout = lim;
+         if(line_buffered)
+           fflush(stdout);
+         return;
+       }
       while ((match_offset = (*execute) (beg, lim - beg, &match_size, 1))
          != (size_t) -1)
         {





reply via email to

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