blob: c48c249cc15fc0a9c38e6914f88748e9442d734b [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
10#
11# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010012
13set -eu
14
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020015if [ -d include/mbedtls ]; then :; else
16 echo "$0: must be run from root" >&2
17 exit 1
18fi
19
Darryl Green383d1fa2019-04-04 11:33:22 +010020INTERNAL=""
21
22until [ -z "${1-}" ]
23do
24 case "$1" in
25 -i|--internal)
26 INTERNAL="1"
27 ;;
28 *)
29 # print error
30 echo "Unknown argument: '$1'"
31 exit 1
32 ;;
33 esac
34 shift
35done
36
37if [ $INTERNAL ]
38then
Jaeden Amero7b3603c2019-05-01 13:14:16 +010039 HEADERS=$( ls include/mbedtls/*_internal.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
Darryl Green383d1fa2019-04-04 11:33:22 +010040else
Jaeden Amero7b3603c2019-05-01 13:14:16 +010041 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 +000042 HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h"
Darryl Green383d1fa2019-04-04 11:33:22 +010043fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010044
45rm -f identifiers
46
47grep '^[^ /#{]' $HEADERS | \
48 sed -e 's/^[^:]*://' | \
Gilles Peskine1d04b05f2019-07-23 17:38:41 +020049 egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010050 > _decls
51
52if true; then
53sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
54 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
55grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
56fi > _identifiers
57
58if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
59 rm _decls
60 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
61 rm _identifiers
62else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020063 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010064 exit 1
65fi
66
67wc -l identifiers