summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-07-21 21:37:35 +0300
committerArnold D. Robbins <arnold@skeeve.com>2015-07-21 21:37:35 +0300
commit0222717b832975115a091d74f9f78bb816760bc6 (patch)
tree73e3fe1929b80ae1cf28b5b59f5dd75ad4ae5bf6
parent6a2e78bc4eb499cf156094f16d3fae246a3982ca (diff)
parentaee0b2e5e1ac7c88de11f65c55a8b35a5b38f3ec (diff)
downloadgawk-0222717b832975115a091d74f9f78bb816760bc6.tar.gz
Merge branch 'gawk-4.1-stable' into feature/zOS
-rw-r--r--ChangeLog4
-rw-r--r--dfa.c86
2 files changed, 82 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 37ca3fb1..bbca613b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-07-21 Arnold D. Robbins <arnold@skeeve.com>
+
+ * dfa.c: Sync with GNU grep.
+
2015-07-18 Arnold D. Robbins <arnold@skeeve.com>
* dfa.c: Sync with GNU grep.
diff --git a/dfa.c b/dfa.c
index c3a5d882..782ef5cb 100644
--- a/dfa.c
+++ b/dfa.c
@@ -544,8 +544,8 @@ prtok (token t)
fprintf (stderr, "END");
else if (t < NOTCHAR)
{
- int ch = t;
- fprintf (stderr, "%c", ch);
+ unsigned int ch = t;
+ fprintf (stderr, "0x%02x", ch);
}
else
{
@@ -2178,6 +2178,28 @@ state_index (struct dfa *d, position_set const *s, int context)
return i;
}
+#ifdef DEBUG
+ fprintf (stderr, "new state %zd\n nextpos:", i);
+ for (j = 0; j < s->nelem; ++j)
+ {
+ fprintf (stderr, " %zu:", s->elems[j].index);
+ prtok (d->tokens[s->elems[j].index]);
+ }
+ fprintf (stderr, "\n context:");
+ if (context ^ CTX_ANY)
+ {
+ if (context & CTX_NONE)
+ fprintf (stderr, " CTX_NONE");
+ if (context & CTX_LETTER)
+ fprintf (stderr, " CTX_LETTER");
+ if (context & CTX_NEWLINE)
+ fprintf (stderr, " CTX_NEWLINE");
+ }
+ else
+ fprintf (stderr, " CTX_ANY");
+ fprintf (stderr, "\n");
+#endif
+
/* We'll have to create a new state. */
d->states = maybe_realloc (d->states, d->sindex, &d->salloc,
sizeof *d->states);
@@ -2408,7 +2430,7 @@ dfaanalyze (struct dfa *d, int searchflag)
fprintf (stderr, "dfaanalyze:\n");
for (i = 0; i < d->tindex; ++i)
{
- fprintf (stderr, " %zd:", i);
+ fprintf (stderr, " %zu:", i);
prtok (d->tokens[i]);
}
putc ('\n', stderr);
@@ -2522,7 +2544,7 @@ dfaanalyze (struct dfa *d, int searchflag)
}
#ifdef DEBUG
/* ... balance the above nonsyntactic #ifdef goo... */
- fprintf (stderr, "node %zd:", i);
+ fprintf (stderr, "node %zu:", i);
prtok (d->tokens[i]);
putc ('\n', stderr);
fprintf (stderr,
@@ -2530,13 +2552,13 @@ dfaanalyze (struct dfa *d, int searchflag)
fprintf (stderr, " firstpos:");
for (j = stk[-1].nfirstpos; j-- > 0;)
{
- fprintf (stderr, " %zd:", firstpos[j].index);
+ fprintf (stderr, " %zu:", firstpos[j].index);
prtok (d->tokens[firstpos[j].index]);
}
fprintf (stderr, "\n lastpos:");
for (j = stk[-1].nlastpos; j-- > 0;)
{
- fprintf (stderr, " %zd:", lastpos[j].index);
+ fprintf (stderr, " %zu:", lastpos[j].index);
prtok (d->tokens[lastpos[j].index]);
}
putc ('\n', stderr);
@@ -2551,12 +2573,12 @@ dfaanalyze (struct dfa *d, int searchflag)
|| d->tokens[i] >= CSET)
{
#ifdef DEBUG
- fprintf (stderr, "follows(%zd:", i);
+ fprintf (stderr, "follows(%zu:", i);
prtok (d->tokens[i]);
fprintf (stderr, "):");
for (j = d->follows[i].nelem; j-- > 0;)
{
- fprintf (stderr, " %zd:", d->follows[i].elems[j].index);
+ fprintf (stderr, " %zu:", d->follows[i].elems[j].index);
prtok (d->tokens[d->follows[i].elems[j].index]);
}
putc ('\n', stderr);
@@ -2646,6 +2668,10 @@ dfastate (state_num s, struct dfa *d, state_num trans[])
bool next_isnt_1st_byte = false; /* We can't add state0. */
size_t i, j, k;
+#ifdef DEBUG
+ fprintf (stderr, "build state %td\n", s);
+#endif
+
zeroset (matches);
for (i = 0; i < d->states[s].elems.nelem; ++i)
@@ -2697,6 +2723,16 @@ dfastate (state_num s, struct dfa *d, state_num trans[])
continue;
}
+#ifdef DEBUG
+ fprintf (stderr, " nextpos %zu:", pos.index);
+ prtok (d->tokens[pos.index]);
+ fprintf (stderr, " of");
+ for (j = 0; j < NOTCHAR; j++)
+ if (tstbit (j, matches))
+ fprintf (stderr, " 0x%02zx", j);
+ fprintf (stderr, "\n");
+#endif
+
for (j = 0; j < ngrps; ++j)
{
/* If matches contains a single character only, and the current
@@ -2857,6 +2893,29 @@ dfastate (state_num s, struct dfa *d, state_num trans[])
else
state_letter = state;
+#ifdef DEBUG
+ fprintf (stderr, "group %zu\n nextpos:", i);
+ for (j = 0; j < grps[i].nelem; ++j)
+ {
+ fprintf (stderr, " %zu:", grps[i].elems[j]);
+ prtok (d->tokens[grps[i].elems[j]]);
+ }
+ fprintf (stderr, "\n follows:");
+ for (j = 0; j < follows.nelem; ++j)
+ {
+ fprintf (stderr, " %zu:", follows.elems[j].index);
+ prtok (d->tokens[follows.elems[j].index]);
+ }
+ fprintf (stderr, "\n states:");
+ if (possible_contexts & CTX_NEWLINE)
+ fprintf (stderr, " CTX_NEWLINE:%td", state_newline);
+ if (possible_contexts & CTX_LETTER)
+ fprintf (stderr, " CTX_LETTER:%td", state_letter);
+ if (possible_contexts & CTX_NONE)
+ fprintf (stderr, " CTX_NONE:%td", state);
+ fprintf (stderr, "\n");
+#endif
+
/* Set the transitions for each character in the current label. */
for (j = 0; j < CHARCLASS_WORDS; ++j)
for (k = 0; k < CHARCLASS_WORD_BITS; ++k)
@@ -2873,6 +2932,17 @@ dfastate (state_num s, struct dfa *d, state_num trans[])
}
}
+#ifdef DEBUG
+ fprintf (stderr, "trans table %td", s);
+ for (i = 0; i < NOTCHAR; ++i)
+ {
+ if (!(i & 0xf))
+ fprintf (stderr, "\n");
+ fprintf (stderr, " %2td", trans[i]);
+ }
+ fprintf (stderr, "\n");
+#endif
+
for (i = 0; i < ngrps; ++i)
free (grps[i].elems);
free (follows.elems);