ソースを参照

Add clang-format

Use clang-format-3.6 for now.
Tatsuhiro Tsujikawa 9 年 前
コミット
0a63a7ecc3
3 ファイル変更80 行追加0 行削除
  1. 65 0
      .clang-format
  2. 10 0
      Makefile.am
  3. 5 0
      src/message.h

+ 65 - 0
.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
+...
+

+ 10 - 0
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}

+ 5 - 0
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