diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-10-08 10:21:10 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-10-08 10:21:10 +0300 |
commit | 0e8a103b9aa1f2411fba665d1656f28fa297e874 (patch) | |
tree | 1edec69c50e8751945ac41a9927366c94920f4ad /dfa.c | |
parent | c86aa5e85c7ced14a81389c0bf96b6c75fe420c9 (diff) | |
download | egawk-0e8a103b9aa1f2411fba665d1656f28fa297e874.tar.gz egawk-0e8a103b9aa1f2411fba665d1656f28fa297e874.tar.bz2 egawk-0e8a103b9aa1f2411fba665d1656f28fa297e874.zip |
Sync dfa with GNU grep.
Diffstat (limited to 'dfa.c')
-rw-r--r-- | dfa.c | 45 |
1 files changed, 33 insertions, 12 deletions
@@ -3432,11 +3432,38 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, goto done; } - /* Can match with a multibyte character (and multi character - collating element). Transition table might be updated. */ - s = transit_state (d, s, &p, (unsigned char *) end); - mbp = p; - trans = d->trans; + /* The following code is used twice. + Use a macro to avoid the risk that they diverge. */ +#define State_transition() \ + do { \ + /* Can match with a multibyte character (and multi-character \ + collating element). Transition table might be updated. */ \ + s = transit_state (d, s, &p, (unsigned char *) end); \ + \ + /* If previous character is newline after a transition \ + for ANYCHAR or MBCSET in non-UTF8 multibyte locales, \ + check whether current position is beyond the end of \ + the input buffer. Also, transit to initial state if \ + !ALLOW_NL, even if RE_DOT_NEWLINE is set. */ \ + if (p[-1] == eol) \ + { \ + if ((char *) p > end) \ + { \ + p = NULL; \ + goto done; \ + } \ + \ + nlcount++; \ + \ + if (!allow_nl) \ + s = 0; \ + } \ + \ + mbp = p; \ + trans = d->trans; \ + } while (0) + + State_transition(); } } else @@ -3479,13 +3506,7 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, s1 = s; if (multibyte) - { - /* Can match with a multibyte character (and multicharacter - collating element). Transition table might be updated. */ - s = transit_state (d, s, &p, (unsigned char *) end); - mbp = p; - trans = d->trans; - } + State_transition(); else s = d->fails[s][*p++]; continue; |