Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix compilation error on windows.
[simgrid.git] / src / xbt / automatonparse_promela.c
1 #include "xbt/automatonparse_promela.h"
2
3 xbt_automaton_t automaton;
4 char* state_id_src;
5
6 void init(){
7   automaton = xbt_automaton_new_automaton();
8 }
9
10 void new_state(char* id, int src){
11
12   char* id_state = strdup(id);
13   char* first_part = strtok(id,"_");
14   int type = 0 ; // -1=état initial, 0=état intermédiaire, 1=état final
15
16   if(strcmp(first_part,"accept")==0){
17     type = 1;
18   }else{
19     char* second_part = strtok(NULL,"_");
20     if(strcmp(second_part,"init")==0){
21       type = -1;
22     }
23   }
24
25   xbt_state_t state = NULL;
26   state = xbt_automaton_state_exists(automaton, id_state);
27   if(state == NULL){
28     state = xbt_automaton_new_state(automaton, type, id_state);
29   }
30
31   if(type==-1)
32     automaton->current_state = state;
33
34   if(src)
35     state_id_src = strdup(id_state);
36     
37 }
38
39 void new_transition(char* id, xbt_exp_label_t label){
40
41   char* id_state = strdup(id);
42   xbt_state_t state_dst = NULL;
43   new_state(id, 0);
44   state_dst = xbt_automaton_state_exists(automaton, id_state);
45   xbt_state_t state_src = xbt_automaton_state_exists(automaton, state_id_src); 
46   
47   //xbt_transition_t trans = NULL;
48   xbt_automaton_new_transition(automaton, state_src, state_dst, label);
49
50 }
51
52 xbt_exp_label_t new_label(int type, ...){
53   xbt_exp_label_t label = NULL;
54   va_list ap;
55   va_start(ap,type);
56   switch(type){
57   case 0 : {
58     xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
59     xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
60     label = xbt_automaton_new_label(type, left, right);
61     break;
62   }
63   case 1 : {
64     xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
65     xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
66     label = xbt_automaton_new_label(type, left, right);
67     break;
68   }
69   case 2 : {
70     xbt_exp_label_t exp_not = va_arg(ap, xbt_exp_label_t);
71     label = xbt_automaton_new_label(type, exp_not);
72     break;
73   }
74   case 3 : {
75     char* p = va_arg(ap, char*);
76     label = xbt_automaton_new_label(type, p);
77     break;
78   }
79   case 4 : {
80     label = xbt_automaton_new_label(type);
81     break;
82   }
83   }
84   va_end(ap);
85   return label;
86 }
87
88 xbt_automaton_t get_automaton(){
89   return automaton;
90 }
91
92
93