summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-03-06 17:30:14 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-03-06 17:30:14 (GMT)
commit0ea582d8785e76223d06415791097fc3400c7bbf (patch)
tree4aa18b0dcf7b94804b0d953ff00717b62ad1d39c
parent596e86d26f839d7ffb40012c2c511e33b6de0b12 (diff)
downloadtcl-0ea582d8785e76223d06415791097fc3400c7bbf.zip
tcl-0ea582d8785e76223d06415791097fc3400c7bbf.tar.gz
tcl-0ea582d8785e76223d06415791097fc3400c7bbf.tar.bz2
Use flag argument to combine copy(nonempty)* routines into copy* routines.
-rw-r--r--generic/regc_nfa.c76
-rw-r--r--generic/regcomp.c8
2 files changed, 25 insertions, 59 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;
}
}
diff --git a/generic/regcomp.c b/generic/regcomp.c
index 68bfb30..8880318 100644
--- a/generic/regcomp.c
+++ b/generic/regcomp.c
@@ -127,11 +127,9 @@ static int nonemptyins(struct state *);
static struct arc *findarc(struct state *, int, pcolor);
static void cparc(struct nfa *, struct arc *, struct state *, struct state *);
static void moveins(struct nfa *, struct state *, struct state *);
-static void copyins(struct nfa *, struct state *, struct state *);
-static void copynonemptyins(struct nfa *, struct state *, struct state *);
+static void copyins(struct nfa *, struct state *, struct state *, int);
static void moveouts(struct nfa *, struct state *, struct state *);
-static void copyouts(struct nfa *, struct state *, struct state *);
-static void copynonemptyouts(struct nfa *, struct state *, struct state *);
+static void copyouts(struct nfa *, struct state *, struct state *, int);
static void cloneouts(struct nfa *, struct state *, struct state *, struct state *, int);
static void delsub(struct nfa *, struct state *, struct state *);
static void deltraverse(struct nfa *, struct state *, struct state *);
@@ -613,7 +611,7 @@ makesearch(
for (s=slist ; s!=NULL ; s=s2) {
s2 = newstate(nfa);
- copyouts(nfa, s, s2);
+ copyouts(nfa, s, s2, 1);
for (a=s->ins ; a!=NULL ; a=b) {
b = a->inchain;