[Top][All Lists]
[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: |
Fri, 18 Aug 2006 16:28:23 +0000 |
CVSROOT: /sources/m4
Module name: m4
Branch: branch-1_4
Changes by: Eric Blake <ericb> 06/08/18 16:28:22
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.34
retrieving revision 1.1.1.1.2.35
diff -u -b -r1.1.1.1.2.34 -r1.1.1.1.2.35
--- src/builtin.c 18 Aug 2006 03:39:11 -0000 1.1.1.1.2.34
+++ src/builtin.c 18 Aug 2006 16:28:22 -0000 1.1.1.1.2.35
@@ -483,7 +483,6 @@
"INTERNAL ERROR: bad token data type in define_macro ()"));
abort ();
}
- return;
}
static void
@@ -1703,6 +1702,33 @@
}
}
+/*------------------------------------------.
+| Initialize regular expression variables. |
+`------------------------------------------*/
+
+static void
+init_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
+{
+ buf->translate = NULL;
+ buf->fastmap = NULL;
+ buf->buffer = NULL;
+ buf->allocated = 0;
+ regs->start = NULL;
+ regs->end = NULL;
+}
+
+/*----------------------------------------.
+| Clean up regular expression variables. |
+`----------------------------------------*/
+
+static void
+free_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
+{
+ regfree (buf);
+ free (regs->start);
+ free (regs->end);
+}
+
/*--------------------------------------------------------------------------.
| 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. |
@@ -1729,31 +1755,26 @@
victim = TOKEN_DATA_TEXT (argv[1]);
regexp = TOKEN_DATA_TEXT (argv[2]);
- buf.buffer = NULL;
- buf.allocated = 0;
- buf.fastmap = NULL;
- buf.translate = NULL;
+ init_pattern_buffer (&buf, ®s);
msg = re_compile_pattern (regexp, strlen (regexp), &buf);
if (msg != NULL)
{
M4ERROR ((warning_status, 0,
"bad regular expression: `%s': %s", regexp, msg));
+ free_pattern_buffer (&buf, ®s);
return;
}
length = strlen (victim);
- startpos = re_search (&buf, victim, length, 0, length, ®s);
- free (buf.buffer);
+ /* Avoid overhead of allocating regs if we won't use it. */
+ startpos = re_search (&buf, victim, length, 0, length,
+ argc == 3 ? NULL : ®s);
if (startpos == -2)
- {
M4ERROR ((warning_status, 0,
"error matching regular expression \"%s\"", regexp));
- return;
- }
-
- if (argc == 3)
+ else if (argc == 3)
shipout_int (obs, startpos);
else if (startpos >= 0)
{
@@ -1761,7 +1782,7 @@
substitute (obs, victim, repl, ®s);
}
- return;
+ free_pattern_buffer (&buf, ®s);
}
/*--------------------------------------------------------------------------.
@@ -1789,10 +1810,7 @@
regexp = TOKEN_DATA_TEXT (argv[2]);
- buf.buffer = NULL;
- buf.allocated = 0;
- buf.fastmap = NULL;
- buf.translate = NULL;
+ init_pattern_buffer (&buf, ®s);
msg = re_compile_pattern (regexp, strlen (regexp), &buf);
if (msg != NULL)
@@ -1846,8 +1864,7 @@
}
obstack_1grow (obs, '\0');
- free (buf.buffer);
- return;
+ free_pattern_buffer (&buf, ®s);
}
/* Finally, a placeholder builtin. This builtin is not installed by
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/04
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/15
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/16
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/17
- Changes to m4/src/Attic/builtin.c,v [branch-1_4],
Eric Blake <=
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/18
- Changes to m4/src/Attic/builtin.c,v [branch-1_4], Eric Blake, 2006/08/24