bkabrda / rpms / grep

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