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 |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 10 | # SPDX-License-Identifier: Apache-2.0 |
| 11 | # |
| 12 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | # not use this file except in compliance with the License. |
| 14 | # You may obtain a copy of the License at |
| 15 | # |
| 16 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | # |
| 18 | # Unless required by applicable law or agreed to in writing, software |
| 19 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | # See the License for the specific language governing permissions and |
| 22 | # limitations under the License. |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 23 | # |
| 24 | # 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] | 25 | |
| 26 | set -eu |
| 27 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 28 | if [ -d include/mbedtls ]; then :; else |
| 29 | echo "$0: must be run from root" >&2 |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 33 | INTERNAL="" |
| 34 | |
| 35 | until [ -z "${1-}" ] |
| 36 | do |
| 37 | case "$1" in |
| 38 | -i|--internal) |
| 39 | INTERNAL="1" |
| 40 | ;; |
| 41 | *) |
| 42 | # print error |
| 43 | echo "Unknown argument: '$1'" |
| 44 | exit 1 |
| 45 | ;; |
| 46 | esac |
| 47 | shift |
| 48 | done |
| 49 | |
| 50 | if [ $INTERNAL ] |
| 51 | then |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 52 | 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] | 53 | else |
Jaeden Amero | 7b3603c | 2019-05-01 13:14:16 +0100 | [diff] [blame] | 54 | 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] | 55 | 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] | 56 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 57 | |
| 58 | rm -f identifiers |
| 59 | |
| 60 | grep '^[^ /#{]' $HEADERS | \ |
| 61 | sed -e 's/^[^:]*://' | \ |
Gilles Peskine | 1d04b05f | 2019-07-23 17:38:41 +0200 | [diff] [blame] | 62 | egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \ |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 63 | > _decls |
| 64 | |
| 65 | if true; then |
| 66 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 67 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 68 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 69 | fi > _identifiers |
| 70 | |
| 71 | if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then |
| 72 | rm _decls |
| 73 | egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers |
| 74 | rm _identifiers |
| 75 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 76 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 77 | exit 1 |
| 78 | fi |
| 79 | |
| 80 | wc -l identifiers |