Logo AND Algorithmique Numérique Distribuée

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