-
Notifications
You must be signed in to change notification settings - Fork 3
/
format.sh
executable file
·47 lines (37 loc) · 875 Bytes
/
format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
set -e
check() {
echo \
"-------------------------------
Checking source code formatting
-------------------------------"
local rc=0
local sources=$(find ./src -name \*.c -type f -or -name \*.h -type f)
for file in $sources; do
count=$(clang-format -output-replacements-xml $file | (grep offset || true) | wc -l)
if [ "$count" -gt "0" ]; then
echo "✗ $file"
rc=1
fi
done
if [ "$count" -gt "0" ]; then
echo ERROR: files are formatted incorrectly
exit 1
fi
exit $rc
}
format() {
find ./src -name \*.c -type f -or -name \*.h -type f | xargs clang-format --style=file -i
}
main() {
case "$1" in
check)
check
;;
format | *)
format
;;
esac
}
# Call main with all the arguments
main $@