blob: 24e74043bec74e79d2f817186d31e7de576b9dc4 [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 ]
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +01008
9set -eu
10
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020011if [ -d include/mbedtls ]; then :; else
12 echo "$0: must be run from root" >&2
13 exit 1
14fi
15
Darryl Green383d1fa2019-04-04 11:33:22 +010016INTERNAL=""
17
18until [ -z "${1-}" ]
19do
20 case "$1" in
21 -i|--internal)
22 INTERNAL="1"
23 ;;
24 *)
25 # print error
26 echo "Unknown argument: '$1'"
27 exit 1
28 ;;
29 esac
30 shift
31done
32
33if [ $INTERNAL ]
34then
Jaeden Amero7b3603c2019-05-01 13:14:16 +010035 HEADERS=$( ls include/mbedtls/*_internal.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
Darryl Green383d1fa2019-04-04 11:33:22 +010036else
Jaeden Amero7b3603c2019-05-01 13:14:16 +010037 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 +000038 HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h"
Darryl Green383d1fa2019-04-04 11:33:22 +010039fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010040
41rm -f identifiers
42
43grep '^[^ /#{]' $HEADERS | \
44 sed -e 's/^[^:]*://' | \
Gilles Peskine1d04b05f2019-07-23 17:38:41 +020045 egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010046 > _decls
47
48if true; then
49sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
50 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
51grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
52fi > _identifiers
53
54if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
55 rm _decls
56 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
57 rm _identifiers
58else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020059 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010060 exit 1
61fi
62
63wc -l identifiers