bug-grep
[Top][All Lists]
Advanced

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

bug? --color/--only-matching when !MBS_SUPPORT or MB_CUR_MAX==1


From: Karl Chen
Subject: bug? --color/--only-matching when !MBS_SUPPORT or MB_CUR_MAX==1
Date: Sun, 19 Apr 2009 13:32:21 -0400

export LANG=en_US.ASCII 
# use a locale with MB_CUR_MAX == 1

echo abcDEF | grep -o -i C.E

Expected result: "cDE"
Seen result: (no output)

I expect this to return "cDE" with patterns "c.e", "C.E", and
"c.E".  However, in grep-2.5.4 with LANG=en_US.ASCII, this only
works with pattern "c.e" (all lowercase).  [In grep-2.5.1, this
only works with pattern "c.E" (case matching text).]

Similar behavior happens with --color=always: "cDE" gets
highlighted in the same situations that --only-matching would
succeed.  This happens with LANG=en_US.ASCII but not
LANG=en_US.UTF-8 (where MB_CUR_MAX==6); it happens if I force
MBS_SUPPORT to 0 in mbsupport.h.

It happens with both --with-included-regex and
--without-included-regex on the Linux and Solaris systems I tried.



This quick hack fixes the problem for me (the real fix may well be
more complicated).

--- grep.c~
+++ grep.c
@@ -1772,7 +1772,14 @@
   int mcm;
 
   if ((mcm = MB_CUR_MAX) == 1)
+    {
+      char *s;
+      for (s = *keys; *s; ++s)
+        {
+          *s = towlower(towupper(*s));
+        }
     return;
+    }
 
   li = *len;
   ki = *keys;

--- grep.c~
+++ grep.c
@@ -2239,10 +2239,18 @@
 
   set_limits();
 
-#ifdef MBS_SUPPORT
   if (match_icase)
+    {
+#ifdef MBS_SUPPORT
     mb_icase_keys (&keys, &keycc);
+#else
+      char *s;
+      for (s = keys; *s; ++s)
+        {
+          *s = tolower(*s);
+        }
 #endif /* MBS_SUPPORT */
+    }
 
   compile(keys, keycc);
 




I suggest adding test cases for this along the lines of:

--- foad1.sh~
+++ foad1.sh
@@ -52,6 +52,10 @@
 # Also check what it does when lines of context are specified.
 grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n
 grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -i
+grep_test "wA wB/wC/" "1:wB/" "wB" -o -n -i
+grep_test "wA wB/wC/" "1:wB/" "WB" -o -n -i
+grep_test "wA wB/wC/" "1:wB/" "wb" -o -n -i
+grep_test "wA wB/wC/" "1:wB/" "Wb" -o -n -i
 grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -3 2>/dev/null
 grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b
 grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b -i


and testing under different values of LANG/LC_ALL.


Also, speaking of foad1.sh, I suggest unsetting GREP_COLOR or
setting it explicitly to '01;31', and not using 'echo -n' because
not all /bin/sh support -n.






reply via email to

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