Skip to content

Commit 2d47a7e

Browse files
authored
Merge pull request #1645 from fpagliughi/clang_format
Added a .clang-format file and bash script to run it
2 parents 6f97eca + 88f6011 commit 2d47a7e

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

.clang-format

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
Language: C
3+
4+
# Indentation: tabs, one tab per indent level
5+
# The Emacs footer in source files specifies indent-tabs-mode: t
6+
UseTab: ForIndentation
7+
TabWidth: 4
8+
IndentWidth: 4
9+
ContinuationIndentWidth: 8
10+
IndentCaseLabels: true
11+
IndentCaseBlocks: false
12+
IndentGotoLabels: false
13+
IndentPPDirectives: None
14+
IndentWrappedFunctionNames: false
15+
16+
# Braces: Allman style - opening brace on its own line for everything
17+
BreakBeforeBraces: Allman
18+
19+
# Alignment
20+
AlignAfterOpenBracket: DontAlign
21+
AlignConsecutiveAssignments: false
22+
AlignConsecutiveDeclarations: false
23+
AlignConsecutiveMacros: false
24+
AlignEscapedNewlines: Left
25+
AlignOperands: true
26+
AlignTrailingComments: true
27+
28+
# Pointer style: mixed in codebase (char* ptr and char *ptr both appear),
29+
# derive per file with Left as default
30+
PointerAlignment: Left
31+
DerivePointerAlignment: true
32+
33+
# Spaces
34+
SpaceAfterCStyleCast: false
35+
SpaceAfterLogicalNot: false
36+
SpaceBeforeAssignmentOperators: true
37+
SpaceBeforeParens: ControlStatements
38+
SpaceInEmptyBlock: false
39+
SpaceInEmptyParentheses: false
40+
SpacesInCStyleCastParentheses: false
41+
SpacesInParentheses: false
42+
SpacesInSquareBrackets: false
43+
SpacesBeforeTrailingComments: 1
44+
45+
# Line breaking
46+
ColumnLimit: 120
47+
AllowAllArgumentsOnNextLine: true
48+
AllowAllParametersOfDeclarationOnNextLine: true
49+
AllowShortBlocksOnASingleLine: Never
50+
AllowShortCaseLabelsOnASingleLine: false
51+
AllowShortEnumsOnASingleLine: false
52+
AllowShortFunctionsOnASingleLine: None
53+
AllowShortIfStatementsOnASingleLine: Never
54+
AllowShortLoopsOnASingleLine: false
55+
AlwaysBreakAfterReturnType: None
56+
AlwaysBreakBeforeMultilineStrings: false
57+
BinPackArguments: true
58+
BinPackParameters: true
59+
BreakBeforeBinaryOperators: None
60+
BreakBeforeTernaryOperators: true
61+
BreakStringLiterals: true
62+
63+
# Includes: preserve existing order, do not sort
64+
SortIncludes: Never
65+
IncludeBlocks: Preserve
66+
67+
# Blank lines
68+
MaxEmptyLinesToKeep: 2
69+
70+
# Comments: do not reflow to preserve manual formatting
71+
ReflowComments: false
72+
73+
# Penalties for line breaking decisions
74+
PenaltyBreakBeforeFirstCallParameter: 19
75+
PenaltyBreakComment: 300
76+
PenaltyBreakFirstLessLess: 120
77+
PenaltyBreakString: 1000
78+
PenaltyExcessCharacter: 1000000
79+
PenaltyReturnTypeOnItsOwnLine: 60

fmt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
#
3+
# Runs clang format over the whole project tree, excluding the 'build/' directory.
4+
#
5+
6+
find . -type d \( -path './build' \) -prune -iname '*.h' -o -iname '*.c' | xargs clang-format -i
7+

0 commit comments

Comments
 (0)