2014-07-15 11:10:49 +02:00
|
|
|
#!/bin/sh
|
2019-06-11 12:51:33 +02:00
|
|
|
#
|
2014-07-15 11:10:49 +02:00
|
|
|
# Calls astyle with settings matching Calamares coding style
|
2019-06-11 12:51:33 +02:00
|
|
|
# Requires astyle >= 2.04 and clang-format-7
|
|
|
|
#
|
|
|
|
# You can pass in directory names, in which case the files
|
|
|
|
# in that directory (NOT below it) are processed.
|
|
|
|
#
|
2020-03-03 14:21:43 +01:00
|
|
|
LANG=C
|
|
|
|
LC_ALL=C
|
|
|
|
LC_NUMERIC=C
|
|
|
|
export LANG LC_ALL LC_NUMERIC
|
|
|
|
|
2019-06-11 12:51:33 +02:00
|
|
|
AS=$( which astyle )
|
2019-07-05 10:47:31 +02:00
|
|
|
|
2020-06-17 13:53:40 +02:00
|
|
|
CF_VERSIONS="clang-format-7 clang-format-8 clang-format70 clang-format80 clang-format-9.0.1 clang-format"
|
2020-04-15 11:54:27 +02:00
|
|
|
for _cf in $CF_VERSIONS
|
2019-07-05 10:47:31 +02:00
|
|
|
do
|
|
|
|
# Not an error if this particular clang-format isn't found
|
2020-04-15 11:54:27 +02:00
|
|
|
CF=$( which $_cf 2> /dev/null || true )
|
2019-07-05 10:47:31 +02:00
|
|
|
test -n "$CF" && break
|
|
|
|
done
|
2019-06-11 12:51:33 +02:00
|
|
|
|
|
|
|
test -n "$AS" || { echo "! No astyle found in PATH"; exit 1 ; }
|
2020-04-15 11:54:27 +02:00
|
|
|
test -n "$CF" || { echo "! No clang-format ($CF_VERSIONS) found in PATH"; exit 1 ; }
|
2019-06-11 12:51:33 +02:00
|
|
|
test -x "$AS" || { echo "! $AS is not executable."; exit 1 ; }
|
|
|
|
test -x "$CF" || { echo "! $CF is not executable."; exit 1 ; }
|
|
|
|
|
2020-06-17 13:53:40 +02:00
|
|
|
expr `"$CF" --version | tr -dc '[^.0-9]' | cut -d . -f 1` '<' 10 > /dev/null || { echo "! $CF is version 10 or later, needs different .clang-format" ; exit 1 ; }
|
|
|
|
|
2019-11-26 22:29:06 +01:00
|
|
|
set -e
|
|
|
|
|
2019-06-11 12:51:33 +02:00
|
|
|
any_dirs=no
|
|
|
|
for d in "$@"
|
|
|
|
do
|
|
|
|
test -d "$d" && any_dirs=yes
|
|
|
|
done
|
|
|
|
|
|
|
|
style_some()
|
|
|
|
{
|
|
|
|
$AS --options=$(dirname $0)/astylerc --quiet "$@"
|
|
|
|
$CF -i -style=file "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
if test "x$any_dirs" = "xyes" ; then
|
|
|
|
for d in "$@"
|
|
|
|
do
|
2019-08-04 22:21:53 +02:00
|
|
|
if test -d "$d" ; then
|
2019-06-11 12:51:33 +02:00
|
|
|
style_some $( find "$d" -maxdepth 1 -type f -name '*.cpp' -o -name '*.h' )
|
|
|
|
else
|
|
|
|
style_some "$d"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
style_some "$@"
|
|
|
|
fi
|