Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
857ff0e53c64a6046cc3592136465b3d443bac2d
[simgrid.git] / examples / msg / mc / automatonparse_promela.c
1 #include "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, 2=état initial/final
14
15   if(strcmp(first_part,"accept")==0){
16      char* second_part = strtok(NULL,"_");
17      if(strcmp(second_part,"init")==0){
18         type = 2;
19      }else{
20         type = 1;
21      }
22      
23   }else{
24     char* second_part = strtok(NULL,"_");
25     if(strcmp(second_part,"init")==0){
26       type = -1;
27     }
28   }
29
30   xbt_state_t state = NULL;
31   state = xbt_automaton_state_exists(automaton, id_state);
32   if(state == NULL){
33     state = xbt_automaton_new_state(automaton, type, id_state);
34   }
35
36   if(type==-1 || type==2)
37     automaton->current_state = state;
38
39   if(src)
40     state_id_src = strdup(id_state);
41     
42 }
43
44 void new_transition(char* id, xbt_exp_label_t label){
45
46   char* id_state = strdup(id);
47   xbt_state_t state_dst = NULL;
48   new_state(id, 0);
49   state_dst = xbt_automaton_state_exists(automaton, id_state);
50   xbt_state_t state_src = xbt_automaton_state_exists(automaton, state_id_src); 
51   
52   xbt_transition_t trans = NULL;
53   trans = xbt_automaton_new_transition(automaton, state_src, state_dst, label);
54
55 }
56
57 xbt_exp_label_t new_label(int type, ...){
58   xbt_exp_label_t label = NULL;
59   va_list ap;
60   va_start(ap,type);
61   switch(type){
62   case 0 : {
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 1 : {
69     xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
70     xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
71     label = xbt_automaton_new_label(type, left, right);
72     break;
73   }
74   case 2 : {
75     xbt_exp_label_t exp_not = va_arg(ap, xbt_exp_label_t);
76     label = xbt_automaton_new_label(type, exp_not);
77     break;
78   }
79   case 3 : {
80     char* p = va_arg(ap, char*);
81     label = xbt_automaton_new_label(type, p);
82     break;
83   }
84   case 4 : {
85     label = xbt_automaton_new_label(type);
86     break;
87   }
88   }
89   va_end(ap);
90   return label;
91 }
92
93 xbt_automaton_t get_automaton(){
94   return automaton;
95 }
96
97 void display_automaton(){
98   xbt_automaton_display(automaton);
99 }
100
101