| fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
| Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 2 | # | 
| Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 3 | # Copyright The Mbed TLS Contributors | 
| Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 | 
|  | 5 | # | 
|  | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 7 | # not use this file except in compliance with the License. | 
|  | 8 | # You may obtain a copy of the License at | 
|  | 9 | # | 
|  | 10 | # http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | # | 
|  | 12 | # Unless required by applicable law or agreed to in writing, software | 
|  | 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | # See the License for the specific language governing permissions and | 
|  | 16 | # limitations under the License. | 
| Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 17 |  | 
|  | 18 | use warnings; | 
|  | 19 | use strict; | 
|  | 20 |  | 
|  | 21 | use utf8; | 
|  | 22 | use open qw(:std utf8); | 
|  | 23 |  | 
| Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 24 | -d 'include/mbedtls' or die "$0: must be run from root\n"; | 
|  | 25 |  | 
| Manuel Pégourié-Gonnard | e137ea6 | 2015-04-09 10:47:44 +0200 | [diff] [blame] | 26 | @ARGV = grep { ! /compat-1\.3\.h/ } <include/mbedtls/*.h>; | 
| Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame] | 27 | push @ARGV, "3rdparty/everest/include/everest/everest.h"; | 
|  | 28 | push @ARGV, "3rdparty/everest/include/everest/x25519.h"; | 
| Dave Rodgman | add60da | 2021-04-07 14:45:36 +0100 | [diff] [blame] | 29 | push @ARGV, glob("library/*.h"); | 
| Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 30 |  | 
|  | 31 | my @consts; | 
|  | 32 | my $state = 'out'; | 
|  | 33 | while (<>) | 
|  | 34 | { | 
| Manuel Pégourié-Gonnard | ae738c2 | 2015-07-01 19:32:00 +0200 | [diff] [blame] | 35 | if( $state eq 'out' and /^(typedef )?enum \{/ ) { | 
| Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 36 | $state = 'in'; | 
|  | 37 | } elsif( $state eq 'out' and /^(typedef )?enum/ ) { | 
|  | 38 | $state = 'start'; | 
|  | 39 | } elsif( $state eq 'start' and /{/ ) { | 
|  | 40 | $state = 'in'; | 
|  | 41 | } elsif( $state eq 'in' and /}/ ) { | 
|  | 42 | $state = 'out'; | 
| Christoph M. Wintersteiger | 7cc4c68 | 2018-12-14 13:18:52 +0000 | [diff] [blame] | 43 | } elsif( $state eq 'in' and not /^#/) { | 
| Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 44 | s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp; | 
|  | 45 | push @consts, $_ if $_; | 
|  | 46 | } | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | open my $fh, '>', 'enum-consts' or die; | 
|  | 50 | print $fh "$_\n" for sort @consts; | 
|  | 51 | close $fh or die; | 
|  | 52 |  | 
|  | 53 | printf "%8d enum-consts\n", scalar @consts; |