blob: 3a07671f5d6258e5b1cf443cf40b477f9269a80a (
plain)
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
|
# eat all comments
/^\s*\/\*/ {
:comment
/\*\/\s*$/ { n; b nocomment }
n; b comment
}
:nocomment
# drop if don't start with (typedef)? enum
/^\s*(typedef\s)?\s*enum/ ! b
#
s/^\s*(typedef\s)?\s*(enum(\s+\w+)?).*$/\1\2 { /
# drop if substitution fail, copy pattern to hold space
T;h
:attrs;n
# read again if {
/^\s*\{/ b attrs
# append each item finished by , or \/
s/^\s*([A-Z0-9_]+)(\s*=\s*[^,\/]+)?\s*([,|\)])?[\/]?.*$/\1\2\3 /
# goto next if subsitution fails, append pattern, loop to attrs
T next;H;b attrs
:next
# try again if } not found
/^\s*\}/ ! b attrs
# read enumeration name if any
s/^\s*}\s*(\w+).*$/ } \1;/
t finish
:close
n
# eat all comments
/^\s*\/\*/ {
:comment2
/\*\/\s*$/ { n; b nocomment2 }
n; b comment2
}
:nocomment2
# eat empty lines
/^\s*$/ b close
# read the enum typedef
s/^\s*typedef\s+enum\s+\w+\s+(\w+)\s*;/ } \1/
# finish if substitution fail
T
:finish
# append pattern, exchange hold space and pattern space
H;x
# remove \n
s/\n//g
# replace multi spaces with one
s/\t/ /g
s/ {2,}/ /g
s/, }/ }/
p
|