blob: 4532c1b2856541f6f86bdd71c1ec963a61b18bd0 [file] [log] [blame]
Darryl Green3ef06d52019-04-04 11:33:22 +01001#!/bin/bash
2#
Darryl Green3997a6c2019-04-18 13:09:25 +01003# 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 Green3ef06d52019-04-04 11:33:22 +01006#
7# Usage: list-identifiers.sh [ -i | --internal ]
Bence Szépkúti468a76f2020-05-26 00:33:31 +02008#
9# Copyright (C) 2015-2019, Arm Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +020010# 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úti51b41d52020-05-26 01:54:15 +020017#
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úti468a76f2020-05-26 00:33:31 +020029#
Bence Szépkútif744bd72020-06-05 13:02:18 +020030# **********
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#
Bence Szépkúti468a76f2020-05-26 00:33:31 +020051# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010052
53set -eu
54
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020055if [ -d include/mbedtls ]; then :; else
56 echo "$0: must be run from root" >&2
57 exit 1
58fi
59
Darryl Green3ef06d52019-04-04 11:33:22 +010060INTERNAL=""
61
62until [ -z "${1-}" ]
63do
64 case "$1" in
65 -i|--internal)
66 INTERNAL="1"
67 ;;
68 *)
69 # print error
70 echo "Unknown argument: '$1'"
71 exit 1
72 ;;
73 esac
74 shift
75done
76
77if [ $INTERNAL ]
78then
79 HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
80else
81 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
82fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010083
84rm -f identifiers
85
86grep '^[^ /#{]' $HEADERS | \
87 sed -e 's/^[^:]*://' | \
88 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
89 > _decls
90
91if true; then
92sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
93 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
94grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
95fi > _identifiers
96
97if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
98 rm _decls
99 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
100 rm _identifiers
101else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +0200102 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +0100103 exit 1
104fi
105
106wc -l identifiers