Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Darryl Green | 1ae4886 | 2019-04-18 13:09:25 +0100 | [diff] [blame] | 3 | # 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 Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 6 | # |
| 7 | # Usage: list-identifiers.sh [ -i | --internal ] |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 8 | |
| 9 | set -eu |
| 10 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 11 | if [ -d include/mbedtls ]; then :; else |
| 12 | echo "$0: must be run from root" >&2 |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 16 | INTERNAL="" |
| 17 | |
| 18 | until [ -z "${1-}" ] |
| 19 | do |
| 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 |
| 31 | done |
| 32 | |
| 33 | if [ $INTERNAL ] |
| 34 | then |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 35 | HEADERS=$( ls include/mbedtls/*_internal.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 36 | else |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 37 | HEADERS=$( ls include/mbedtls/*.h include/psa/*.h library/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame^] | 38 | HEADERS="$HEADERS 3rdparty/everest/include/everest/everest.h 3rdparty/everest/include/everest/x25519.h" |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 39 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 40 | |
| 41 | rm -f identifiers |
| 42 | |
| 43 | grep '^[^ /#{]' $HEADERS | \ |
| 44 | sed -e 's/^[^:]*://' | \ |
Gilles Peskine | 1d04b05f | 2019-07-23 17:38:41 +0200 | [diff] [blame] | 45 | egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \ |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 46 | > _decls |
| 47 | |
| 48 | if true; then |
| 49 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 50 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 51 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 52 | fi > _identifiers |
| 53 | |
| 54 | if [ $( 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 |
| 58 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 59 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | wc -l identifiers |