1#!/bin/sh
2
3set -eu
4
5if [ -d include/mbedtls ]; then :; else
6    echo "$0: must be run from root" >&2
7    exit 1
8fi
9
10HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
11
12rm -f identifiers
13
14grep '^[^ /#{]' $HEADERS | \
15    sed -e 's/^[^:]*://' | \
16    egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
17    > _decls
18
19if true; then
20sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
21       -e 's/.*(\*\(.*\))(.*/\1/p' _decls
22grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
23fi > _identifiers
24
25if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
26    rm _decls
27    egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
28    rm _identifiers
29else
30    echo "$0: oops, lost some identifiers" 2>&1
31    exit 1
32fi
33
34wc -l identifiers
35