fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 2 | |
| 3 | use warnings; |
| 4 | use strict; |
| 5 | |
| 6 | use utf8; |
| 7 | use open qw(:std utf8); |
| 8 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 9 | -d 'include/mbedtls' or die "$0: must be run from root\n"; |
| 10 | |
Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 11 | @ARGV = grep { ! /compat-1\.3\.h/ } <include/mbedtls/*.h>; |
Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame] | 12 | push @ARGV, "3rdparty/everest/include/everest/everest.h"; |
| 13 | push @ARGV, "3rdparty/everest/include/everest/x25519.h"; |
| 14 | |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 15 | |
| 16 | my @consts; |
| 17 | my $state = 'out'; |
| 18 | while (<>) |
| 19 | { |
Manuel Pégourié-Gonnard | ae738c2 | 2015-07-01 19:32:00 +0200 | [diff] [blame] | 20 | if( $state eq 'out' and /^(typedef )?enum \{/ ) { |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 21 | $state = 'in'; |
| 22 | } elsif( $state eq 'out' and /^(typedef )?enum/ ) { |
| 23 | $state = 'start'; |
| 24 | } elsif( $state eq 'start' and /{/ ) { |
| 25 | $state = 'in'; |
| 26 | } elsif( $state eq 'in' and /}/ ) { |
| 27 | $state = 'out'; |
Christoph M. Wintersteiger | 7cc4c68 | 2018-12-14 13:18:52 +0000 | [diff] [blame] | 28 | } elsif( $state eq 'in' and not /^#/) { |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 29 | s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp; |
| 30 | push @consts, $_ if $_; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | open my $fh, '>', 'enum-consts' or die; |
| 35 | print $fh "$_\n" for sort @consts; |
| 36 | close $fh or die; |
| 37 | |
| 38 | printf "%8d enum-consts\n", scalar @consts; |