blob: 4303413c491c2bec3ca876daaffdba590446e23b [file] [log] [blame]
Darryl Green383d1fa2019-04-04 11:33:22 +01001#!/bin/bash
2#
3# Outputs a file containing identifiers from internal header files or all
4# header files, based on --internal flag.
5#
6# Usage: list-identifiers.sh [ -i | --internal ]
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +01007
8set -eu
9
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020010if [ -d include/mbedtls ]; then :; else
11 echo "$0: must be run from root" >&2
12 exit 1
13fi
14
Darryl Green383d1fa2019-04-04 11:33:22 +010015INTERNAL=""
16
17until [ -z "${1-}" ]
18do
19 case "$1" in
20 -i|--internal)
21 INTERNAL="1"
22 ;;
23 *)
24 # print error
25 echo "Unknown argument: '$1'"
26 exit 1
27 ;;
28 esac
29 shift
30done
31
32if [ $INTERNAL ]
33then
34 HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
35else
36 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
37fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010038
39rm -f identifiers
40
41grep '^[^ /#{]' $HEADERS | \
42 sed -e 's/^[^:]*://' | \
43 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
44 > _decls
45
46if true; then
47sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
48 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
49grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
50fi > _identifiers
51
52if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
53 rm _decls
54 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
55 rm _identifiers
56else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020057 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010058 exit 1
59fi
60
61wc -l identifiers