From 7d6a5247954d16221dacbd7d0c2bf3eb4965ac00 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 28 Jun 2022 12:47:59 +0100 Subject: [PATCH] Add clang-format configuration and reformat script. --- .clang-format | 80 ++++++++++++++++++++++++++++++++++++++++ tools/reformat-source.sh | 18 +++++++++ 2 files changed, 98 insertions(+) create mode 100644 .clang-format create mode 100755 tools/reformat-source.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..64192eca --- /dev/null +++ b/.clang-format @@ -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 +... diff --git a/tools/reformat-source.sh b/tools/reformat-source.sh new file mode 100755 index 00000000..754717c4 --- /dev/null +++ b/tools/reformat-source.sh @@ -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}