- Added bindings module.
This commit is contained in:
parent
0fee6b5797
commit
ef2586236c
125
src/binding.c
Normal file
125
src/binding.c
Normal file
@ -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;
|
||||
}
|
10
src/binding.h
Normal file
10
src/binding.h
Normal file
@ -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
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user