Comment 8 for bug 9231

Revision history for this message
In , Fumitoshi UKAI (ukai) wrote : ignore case bug

tags 226397 + patch
tags 238167 + patch
thanks

This bug is only in singlebyte locales.
Above chunk, which does the same way as if (color_option) {} (special
handling for match_icase), fixes Bug#238167.
Next 2 chunks, which does the same way as MB_CUR_MAX != 1 (tolower
pattern), is necessary to fix both of these bugs.

Anyway, this is tricky, and I think regex library should be fixed
as if glibc's regex library, which has RE_ICASE syntax, so that
we may not need such a trick.

--- grep-2.5.1.orig/src/grep.c 2004-10-21 00:57:33.000000000 +0900
+++ grep-2.5.1/src/grep.c 2004-10-21 01:39:24.000000000 +0900
@@ -554,6 +554,38 @@
     {
       size_t match_size;
       size_t match_offset;
+ if(match_icase)
+ {
+ /* Yuck, this is tricky */
+ 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, ilim-ibeg, &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);
+ beg = b + match_size;
+ 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)
         {
@@ -1719,8 +1751,9 @@
   if (!install_matcher (matcher) && !install_matcher ("default"))
     abort ();

+ if (match_icase) {
 #ifdef MBS_SUPPORT
- if (MB_CUR_MAX != 1 && match_icase)
+ if (MB_CUR_MAX != 1)
     {
       wchar_t wc;
       mbstate_t cur_state, prev_state;
@@ -1747,8 +1780,17 @@
      }
    i += mbclen;
  }
- }
+ } else
 #endif /* MBS_SUPPORT */
+ {
+ int i, len = strlen(keys);
+ for (i = 0; i < len; i++) {
+ if (isupper(keys[i]))
+ keys[i] = tolower(keys[i]);
+ }
+ }
+ }
+

   (*compile)(keys, keycc);

Regards,
Fumitoshi UKAI