-
Notifications
You must be signed in to change notification settings - Fork 4
/
astyle.bash
executable file
·53 lines (47 loc) · 968 Bytes
/
astyle.bash
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
48
49
50
51
52
53
#!/usr/bin/env bash
# files to check
if [ $# -eq 0 ]; then
# No arguments provided
FILES=`git diff --name-only --diff-filter=ACMR`
else
FILES="$@"
fi
echo "running astyle for $FILES"
OPTIONS=$(cat <<-END
--style=ansi
--indent=spaces=4
--convert-tabs
--lineend=linux
--suffix=none
--unpad-paren
--indent-switches
--indent-cases
--indent-labels
--pad-header
END
)
RETURN=0
ASTYLE=$(which astyle)
if [ $? -ne 0 ]; then
echo "[!] astyle not installed." >&2
exit 1
fi
$ASTYLE --version
for FILE in $FILES; do
if [[ $FILE =~ \.(c|cpp|h|hpp)$ ]]; then
$ASTYLE $OPTIONS < $FILE > $FILE.astyle
cmp -s $FILE $FILE.astyle
if [ $? -ne 0 ]; then
echo "Changed $FILE" >&2
RETURN=1
diff $FILE $FILE.astyle >&2
mv $FILE.astyle $FILE
else
rm $FILE.astyle
echo "Unchanged $FILE" >&2
fi
else
echo "Skipping $FILE" >&2
fi
done
exit $RETURN