list-enum-consts.pl 797 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use utf8;
  5. use open qw(:std utf8);
  6. -d 'include/mbedtls' or die "$0: must be run from root\n";
  7. @ARGV = grep { ! /compat-1\.3\.h/ } <include/mbedtls/*.h>;
  8. my @consts;
  9. my $state = 'out';
  10. while (<>)
  11. {
  12. if( $state eq 'out' and /^(typedef )?enum \{/ ) {
  13. $state = 'in';
  14. } elsif( $state eq 'out' and /^(typedef )?enum/ ) {
  15. $state = 'start';
  16. } elsif( $state eq 'start' and /{/ ) {
  17. $state = 'in';
  18. } elsif( $state eq 'in' and /}/ ) {
  19. $state = 'out';
  20. } elsif( $state eq 'in' ) {
  21. s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp;
  22. push @consts, $_ if $_;
  23. }
  24. }
  25. open my $fh, '>', 'enum-consts' or die;
  26. print $fh "$_\n" for sort @consts;
  27. close $fh or die;
  28. printf "%8d enum-consts\n", scalar @consts;