From ef2586236ce1ed3572cdd07a214978f239eacd0b Mon Sep 17 00:00:00 2001 From: ccremers Date: Sun, 15 Aug 2004 11:55:22 +0000 Subject: [PATCH] - Added bindings module. --- src/binding.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/binding.h | 10 ++++ src/main.c | 3 ++ src/system.h | 4 ++ 4 files changed, 142 insertions(+) create mode 100644 src/binding.c create mode 100644 src/binding.h diff --git a/src/binding.c b/src/binding.c new file mode 100644 index 0000000..46a465f --- /dev/null +++ b/src/binding.c @@ -0,0 +1,125 @@ +/** + * Handle bindings for Arache engine. + */ + +#include "list.h" +#include "system.h" +#include "binding.h" +#include "memory.h" + +struct binding +{ + int run_from; + int ev_from; + + int run_to; + int ev_to; + + int manual; +}; + +typedef struct binding *Binding; + +static System sys; + +/* + * + * Assist stuff + * + */ + +//! Create mem for binding +Binding +binding_create (int run_from, int ev_from, int run_to, int ev_to, int manual) +{ + Binding b; + + b = memAlloc (sizeof (struct binding)); + b->run_from = run_from; + b->ev_from = ev_from; + b->run_to = run_to; + b->ev_to = ev_to; + b->manual = manual; + return b; +} + +//! Remove mem for binding +void +binding_destroy (Binding b) +{ + memFree (b, sizeof (struct binding)); +} + +/* + * + * Main + * + */ + +//! Init module +void +bindingInit (const System mysys) +{ + sys = mysys; + sys->bindings = NULL; +} + +//! Close up +void +bindingDone () +{ + int delete (Binding b) + { + binding_destroy (b); + return 1; + } + list_iterate (sys->bindings, delete); + list_destroy (sys->bindings); +} + + +/** + * + * Externally available functions + * + */ + +//! Add a binding +/** + * Note that bindings are added to the head of the list. + *@returns True iff is a valid additional binding. False if not. If false, nothing needs to be destroyed. + */ +int +binding_add (int run_from, int ev_from, int run_to, int ev_to) +{ + Binding b; + + b = binding_create (run_from, ev_from, run_to, ev_to, 1); + sys->bindings = list_insert (sys->bindings, b); + return 1; +} + +//! Remove last additions, including last manual addition +/** + * Note that this concerns the head of the list. + */ +void +binding_remove_last () +{ + List list; + int manual; + + manual = 0; + list = sys->bindings; + + while (!manual && list != NULL); + { + Binding b; + + b = (Binding) list->data; + manual = b->manual; + binding_destroy (b); + list = list_delete (list); + } + sys->bindings = list; +} diff --git a/src/binding.h b/src/binding.h new file mode 100644 index 0000000..ece4204 --- /dev/null +++ b/src/binding.h @@ -0,0 +1,10 @@ +#ifndef BINDINGS +#define BINDINGS + +void bindingInit (const System mysys); +void bindingDone (); + +int binding_add (int run_from, int ev_from, int run_to, int ev_to); +void binding_remove_last (); + +#endif diff --git a/src/main.c b/src/main.c index 5f62a69..e6986b1 100644 --- a/src/main.c +++ b/src/main.c @@ -53,6 +53,7 @@ #include "compiler.h" #include "latex.h" #include "output.h" +#include "binding.h" #include "argtable2.h" @@ -339,6 +340,7 @@ main (int argc, char **argv) if (switch_arachne->count > 0) { sys->engine = ARACHNE_ENGINE; + bindingInit (sys); } /* init compiler for this system */ compilerInit (sys); @@ -628,6 +630,7 @@ main (int argc, char **argv) if (sys->engine == ARACHNE_ENGINE) { arachneDone (); + bindingDone (); } knowledgeDestroy (sys->know); systemDone (sys); diff --git a/src/system.h b/src/system.h index 4490eef..cf4b3fc 100644 --- a/src/system.h +++ b/src/system.h @@ -8,6 +8,7 @@ #include "constraint.h" #include "states.h" #include "role.h" +#include "list.h" #define runPointerGet(sys,run) sys->runs[run].index #define runPointerSet(sys,run,newp) sys->runs[run].index = newp @@ -186,6 +187,9 @@ struct system int knowPhase; //!< Which knowPhase have we already explored? Constraintlist constraints; //!< Only needed for CLP match + /* Arachne assistance */ + List bindings; //!< List of bindings + //! Shortest attack storage. struct tracebuf *attack;