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 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 9 | # Copyright The Mbed TLS Contributors |
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. |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 23 | |
| 24 | set -eu |
| 25 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 26 | if [ -d include/mbedtls ]; then :; else |
| 27 | echo "$0: must be run from root" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 31 | INTERNAL="" |
| 32 | |
| 33 | until [ -z "${1-}" ] |
| 34 | do |
| 35 | case "$1" in |
| 36 | -i|--internal) |
| 37 | INTERNAL="1" |
| 38 | ;; |
| 39 | *) |
| 40 | # print error |
| 41 | echo "Unknown argument: '$1'" |
| 42 | exit 1 |
| 43 | ;; |
| 44 | esac |
| 45 | shift |
| 46 | done |
| 47 | |
| 48 | if [ $INTERNAL ] |
| 49 | then |
Chris Jones | f6643cc | 2021-02-19 12:49:17 +0000 | [diff] [blame] | 50 | HEADERS=$( ls library/*.h ) |
Darryl Green | 383d1fa | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 51 | else |
Chris Jones | f6643cc | 2021-02-19 12:49:17 +0000 | [diff] [blame] | 52 | HEADERS=$( ls include/mbedtls/*.h include/psa/*.h library/*.h ) |
Christoph M. Wintersteiger | 8a0f5bb | 2018-12-14 15:46:34 +0000 | [diff] [blame] | 53 | 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] | 54 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 55 | |
| 56 | rm -f identifiers |
| 57 | |
| 58 | grep '^[^ /#{]' $HEADERS | \ |
| 59 | sed -e 's/^[^:]*://' | \ |
Gilles Peskine | 1d04b05f | 2019-07-23 17:38:41 +0200 | [diff] [blame] | 60 | egrep -v '^(extern "C"|(typedef )?(struct|union|enum)( {)?$|};?$)' \ |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 61 | > _decls |
| 62 | |
| 63 | if true; then |
| 64 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 65 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 66 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 67 | fi > _identifiers |
| 68 | |
| 69 | if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then |
| 70 | rm _decls |
| 71 | egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers |
| 72 | rm _identifiers |
| 73 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 74 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 75 | exit 1 |
| 76 | fi |
| 77 | |
| 78 | wc -l identifiers |