[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/modules/gnu.c,v
From: |
Eric Blake |
Subject: |
Changes to m4/modules/gnu.c,v |
Date: |
Sun, 30 Sep 2007 01:31:38 +0000 |
CVSROOT: /sources/m4
Module name: m4
Changes by: Eric Blake <ericb> 07/09/30 01:31:38
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -b -r1.75 -r1.76
--- modules/gnu.c 7 Aug 2007 03:15:28 -0000 1.75
+++ modules/gnu.c 30 Sep 2007 01:31:38 -0000 1.76
@@ -646,10 +646,14 @@
M4BUILTIN_HANDLER (patsubst)
{
const char *me; /* name of this macro */
+ const char *pattern; /* regular expression */
+ const char *replace; /* replacement */
m4_pattern_buffer *buf; /* compiled regular expression */
int resyntax;
me = M4ARG (0);
+ pattern = M4ARG (2);
+ replace = M4ARG (3);
resyntax = m4_get_regexp_syntax_opt (context);
if (argc >= 5) /* additional args ignored */
@@ -659,12 +663,21 @@
return;
}
- buf = m4_regexp_compile (context, me, M4ARG (2), resyntax, false);
+ /* The empty regex matches everywhere, but if there is no
+ replacement, we need not waste time with it. */
+ if (!*pattern && !*replace)
+ {
+ const char *str = M4ARG (1);
+ obstack_grow (obs, str, strlen (str));
+ return;
+ }
+
+ buf = m4_regexp_compile (context, me, pattern, resyntax, false);
if (!buf)
return;
- m4_regexp_substitute (context, obs, me, M4ARG (1), M4ARG (2), buf,
- M4ARG (3), false);
+ m4_regexp_substitute (context, obs, me, M4ARG (1), pattern, buf,
+ replace, false);
}
@@ -680,6 +693,7 @@
M4BUILTIN_HANDLER (regexp)
{
const char *me; /* name of this macro */
+ const char *pattern; /* regular expression */
const char *replace; /* optional replacement string */
m4_pattern_buffer *buf; /* compiled regular expression */
int startpos; /* start position of match */
@@ -687,6 +701,7 @@
int resyntax;
me = M4ARG (0);
+ pattern = M4ARG (2);
replace = M4ARG (3);
resyntax = m4_get_regexp_syntax_opt (context);
@@ -716,7 +731,17 @@
/* regexp(VICTIM, REGEXP) */
replace = NULL;
- buf = m4_regexp_compile (context, me, M4ARG (2), resyntax, replace == NULL);
+ if (!*pattern)
+ {
+ /* The empty regex matches everything. */
+ if (replace)
+ obstack_grow (obs, replace, strlen (replace));
+ else
+ m4_shipout_int (obs, 0);
+ return;
+ }
+
+ buf = m4_regexp_compile (context, me, pattern, resyntax, replace == NULL);
if (!buf)
return;
@@ -726,7 +751,7 @@
if (startpos == -2)
{
m4_error (context, 0, 0, _("%s: error matching regular expression `%s'"),
- me, M4ARG (2));
+ me, pattern);
return;
}
@@ -734,8 +759,6 @@
m4_shipout_int (obs, startpos);
else if (startpos >= 0)
substitute (context, obs, me, M4ARG (1), replace, buf);
-
- return;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Changes to m4/modules/gnu.c,v,
Eric Blake <=