m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changes to m4/src/input.c [branch-1_4]


From: Gary V . Vaughan
Subject: Changes to m4/src/input.c [branch-1_4]
Date: Fri, 04 Feb 2005 08:03:15 -0500

Index: m4/src/input.c
diff -u m4/src/input.c:1.1.1.1.2.1 m4/src/input.c:1.1.1.1.2.2
--- m4/src/input.c:1.1.1.1.2.1  Thu Sep  9 20:20:17 2004
+++ m4/src/input.c      Fri Feb  4 13:03:11 2005
@@ -1,5 +1,5 @@
 /* GNU m4 -- A simple macro processor
-   Copyright (C) 1989, 90, 91, 92, 93, 94, 04 Free Software Foundation, Inc.
+   Copyright (C) 1989, 90, 91, 92, 93, 94, 04, 05 Free Software Foundation, 
Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -622,11 +622,21 @@
 #ifdef ENABLE_CHANGEWORD
 
 void
+init_pattern_buffer (struct re_pattern_buffer *buf)
+{
+  buf->translate = 0;
+  buf->fastmap = 0;
+  buf->buffer = 0;
+  buf->allocated = 0;
+}
+
+void
 set_word_regexp (const char *regexp)
 {
   int i;
   char test[2];
   const char *msg;
+  struct re_pattern_buffer new_word_regexp;
 
   if (!strcmp (regexp, DEFAULT_WORD_REGEXP))
     {
@@ -634,9 +644,10 @@
       return;
     }
 
-  default_word_regexp = FALSE;
-
-  msg = re_compile_pattern (regexp, strlen (regexp), &word_regexp);
+  /* Dry run to see whether the new expression is compilable.  */
+  init_pattern_buffer (&new_word_regexp);
+  msg = re_compile_pattern (regexp, strlen (regexp), &new_word_regexp);
+  regfree (&new_word_regexp);
 
   if (msg != NULL)
     {
@@ -645,6 +656,19 @@
       return;
     }
 
+  /* If compilation worked, retry using the word_regexp struct.
+     Can't rely on struct assigns working, so redo the compilation.  */
+  msg = re_compile_pattern (regexp, strlen (regexp), &word_regexp);
+
+  if (msg != NULL)
+    {
+      M4ERROR ((EXIT_FAILURE, 0,
+               "Internal error: Expression recompilation `%s': %s",
+               regexp, msg));
+    }
+
+  default_word_regexp = FALSE;
+
   if (word_start == NULL)
     word_start = xmalloc (256);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]