-
Notifications
You must be signed in to change notification settings - Fork 92
/
code_formatter.sh
executable file
·78 lines (67 loc) · 1.93 KB
/
code_formatter.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
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
#!/bin/bash
#######################################
required_command="astyle"
code_directory="include/"
code_exclude="include/external"
tutorial_directory="tutorials/"
#######################################
usage() {
echo
echo -e "\tUsage: $(basename $0) [files]"
echo
echo -e "\tIf files are not specified, $(basename $0) formats all ".C" and ".H" files"
echo -e "\tin source directory; otherwise, it formats all given files."
echo
echo -e "\tRequired command: $required_command"
echo
exit 0
}
[[ $1 == "-h" ]] && usage
# Test for required program
for comm in $required_command; do
command -v $comm >/dev/null 2>&1 || {
echo "I require $comm but it's not installed. Aborting." >&2;
exit 1
}
done
# Set the files to format
[[ $# != 0 ]] && src_files=$@ || src_files="--recursive $code_directory**.h,**.H --exclude=$code_exclude"
[[ $# != 0 ]] && tutorial_files=$@ || tutorial_files="--recursive $tutorial_directory**.cpp,**.H"
echo $tutorial_files
echo $src_files
# Here the important part: astyle formats the src files.
astyle --style=bsd\
--indent=spaces=4\
--indent-classes\
--indent-switches\
--indent-col1-comments\
--break-blocks\
--pad-oper\
--pad-comma\
--pad-header\
--delete-empty-lines\
--align-pointer=type\
--align-reference=type\
--add-braces\
--convert-tabs\
--max-code-length=80\
--mode=c\
$src_files
# Here the important part: astyle formats the tutorial files.
astyle --style=bsd\
--indent=spaces=4\
--indent-classes\
--indent-switches\
--indent-col1-comments\
--break-blocks\
--pad-oper\
--pad-comma\
--pad-header\
--delete-empty-lines\
--align-pointer=type\
--align-reference=type\
--add-braces\
--convert-tabs\
--max-code-length=80\
--mode=c\
$tutorial_files