summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-07-17 14:00:23 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2017-07-17 14:00:23 +0200
commit888ac268a0077fc9ebd1218cec6ae472af0bfc40 (patch)
tree5fa6358a650c1b078f36b2d9ecaf94a368fa2d53
parentMerge pull request #818 from donaldsharp/eigrp_afi (diff)
downloadfrr-888ac268a0077fc9ebd1218cec6ae472af0bfc40.tar.xz
frr-888ac268a0077fc9ebd1218cec6ae472af0bfc40.zip
*: add indent control filesreindent-master-before
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--.clang-format25
-rw-r--r--indent.py47
2 files changed, 72 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..07f558d92
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,25 @@
+---
+BasedOnStyle: LLVM
+Language: Cpp
+IndentWidth: 8
+UseTab: Always
+BreakBeforeBraces: Linux
+AlwaysBreakBeforeMultilineStrings: true
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+IndentCaseLabels: false
+AlignEscapedNewlinesLeft: false
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AlignAfterOpenBracket: true
+SpaceAfterCStyleCast: false
+MaxEmptyLinesToKeep: 2
+BreakBeforeBinaryOperators: NonAssignment
+BreakStringLiterals: false
+SortIncludes: false
+IncludeCategories:
+ - Regex: '^(<|lib)'
+ Priority: 0
+CommentPragmas: '\$(FRR|clippy)'
+ContinuationIndentWidth: 8
diff --git a/indent.py b/indent.py
new file mode 100644
index 000000000..a2c18e556
--- /dev/null
+++ b/indent.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# 2017 by David Lamparter, placed in public domain
+
+import sys, re, subprocess, os
+
+# find all DEFUNs
+defun_re = re.compile(
+ r'^(DEF(UN(_NOSH|_HIDDEN)?|PY)\s*\(.*?)^(?=\s*\{)',
+ re.M | re.S)
+define_re = re.compile(
+ r'((^#\s*define[^\n]+[^\\]\n)+)',
+ re.M | re.S)
+# find clang-format control that we just inserted
+clean_re = re.compile(
+ r'^/\* \$FRR indent\$ \*/\s*\n\s*/\* clang-format (on|off) \*/\s*\n',
+ re.M)
+
+def wrap_file(fn):
+ with open(fn, 'r') as fd:
+ text = fd.read()
+
+ repl = r'/* $FRR indent$ */\n/* clang-format off */\n' + \
+ r'\1' + \
+ r'/* $FRR indent$ */\n/* clang-format on */\n'
+
+ # around each DEFUN, insert an indent-on/off comment
+ text = defun_re.sub(repl, text)
+ text = define_re.sub(repl, text)
+
+ ci = subprocess.Popen(['clang-format'], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
+ stdout, ign = ci.communicate(text)
+ ci.wait()
+ if ci.returncode != 0:
+ raise IOError('clang-format returned %d' % (ci.returncode))
+
+ # remove the bits we inserted above
+ final = clean_re.sub('', stdout)
+
+ tmpname = fn + '.indent'
+ with open(tmpname, 'w') as ofd:
+ ofd.write(final)
+ os.rename(tmpname, fn)
+
+if __name__ == '__main__':
+ for fn in sys.argv[1:]:
+ wrap_file(fn)