-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_formatter.sh
executable file
·84 lines (72 loc) · 2.06 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
79
80
81
82
83
84
#!/bin/bash
#######################################
required_command="astyle"
code_directory="src/"
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**.C,**.H --exclude=lnInclude"
[[ $# != 0 ]] && tutorial_files=$@ || tutorial_files="--recursive $tutorial_directory**.C,**.H --exclude=ITHACAoutput --exclude=ITHACAoutput_old"
echo $tutorial_files
echo $src_files
for f in $(find . -name "*.H" -o -name "*.C"); do
sed -i -e '$a\' $f
done
# 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\
--close-templates\
--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\
--close-templates\
--max-code-length=80\
--mode=c\
--ignore-exclude-errors\
$tutorial_files