2022-04-09 15:54:27 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Formatting rules are in .clang-format.
|
|
|
|
|
|
|
|
# To protect a block of code from automatic formatting, enclose in
|
|
|
|
# comments such as
|
|
|
|
#
|
|
|
|
# // clang-format off
|
|
|
|
# ...
|
|
|
|
# // clang-format on
|
|
|
|
|
|
|
|
# Sometimes, a comment of the form `// line-break` may appear in the
|
|
|
|
# code to prevent clang-format from removing an intentional line
|
|
|
|
# break.
|
|
|
|
|
|
|
|
# For emacs users, the file `.dir-locals.el` configures cc-mode for an
|
|
|
|
# indentation style that is close to but not exactly like what
|
|
|
|
# clang-format produces. clang-format is authoritative.
|
|
|
|
|
|
|
|
# Please see "Code Formatting" in the manual for additional notes.
|
|
|
|
|
2023-06-17 15:45:06 +00:00
|
|
|
# If a newer version of clang-format causes changes to the output that
|
|
|
|
# are improvements, bump the minimum required version of clang-format
|
|
|
|
# here, and update manual/contributing.rst. There's a comment there
|
|
|
|
# that refers to this comment. See also .clang-format.
|
2023-12-23 02:45:10 +00:00
|
|
|
min_version=18
|
2023-06-17 15:45:06 +00:00
|
|
|
|
|
|
|
clang_version=$(clang-format --version | \
|
|
|
|
awk '{for (i=1; i<=NF; i++) if ($i == "version") {print int($(i+1)); exit}}')
|
|
|
|
if [ "$clang_version" -lt "$min_version" ]; then
|
|
|
|
echo "clang-format version >= $min_version is required"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-04-09 15:54:27 +00:00
|
|
|
cd $(dirname $0)
|
|
|
|
for i in $(find . -name 'build*' -prune -o '(' \
|
|
|
|
-name '*.hh' -o -name '*.h' -o -name '*.cc' -o -name '*.c' \
|
|
|
|
')' -print); do
|
|
|
|
if clang-format < $i >| $i.new; then
|
|
|
|
if diff -q $i $i.new >/dev/null 2>/dev/null; then
|
|
|
|
echo "okay: $i"
|
|
|
|
rm $i.new
|
|
|
|
else
|
|
|
|
echo "updated: $i"
|
|
|
|
mv $i.new $i
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|