3 # This file is part of mbed TLS (https://tls.mbed.org)
5 # Copyright (c) 2015-2019, ARM Limited, All Rights Reserved
9 if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
12 This script confirms that the naming of all symbols and identifiers in mbed
13 TLS are consistent with the house style and are also self-consistent.
15 -v If the script fails unexpectedly, print a command trace.
20 if grep --version|head -n1|grep GNU >/dev/null; then :; else
21 echo "This script requires GNU grep.">&2
26 if [ $# -ne 0 ] && [ "$1" = "-v" ]; then
29 exec 2>check-names.err
30 trap 'echo "FAILED UNEXPECTEDLY, status=$?";
31 cat check-names.err' EXIT
35 printf "Analysing source code...\n"
37 sh $trace tests/scripts/list-macros.sh
38 tests/scripts/list-enum-consts.pl
39 sh $trace tests/scripts/list-identifiers.sh
40 sh $trace tests/scripts/list-symbols.sh
44 printf "\nExported symbols declared in header: "
45 UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' )
46 if [ "x$UNDECLARED" = "x" ]; then
54 diff macros identifiers | sed -n -e 's/< //p' > actual-macros
56 for THING in actual-macros enum-consts; do
57 printf "Names of $THING: "
59 BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
60 if [ "x$BAD" = "x" ]; then
69 for THING in identifiers; do
70 printf "Names of $THING: "
72 BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true )
73 if [ "x$BAD" = "x" ]; then
82 printf "Likely typos: "
83 sort -u actual-macros enum-consts > _caps
84 HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
87 sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
88 $HEADERS library/*.c \
89 | grep MBEDTLS | sort -u > _MBEDTLS_XXX
90 TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
91 | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
93 if [ "x$TYPOS" = "x" ]; then
101 if [ -n "$trace" ]; then
108 if [ "$FAIL" -eq 0 ]; then
109 rm macros actual-macros enum-consts identifiers exported-symbols