2004-08-27 12:52:43 +01:00
|
|
|
/**
|
|
|
|
* Label info
|
|
|
|
*/
|
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
#include <stdlib.h>
|
2004-08-27 12:52:43 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "label.h"
|
2004-08-27 13:36:23 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include "system.h"
|
2004-08-27 12:52:43 +01:00
|
|
|
|
2006-04-25 14:58:14 +01:00
|
|
|
//! Retrieve rightmost thing of label
|
|
|
|
Term
|
|
|
|
rightMostTerm (Term t)
|
|
|
|
{
|
|
|
|
if (t != NULL)
|
|
|
|
{
|
|
|
|
t = deVar (t);
|
|
|
|
if (realTermTuple (t))
|
|
|
|
{
|
|
|
|
return rightMostTerm (TermOp2 (t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Create a new labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_create (const Term label, const Protocol protocol)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
|
|
|
Labelinfo li;
|
2006-04-25 14:58:14 +01:00
|
|
|
Term tl;
|
2004-08-27 12:52:43 +01:00
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
li = (Labelinfo) malloc (sizeof (struct labelinfo));
|
2004-08-27 12:52:43 +01:00
|
|
|
li->label = label;
|
|
|
|
li->protocol = protocol;
|
|
|
|
li->sendrole = NULL;
|
|
|
|
li->readrole = NULL;
|
2006-04-25 14:58:14 +01:00
|
|
|
// Should we ignore it?
|
|
|
|
li->ignore = false;
|
|
|
|
tl = rightMostTerm (label);
|
|
|
|
if (tl != NULL)
|
|
|
|
{
|
|
|
|
if (TermSymb (tl)->text[0] == '!')
|
|
|
|
{
|
|
|
|
li->ignore = true;
|
|
|
|
}
|
|
|
|
}
|
2004-08-27 12:52:43 +01:00
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Destroy a labelinfo node
|
2004-11-16 12:07:55 +00:00
|
|
|
void
|
|
|
|
label_destroy (Labelinfo linfo)
|
2004-08-27 12:52:43 +01:00
|
|
|
{
|
2006-03-08 13:58:46 +00:00
|
|
|
free (linfo);
|
2004-08-27 12:52:43 +01:00
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Given a list of label infos, yield the correct one or NULL
|
2004-11-16 12:07:55 +00:00
|
|
|
Labelinfo
|
|
|
|
label_find (List labellist, const Term label)
|
2004-08-27 13:36:23 +01:00
|
|
|
{
|
|
|
|
Labelinfo linfo;
|
|
|
|
|
2004-08-30 21:08:11 +01:00
|
|
|
int label_find_scan (void *data)
|
2004-11-16 12:07:55 +00:00
|
|
|
{
|
|
|
|
Labelinfo linfo_scan;
|
|
|
|
|
|
|
|
linfo_scan = (Labelinfo) data;
|
|
|
|
if (isTermEqual (label, linfo_scan->label))
|
|
|
|
{
|
|
|
|
linfo = linfo_scan;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
|
|
|
|
linfo = NULL;
|
2004-08-30 21:08:11 +01:00
|
|
|
if (label != NULL)
|
|
|
|
{
|
|
|
|
list_iterate (labellist, label_find_scan);
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
return linfo;
|
|
|
|
}
|