From 50629eec271e5815614f607c35a85381a18a734a Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Tue, 16 Jul 2019 13:49:27 +0700 Subject: [PATCH] tools: Add a script to fix up empty prototypes --- tools/ci/executable-list.txt | 1 + tools/ci/fix_empty_prototypes.sh | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 tools/ci/fix_empty_prototypes.sh diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index 9ae3ae702..4e580c5a8 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -39,6 +39,7 @@ tools/ci/check_idf_version.sh tools/ci/check_ut_cmake_make.sh tools/ci/checkout_project_ref.py tools/ci/envsubst.py +tools/ci/fix_empty_prototypes.sh tools/ci/get-full-sources.sh tools/ci/get_supported_examples.sh tools/ci/mirror-submodule-update.sh diff --git a/tools/ci/fix_empty_prototypes.sh b/tools/ci/fix_empty_prototypes.sh new file mode 100755 index 000000000..0aade7861 --- /dev/null +++ b/tools/ci/fix_empty_prototypes.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# This script finds and fixes up empty prototypes, to satisfy `-Wstrict-prototypes` and to сomply the C Standard + +set -o errexit +set -o pipefail +set -o nounset + +ctags -R -f - --c-kinds=pf --languages="c" --langmap=c:.c.h | grep "([[:space:]]*)" > tmp_ctags.txt || : + +ctags -R -f - --c-kinds=pf --languages="c++" --langmap=c++:.cpp | grep "([[:space:]]*)" | grep -F 'extern "C"' >> tmp_ctags.txt || : + +while read TAGLINE; do + + # a format of ctags: + # https://en.wikipedia.org/wiki/Ctags + + # a 2nd column, + FILENAME=$(printf "$TAGLINE" | sed -E "s/([^[:space:]]+)[[:space:]]([^[:space:]]+)[[:space:]](.+)\;\".*/\2/g") + + # a 3rd column + # a pattern + # /^ void sdmmc_host_dma_stop ( );$/ + OLDLINE=$(printf "$TAGLINE" | sed -E "s/([^[:space:]]+)[[:space:]]([^[:space:]]+)[[:space:]](.+)\;\".*/\3/g") + + # remove leading and trailng '/'-s + OLDLINE="${OLDLINE#/}" + OLDLINE="${OLDLINE%/}" + + # remove leading '^' and trailing '$' + OLDLINE="${OLDLINE#^}" + OLDLINE="${OLDLINE%$}" + + + OLDBRACERS=$(printf "$OLDLINE" | sed "s/.*\(([[:space:]]*)\).*/\1/") + NEWBRACERS="(void)" + + NEWLINE=${OLDLINE/$OLDBRACERS/$NEWBRACERS} + + # escaping + OLDLINE=$(printf "%q" "$OLDLINE") + NEWLINE=$(printf "%q" "$NEWLINE") + + sed -i -E 's,'"^$OLDLINE\$"','"$NEWLINE"',' $FILENAME + +done < tmp_ctags.txt + +echo "+++" +echo "Also 'git grep -E \"^.*\([^\)]+\) *\(\).*$\"' will help to find some callback declarations" +echo "+++"