blob: d01e5b630cd1768d9d327b75fdddc2f967d43bdb [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#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02009# Copyright The Mbed TLS Contributors
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# **********
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010050
51set -eu
52
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020053if [ -d include/mbedtls ]; then :; else
54 echo "$0: must be run from root" >&2
55 exit 1
56fi
57
Darryl Green3ef06d52019-04-04 11:33:22 +010058INTERNAL=""
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
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010081
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
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +0200100 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +0100101 exit 1
102fi
103
104wc -l identifiers