Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use warnings; |
| 4 | use strict; |
| 5 | |
| 6 | use utf8; |
| 7 | use open qw(:std utf8); |
| 8 | |
| 9 | @ARGV = <include/mbedtls/*.h>; |
| 10 | |
| 11 | my @consts; |
| 12 | my $state = 'out'; |
| 13 | while (<>) |
| 14 | { |
| 15 | if( $state eq 'out' and /^(typedef )?enum {/ ) { |
| 16 | $state = 'in'; |
| 17 | } elsif( $state eq 'out' and /^(typedef )?enum/ ) { |
| 18 | $state = 'start'; |
| 19 | } elsif( $state eq 'start' and /{/ ) { |
| 20 | $state = 'in'; |
| 21 | } elsif( $state eq 'in' and /}/ ) { |
| 22 | $state = 'out'; |
| 23 | } elsif( $state eq 'in' ) { |
| 24 | s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp; |
| 25 | push @consts, $_ if $_; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | open my $fh, '>', 'enum-consts' or die; |
| 30 | print $fh "$_\n" for sort @consts; |
| 31 | close $fh or die; |
| 32 | |
| 33 | printf "%8d enum-consts\n", scalar @consts; |