Tim Waugh acd16e
--- grep-2.5.1/src/search.c	2004-11-07 20:11:07.437866925 +0000
Tim Waugh acd16e
+++ grep-2.5.1/src/search.c	2004-11-10 09:40:44.994750111 +0000
Tim Waugh 553606
@@ -305,11 +305,33 @@
Tim Waugh d619d2
   int backref, start, len;
Tim Waugh d619d2
   struct kwsmatch kwsm;
Tim Waugh d619d2
   size_t i, ret_val;
Tim Waugh d619d2
+  static int use_dfa;
Tim Waugh d619d2
+  static int use_dfa_checked = 0;
Tim Waugh d619d2
 #ifdef MBS_SUPPORT
Tim Waugh d619d2
   mbstate_t mbs;
Tim Waugh d619d2
   memset (&mbs, '\0', sizeof (mbstate_t));
Tim Waugh d619d2
 #endif /* MBS_SUPPORT */
Tim Waugh d619d2
 
Tim Waugh d619d2
+  if (!use_dfa_checked)
Tim Waugh d619d2
+    {
Tim Waugh 553606
+      char *grep_use_dfa = getenv ("GREP_USE_DFA");
Tim Waugh 553606
+      if (!grep_use_dfa)
Tim Waugh 553606
+	{
Tim Waugh 553606
+#ifdef MBS_SUPPORT
Tim Waugh 553606
+	  /* Turn off DFA when processing multibyte input. */
Tim Waugh 553606
+	  use_dfa = (MB_CUR_MAX == 1);
Tim Waugh 553606
+#else
Tim Waugh 553606
+	  use_dfa = 1;
Tim Waugh 553606
+#endif /* MBS_SUPPORT */
Tim Waugh 553606
+	}
Tim Waugh 553606
+      else
Tim Waugh 553606
+	{
Tim Waugh 553606
+	  use_dfa = atoi (grep_use_dfa);
Tim Waugh 553606
+	}
Tim Waugh 553606
+
Tim Waugh d619d2
+      use_dfa_checked = 1;
Tim Waugh d619d2
+    }
Tim Waugh d619d2
+
Tim Waugh d619d2
   buflim = buf + size;
Tim Waugh d619d2
 
Tim Waugh d619d2
   for (beg = end = buf; end < buflim; beg = end)
Tim Waugh 553606
@@ -365,7 +387,8 @@
Tim Waugh d619d2
 		--beg;
Tim Waugh d619d2
 	      if (kwsm.index < kwset_exact_matches)
Tim Waugh d619d2
 		goto success_in_beg_and_end;
Tim Waugh d619d2
-	      if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
Tim Waugh d619d2
+	      if (use_dfa &&
Tim Waugh d619d2
+		  dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
Tim Waugh d619d2
 		continue;
Tim Waugh d619d2
 	    }
Tim Waugh d619d2
 	  else
Tim Waugh 553606
@@ -374,7 +397,9 @@
Tim Waugh d619d2
 #ifdef MBS_SUPPORT
Tim Waugh d619d2
 	      size_t bytes_left = 0;
Tim Waugh d619d2
 #endif /* MBS_SUPPORT */
Tim Waugh d619d2
-	      size_t offset = dfaexec (&dfa, beg, buflim - beg, &backref);
Tim Waugh d619d2
+	      size_t offset = 0;
Tim Waugh d619d2
+	      if (use_dfa)
Tim Waugh d619d2
+		offset = dfaexec (&dfa, beg, buflim - beg, &backref);
Tim Waugh d619d2
 	      if (offset == (size_t) -1)
Tim Waugh d619d2
 		break;
Tim Waugh d619d2
 	      /* Narrow down to the line we've found. */
Tim Waugh acd16e
@@ -416,7 +441,7 @@
Tim Waugh acd16e
 		--beg;
Tim Waugh acd16e
 	    }
Tim Waugh acd16e
 	  /* Successful, no backreferences encountered! */
Tim Waugh acd16e
-	  if (!backref)
Tim Waugh acd16e
+	  if (use_dfa && !backref)
Tim Waugh acd16e
 	    goto success_in_beg_and_end;
Tim Waugh acd16e
 	}
Tim Waugh acd16e
       else