From a8485b3c26308b4ebd260fc40b9de81e56e8b5eb Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Mon, 20 Feb 2006 14:36:53 +0000 Subject: [PATCH] - Applied Tim Robbins' patch for 'grep -w' (bug #179698). --- grep-2.5.1-w.patch | 72 ++++++++++++++++++++++++---------------------- grep.spec | 5 +++- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/grep-2.5.1-w.patch b/grep-2.5.1-w.patch index e4d6ea2..79ae2ae 100644 --- a/grep-2.5.1-w.patch +++ b/grep-2.5.1-w.patch @@ -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 diff --git a/grep.spec b/grep.spec index 972cfde..8925184 100644 --- a/grep.spec +++ b/grep.spec @@ -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 2.5.1-53 +- Applied Tim Robbins' patch for 'grep -w' (bug #179698). + * Fri Feb 10 2006 Jesse Keating - 2.5.1-52.2 - bump again for double-long bug on ppc(64)