blob: d5af042d1993a1162cc013350a0778fccaba77ea [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úti51b41d52020-05-26 01:54:15 +020010# 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.
Bence Szépkúti468a76f2020-05-26 00:33:31 +020023#
24# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010025
26set -eu
27
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020028if [ -d include/mbedtls ]; then :; else
29 echo "$0: must be run from root" >&2
30 exit 1
31fi
32
Darryl Green3ef06d52019-04-04 11:33:22 +010033INTERNAL=""
34
35until [ -z "${1-}" ]
36do
37 case "$1" in
38 -i|--internal)
39 INTERNAL="1"
40 ;;
41 *)
42 # print error
43 echo "Unknown argument: '$1'"
44 exit 1
45 ;;
46 esac
47 shift
48done
49
50if [ $INTERNAL ]
51then
52 HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
53else
54 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
55fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010056
57rm -f identifiers
58
59grep '^[^ /#{]' $HEADERS | \
60 sed -e 's/^[^:]*://' | \
61 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
62 > _decls
63
64if true; then
65sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
66 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
67grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
68fi > _identifiers
69
70if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
71 rm _decls
72 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
73 rm _identifiers
74else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020075 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010076 exit 1
77fi
78
79wc -l identifiers