Debian Codegraph @

scripts/check-format.sh

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