- Applied Tim Robbins' patch for 'grep -w' (bug #179698).

This commit is contained in:
Tim Waugh 2006-02-20 14:36:53 +00:00
parent c3d51bf337
commit a8485b3c26
2 changed files with 42 additions and 35 deletions

View File

@ -1,32 +1,6 @@
--- grep-2.5.1a/src/search.c.w 2005-01-07 15:04:18.766280754 +0000
+++ grep-2.5.1a/src/search.c 2005-01-07 16:59:19.287275172 +0000
@@ -330,6 +330,7 @@
static int use_dfa;
static int use_dfa_checked = 0;
#ifdef MBS_SUPPORT
+ const char *last_char = NULL;
int mb_cur_max = MB_CUR_MAX;
mbstate_t mbs;
memset (&mbs, '\0', sizeof (mbstate_t));
@@ -385,6 +386,8 @@
while (bytes_left)
{
size_t mlen = mbrlen (beg, bytes_left, &mbs);
+
+ last_char = beg;
if (mlen == (size_t) -1 || mlen == 0)
{
/* Incomplete character: treat as single-byte. */
@@ -445,6 +448,8 @@
while (bytes_left)
{
size_t mlen = mbrlen (beg, bytes_left, &mbs);
+
+ last_char = beg;
if (mlen == (size_t) -1 || mlen == 0)
{
/* Incomplete character: treat as single-byte. */
@@ -507,10 +512,84 @@
--- grep-2.5.1a/src/search.c.w 2006-02-20 14:27:27.000000000 +0000
+++ grep-2.5.1a/src/search.c 2006-02-20 14:32:07.000000000 +0000
@@ -507,10 +507,114 @@
if (match_words)
while (start >= 0)
{
@ -44,11 +18,16 @@
+ if (mb_cur_max > 1)
+ {
+ const char *s;
+ int mr;
+ size_t mr;
+ wchar_t pwc;
+
+ /* Locate the start of the multibyte character
+ before the match position (== beg + start). */
+ if (using_utf8)
+ {
+ /* UTF-8 is a special case: scan backwards
+ until we find a 7-bit character or a
+ lead byte. */
+ s = beg + start - 1;
+ while (s > buf
+ && (unsigned char) *s >= 0x80
@ -56,15 +35,40 @@
+ --s;
+ }
+ else
+ s = last_char;
+ mr = mbtowc (&pwc, s, beg + start - s);
+ if (mr <= 0)
+ {
+ /* Scan forwards to find the start of the
+ last complete character before the
+ match position. */
+ size_t bytes_left = start - 1;
+ s = beg;
+ while (bytes_left > 0)
+ {
+ mr = mbrlen (s, bytes_left, &mbs);
+ if (mr == (size_t) -1 || mr == 0)
+ {
+ memset (&mbs, '\0', sizeof (mbs));
+ s++;
+ bytes_left--;
+ continue;
+ }
+ if (mr == (size_t) -2)
+ {
+ memset (&mbs, '\0', sizeof (mbs));
+ break;
+ }
+ s += mr;
+ bytes_left -= mr;
+ }
+ }
+ mr = mbrtowc (&pwc, s, beg + start - s, &mbs);
+ if (mr == (size_t) -2 || mr == (size_t) -1 ||
+ mr == 0)
+ {
+ memset (&mbs, '\0', sizeof (mbstate_t));
+ lword_match = 1;
+ }
+ else if (!(iswalnum (pwc) || pwc == L'_')
+ && mr == (int) (beg + start - s))
+ && mr == beg + start - s)
+ lword_match = 1;
+ }
+ else

View File

@ -1,7 +1,7 @@
Summary: The GNU versions of grep pattern matching utilities.
Name: grep
Version: 2.5.1
Release: 52.2
Release: 53
License: GPL
Group: Applications/Text
Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}a.tar.bz2
@ -94,6 +94,9 @@ fi
%{_mandir}/*/*
%changelog
* Mon Feb 20 2006 Tim Waugh <twaugh@redhat.com> 2.5.1-53
- Applied Tim Robbins' patch for 'grep -w' (bug #179698).
* Fri Feb 10 2006 Jesse Keating <jkeating@redhat.com> - 2.5.1-52.2
- bump again for double-long bug on ppc(64)