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