blob: 225612f8efbbc6baf094488d17093e02170124c9 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Bence Szépkúti700ee442020-05-26 00:33:31 +02002#
Bence Szépkúti1e148272020-08-07 13:07:28 +02003# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02004# 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é-Gonnard3385cf42015-04-02 17:59:30 +010017
18use warnings;
19use strict;
20
21use utf8;
22use open qw(:std utf8);
23
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020024-d 'include/mbedtls' or die "$0: must be run from root\n";
25
Mateusz Starzyk7d48b282021-02-16 14:07:47 +010026@ARGV = <include/mbedtls/*.h>;
Chris Jonesf6643cc2021-02-19 12:49:17 +000027push @ARGV, <library/*.h>;
Christoph M. Wintersteiger8a0f5bb2018-12-14 15:46:34 +000028push @ARGV, "3rdparty/everest/include/everest/everest.h";
29push @ARGV, "3rdparty/everest/include/everest/x25519.h";
Dave Rodgmanadd60da2021-04-07 14:45:36 +010030push @ARGV, glob("library/*.h");
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010031
32my @consts;
33my $state = 'out';
34while (<>)
35{
Manuel Pégourié-Gonnardae738c22015-07-01 19:32:00 +020036 if( $state eq 'out' and /^(typedef )?enum \{/ ) {
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010037 $state = 'in';
38 } elsif( $state eq 'out' and /^(typedef )?enum/ ) {
39 $state = 'start';
40 } elsif( $state eq 'start' and /{/ ) {
41 $state = 'in';
42 } elsif( $state eq 'in' and /}/ ) {
43 $state = 'out';
Christoph M. Wintersteiger7cc4c682018-12-14 13:18:52 +000044 } elsif( $state eq 'in' and not /^#/) {
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010045 s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp;
46 push @consts, $_ if $_;
47 }
48}
49
50open my $fh, '>', 'enum-consts' or die;
51print $fh "$_\n" for sort @consts;
52close $fh or die;
53
54printf "%8d enum-consts\n", scalar @consts;