Added version check for astyle, versions below 2.03 indent extern "C" scope

This commit is contained in:
Armin Novak 2014-09-11 12:38:32 +02:00
parent 263393d649
commit d4f5ed640f

38
scripts/format_code.sh Normal file → Executable file
View File

@ -1,24 +1,38 @@
#!/bin/sh
#!/bin/bash
ASTYLE=`which astyle`
ASTYLE=$(which astyle)
if [ ! -x $ASTYLE ];
if [ ! -x $ASTYLE ]; then
echo "No astyle found in path, please install."
exit 1
fi
then
echo "No astyle found in path, please install."
exit 1
# Need at least astyle 2.03 due to bugs in older versions
# indenting headers with extern "C"
STR_VERSION=$(($ASTYLE --version) 2>&1)
VERSION=$(echo $STR_VERSION | cut -d ' ' -f4)
MAJOR_VERSION=$(echo $VERSION | cut -d'.' -f1)
MINOR_VERSION=$(echo $VERSION | cut -d'.' -f2)
if [ "$MAJOR_VERSION" -lt "2" ]; then
echo "Your version of astyle($VERSION) is too old, need at least 2.03"
exit 1
fi
if [ "$MINOR_VERSION" -lt "3" ]; then
echo "Your version of astyle($VERSION) is too old, need at least 2.03"
exit 1
fi
if [ $# -le 0 ]; then
echo "Usage:"
echo "\t$0 <file1> [<file2> ...]"
# echo "\t$0 -r <directory>"
exit 2
echo "Usage:"
echo -e "\t$0 <file1> [<file2> ...]"
exit 2
fi
$ASTYLE --lineend=linux --mode=c --indent=force-tab=4 --brackets=linux --pad-header \
--indent-switches --indent-cases --indent-preprocessor \
--indent-col1-comments --delete-empty-lines --break-closing-brackets \
--align-pointer=type --indent-labels --brackets=break \
--unpad-paren --break-blocks $@
exit $?
--unpad-paren --break-blocks $@
exit $?