forked from imitator-model-checker/imitator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.sh
executable file
·115 lines (104 loc) · 2.65 KB
/
queries.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
####################################
# Script for querying a statespace #
# in the .states format #
# Author: Laure Petrucci #
# Version: 1.0 #
# Date: 08/03/2019 #
####################################
function usage {
if [ $1 -ne 1 ]
then echo -e "\033[1;31musage\033[0m: $0 filename"
echo "where the file contains a state space generated by imitator"
echo "INSERT a line of /***** before DESCRIPTION OF TRANSITIONS"
exit
fi
}
function read_state {
read -p "State number? " state_number
res=`grep -n "STATE $state_number:" $filename`
if [ "$res" = "" ]
then echo "State $state_number does not exist"
return
fi
}
function find_state_number {
read_state
sed -n -e "/STATE $state_number:/,/\/\*\*\*\*/p" $filename
}
function find_state_location {
read -p "Automaton? " automaton
read -p "Location? " location
sed -n -e "/STATE/N;/$automaton: $location/P" $filename
}
function find_state_variable {
read -p "Variable? " varName
read -p "Value? " varValue
sed -n -e "/STATE/N;/$varName = $varValue/P" $filename
}
function find_successors {
read_state
grep "s_$state_number ->" $filename
}
function find_predecessors {
read_state
grep -e " -> s_$state_number " $filename
grep -e " -> s_${state_number}$" $filename
}
function log_path {
read -p "Path file name (.dot)? " pathfile
tmpfile="temp.txt"
select GRAPHOPT in 'Find predecessors' \
'Find successors' \
'Display a state on screen' \
'End path generation';
do
case $REPLY in
1) find_predecessors
grep -e " -> s_$state_number " $filename | \
sed -e 's/ via /[label=/;s/\"/\"];/2' \
>> $tmpfile
grep -e " -> s_${state_number}$" $filename | \
sed -e "s/$/\;/" \
>> $tmpfile;;
2) find_successors
grep -e "s_$state_number ->" $filename | grep "via" | \
sed -e 's/ via /[label=/;s/\"/\"];/2' \
>> $tmpfile
grep -e "s_$state_number ->" $filename | grep -v "via" | \
sed -e "s/$/\;/" \
>> $tmpfile;;
3) find_state_number;;
4) echo 'digraph {' > $pathfile
sort $tmpfile | uniq >> $pathfile
echo '}' >> $pathfile
rm $tmpfile
return;;
esac
done
}
# main part of the script
usage $#
filename=$1
if [ ! -f $1 ]
then echo -e "\033[1;31mError\033[0m: $1 is a not a file"
exit
fi
select OPTION in 'Display state from number' \
'Successors of a state' \
'Predecessors of a state' \
'Log a path' \
'Display states from location' \
'Display states from variable value' \
'Quit';
do
case $REPLY in
1) find_state_number;;
2) find_successors;;
3) find_predecessors;;
4) log_path;;
5) find_state_location;;
6) find_state_variable;;
*) break;;
esac
done