blob: 1284552213f2ff66ff636d5a96d2aac873857b61 [file] [log] [blame]
Darryl Green383d1fa2019-04-04 11:33:22 +01001#!/bin/bash
2#
Darryl Green1ae48862019-04-18 13:09:25 +01003# Create a file named identifiers containing identifiers from internal header
4# files or all header files, based on --internal flag.
5# Outputs the line count of the file to stdout.
Darryl Green383d1fa2019-04-04 11:33:22 +01006#
7# Usage: list-identifiers.sh [ -i | --internal ]
Bence Szépkúti700ee442020-05-26 00:33:31 +02008#
9# Copyright (C) 2015-2019, Arm Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020010# SPDX-License-Identifier: Apache-2.0
11#
12# Licensed under the Apache License, Version 2.0 (the "License"); you may
13# not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
Bence Szépkúti700ee442020-05-26 00:33:31 +020023#
24# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010025
26set -eu
27
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020028if [ -d include/mbedtls ]; then :; else
29 echo "$0: must be run from root" >&2
30 exit 1
31fi
32
Darryl Green383d1fa2019-04-04 11:33:22 +010033INTERNAL=""
34
35until [ -z "${1-}" ]
36do
37 case "$1" in
38 -i|--internal)
39 INTERNAL="1"
40 ;;
41 *)
42 # print error
43 echo "Unknown argument: '$1'"
44 exit 1
45 ;;
46 esac
47 shift
48done
49
50if [ $INTERNAL ]
51then
Jaeden Amero7b3603c2019-05-01 13:14:16 +010052 HEADERS=$( ls include/mbedtls/*_internal.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
Darryl Green383d1fa2019-04-04 11:33:22 +010053else
Jaeden Amero7b3603c2019-05-01 13:14:16 +010054 HEADERS=$( ls include/mbedtls/*.h include/psa/*.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
Christoph M. Wintersteiger8a0f5bb2018-12-14 15:46:34 +000055 HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h"
Darryl Green383d1fa2019-04-04 11:33:22 +010056fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010057
58rm -f identifiers
59
60grep '^[^ /#{]' $HEADERS | \
61 sed -e 's/^[^:]*://' | \
Gilles Peskine1d04b05f2019-07-23 17:38:41 +020062 egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010063 > _decls
64
65if true; then
66sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
67 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
68grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
69fi > _identifiers
70
71if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
72 rm _decls
73 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
74 rm _identifiers
75else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020076 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010077 exit 1
78fi
79
80wc -l identifiers