summaryrefslogtreecommitdiffstats
path: root/tools/sed-callbacks
blob: f94309c08ffbb9e6c6c4f804e6e03928e4b7aeb8 (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
# eat all comments
/^\s*\/\*/ {
  :comment
  /\*\/\s*$/ { n; b nocomment }
  n; b comment
}
:nocomment
# drop if don't start with typedef
/^\s*typedef/ ! b
# one line typedef xxx (...); we are done
s/^\s*typedef\s+(.*)(\(\*?\w+\))?\s*(\(.*\));.*$/typedef \1 \2 \3;/
t finish
# if ends with ,
s/^\s*typedef\s+(.*)(\(\*?\w+\))?\s*(\(.*,)/typedef \1 \2 \3/
# drop if substitution fail, copy pattern to  hold space
T;h
:loop;n
# append each parameters
/,$/ { H; b loop }
# when ; reached, append a swap hold space to pattern space
/;.*$/ { H;x}
:finish
# drop \n
s/\n//g
# replace multi spaces with one
s/ {2,}/ /g
p