From 8f441ac9131d860b85028f774955410b3bd94cd9 Mon Sep 17 00:00:00 2001 From: ccremers Date: Mon, 30 Aug 2004 20:08:11 +0000 Subject: [PATCH] - Fixed some minor issues. - Fixed type flaw in labellist type. --- src/label.c | 9 +++++--- src/label.h | 2 +- src/term.c | 66 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/label.c b/src/label.c index 9aa228b..3f262a9 100644 --- a/src/label.c +++ b/src/label.c @@ -28,11 +28,11 @@ void label_destroy (Labelinfo linfo) } //! Given a list of label infos, yield the correct one or NULL -Labelinfo label_find (List labellist, const Term label) +Labelinfo label_find (List labellist, Term label) { Labelinfo linfo; - int scan (void *data) + int label_find_scan (void *data) { Labelinfo linfo_scan; @@ -49,7 +49,10 @@ Labelinfo label_find (List labellist, const Term label) } linfo = NULL; - list_iterate (labellist, scan); + if (label != NULL) + { + list_iterate (labellist, label_find_scan); + } return linfo; } diff --git a/src/label.h b/src/label.h index 2f6b1fa..b74f70d 100644 --- a/src/label.h +++ b/src/label.h @@ -11,7 +11,7 @@ struct labelinfo { Term label; - Term protocol; + Protocol protocol; Term sendrole; Term readrole; }; diff --git a/src/term.c b/src/term.c index 6e1a7d0..00890e1 100644 --- a/src/term.c +++ b/src/term.c @@ -906,6 +906,7 @@ term_iterate (const Term term, int (*leaf) (), int (*nodel) (), if (nodel != NULL) flag = flag && nodel (term); + // Left part if (realTermTuple (term)) flag = flag && (term_iterate (term->left.op1, leaf, nodel, nodem, noder)); @@ -916,12 +917,13 @@ term_iterate (const Term term, int (*leaf) (), int (*nodel) (), if (nodem != NULL) flag = flag && nodem (term); + // Right part if (realTermTuple (term)) flag = flag - && (term_iterate (term->left.op1, leaf, nodel, nodem, noder)); + && (term_iterate (term->right.op2, leaf, nodel, nodem, noder)); else flag = flag - && (term_iterate (term->left.op, leaf, nodel, nodem, noder)); + && (term_iterate (term->right.key, leaf, nodel, nodem, noder)); if (noder != NULL) flag = flag && noder (term); @@ -947,6 +949,10 @@ term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (), { return leaf (term); } + else + { + return 1; + } } else { @@ -957,6 +963,7 @@ term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (), if (nodel != NULL) flag = flag && nodel (term); + // Left part if (realTermTuple (term)) flag = flag && @@ -970,15 +977,16 @@ term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (), if (nodem != NULL) flag = flag && nodem (term); + // right part if (realTermTuple (term)) flag = flag && (term_iterate_deVar - (term->left.op1, leaf, nodel, nodem, noder)); + (term->right.op2, leaf, nodel, nodem, noder)); else flag = flag && - (term_iterate_deVar (term->left.op, leaf, nodel, nodem, noder)); + (term_iterate_deVar (term->right.key, leaf, nodel, nodem, noder)); if (noder != NULL) flag = flag && noder (term); @@ -1047,31 +1055,35 @@ term_rolelocals_are_variables () int term_encryption_level (const Term term) { - int level, maxlevel, flag; + int iter_maxencrypt (Term term) + { + term = deVar (term); + if (realTermLeaf (term)) + { + return 0; + } + else + { + if (realTermTuple (term)) + { + int l,r; - int nodel (const Term term) - { - if (realTermEncrypt (term)) - { - level++; - if (level > maxlevel) - maxlevel = level; - } - return 1; - } - int noder (const Term term) - { - if (realTermEncrypt (term)) - { - level--; - } - return 1; - } + l = iter_maxencrypt (term->left.op1); + r = iter_maxencrypt (term->right.op2); + if (l>r) + return l; + else + return r; + } + else + { + // encrypt + return 1+iter_maxencrypt (term->left.op); + } + } + } - maxlevel = 0; - level = 0; - flag = term_iterate_deVar (term, NULL, nodel, NULL, noder); - return maxlevel; + return iter_maxencrypt (term); } //! Determine 'constrained factor' of a term