blob: 1887061457ddc32b68dd62f0a77ad33e09007507 [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
10#
11# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010012
13set -eu
14
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020015if [ -d include/mbedtls ]; then :; else
16 echo "$0: must be run from root" >&2
17 exit 1
18fi
19
Darryl Green3ef06d52019-04-04 11:33:22 +010020INTERNAL=""
21
22until [ -z "${1-}" ]
23do
24 case "$1" in
25 -i|--internal)
26 INTERNAL="1"
27 ;;
28 *)
29 # print error
30 echo "Unknown argument: '$1'"
31 exit 1
32 ;;
33 esac
34 shift
35done
36
37if [ $INTERNAL ]
38then
39 HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
40else
41 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
42fi
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010043
44rm -f identifiers
45
46grep '^[^ /#{]' $HEADERS | \
47 sed -e 's/^[^:]*://' | \
48 egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
49 > _decls
50
51if true; then
52sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
53 -e 's/.*(\*\(.*\))(.*/\1/p' _decls
54grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
55fi > _identifiers
56
57if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
58 rm _decls
59 egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
60 rm _identifiers
61else
Manuel Pégourié-Gonnardd1ddd292015-04-09 10:15:10 +020062 echo "$0: oops, lost some identifiers" 2>&1
Manuel Pégourié-Gonnard3385cf42015-04-02 17:59:30 +010063 exit 1
64fi
65
66wc -l identifiers