1#!/usr/bin/env perl 2# 3# Copyright The Mbed TLS Contributors 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. 17 18use warnings; 19use strict; 20 21use utf8; 22use open qw(:std utf8); 23 24-d 'include/mbedtls' or die "$0: must be run from root\n"; 25 26@ARGV = grep { ! /compat-1\.3\.h/ } <include/mbedtls/*.h>; 27push @ARGV, "3rdparty/everest/include/everest/everest.h"; 28push @ARGV, "3rdparty/everest/include/everest/x25519.h"; 29 30 31my @consts; 32my $state = 'out'; 33while (<>) 34{ 35 if( $state eq 'out' and /^(typedef )?enum \{/ ) { 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'; 43 } elsif( $state eq 'in' and not /^#/) { 44 s/=.*//; s!/\*.*!!; s/,.*//; s/\s+//g; chomp; 45 push @consts, $_ if $_; 46 } 47} 48 49open my $fh, '>', 'enum-consts' or die; 50print $fh "$_\n" for sort @consts; 51close $fh or die; 52 53printf "%8d enum-consts\n", scalar @consts; 54