Darryl Green | 3ef06d5 | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Darryl Green | 3997a6c | 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 | 3ef06d5 | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 6 | # |
| 7 | # Usage: list-identifiers.sh [ -i | --internal ] |
Bence Szépkúti | 468a76f | 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 | 3ef06d5 | 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 |
| 39 | HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
| 40 | else |
| 41 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
| 42 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 43 | |
| 44 | rm -f identifiers |
| 45 | |
| 46 | grep '^[^ /#{]' $HEADERS | \ |
| 47 | sed -e 's/^[^:]*://' | \ |
| 48 | egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \ |
| 49 | > _decls |
| 50 | |
| 51 | if true; then |
| 52 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 53 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 54 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 55 | fi > _identifiers |
| 56 | |
| 57 | if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then |
| 58 | rm _decls |
| 59 | egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers |
| 60 | rm _identifiers |
| 61 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 62 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | wc -l identifiers |