cvsdist ac51d8
--- grep-2.5.1/src/search.c.fgrep	2001-04-19 04:42:14.000000000 +0100
cvsdist ac51d8
+++ grep-2.5.1/src/search.c	2004-02-26 13:09:32.000000000 +0000
cvsdist ac51d8
@@ -360,13 +360,7 @@
cvsdist ac51d8
 	      /* Find a possible match using the KWset matcher. */
cvsdist ac51d8
 	      size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm);
cvsdist ac51d8
 	      if (offset == (size_t) -1)
cvsdist ac51d8
-		{
cvsdist ac51d8
-#ifdef MBS_SUPPORT
cvsdist ac51d8
-		  if (MB_CUR_MAX > 1)
cvsdist ac51d8
-		    free(mb_properties);
cvsdist ac51d8
-#endif
cvsdist ac51d8
-		  return (size_t)-1;
cvsdist ac51d8
-		}
cvsdist ac51d8
+	        goto failure;
cvsdist ac51d8
 	      beg += offset;
cvsdist ac51d8
 	      /* Narrow down to the line containing the candidate, and
cvsdist ac51d8
 		 run it through DFA. */
cvsdist ac51d8
@@ -379,7 +373,7 @@
cvsdist ac51d8
 	      while (beg > buf && beg[-1] != eol)
cvsdist ac51d8
 		--beg;
cvsdist ac51d8
 	      if (kwsm.index < kwset_exact_matches)
cvsdist ac51d8
-		goto success;
cvsdist ac51d8
+		goto success_in_beg_and_end;
cvsdist ac51d8
 	      if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
cvsdist ac51d8
 		continue;
cvsdist ac51d8
 	    }
cvsdist ac51d8
@@ -398,7 +392,7 @@
cvsdist ac51d8
 	    }
cvsdist ac51d8
 	  /* Successful, no backreferences encountered! */
cvsdist ac51d8
 	  if (!backref)
cvsdist ac51d8
-	    goto success;
cvsdist ac51d8
+	    goto success_in_beg_and_end;
cvsdist ac51d8
 	}
cvsdist ac51d8
       else
cvsdist ac51d8
 	end = beg + size;
cvsdist ac51d8
@@ -413,14 +407,11 @@
cvsdist ac51d8
 				       end - beg - 1, &(patterns[i].regs))))
cvsdist ac51d8
 	    {
cvsdist ac51d8
 	      len = patterns[i].regs.end[0] - start;
cvsdist ac51d8
-	      if (exact)
cvsdist ac51d8
-		{
cvsdist ac51d8
-		  *match_size = len;
cvsdist ac51d8
-		  return start;
cvsdist ac51d8
-		}
cvsdist ac51d8
+	      if (exact && !match_words)
cvsdist ac51d8
+	        goto success_in_start_and_len;
cvsdist ac51d8
 	      if ((!match_lines && !match_words)
cvsdist ac51d8
 		  || (match_lines && len == end - beg - 1))
cvsdist ac51d8
-		goto success;
cvsdist ac51d8
+		goto success_in_beg_and_end;
cvsdist ac51d8
 	      /* If -w, check if the match aligns with word boundaries.
cvsdist ac51d8
 		 We do this iteratively because:
cvsdist ac51d8
 		 (a) the line may contain more than one occurence of the
cvsdist ac51d8
@@ -434,7 +425,7 @@
cvsdist ac51d8
 		    if ((start == 0 || !WCHAR ((unsigned char) beg[start - 1]))
cvsdist ac51d8
 			&& (len == end - beg - 1
cvsdist ac51d8
 			    || !WCHAR ((unsigned char) beg[start + len])))
cvsdist ac51d8
-		      goto success;
Tim Waugh 41ed49
+		      goto success_in_beg_and_end;
cvsdist ac51d8
 		    if (len > 0)
cvsdist ac51d8
 		      {
cvsdist ac51d8
 			/* Try a shorter length anchored at the same place. */
cvsdist ac51d8
@@ -461,19 +452,26 @@
cvsdist ac51d8
 	    }
cvsdist ac51d8
 	} /* for Regex patterns.  */
cvsdist ac51d8
     } /* for (beg = end ..) */
cvsdist ac51d8
+
cvsdist ac51d8
+ failure:
cvsdist ac51d8
 #ifdef MBS_SUPPORT
cvsdist ac51d8
   if (MB_CUR_MAX > 1 && mb_properties)
cvsdist ac51d8
     free (mb_properties);
cvsdist ac51d8
 #endif /* MBS_SUPPORT */
cvsdist ac51d8
   return (size_t) -1;
cvsdist ac51d8
 
cvsdist ac51d8
- success:
cvsdist ac51d8
+ success_in_beg_and_end:
cvsdist ac51d8
+  len = end - beg;
cvsdist ac51d8
+  start = beg - buf;
cvsdist ac51d8
+  /* FALLTHROUGH */
cvsdist ac51d8
+
cvsdist ac51d8
+ success_in_start_and_len:
cvsdist ac51d8
 #ifdef MBS_SUPPORT
cvsdist ac51d8
   if (MB_CUR_MAX > 1 && mb_properties)
cvsdist ac51d8
     free (mb_properties);
cvsdist ac51d8
 #endif /* MBS_SUPPORT */
cvsdist ac51d8
-  *match_size = end - beg;
cvsdist ac51d8
-  return beg - buf;
cvsdist ac51d8
+  *match_size = len;
cvsdist ac51d8
+  return start;
cvsdist ac51d8
 }
cvsdist ac51d8
 
cvsdist ac51d8
 static void
cvsdist ac51d8
@@ -516,28 +514,15 @@
cvsdist ac51d8
     {
cvsdist ac51d8
       size_t offset = kwsexec (kwset, beg, buf + size - beg, &kwsmatch);
cvsdist ac51d8
       if (offset == (size_t) -1)
cvsdist ac51d8
-	{
cvsdist ac51d8
-#ifdef MBS_SUPPORT
cvsdist ac51d8
-	  if (MB_CUR_MAX > 1)
cvsdist ac51d8
-	    free(mb_properties);
cvsdist ac51d8
-#endif /* MBS_SUPPORT */
cvsdist ac51d8
-	  return offset;
cvsdist ac51d8
-	}
cvsdist ac51d8
+	goto failure;
cvsdist ac51d8
 #ifdef MBS_SUPPORT
cvsdist ac51d8
       if (MB_CUR_MAX > 1 && mb_properties[offset+beg-buf] == 0)
cvsdist ac51d8
 	continue; /* It is a part of multibyte character.  */
cvsdist ac51d8
 #endif /* MBS_SUPPORT */
cvsdist ac51d8
       beg += offset;
cvsdist ac51d8
       len = kwsmatch.size[0];
cvsdist ac51d8
-      if (exact)
cvsdist ac51d8
-	{
cvsdist ac51d8
-	  *match_size = len;
cvsdist ac51d8
-#ifdef MBS_SUPPORT
cvsdist ac51d8
-	  if (MB_CUR_MAX > 1)
cvsdist ac51d8
-	    free (mb_properties);
cvsdist ac51d8
-#endif /* MBS_SUPPORT */
cvsdist ac51d8
-	  return beg - buf;
cvsdist ac51d8
-	}
cvsdist ac51d8
+      if (exact && !match_words)
cvsdist ac51d8
+	goto success_in_beg_and_len;
cvsdist ac51d8
       if (match_lines)
cvsdist ac51d8
 	{
cvsdist ac51d8
 	  if (beg > buf && beg[-1] != eol)
Tim Waugh 4c3885
@@ -551,6 +536,7 @@
cvsdist ac51d8
 	goto success;
cvsdist ac51d8
     }
cvsdist ac51d8
 
cvsdist ac51d8
+ failure:
cvsdist ac51d8
 #ifdef MBS_SUPPORT
cvsdist ac51d8
   if (MB_CUR_MAX > 1)
cvsdist ac51d8
     free (mb_properties);
Tim Waugh 4c3885
@@ -583,7 +569,11 @@
cvsdist ac51d8
   end++;
cvsdist ac51d8
   while (buf < beg && beg[-1] != eol)
cvsdist ac51d8
     --beg;
cvsdist ac51d8
-  *match_size = end - beg;
cvsdist ac51d8
+  len = end - beg;
cvsdist ac51d8
+  /* FALLTHROUGH */
cvsdist ac51d8
+
cvsdist ac51d8
+ success_in_beg_and_len:
cvsdist ac51d8
+  *match_size = len;
cvsdist ac51d8
 #ifdef MBS_SUPPORT
cvsdist ac51d8
   if (MB_CUR_MAX > 1)
cvsdist ac51d8
     free (mb_properties);