blob: 9698fc86c0ff18d6f51f08c3d74113b9fe4c4f9c [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#
Bence Szépkúti1e148272020-08-07 13:07:28 +02009# Copyright The Mbed TLS Contributors
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.
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010023
24set -eu
25
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020026if [ -d include/mbedtls ]; then :; else
27 echo "$0: must be run from root" >&2
28 exit 1
29fi
30
Darryl Green383d1fa2019-04-04 11:33:22 +010031INTERNAL=""
32
33until [ -z "${1-}" ]
34do
35 case "$1" in
36 -i|--internal)
37 INTERNAL="1"
38 ;;
39 *)
40 # print error
41 echo "Unknown argument: '$1'"
42 exit 1
43 ;;
44 esac
45 shift
46done
47
48if [ $INTERNAL ]
49then
TRodziewicz28a4a962021-06-15 00:18:32 +020050 HEADERS=$( ls include/mbedtls/*_internal.h library/*.h | egrep -v 'compat-2\.x\.h' )
Darryl Green383d1fa2019-04-04 11:33:22 +010051else
TRodziewicz28a4a962021-06-15 00:18:32 +020052 HEADERS=$( ls include/mbedtls/*.h include/psa/*.h library/*.h | egrep -v 'compat-2\.x\.h' )
Christoph M. Wintersteiger8a0f5bb2018-12-14 15:46:34 +000053 HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h"
Darryl Green383d1fa2019-04-04 11:33:22 +010054fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010055
56rm -f identifiers
57
58grep '^[^ /#{]' $HEADERS | \
59 sed -e 's/^[^:]*://' | \
Gilles Peskine1d04b05f2019-07-23 17:38:41 +020060 egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010061 > _decls
62
63if true; then
64sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
65 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
66grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
67fi > _identifiers
68
69if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
70 rm _decls
71 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
72 rm _identifiers
73else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020074 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010075 exit 1
76fi
77
78wc -l identifiers