2014-09-11 14:38:32 +04:00
|
|
|
#!/bin/bash
|
2014-05-23 15:07:07 +04:00
|
|
|
|
2014-09-11 14:38:32 +04:00
|
|
|
ASTYLE=$(which astyle)
|
2014-05-23 15:07:07 +04:00
|
|
|
|
2014-09-11 14:38:32 +04:00
|
|
|
if [ ! -x $ASTYLE ]; then
|
|
|
|
echo "No astyle found in path, please install."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Need at least astyle 2.03 due to bugs in older versions
|
|
|
|
# indenting headers with extern "C"
|
2016-04-05 18:07:45 +03:00
|
|
|
STR_VERSION=$($ASTYLE --version 2>&1)
|
2014-09-11 14:38:32 +04:00
|
|
|
VERSION=$(echo $STR_VERSION | cut -d ' ' -f4)
|
|
|
|
MAJOR_VERSION=$(echo $VERSION | cut -d'.' -f1)
|
|
|
|
MINOR_VERSION=$(echo $VERSION | cut -d'.' -f2)
|
|
|
|
|
2018-03-08 15:46:46 +03:00
|
|
|
if [ "$MAJOR_VERSION" -lt "2" ];
|
|
|
|
then
|
2014-09-11 14:38:32 +04:00
|
|
|
echo "Your version of astyle($VERSION) is too old, need at least 2.03"
|
|
|
|
exit 1
|
2018-03-08 15:46:46 +03:00
|
|
|
elif [ "$MAJOR_VERSION" -eq "2" ];
|
|
|
|
then
|
|
|
|
if [ "$MINOR_VERSION" -lt "3" ];
|
|
|
|
then
|
|
|
|
echo "Your version of astyle($VERSION) is too old, need at least 2.03"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-05-23 15:07:07 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -le 0 ]; then
|
2014-09-11 14:38:32 +04:00
|
|
|
echo "Usage:"
|
|
|
|
echo -e "\t$0 <file1> [<file2> ...]"
|
|
|
|
exit 2
|
2014-05-23 15:07:07 +04:00
|
|
|
fi
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
$ASTYLE --lineend=linux --mode=c --indent=tab=4 --pad-header --pad-oper --style=allman --min-conditional-indent=0 \
|
2018-03-08 15:46:46 +03:00
|
|
|
--indent-switches --indent-cases --indent-preprocessor -k1 --max-code-length=100 \
|
|
|
|
--indent-col1-comments --delete-empty-lines --break-closing-brackets \
|
|
|
|
--align-pointer=type --indent-labels -xe --break-after-logical \
|
|
|
|
--unpad-paren --break-blocks $@
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
exit $?
|