]> granicus.if.org Git - esp-idf/commitdiff
tools: Add a script to fix up empty prototypes
authorAnton Maklakov <anton@espressif.com>
Tue, 16 Jul 2019 06:49:27 +0000 (13:49 +0700)
committerAnton Maklakov <anton@espressif.com>
Thu, 1 Aug 2019 09:28:55 +0000 (16:28 +0700)
tools/ci/executable-list.txt
tools/ci/fix_empty_prototypes.sh [new file with mode: 0755]

index 9ae3ae702e284b586bf5e7fb5e61173c900d3ad5..4e580c5a85040f9021d38e762143bbab0add1fe8 100644 (file)
@@ -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 (executable)
index 0000000..0aade78
--- /dev/null
@@ -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 "+++"