m4-commit
[Top][All Lists]
Advanced

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

Changes to m4/src/Attic/builtin.c,v [branch-1_4]


From: Eric Blake
Subject: Changes to m4/src/Attic/builtin.c,v [branch-1_4]
Date: Sun, 30 Sep 2007 00:35:36 +0000

CVSROOT:        /sources/m4
Module name:    m4
Branch:         branch-1_4
Changes by:     Eric Blake <ericb>      07/09/30 00:35:36

Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.62
retrieving revision 1.1.1.1.2.63
diff -u -b -r1.1.1.1.2.62 -r1.1.1.1.2.63
--- src/builtin.c       9 Aug 2007 13:39:10 -0000       1.1.1.1.2.62
+++ src/builtin.c       30 Sep 2007 00:35:35 -0000      1.1.1.1.2.63
@@ -1968,8 +1968,19 @@
       return;
     }
 
-  victim = TOKEN_DATA_TEXT (argv[1]);
-  regexp = TOKEN_DATA_TEXT (argv[2]);
+  victim = ARG (1);
+  regexp = ARG (2);
+  repl = ARG (3);
+
+  if (!*regexp)
+    {
+      /* The empty regex matches everything!  */
+      if (argc == 3)
+       shipout_int (obs, 0);
+      else
+       obstack_grow (obs, repl, strlen (repl));
+      return;
+    }
 
   init_pattern_buffer (&buf, &regs);
   msg = re_compile_pattern (regexp, strlen (regexp), &buf);
@@ -1993,10 +2004,7 @@
   else if (argc == 3)
     shipout_int (obs, startpos);
   else if (startpos >= 0)
-    {
-      repl = TOKEN_DATA_TEXT (argv[3]);
       substitute (obs, victim, repl, &regs);
-    }
 
   free_pattern_buffer (&buf, &regs);
 }
@@ -2013,6 +2021,7 @@
 {
   const char *victim;          /* first argument */
   const char *regexp;          /* regular expression */
+  const char *repl;
 
   struct re_pattern_buffer buf;        /* compiled regular expression */
   struct re_registers regs;    /* for subexpression matches */
@@ -2029,7 +2038,17 @@
       return;
     }
 
-  regexp = TOKEN_DATA_TEXT (argv[2]);
+  victim = ARG (1);
+  regexp = ARG (2);
+  repl = ARG (3);
+
+  /* The empty regex matches everywhere, but if there is no
+     replacement, we need not waste time with it.  */
+  if (!*regexp && !*repl)
+    {
+      obstack_grow (obs, victim, strlen (victim));
+      return;
+    }
 
   init_pattern_buffer (&buf, &regs);
   msg = re_compile_pattern (regexp, strlen (regexp), &buf);
@@ -2042,7 +2061,6 @@
       return;
     }
 
-  victim = TOKEN_DATA_TEXT (argv[1]);
   length = strlen (victim);
 
   offset = 0;
@@ -2073,7 +2091,7 @@
 
       /* Handle the part of the string that was covered by the match.  */
 
-      substitute (obs, victim, ARG (3), &regs);
+      substitute (obs, victim, repl, &regs);
 
       /* Update the offset to the end of the match.  If the regexp
         matched a null string, advance offset one more, to avoid




reply via email to

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