-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat-source.sh
More file actions
executable file
·36 lines (31 loc) · 904 Bytes
/
format-source.sh
File metadata and controls
executable file
·36 lines (31 loc) · 904 Bytes
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
#!/usr/bin/env bash
if ! type -path clang-format &> /dev/null; then
echo "clang-format is not installed" >&2
exit 1;
fi
wdir=$(dirname "$(readlink -f "$0")")
srcdir="$wdir/src"
remove_eol_spaces=yes
function format_source {
if ! [ -d "$srcdir" ]; then
echo "source code directory not found at [$srcdir]" >&2
exit 1;
fi
find "$srcdir" -iname \*.cc \
-o -iname \*.h \
-o -iname \*.cpp \
-o -iname \*.cxx \
-o -iname \*.hpp \
-o -iname \*.hh |
xargs -r -n 1 -I@ clang-format -style=LLVM -i @
if [ "$remove_eol_spaces" = yes ]; then
find "$srcdir" -iname \*.cc \
-o -iname \*.h \
-o -iname \*.cpp \
-o -iname \*.cxx \
-o -iname \*.hpp \
-o -iname \*.hh |
xargs -r -n 1 -I@ sed -i 's!\s*$!!' @
fi
}
format_source "$@"