From 895852de89e5481021738e86806a353114e6cb0e Mon Sep 17 00:00:00 2001 From: ccremers Date: Fri, 10 Mar 2006 14:48:40 +0000 Subject: [PATCH] - Added iterators. - More space in encryption notation for better readability. --- src/binding.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/binding.h | 4 ++++ src/term.c | 4 ++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/binding.c b/src/binding.c index 8842773..fe80f3b 100644 --- a/src/binding.c +++ b/src/binding.c @@ -361,6 +361,55 @@ valid_binding (Binding b) return false; } +//! Iterate over valid bindings +/** + * Iterator should return true to proceed + */ +int +iterate_bindings (int (*func) (Binding b)) +{ + List bl; + + for (bl = sys->bindings; bl != NULL; bl = bl->next) + { + Binding b; + + b = (Binding) bl->data; + if (valid_binding (b)) + { + if (!func (b)) + { + return false; + } + } + + } + return true; +} + + + +//! Iterate over preceding bindings (this does not include stuff bound to the same destination) +/** + * Iterator should return true to proceed + */ +int +iterate_preceding_bindings (const int run, const int ev, + int (*func) (Binding b)) +{ + int precs (Binding b) + { + if (isDependEvent (b->run_to, b->ev_to, run, ev)) + { + return func (b); + } + return true; + } + + return iterate_bindings (precs); +} + + //! Check for unique origination /* * Contrary to a previous version, we simply check for unique origination. @@ -435,6 +484,7 @@ unique_origination () return true; } + //! Prune invalid state w.r.t. <=C minimal requirement /** * Intuition says this can be done a lot more efficient. Luckily this is the prototype. diff --git a/src/binding.h b/src/binding.h index bff1da3..0ff5d51 100644 --- a/src/binding.h +++ b/src/binding.h @@ -43,6 +43,10 @@ int binding_block (Binding b); int binding_unblock (Binding b); int labels_ordered (Termmap runs, Termlist labels); +int iterate_bindings (int (*func) (Binding b)); +int iterate_preceding_bindings (const int run, const int ev, + int (*func) (Binding b)); + int bindings_c_minimal (); #endif diff --git a/src/term.c b/src/term.c index c900489..3e97aad 100644 --- a/src/term.c +++ b/src/term.c @@ -364,9 +364,9 @@ termPrint (Term term) else { /* normal encryption */ - eprintf ("{"); + eprintf ("{ "); termTuplePrint (TermOp (term)); - eprintf ("}"); + eprintf (" }"); termPrint (TermKey (term)); } }