Skip to content

Commit 87fb2c2

Browse files
committed
MANTA-1534 Update formatting scripts
1 parent 26fcd08 commit 87fb2c2

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed
2.06 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
#!/usr/bin/env bash
22
#
3-
# run astyle on all cxx source
3+
# run clang-format on all cxx source
44
#
55

66
set -o nounset
77

8-
scriptName=$(basename $0)
8+
this_dir=$(dirname $0)
99

10-
if ! which -a astyle > /dev/null 2>&1 ; then
11-
echo "ERROR: Can't find required utility 'astyle' in PATH" 1>&2
12-
exit 1;
13-
fi
10+
cxx_base_dir=$this_dir/../../src/c++
1411

15-
thisDir=$(dirname $0)
12+
get_c_and_cpp_files() {
13+
find $cxx_base_dir \( -name *.cpp -or -name *.cc -or -name *.c -or -name *.hpp -or -name *.hh -or -name *.h \)
14+
}
1615

17-
cxx_base_dir=$thisDir/../../src/c++
16+
# remove windows line endings from source:
17+
get_c_and_cpp_files | xargs -P8 -n1 sed $'s/\r$//' -i
1818

19-
20-
cd $cxx_base_dir
21-
astyle \
22-
--style=ansi \
23-
--align-pointer=type \
24-
--max-instatement-indent=80 \
25-
--min-conditional-indent=0 \
26-
--pad-header \
27-
--lineend=linux \
28-
--suffix=none \
29-
--recursive \
30-
"*.cpp" "*.hh" "*.h" "*.h.in"
31-
32-
#--keep-one-line-blocks \
33-
#--keep-one-line-statements \
19+
# general c/c++ source reformatting:
20+
get_c_and_cpp_files | xargs -P8 -n1 $this_dir/clang-format -style=file -i
21+

src/c++/.clang-format

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
BasedOnStyle: Google
2+
3+
# These are already part of Google style, but explicitly add them here because
4+
# they're called out in the coding guidelines:
5+
Standard: Cpp11
6+
IndentWidth: 2
7+
UseTab: Never
8+
9+
# Google default of 80 columns is a little tight:
10+
ColumnLimit: 110
11+
12+
# Protect long string literals already in source:
13+
BreakStringLiterals: false
14+
15+
# Comment lines that follow these patterns are likely to be commented out code. Don't reflow these.
16+
#
17+
# Patterns in this regex are:
18+
# 1. a line comment (ie. a second one inside of the first comment)
19+
# 2. preprocessor directive
20+
# 3. various common code line endings
21+
CommentPragmas: '(//|^\s*#|(;|:|"|{|}|\(|\)|\[|\]|<|>)\s*$)'
22+
23+
# Indent before the ':'
24+
ConstructorInitializerIndentWidth: 2
25+
26+
# If false, leave case labels at the same level as the switch:
27+
IndentCaseLabels: false
28+
29+
# Set the indent for public/protected/private in classes:
30+
AccessModifierOffset: -2
31+
32+
# Only allow empty functions and inline methods in class headers to go on a single line:
33+
AllowShortFunctionsOnASingleLine: Inline
34+
35+
# Use one pointer alignment everywhere:
36+
DerivePointerAlignment: false
37+
38+
# Try to preserve the dominant alignment style
39+
AlignConsecutiveAssignments: true
40+
AlignConsecutiveDeclarations: true
41+
42+
# Try to preserve the dominant style for function parameters:
43+
AlignAfterOpenBracket: AlwaysBreak
44+
BinPackArguments: false
45+
BinPackParameters: false
46+
47+
# This copies the Google format for brace breaking, except for adding a break after functions
48+
BreakBeforeBraces: Custom
49+
BraceWrapping:
50+
AfterClass: false
51+
AfterControlStatement: false
52+
AfterEnum: false
53+
AfterFunction: true
54+
AfterNamespace: false
55+
AfterObjCDeclaration: false
56+
AfterStruct: false
57+
AfterUnion: false
58+
AfterExternBlock: false
59+
BeforeCatch: false
60+
BeforeElse: false
61+
IndentBraces: false
62+
SplitEmptyFunction: true
63+
SplitEmptyRecord: true
64+
SplitEmptyNamespace: true
65+

0 commit comments

Comments
 (0)