diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..3e35d68e --- /dev/null +++ b/.clang-format @@ -0,0 +1,65 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: true +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakTemplateDeclarations: false +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BinPackParameters: true +BinPackArguments: true +ColumnLimit: 80 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +DerivePointerAlignment: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: false +IndentWrappedFunctionNames: false +IndentFunctionDeclarationAfterType: false +MaxEmptyLinesToKeep: 1 +KeepEmptyLinesAtTheStartOfBlocks: true +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakString: 1000 +PenaltyBreakFirstLessLess: 120 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +SpacesBeforeTrailingComments: 1 +Cpp11BracedListStyle: true +Standard: Cpp11 +IndentWidth: 2 +TabWidth: 8 +UseTab: Never +BreakBeforeBraces: Stroustrup +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterCStyleCast: false +SpacesInContainerLiterals: true +SpaceBeforeAssignmentOperators: true +ContinuationIndentWidth: 4 +CommentPragmas: '^ IWYU pragma:' +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +SpaceBeforeParens: ControlStatements +DisableFormat: false +... + diff --git a/Makefile.am b/Makefile.am index c6b7c4cd..bdd7d513 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,8 @@ EXTRA_DIST = config.rpath \ dist_doc_DATA = README README.rst README.html +.PHONY: clang-format + if HAVE_RST2HTML README.html: README.rst $(RST2HTML) $< > $@ @@ -27,3 +29,11 @@ endif # !HAVE_RST2HTML dist_noinst_DATA = LICENSE.OpenSSL +# Format source files using clang-format. Don't format source files +# under deps directory since we are not responsible for thier coding +# style. +clang-format: + CLANGFORMAT=`git config --get clangformat.binary`; \ + test -z $${CLANGFORMAT} && CLANGFORMAT="clang-format"; \ + $${CLANGFORMAT} -i src/*.{c,cc,h} src/includes/aria2/*.h \ + examples/*.cc test/*.{cc,h} diff --git a/src/message.h b/src/message.h index c1ea7883..4705d7fb 100644 --- a/src/message.h +++ b/src/message.h @@ -37,6 +37,8 @@ #include "common.h" +// clang-format off + #define MSG_SEGMENT_DOWNLOAD_COMPLETED \ "CUID#%" PRId64 " - The download for one segment completed successfully." #define MSG_NO_SEGMENT_AVAILABLE "CUID#%" PRId64 " - No segment available." @@ -286,4 +288,7 @@ #define EX_EXCEPTION_CAUGHT _("Exception caught") #define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u") #define EX_FILE_LENGTH_MISMATCH_BETWEEN_LOCAL_AND_REMOTE _("Invalid file length. Cannot continue download %s: local %s, remote %s") + +// clang-format on + #endif // D_MESSAGE_H