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