aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-05-29 21:29:16 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-05-29 21:29:16 +0300
commit4392e20625836b88b47272c935c990fd72ca4f4c (patch)
treeb2f07aae6f1538eae491bf78b0674d378d56b48e
parenta7eae6112b56320655433e4e3c8a67f6f7321bdd (diff)
downloadegawk-4392e20625836b88b47272c935c990fd72ca4f4c.tar.gz
egawk-4392e20625836b88b47272c935c990fd72ca4f4c.tar.bz2
egawk-4392e20625836b88b47272c935c990fd72ca4f4c.zip
Sync dfa.c with grep.
-rw-r--r--ChangeLog4
-rw-r--r--dfa.c49
2 files changed, 26 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 51becff7..0b5df5e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-05-29 Arnold D. Robbins <arnold@skeeve.com>
+
+ * dfa.c: Sync with GNU grep.
+
2014-05-26 Arnold D. Robbins <arnold@skeeve.com>
* io.c (inetfile): Change return type to bool. Wrap code
diff --git a/dfa.c b/dfa.c
index 18f8faf1..d1046b31 100644
--- a/dfa.c
+++ b/dfa.c
@@ -1475,10 +1475,10 @@ lex (void)
{
if (syntax_bits & RE_INVALID_INTERVAL_ORD)
goto normal_char;
- dfaerror (_("Invalid content of \\{\\}"));
+ dfaerror (_("invalid content of \\{\\}"));
}
if (RE_DUP_MAX < maxrep)
- dfaerror (_("Regular expression too big"));
+ dfaerror (_("regular expression too big"));
lexptr = p;
lexleft = lim - p;
}
@@ -2932,16 +2932,17 @@ build_state (state_num s, struct dfa *d)
/* Set an upper limit on the number of transition tables that will ever
exist at once. 1024 is arbitrary. The idea is that the frequently
used transition tables will be quickly rebuilt, whereas the ones that
- were only needed once or twice will be cleared away. */
+ were only needed once or twice will be cleared away. However, do
+ not clear the initial state, as it's always used. */
if (d->trcount >= 1024)
{
- for (i = 0; i < d->tralloc; ++i)
+ for (i = 1; i < d->tralloc; ++i)
{
free (d->trans[i]);
free (d->fails[i]);
d->trans[i] = d->fails[i] = NULL;
}
- d->trcount = 0;
+ d->trcount = 1;
}
++d->trcount;
@@ -2978,22 +2979,6 @@ build_state (state_num s, struct dfa *d)
d->trans[s] = trans;
}
-static void
-build_state_zero (struct dfa *d)
-{
- /* Initial size of the transition tables; must be positive. */
- int initial_tab_size = 1;
-
- d->tralloc = 0;
- d->trcount = 0;
- d->trans = NULL;
- d->fails = NULL;
- d->success = NULL;
- d->newlines = NULL;
- realloc_trans_if_necessary (d, initial_tab_size);
- build_state (0, d);
-}
-
/* Multibyte character handling sub-routines for dfaexec. */
/* Return values of transit_state_singlebyte, and
@@ -3357,7 +3342,10 @@ dfaexec (struct dfa *d, char const *begin, char *end,
size_t nlcount = 0;
if (!d->tralloc)
- build_state_zero (d);
+ {
+ realloc_trans_if_necessary (d, 1);
+ build_state (0, d);
+ }
s = s1 = 0;
p = mbp = (unsigned char const *) begin;
@@ -3478,7 +3466,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
/* If the previous character was a newline, count it, and skip
checking of multibyte character boundary until here. */
- if (p[-1] == eol && (char *) p != begin)
+ if (p[-1] == eol)
{
nlcount++;
mbp = p;
@@ -4056,10 +4044,17 @@ dfamust (struct dfa *d)
size_t j, ln, rn, n;
/* Guaranteed to be. Unlikely, but ... */
- if (!STREQ (lmp->is, rmp->is))
- lmp->is[0] = '\0';
- lmp->begline &= rmp->begline;
- lmp->endline &= rmp->endline;
+ if (STREQ (lmp->is, rmp->is))
+ {
+ lmp->begline &= rmp->begline;
+ lmp->endline &= rmp->endline;
+ }
+ else
+ {
+ lmp->is[0] = '\0';
+ lmp->begline = false;
+ lmp->endline = false;
+ }
/* Left side--easy */
i = 0;
while (lmp->left[i] != '\0' && lmp->left[i] == rmp->left[i])