summaryrefslogtreecommitdiffstats
path: root/generic/regc_nfa.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-03-06 16:57:41 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-03-06 16:57:41 (GMT)
commit37745421ae8d82481007aca3632c76c589a1ff63 (patch)
tree6790c9bb822cf17609af396684702ab8bd6df0a2 /generic/regc_nfa.c
parent92e5e02234ad7151efec211f580998994de8d392 (diff)
downloadtcl-37745421ae8d82481007aca3632c76c589a1ff63.zip
tcl-37745421ae8d82481007aca3632c76c589a1ff63.tar.gz
tcl-37745421ae8d82481007aca3632c76c589a1ff63.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.c74
1 files changed, 20 insertions, 54 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c
index 852a676..6e32cc9 100644
--- a/generic/regc_nfa.c
+++ b/generic/regc_nfa.c
@@ -572,44 +572,27 @@ struct state *new;
}
/*
- - 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(nfa, old, new)
+copyins(nfa, old, new, all)
struct nfa *nfa;
struct state *old;
struct state *new;
+int all;
{
struct arc *a;
assert(old != new);
for (a = old->ins; a != NULL; a = a->inchain)
- cparc(nfa, a, a->from, new);
+ if (all || a->type != EMPTY)
+ cparc(nfa, a, a->from, new);
}
/*
- - copynonemptyins - as above, but ignore empty arcs
- ^ static void copynonemptyins(struct nfa *, struct state *, struct state *);
- */
-static VOID
-copynonemptyins(nfa, oldState, newState)
-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)
- cparc(nfa, a, a->from, newState);
- }
-}
-
-/*
- moveouts - move all out arcs of a state to another state
^ static VOID moveouts(struct nfa *, struct state *, struct state *);
*/
@@ -630,41 +613,24 @@ struct state *new;
}
/*
- - 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(nfa, old, new)
+copyouts(nfa, old, new, all)
struct nfa *nfa;
struct state *old;
struct state *new;
+int all;
{
struct arc *a;
assert(old != new);
for (a = old->outs; a != NULL; a = a->outchain)
- cparc(nfa, a, new, a->to);
-}
-
-/*
- - copynonemptyouts - as above, but ignore empty arcs
- ^ static void copynonemptyouts(struct nfa *, struct state *, struct state *);
- */
-static VOID
-copynonemptyouts(nfa, oldState, newState)
-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)
- cparc(nfa, a, newState, a->to);
- }
+ if (all || a->type != EMPTY)
+ cparc(nfa, a, new, a->to);
}
/*
@@ -983,7 +949,7 @@ struct arc *con;
if (NISERR())
return 0;
assert(to != from); /* con is not an inarc */
- copyins(nfa, from, s); /* duplicate inarcs */
+ copyins(nfa, from, s, 1); /* duplicate inarcs */
cparc(nfa, con, s, to); /* move constraint arc */
freearc(nfa, con);
from = s;
@@ -1123,7 +1089,7 @@ struct arc *con;
s = newstate(nfa);
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;
@@ -1393,11 +1359,11 @@ struct state *to;
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;
}
@@ -1409,10 +1375,10 @@ struct state *to;
* 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;
}
}