From 4a95f48489d0046c4aad919d73573e1a6616688b Mon Sep 17 00:00:00 2001 From: Nils Gillmann Date: Thu, 17 May 2018 16:38:30 +0000 Subject: [PATCH] contrib/removetrailingwhitespace: sed the python Signed-off-by: Nils Gillmann --- contrib/Makefile.am | 2 ++ contrib/removetrailingwhitespace | 14 -------------- contrib/removetrailingwhitespace.py.in | 15 +++++++++++++++ pre-commit | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) delete mode 100755 contrib/removetrailingwhitespace create mode 100755 contrib/removetrailingwhitespace.py.in diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 1db5b3091..40e6d3e92 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -19,6 +19,7 @@ endif noinst_SCRIPTS = \ terminate.py \ pydiffer.py \ + removetrailingwhitespace.py \ gnunet_pyexpect.py \ gnunet_janitor.py \ gnunet-chk.py @@ -52,6 +53,7 @@ EXTRA_DIST = \ gnunet_pyexpect.py.in \ gnunet_janitor.py.in \ gnunet-chk.py.in \ + removetrailingwhitespace.py.in \ pydiffer.py.in \ gnunet-gns-import.sh \ openvpn-tap32/tapw32/tap0901.sys \ diff --git a/contrib/removetrailingwhitespace b/contrib/removetrailingwhitespace deleted file mode 100755 index 9e620cbb2..000000000 --- a/contrib/removetrailingwhitespace +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/python - -import sys -import re - -for fileName in sys.argv[1:]: - f = open(fileName, 'r+') - fileString = f.read() - - fileString = re.sub(r'[ ]+\n', r'\n', fileString) - fileString = re.sub(r'\r', r'', fileString) - f.seek(0) - f.write(fileString) - f.truncate(len(fileString)) diff --git a/contrib/removetrailingwhitespace.py.in b/contrib/removetrailingwhitespace.py.in new file mode 100755 index 000000000..5824fb591 --- /dev/null +++ b/contrib/removetrailingwhitespace.py.in @@ -0,0 +1,15 @@ +#!@PYTHON@ + +import sys +import re + + +for fileName in sys.argv[1:]: + f = open(fileName, 'r+') + fileString = f.read() + + fileString = re.sub(r'[ ]+\n', r'\n', fileString) + fileString = re.sub(r'\r', r'', fileString) + f.seek(0) + f.write(fileString) + f.truncate(len(fileString)) diff --git a/pre-commit b/pre-commit index 5213f2cf4..777728a6b 100755 --- a/pre-commit +++ b/pre-commit @@ -12,8 +12,8 @@ find $PATHS -name "*.c" -exec indent {} \; find $PATHS -name "*.h" -exec indent {} \; find $PATHS -name "*.c" -exec indent {} \; find $PATHS -name "*.h" -exec indent {} \; -find $PATHS -name "*.c" -exec contrib/removetrailingwhitespace {} \; -find $PATHS -name "*.h" -exec contrib/removetrailingwhitespace {} \; +find $PATHS -name "*.c" -exec contrib/removetrailingwhitespace.py {} \; +find $PATHS -name "*.h" -exec contrib/removetrailingwhitespace.py {} \; if test -x "`which 'dos2unix'`" then find $PATHS -name "*.c" -exec dos2unix {} \; -- 2.25.1