forked from paparazzi/paparazzi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_code_style.sh
More file actions
executable file
·80 lines (73 loc) · 2.04 KB
/
fix_code_style.sh
File metadata and controls
executable file
·80 lines (73 loc) · 2.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
if ! type "astyle" > /dev/null; then
echo "You need to install astyle to use this script!"
exit 1
fi
if [ $# -eq 0 ]; then
echo "Please provide one or multiple files as arguments!"
exit 1
fi
ASTYLE_VERSION=$(astyle --version 2>&1 | awk '{print $4}' | head -1)
echo "Using astyle version $ASTYLE_VERSION"
set -f
# Safe version parsing with defaults
major=${ASTYLE_VERSION%%.*}
minor=$(echo "$ASTYLE_VERSION" | cut -d. -f2)
# Fix unary operator - quote variables and provide defaults
major=${major:-0}
minor=${minor:-0}
if [ "$major" -ge 3 ]; then
echo "Using AStyle 3.x options"
astyle --style=kr \
--indent=spaces=2 \
--convert-tabs \
--indent-switches \
--indent-preproc-block \
--pad-oper \
--pad-header \
--unpad-paren \
--keep-one-line-blocks \
--keep-one-line-statements \
--align-pointer=name \
--suffix=none \
--lineend=linux \
--ignore-exclude-errors-x \
--max-code-length=120 \
"$@"
elif [ "$major" -ge 2 ]; then
echo "Using AStyle 2.x options"
astyle --style=kr \
--indent=spaces=2 \
--convert-tabs \
--indent-switches \
--indent-preprocessor \
--pad-oper \
--pad-header \
--unpad-paren \
--keep-one-line-blocks \
--keep-one-line-statements \
--align-pointer=name \
--suffix=none \
--lineend=linux \
--add-brackets \
--ignore-exclude-errors-x \
--max-code-length=120 \
"$@"
else
echo "Using AStyle 1.x options"
astyle --style=kr \
--indent=spaces=2 \
--convert-tabs \
--indent-switches \
--indent-preprocessor \
--pad-oper \
--pad-header \
--unpad-paren \
--keep-one-line-blocks \
--keep-one-line-statements \
--align-pointer=name \
--suffix=none \
--lineend=linux \
--add-brackets \
"$@"
fi