diff options
author | dgp <dgp@users.sourceforge.net> | 2013-03-06 17:30:14 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2013-03-06 17:30:14 (GMT) |
commit | 0ea582d8785e76223d06415791097fc3400c7bbf (patch) | |
tree | 4aa18b0dcf7b94804b0d953ff00717b62ad1d39c /generic/regc_nfa.c | |
parent | 596e86d26f839d7ffb40012c2c511e33b6de0b12 (diff) | |
download | tcl-0ea582d8785e76223d06415791097fc3400c7bbf.zip tcl-0ea582d8785e76223d06415791097fc3400c7bbf.tar.gz tcl-0ea582d8785e76223d06415791097fc3400c7bbf.tar.bz2 |
Use flag argument to combine copy(nonempty)* routines into copy* routines.
Diffstat (limited to 'generic/regc_nfa.c')
-rw-r--r-- | generic/regc_nfa.c | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c index f072985..5e2ad3a 100644 --- a/generic/regc_nfa.c +++ b/generic/regc_nfa.c @@ -611,41 +611,25 @@ moveins( } /* - - copyins - copy all in arcs of a state to another state - ^ static VOID copyins(struct nfa *, struct state *, struct state *); + - copyins - copy in arcs of a state to another state + * Either all arcs, or only non-empty ones as determined by all value. + ^ static VOID copyins(struct nfa *, struct state *, struct state *, int); */ static void copyins( struct nfa *nfa, struct state *oldState, - struct state *newState) + struct state *newState, + int all) { struct arc *a; assert(oldState != newState); for (a=oldState->ins ; a!=NULL ; a=a->inchain) { - cparc(nfa, a, a->from, newState); - } -} - -/* - - copynonemptyins - as above, but ignore empty arcs - ^ static void copynonemptyins(struct nfa *, struct state *, struct state *); - */ -static void -copynonemptyins( - struct nfa *nfa, - struct state *oldState, - struct state *newState) -{ - struct arc *a; - - assert(oldState != newState); - - for (a=oldState->ins ; a!=NULL ; a=a->inchain) { - if (a->type != EMPTY) + if (all || a->type != EMPTY) { cparc(nfa, a, a->from, newState); + } } } @@ -670,41 +654,25 @@ moveouts( } /* - - copyouts - copy all out arcs of a state to another state - ^ static VOID copyouts(struct nfa *, struct state *, struct state *); + - copyouts - copy out arcs of a state to another state + * Either all arcs, or only non-empty ones as determined by all value. + ^ static VOID copyouts(struct nfa *, struct state *, struct state *, int); */ static void copyouts( struct nfa *nfa, struct state *oldState, - struct state *newState) + struct state *newState, + int all) { struct arc *a; assert(oldState != newState); for (a=oldState->outs ; a!=NULL ; a=a->outchain) { - cparc(nfa, a, newState, a->to); - } -} - -/* - - copynonemptyouts - as above, but ignore empty arcs - ^ static void copynonemptyouts(struct nfa *, struct state *, struct state *); - */ -static void -copynonemptyouts( - struct nfa *nfa, - struct state *oldState, - struct state *newState) -{ - struct arc *a; - - assert(oldState != newState); - - for (a=oldState->outs ; a!=NULL ; a=a->outchain) { - if (a->type != EMPTY) + if (all || a->type != EMPTY) { cparc(nfa, a, newState, a->to); + } } } @@ -1049,9 +1017,9 @@ pull( if (NISERR()) { return 0; } - assert(to != from); /* con is not an inarc */ - copyins(nfa, from, s); /* duplicate inarcs */ - cparc(nfa, con, s, to); /* move constraint arc */ + assert(to != from); /* con is not an inarc */ + copyins(nfa, from, s, 1); /* duplicate inarcs */ + cparc(nfa, con, s, to); /* move constraint arc */ freearc(nfa, con); from = s; con = from->outs; @@ -1209,7 +1177,7 @@ push( if (NISERR()) { return 0; } - copyouts(nfa, to, s); /* duplicate outarcs */ + copyouts(nfa, to, s, 1); /* duplicate outarcs */ cparc(nfa, con, from, s); /* move constraint */ freearc(nfa, con); to = s; @@ -1489,11 +1457,11 @@ replaceempty( toins = (fromouts == 0) ? 1 : nonemptyins(to); if (fromouts > toins) { - copynonemptyouts(nfa, to, from); + copyouts(nfa, to, from, 0); return; } if (fromouts < toins) { - copynonemptyins(nfa, from, to); + copyins(nfa, from, to, 0); return; } @@ -1505,10 +1473,10 @@ replaceempty( * resulting graph much. */ if (from->nins > to->nouts) { - copynonemptyouts(nfa, to, from); + copyouts(nfa, to, from, 0); return; } else { - copynonemptyins(nfa, from, to); + copyins(nfa, from, to, 0); return; } } |