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 ] |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame^] | 8 | # |
| 9 | # Copyright (C) 2015-2019, Arm Limited, All Rights Reserved |
| 10 | # |
| 11 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 12 | |
| 13 | set -eu |
| 14 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 15 | if [ -d include/mbedtls ]; then :; else |
| 16 | echo "$0: must be run from root" >&2 |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 20 | INTERNAL="" |
| 21 | |
| 22 | until [ -z "${1-}" ] |
| 23 | do |
| 24 | case "$1" in |
| 25 | -i|--internal) |
| 26 | INTERNAL="1" |
| 27 | ;; |
| 28 | *) |
| 29 | # print error |
| 30 | echo "Unknown argument: '$1'" |
| 31 | exit 1 |
| 32 | ;; |
| 33 | esac |
| 34 | shift |
| 35 | done |
| 36 | |
| 37 | if [ $INTERNAL ] |
| 38 | then |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 39 | 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] | 40 | else |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 41 | 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] | 42 | 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] | 43 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 44 | |
| 45 | rm -f identifiers |
| 46 | |
| 47 | grep '^[^ /#{]' $HEADERS | \ |
| 48 | sed -e 's/^[^:]*://' | \ |
Gilles Peskine | 1d04b05f | 2019-07-23 17:38:41 +0200 | [diff] [blame] | 49 | egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \ |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 50 | > _decls |
| 51 | |
| 52 | if true; then |
| 53 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 54 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 55 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 56 | fi > _identifiers |
| 57 | |
| 58 | if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then |
| 59 | rm _decls |
| 60 | egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers |
| 61 | rm _identifiers |
| 62 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 63 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 64 | exit 1 |
| 65 | fi |
| 66 | |
| 67 | wc -l identifiers |