Add clang-format configuration and reformat script.

This commit is contained in:
Martin Ling
2022-06-28 12:47:59 +01:00
parent ebb9e43fde
commit 7d6a524795
2 changed files with 98 additions and 0 deletions

80
.clang-format Normal file
View File

@ -0,0 +1,80 @@
# clang-format configuration file. Intended for clang-format >= 14.
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: None
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros: ['ADDAPI', 'ADDCALL']
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterStruct: false
AfterUnion: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakStringLiterals: false
ColumnLimit: 90
ContinuationIndentWidth: 8
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentWidth: 8
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
PenaltyBreakAssignment: 0
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakOpenParenthesis: 0
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: false
SeparateDefinitionBlocks: Always
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 8
UseTab: ForContinuationAndIndentation
...

18
tools/reformat-source.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
VERSION=`clang-format --version | grep -o '[^ ]*$' | cut -d '.' -f 1`
if [ "$VERSION" -ge "14" ]; then
CLANG_FORMAT=clang-format
elif clang-format-14 --version > /dev/null; then
CLANG_FORMAT=clang-format-14
else
echo "clang-format version 14 or higher is required."
exit 1
fi
$CLANG_FORMAT \
-i \
--style=file \
host/libhackrf/src/*.{c,h} \
host/hackrf-tools/src/*.c \
firmware/{common,common/rad1o,hackrf_usb}/*.{c,h}