diff options
Diffstat (limited to 'tools/sed-enums')
-rw-r--r-- | tools/sed-enums | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tools/sed-enums b/tools/sed-enums index ffc193b..14738ac 100644 --- a/tools/sed-enums +++ b/tools/sed-enums @@ -1,17 +1,32 @@ -s/^\s*(typedef)?\s+(enum(\s+\w+)?).*$/typedef \2 { / +# drop if don't start with (typedef)? enum +/^\s*(typedef\s)?\s*enum/ ! b +# +s/^\s*(typedef\s)?\s*(enum(\s+\w+)?).*$/typedef \2 { / +# drop if substitution fail, copy pattern to hold space T;h :attrs;n +# read again if { +/^\s*\{/ b attrs +# append each item s/^\s*([A-Z0-9_]+)(\s*=\s*-?[0-9]+)?.*$/\1\2, / +# goto next if subsitution fails, append pattern, loop T next;H;b attrs :next +# try again if } not found /^\s*\}/ ! b attrs +# read enumeration name s/^\s*}\s*(\w+).*$/ } \1;/ t finish :close +# read the enum typedef s/^\s*typedef\s+enum\s+\w+\s+(\w+)\s*;/ } \1/ +# leave if substitution works, or read next line and retry t finish;n;b close :finish +# append pattern, exchange hold space and pattern space H;x +# remove \n s/\n//g +# replace multi spaces with one s/ {2,}/ /g s/, }/ }/p |