1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#!/bin/bash
set -e
cd "$(dirname "$0")/.."
# Check or fix C source formatting with clang-format.
# Usage:
# scripts/check-format.sh # check only (exits non-zero on diff)
# scripts/check-format.sh fix # reformat files in place
mapfile -t FILES < <(find . -maxdepth 1 -name '*.c' -o -name '*.h' | sort)
if [ "$1" = "fix" ]; then
echo "==> Reformatting C sources..."
clang-format -i "${FILES[@]}"
echo "Done."
else
echo "==> Checking C source formatting..."
clang-format --dry-run --Werror "${FILES[@]}"
echo "Formatting OK."
fi
|