exit 1
fi
-# Add the location 'setup_astyle.sh' installs astyle to to the local PATH.
-ASTYLE_PATH="$(cd "$(dirname "$0")" && pwd)/programs/astyle/bin"
-export PATH=$ASTYLE_PATH:$PATH
+# Add the location 'download_clang_format' or 'compile_clang_format'
+# installs clang-format to to the local PATH.
+CLANG_FORMAT_PATH="$(cd "$(dirname "$0")" && pwd)/programs/clang-6/bin"
+export PATH="${CLANG_FORMAT_PATH}:${PATH}"
-if test ! -f contrib/styles/astyle.rc ; then
- echo "*** No style file contrib/styles/astyle.rc found."
- exit 1
-fi
-
-if test -z "$(command -v astyle)" ; then
- echo "*** No astyle program found."
+if ! [ -x "$(command -v clang-format)" ]; then
+ echo "*** No clang-format program found."
echo "***"
- echo "*** You can download astyle from http://astyle.sourceforge.net/"
- echo "*** Note that you will need exactly version 2.04 (no newer or"
- echo "*** older version will yield the correct indentation)."
- echo "*** You can run the 'setup_astyle.sh' script for that."
+ echo "*** You can run the 'download_clang_format' script or the"
+ echo "*** 'compile_clang_format' script for obtaining a compatible"
+ echo "*** binary and installing to an appropriate directory."
exit 1
fi
-if test "$(astyle --version 2>&1)" != "Artistic Style Version 2.04" ; then
- echo "*** Found a version of astyle different than the required version 2.04."
+# Make sure to have the right version. We know that clang-6.0.0
+# and clang-6.0.1 work. Hence, test for clang-6.0.
+CLANG_FORMAT_VERSION="$(clang-format --version)"
+CLANG_FORMAT_MAJOR_VERSION=$(echo "${CLANG_FORMAT_VERSION}" | sed 's/^[^0-9]*\([0-9]*\).*$/\1/g')
+CLANG_FORMAT_MINOR_VERSION=$(echo "${CLANG_FORMAT_VERSION}" | sed 's/^[^0-9]*[0-9]*\.\([0-9]*\).*$/\1/g')
+
+if [ "${CLANG_FORMAT_MAJOR_VERSION}" -ne 6 ] || [ "${CLANG_FORMAT_MINOR_VERSION}" -ne 0 ]; then
+ echo "*** Found a version of clang-format different than the required version 6.0."
exit 1
fi
# collect all header and source files and process them in batches of 50 files
# with up to 10 in parallel
-find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 astyle --options=contrib/styles/astyle.rc
+find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 clang-format -i
# use the same process to set file permissions for all source files
find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 chmod 644
find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 1 -P 10 -I {} bash -c 'dos_to_unix "$@"' _ {}
# format .inst.in files. We need to replace \{ and \} because it confuses
-# astyle.
+# clang-format
format_inst()
{
f=$1
cp "$f" "$f.tmp"
sed -i.orig 's#\\{#{ //#g' "$f.tmp"
sed -i.orig 's#\\}#} //#g' "$f.tmp"
- astyle --options=none --quiet "$f.tmp"
+ clang-format -i "$f.tmp"
sed -i.orig 's#{ //#\\{#g' "$f.tmp"
sed -i.orig 's#} //#\\}#g' "$f.tmp"
if ! diff -q "$f" "$f.tmp" >/dev/null
<h3>Notes on deal.II indentation</h3>
-<p>deal.II uses <code>astyle</code> 2.04 to normalize indentation. A
+<p>deal.II uses <code>clang-format</code> 6.0 to normalize indentation. A
style file is provided at
<code>
<pre>
- ./contrib/styles/astyle.rc
+ ${SOURCE_DIR}/.clang-format
</pre>
</code>
<p>Before a commit, you should run
<code>
<pre>
- astyle --options=<SOURCE DIRECTORY>/contrib/styles/astyle.rc <file>
+ clang-format -i <file>
</pre>
</code>
on each of your files. This will make sure indentation is conforming to the
-style guidelines outlined in this page. Alternatively, if you are using a recent
-version of the library, you can run
+style guidelines outlined in this page. Alternatively, you can run
<code>
<pre>
make indent
equivalents (i.e., use <code>&&</code>, <code>||</code>, and <code>!</code>
instead of <code>and</code>, <code>or</code>, and <code>not</code>).
-<li> In the implementation files, after each function, at least three
- empty lines are expected to
- enable better readability. One empty line occurs in functions to
- group blocks of code, two empty lines are not enough to visibly
+<li> In the implementation files, after each function, three empty lines are
+ expected to enable better readability. One empty line occurs in functions to
+ group blocks of code, since two empty lines are not enough to visibly
distinguish sufficiently that the code belongs to two different functions.</li>
<li> Whenever an integer variable can only assume nonnegative values,