forked from openthread/openthread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_enums.sh
More file actions
executable file
·53 lines (48 loc) · 1.03 KB
/
convert_enums.sh
File metadata and controls
executable file
·53 lines (48 loc) · 1.03 KB
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
#!/bin/bash
#for file in $(grep -rnl $1 -e 'enum')
#do
#done
cname="[a-zA-Z0-9_-]"
# for comparsion
sed -n "/enum/,/}/p" test.hpp
# scope the enum again
sed -nr "/enum/,/\}/ {
# scope the brackets
/\{/,/\}/ {
# search for enums with a defined value
s/($cname$cname*) *= *(.*),/#define \1 \2/p
T count
b exit
# search for enums with an implicit counter
:count
/$cname$cname*/ {
x
:b
s/9(_*)$/_\1/
t b
s/^(_*)$/0\1/
s/$/:0123456789/
s/([^_])(_*):.*\1(.).*/\3\2/
s/_/0/g
x
G
s/($cname$cname*).*\n(.*)/#define \1 \2/p
}
:exit
}
}" test.hpp
sed -nr ':a
/A/ {
x
:b
s/9(_*)$/_\1/
tb
s/^(_*)$/0\1/
s/$/:0123456789/
s/([^_])(_*):.*\1(.).*/\3\2/
s/_/0/g
x
G
s/A(.*)\n(.*)/\2\1/
ta
}' a.txt