From abc1c2ef374e100409ac3ae02ed6da1a0353425b Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Tue, 22 Apr 2008 19:38:45 +0200 Subject: [PATCH] Ignore whitespace after #include's. --- src/Core/Editors/fixincludes.py | 44 ++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Core/Editors/fixincludes.py b/src/Core/Editors/fixincludes.py index 6bcf69e..cf9300c 100755 --- a/src/Core/Editors/fixincludes.py +++ b/src/Core/Editors/fixincludes.py @@ -1,12 +1,13 @@ #!/usr/bin/env python -def doImport(name): +def doSortIncludes(name): print('Processing ' + name) try: includesfound = False precontent = [] + gincludes = [] includes = [] postcontent = [] @@ -14,7 +15,10 @@ def doImport(name): lines = file.readlines() for line in lines: - if line.startswith('#include'): + if line.startswith('#include <'): + gincludes.append(line) + includesfound = True + elif line.startswith('#include'): includes.append(line) includesfound = True else: @@ -28,33 +32,45 @@ def doImport(name): if len(includes) == 0: return; - includes.sort() + gincludes.sort() + gincludes.append("\n") + + includes.sort() + includes.append("\n") + + postcontentclean = [] + cleaning = True + + for line in postcontent: + if cleaning and (len(line) == 0 or line.expandtabs().isspace() ): + continue + + postcontentclean.append(line) + cleaning = False try: fixfile = open(name, 'w') fixfile.writelines(precontent) + fixfile.writelines(gincludes) fixfile.writelines(includes) - fixfile.writelines(postcontent) + fixfile.writelines(postcontentclean) finally: fixfile.close() -if __name__ == "__main__": - print("Trying file opening") - afile = open('test.txt','w') - afile.write('lol') - print('Success') +if __name__ == "__main__": import sys - files = sys.argv + filenames = sys.argv - if len(files) == 1: + if len(filenames) == 1: import glob print("no args, using all *.cpp and *.h files") - files = glob.glob('*.cpp') + glob.glob('*.h') + filenames = glob.glob('*.cpp') + glob.glob('*.h') - for arg in files: - doImport(arg) + for filename in filenames: + # doRemoveWhitespace(filename) + doSortIncludes(filename) -- 2.11.4.GIT