#include "xbt/automaton.h"
#include <stdio.h> /* printf */
-#include <xbt/log.h>
#include <xbt/sysdep.h>
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_automaton, xbt, "Automaton");
-
struct xbt_automaton_propositional_symbol{
char* pred;
/** Callback used to evaluate the value of the symbol */
return a->current_state;
}
-static int call_simple_function(void* function)
+static int call_simple_function(int function(void) )
{
- return ((int (*)(void)) function)();
+ return function();
}
xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new(xbt_automaton_t a, const char* id,
{
xbt_automaton_propositional_symbol_t prop_symb = xbt_new0(struct xbt_automaton_propositional_symbol, 1);
prop_symb->pred = xbt_strdup(id);
- prop_symb->callback = &call_simple_function;
- prop_symb->data = fct;
+ prop_symb->callback = ((int (*)(void *))&call_simple_function);
+ prop_symb->data = (void*)&fct;
prop_symb->free_function = NULL;
xbt_dynar_push(a->propositional_symbols, &prop_symb);
return prop_symb;
}
int xbt_automaton_state_compare(xbt_automaton_state_t s1, xbt_automaton_state_t s2){
-
/* single id for each state, id and type sufficient for comparison*/
-
- if(strcmp(s1->id, s2->id))
- return 1;
-
- if(s1->type != s2->type)
- return 1;
-
- return 0;
-
+ return (strcmp(s1->id, s2->id) != 0) || (s1->type != s2->type);
}
-int xbt_automaton_transition_compare(const void *t1, const void *t2){
-
- if(xbt_automaton_state_compare(((xbt_automaton_transition_t)t1)->src, ((xbt_automaton_transition_t)t2)->src))
- return 1;
-
- if(xbt_automaton_state_compare(((xbt_automaton_transition_t)t1)->dst, ((xbt_automaton_transition_t)t2)->dst))
- return 1;
-
- if(xbt_automaton_exp_label_compare(((xbt_automaton_transition_t)t1)->label,((xbt_automaton_transition_t)t2)->label))
- return 1;
-
- return 0;
-
+int xbt_automaton_transition_compare(xbt_automaton_transition_t t1, xbt_automaton_transition_t t2)
+{
+ return xbt_automaton_state_compare(t1->src, t2->src) || xbt_automaton_state_compare(t1->dst, t2->dst) ||
+ xbt_automaton_exp_label_compare(t1->label, t2->label);
}
int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_exp_label_t l2){
switch(l1->type){
case 0 : // OR
case 1 : // AND
- if(xbt_automaton_exp_label_compare(l1->u.or_and.left_exp, l2->u.or_and.left_exp))
- res = 1;
- else
- res = xbt_automaton_exp_label_compare(l1->u.or_and.right_exp, l2->u.or_and.right_exp);
+ res = xbt_automaton_exp_label_compare(l1->u.or_and.left_exp, l2->u.or_and.left_exp) ||
+ xbt_automaton_exp_label_compare(l1->u.or_and.right_exp, l2->u.or_and.right_exp);
break;
case 2 : // NOT
res = xbt_automaton_exp_label_compare(l1->u.exp_not, l2->u.exp_not);
break;
case 3 : // predicat
- res = strcmp(l1->u.predicat, l2->u.predicat);
+ res = strcmp(l1->u.predicat, l2->u.predicat) != 0;
break;
case 4 : // 1
res = 0;