[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 3/3] xen/tools: script for automatically adjusting the coding style to xen style


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>
  • Date: Tue, 9 Sep 2014 05:32:09 +0300
  • Cc: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>
  • Comment: DomainKeys? See http://domainkeys.sourceforge.net/
  • Delivery-date: Tue, 09 Sep 2014 02:32:42 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=tLuAa+e1qL/WgZl7jHg4CAuiUDqfho5WGBFqq10VPnhjCVXFsds2m4S7UA1gIPlbFkif+Vp5Mk7+y9Yo8jEO9mMYGQexHwvNj9mRtmvUxJmkiCOc4eNGtybdi3j51M+me4QEnnOni+akBXja6fdjE7d64KHqDOXDA4tsf9vQX/C5SXgcK7a72xr8tPiF17y5DA1MkDy16mUDzhfaPDMr9pJsrh5KkdCNWg3asa3MBObNEus2HAJeCF85scqB04mri7Fil1pexfnWeIVpzdxA600Q4mDuoTlXcpmME9yEU8c94UEjmtYCwi+DxCNySE+Tdh2K/IqXYo4BL2Y7e7XDKQ==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp;
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

This is a clang-format wrapper script that can be used to do the bulk of the
coding style work on a foreign source file. It is not yet complete, but it's
sufficient for 98% of the cases.

Signed-off-by: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>
---
 xen/tools/xen-indent | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100755 xen/tools/xen-indent

diff --git a/xen/tools/xen-indent b/xen/tools/xen-indent
new file mode 100755
index 0000000..6be507c
--- /dev/null
+++ b/xen/tools/xen-indent
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+CLANG_FORMAT=`which clang-format 2>/dev/null`
+
+if [ "x$CLANG_FORMAT" = "x" ]; then
+       printf "Error: \`clang-format' is not installed. It is usually part of 
clang (3.4 and newer)\n" >&2
+       exit 1
+fi
+
+if [ "x$1" = "x" ]; then
+       printf "Usage: $0 <file[s]>\n"
+       exit 2
+fi
+
+for i in $@; do
+       DN=`dirname "$i"`
+       cat >"$DN/.clang-format" <<EOF
+---
+AccessModifierOffset:                           -8
+IndentWidth:                                    4
+TabWidth:                                       4
+ConstructorInitializerIndentWidth:              4
+AlignEscapedNewlinesLeft:                       true
+AlignTrailingComments:                          true
+AllowAllParametersOfDeclarationOnNextLine:      true
+AllowShortIfStatementsOnASingleLine:            false
+AllowShortLoopsOnASingleLine:                   false
+AllowShortFunctionsOnASingleLine:               false
+AlwaysBreakTemplateDeclarations:                false
+AlwaysBreakBeforeMultilineStrings:              false
+BreakBeforeBinaryOperators:                     false
+BreakBeforeTernaryOperators:                    true
+BreakConstructorInitializersBeforeComma:        false
+BinPackParameters:                              true
+ColumnLimit:                                    80
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+DerivePointerBinding:                           false
+ExperimentalAutoDetectBinPacking:               false
+IndentCaseLabels:                               false
+MaxEmptyLinesToKeep:                            1
+NamespaceIndentation:                           All
+ObjCSpaceBeforeProtocolList:                    true
+PenaltyBreakBeforeFirstCallParameter:           19
+PenaltyBreakComment:                            60
+PenaltyBreakString:                             1000
+PenaltyBreakFirstLessLess:                      120
+PenaltyExcessCharacter:                         1000000
+PenaltyReturnTypeOnItsOwnLine:                  60
+PointerBindsToType:                             false
+SpacesBeforeTrailingComments:                   1
+Cpp11BracedListStyle:                           false
+Standard:                                       Cpp11
+UseTab:                                         Never
+BreakBeforeBraces:                              Allman
+IndentFunctionDeclarationAfterType:             false
+SpaceBeforeParens:                              ControlStatements
+SpacesInParentheses:                            false
+SpacesInAngles:                                 false
+SpaceInEmptyParentheses:                        false
+SpacesInCStyleCastParentheses:                  false
+SpaceAfterControlStatementKeyword:              true
+SpaceBeforeAssignmentOperators:                 true
+ContinuationIndentWidth:                        4
+EOF
+       ERR=0
+       $CLANG_FORMAT "$i" >"${i}.clang-tmp" || ERR=1
+       rm -f "$DN/.clang-format"
+       if [ $ERR -ne 0 ]; then
+               rm -f "${i}.clang-tmp"
+               exit 3
+       fi
+       sed 's#if\s*(\(.*\))#if ( \1 )#m' "${i}.clang-tmp" >"${i}.clang-tmp.1"
+       sed 's#switch\s*(\(.*\))#switch ( \1 )#m' "${i}.clang-tmp.1" 
>"${i}.clang-tmp.2"
+       sed 's#while\s*(\(.*\))#while ( \1 )#m' "${i}.clang-tmp.2" 
>"${i}.clang-tmp.3"
+       mv -f "${i}.clang-tmp.3" "${i}"
+       rm -f "${i}.clang-tmp" "${i}.clang-tmp.1" "${i}.clang-tmp.2"
+done
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.