1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # This file is part of rasdaman community.
|
---|
4 | #
|
---|
5 | # Rasdaman community is free software: you can redistribute it and/or modify
|
---|
6 | # it under the terms of the GNU General Public License as published by
|
---|
7 | # the Free Software Foundation, either version 3 of the License, or
|
---|
8 | # (at your option) any later version.
|
---|
9 | #
|
---|
10 | # Rasdaman community is distributed in the hope that it will be useful,
|
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | # GNU General Public License for more details.
|
---|
14 | #
|
---|
15 | # You should have received a copy of the GNU General Public License
|
---|
16 | # along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | #
|
---|
18 | # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
|
---|
19 | # rasdaman GmbH.
|
---|
20 | #
|
---|
21 | # For more information please see <http://www.rasdaman.org>
|
---|
22 | # or contact Peter Baumann via <baumann@rasdaman.com>.
|
---|
23 | #
|
---|
24 | ########################################################################
|
---|
25 |
|
---|
26 | #
|
---|
27 | # This script reformats the C++/Java code in the rasdaman repository with astyle.
|
---|
28 | # Execute either
|
---|
29 | # * with no arguments from the top-level source directory, or
|
---|
30 | # * with a path to a specific file to be formated.
|
---|
31 | #
|
---|
32 |
|
---|
33 | usage() {
|
---|
34 | echo "Usage: /path/to/format-sources.sh [FILE]"
|
---|
35 | echo "With no arguments all C++ and Java files (recursively) are reformatted."
|
---|
36 | exit 1
|
---|
37 | }
|
---|
38 |
|
---|
39 | reformat() {
|
---|
40 | astyle \
|
---|
41 | --suffix=none \
|
---|
42 | --convert-tabs \
|
---|
43 | $EXCLUDE \
|
---|
44 | $RECURSIVE \
|
---|
45 | --options=none \
|
---|
46 | --add-brackets \
|
---|
47 | --convert-tabs \
|
---|
48 | --close-templates \
|
---|
49 | --pad-oper \
|
---|
50 | --pad-header \
|
---|
51 | --unpad-paren \
|
---|
52 | --align-pointer=type \
|
---|
53 | --align-reference=type \
|
---|
54 | --indent-preproc-define \
|
---|
55 | --indent=spaces=4 \
|
---|
56 | --formatted \
|
---|
57 | "$@"
|
---|
58 | }
|
---|
59 |
|
---|
60 | if [ -n "$1" ]; then
|
---|
61 | [ "$1" == "-h" -o "$1" == "--help" ] && usage
|
---|
62 | [ -f "$1" ] || usage
|
---|
63 | echo "Formatting file '$1'..."
|
---|
64 | echo "$1" | grep '.java' > /dev/null 2>&1
|
---|
65 | if [ $? -eq 0 ]; then
|
---|
66 | reformat --style=java --mode=java "$1"
|
---|
67 | else
|
---|
68 | reformat --style=allman --mode=c "$1"
|
---|
69 | fi
|
---|
70 | else
|
---|
71 | echo "Format all C++ and Java files in the current directory? (Enter to continue, Ctrl-C to abort)"
|
---|
72 | read
|
---|
73 | RECURSIVE="--recursive"
|
---|
74 | EXCLUDE="--exclude=third_party"
|
---|
75 | reformat --style=allman --mode=c --recursive *.cc *.hh *.sc *.c *.cpp '*.h'
|
---|
76 | reformat --style=java --mode=java --recursive *.java
|
---|
77 | fi
|
---|
78 |
|
---|
79 | echo "Done."
|
---|