blob: eaf270c7ae372c89118747d4246fe148e7e2b28b [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' )
Darryl Green383d1fa2019-04-04 11:33:22 +010038fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010039
40rm -f identifiers
41
42grep '^[^ /#{]' $HEADERS | \
43 sed -e 's/^[^:]*://' | \
44 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
45 > _decls
46
47if true; then
48sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
49 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
50grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
51fi > _identifiers
52
53if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
54 rm _decls
55 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
56 rm _identifiers
57else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020058 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010059 exit 1
60fi
61
62wc -l identifiers