1#!/bin/bash 2# 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. 6# 7# Usage: list-identifiers.sh [ -i | --internal ] 8# 9# Copyright The Mbed TLS Contributors 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: 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. 29# 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# ********** 50 51set -eu 52 53if [ -d include/mbedtls ]; then :; else 54 echo "$0: must be run from root" >&2 55 exit 1 56fi 57 58INTERNAL="" 59 60until [ -z "${1-}" ] 61do 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 73done 74 75if [ $INTERNAL ] 76then 77 HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' ) 78else 79 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) 80fi 81 82rm -f identifiers 83 84grep '^[^ /#{]' $HEADERS | \ 85 sed -e 's/^[^:]*://' | \ 86 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \ 87 > _decls 88 89if true; then 90sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \ 91 -e 's/.*(\*\(.*\))(.*/\1/p' _decls 92grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//' 93fi > _identifiers 94 95if [ $( 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 99else 100 echo "$0: oops, lost some identifiers" 2>&1 101 exit 1 102fi 103 104wc -l identifiers 105