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 | # |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 9 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 10 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 11 | # |
| 12 | # This file is provided under the Apache License 2.0, or the |
| 13 | # GNU General Public License v2.0 or later. |
| 14 | # |
| 15 | # ********** |
| 16 | # Apache License 2.0: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 17 | # |
| 18 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 19 | # not use this file except in compliance with the License. |
| 20 | # You may obtain a copy of the License at |
| 21 | # |
| 22 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 23 | # |
| 24 | # Unless required by applicable law or agreed to in writing, software |
| 25 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 26 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 27 | # See the License for the specific language governing permissions and |
| 28 | # limitations under the License. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 29 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 30 | # ********** |
| 31 | # |
| 32 | # ********** |
| 33 | # GNU General Public License v2.0 or later: |
| 34 | # |
| 35 | # This program is free software; you can redistribute it and/or modify |
| 36 | # it under the terms of the GNU General Public License as published by |
| 37 | # the Free Software Foundation; either version 2 of the License, or |
| 38 | # (at your option) any later version. |
| 39 | # |
| 40 | # This program is distributed in the hope that it will be useful, |
| 41 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 | # GNU General Public License for more details. |
| 44 | # |
| 45 | # You should have received a copy of the GNU General Public License along |
| 46 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 47 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 48 | # |
| 49 | # ********** |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 50 | |
| 51 | set -eu |
| 52 | |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 53 | if [ -d include/mbedtls ]; then :; else |
| 54 | echo "$0: must be run from root" >&2 |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
Darryl Green | 3ef06d5 | 2019-04-04 11:33:22 +0100 | [diff] [blame] | 58 | INTERNAL="" |
| 59 | |
| 60 | until [ -z "${1-}" ] |
| 61 | do |
| 62 | case "$1" in |
| 63 | -i|--internal) |
| 64 | INTERNAL="1" |
| 65 | ;; |
| 66 | *) |
| 67 | # print error |
| 68 | echo "Unknown argument: '$1'" |
| 69 | exit 1 |
| 70 | ;; |
| 71 | esac |
| 72 | shift |
| 73 | done |
| 74 | |
| 75 | if [ $INTERNAL ] |
| 76 | then |
| 77 | HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
| 78 | else |
| 79 | HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) |
| 80 | fi |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 81 | |
| 82 | rm -f identifiers |
| 83 | |
| 84 | grep '^[^ /#{]' $HEADERS | \ |
| 85 | sed -e 's/^[^:]*://' | \ |
| 86 | egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \ |
| 87 | > _decls |
| 88 | |
| 89 | if true; then |
| 90 | sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ |
| 91 | -e 's/.*(\*\(.*\))(.*/\1/p' _decls |
| 92 | grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' |
| 93 | fi > _identifiers |
| 94 | |
| 95 | if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then |
| 96 | rm _decls |
| 97 | egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers |
| 98 | rm _identifiers |
| 99 | else |
Manuel Pégourié-Gonnard | d1ddd29 | 2015-04-09 10:15:10 +0200 | [diff] [blame] | 100 | echo "$0: oops, lost some identifiers" 2>&1 |
Manuel Pégourié-Gonnard | 3385cf4 | 2015-04-02 17:59:30 +0100 | [diff] [blame] | 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | wc -l identifiers |