Tim Waugh 1b8d44
--- grep-2.5.1a/src/search.c.dfa-optional	2005-01-07 14:58:45.714869815 +0000
Tim Waugh 1b8d44
+++ grep-2.5.1a/src/search.c	2005-01-07 14:58:45.725867716 +0000
Tim Waugh 1b8d44
@@ -327,12 +327,34 @@
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 1b8d44
   int mb_cur_max = MB_CUR_MAX;
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 1b8d44
@@ -400,7 +422,8 @@
Tim Waugh 1b8d44
 #endif /* MBS_SUPPORT */
Tim Waugh 1b8d44
 		  (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 1b8d44
@@ -409,7 +432,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 1b8d44
@@ -451,7 +476,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