[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: |
Tue, 09 Oct 2007 20:10:46 +0000 |
CVSROOT: /sources/m4
Module name: m4
Changes by: Eric Blake <ericb> 07/10/09 20:10:46
Index: modules/gnu.c
===================================================================
RCS file: /sources/m4/m4/modules/gnu.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -b -r1.77 -r1.78
--- modules/gnu.c 9 Oct 2007 20:06:52 -0000 1.77
+++ modules/gnu.c 9 Oct 2007 20:10:46 -0000 1.78
@@ -223,11 +223,13 @@
}
-/* Function to perform substitution by regular expressions. Used by the
- builtins regexp, patsubst and renamesyms. The changed text is placed on
- the obstack. The substitution is REPL, with \& substituted by this part
- of VICTIM matched by the last whole regular expression, and \N
- substituted by the text matched by the Nth parenthesized sub-expression. */
+/* Function to perform substitution by regular expressions. Used by
+ the builtins regexp, patsubst and renamesyms. The changed text is
+ placed on the obstack OBS. The substitution is REPL, with \&
+ substituted by this part of VICTIM matched by the last whole
+ regular expression, and \N substituted by the text matched by the
+ Nth parenthesized sub-expression in BUF. Any warnings are issued
+ on behalf of CALLER. BUF may be NULL for the empty regex. */
static void
substitute (m4 *context, m4_obstack *obs, const char *caller,
@@ -247,6 +249,7 @@
switch ((ch = *repl++))
{
case '&':
+ if (buf)
obstack_grow (obs, victim + buf->regs.start[0],
buf->regs.end[0] - buf->regs.start[0]);
break;
@@ -254,7 +257,7 @@
case '1': case '2': case '3': case '4': case '5': case '6':
case '7': case '8': case '9':
ch -= '0';
- if (buf->pat->re_nsub < ch)
+ if (!buf || buf->pat->re_nsub < ch)
m4_warn (context, 0, _("%s: sub-expression %d not present"),
caller, ch);
else if (buf->regs.end[ch] > 0)
@@ -704,10 +707,12 @@
}
-/* Substitute all matches of a regexp occuring in a string. Each match of
- the second argument (a regexp) in the first argument is changed to the
- third argument, with \& substituted by the matched text, and \N
- substituted by the text matched by the Nth parenthesized sub-expression. */
+/* Substitute all matches of a regexp occurring in a string. Each
+ match of the second argument (a regexp) in the first argument is
+ changed to the optional third argument, with \& substituted by the
+ matched text, and \N substituted by the text matched by the Nth
+ parenthesized sub-expression. The optional fourth argument changes
+ the regex flavor. */
/**
* patsubst(VICTIM, REGEXP, [REPLACEMENT], [RESYNTAX])
@@ -750,10 +755,11 @@
}
-/* Regular expression version of index. Given two arguments, expand to the
- index of the first match of the second argument (a regexp) in the first.
- Expand to -1 if here is no match. Given a third argument, it changes
- the expansion to this argument. */
+/* Regular expression version of index. Given two arguments, expand
+ to the index of the first match of the second argument (a regexp)
+ in the first. Expand to -1 if there is no match. Given a third
+ argument, a match is substituted according to this argument. The
+ optional fourth argument changes the regex flavor. */
/**
* regexp(VICTIM, REGEXP, RESYNTAX)
@@ -804,7 +810,7 @@
{
/* The empty regex matches everything. */
if (replace)
- obstack_grow (obs, replace, strlen (replace));
+ substitute (context, obs, me, M4ARG (1), replace, NULL);
else
m4_shipout_int (obs, 0);
return;