1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | my %const_iv; |
3 | my %const_iv; |
4 | |
4 | |
5 | while (<>) { |
5 | sub gl() { |
|
|
6 | $_ = <>; |
|
|
7 | |
|
|
8 | defined $_ or last file; |
|
|
9 | |
6 | 1 while s/\/\*.*?\*\///; |
10 | 1 while s/\/\*.*?\*\///; |
|
|
11 | s/\/\*.*$//; # we don't handle multiline-/* comments, so hack around |
7 | s/\/\/.*$//; |
12 | s/\/\/.*$//; |
|
|
13 | s/^\s+//; |
8 | s/\s+$//; |
14 | s/\s+$//; |
9 | |
15 | |
|
|
16 | $_ |
|
|
17 | } |
|
|
18 | |
|
|
19 | file: |
|
|
20 | while () { |
|
|
21 | gl; |
10 | if (/^#define\s+([A-Z_0-9]+)\s+(0x[0-9a-fA-F]+|[0-9]+)$/) { |
22 | if (/^#define\s+([A-Z_0-9]+)\s+(0x[0-9a-fA-F]+|[0-9\.]+)$/) { |
11 | undef $const_iv{$1}; |
23 | undef $const_iv{$1}; |
|
|
24 | } elsif (/^enum\b/) { |
|
|
25 | while () { |
|
|
26 | gl; |
|
|
27 | if (/^([a-zA-Z_0-9]+)\s*(?:,|=|$)/) { |
|
|
28 | undef $const_iv{$1}; |
|
|
29 | } elsif (/^\}/) { |
|
|
30 | last; |
|
|
31 | } |
|
|
32 | } |
12 | } |
33 | } |
13 | } |
34 | } |
14 | |
35 | |
15 | open my $fh, ">", "const_iv.h~" |
|
|
16 | or die "const_iv.h~: $!"; |
|
|
17 | for (sort keys %const_iv) { |
36 | for (sort keys %const_iv) { |
18 | print $fh "const_iv($_)\n"; |
37 | print "const_iv($_)\n"; |
19 | } |
38 | } |
20 | close $fh; |
|
|
21 | rename "const_iv.h~", "const_iv.h"; |
|
|