OVMS3-idf/tools/ci/fix_empty_prototypes.sh
Ivan Grokhotkov e94288da31 global: use '/usr/bin/env bash' instead of '/usr/bin/bash' in shebangs
Using the method from @cemeyer
(https://github.com/espressif/esp-idf/pull/3166):

find . -name \*.sh -exec sed -i "" -e 's|^#!.*bin/bash|#!/usr/bin/env bash|' {} +

Closes https://github.com/espressif/esp-idf/pull/3166.
2020-04-03 01:10:02 +02:00

51 lines
1.4 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env 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 "+++"