diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-03-01 11:10:01 -0500 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-03-01 11:10:01 -0500 |
| commit | a975744835bb87e3cf62701e13248d66f1dac1df (patch) | |
| tree | bca5ab1f29594688c43e0c36c9eb2f0c5c8e66c6 /tools/indent.py | |
| parent | 351c56649bfd8487676704a10995d736d1d893cc (diff) | |
| parent | c98f4d81aa5d4113ceea58ce6db4bebab5c99735 (diff) | |
Merge branch 'master' into docuser
* New manpage: mtracebis.rst
* Makefile.am includes mtracebis.rst
* configure.ac lines removed
* Debian packaging files updated
* Fixed up manpage |seealso-programs| in the process
* Centos7 build package list updated to include systemd-devel
* New paragraph on netns vrf support in zebra manpage
Conflicts:
configure.ac
debianpkg/backports/ubuntu14.04/debian/frr.install
debianpkg/frr.install
doc/Makefile.am
doc/developer/Building_FRR_on_CentOS7.rst
doc/zebra.8.in
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tools/indent.py')
| -rw-r--r-- | tools/indent.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/indent.py b/tools/indent.py new file mode 100644 index 0000000000..560c13c77d --- /dev/null +++ b/tools/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)|ALIAS)\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) |
