Tweaked single include merging to remove comment blocks

Also removed multiple blank lines
This commit is contained in:
Phil Nash 2012-05-09 19:37:51 +01:00
parent e0dd4a5469
commit aec1e5ed86
2 changed files with 27 additions and 629 deletions

View file

@ -5,11 +5,15 @@ import re
includesParser = re.compile( r'\s*#include\s*"(.*)"' )
guardParser = re.compile( r'\s*#.*_INCLUDED')
defineParser = re.compile( r'\s*#define')
commentParser1 = re.compile( r'^\s*/\*')
commentParser2 = re.compile( r'^\s*\*')
blankParser = re.compile( r'^\s*$')
seenHeaders = set([])
rootPath = os.path.join( os.path.realpath(os.path.dirname(sys.argv[0])), 'include/' )
def parseFile( path, filename ):
f = open( path + filename, 'r' )
blanks = 0
for line in f:
m = includesParser.match( line )
if m:
@ -18,7 +22,6 @@ def parseFile( path, filename ):
if not headerFile in seenHeaders:
seenHeaders.add( headerFile )
print "// #included from: " + header
print
if( headerPath == "internal" and path.endswith( "internal/" ) ):
headerPath = ""
sep = ""
@ -26,16 +29,23 @@ def parseFile( path, filename ):
parseFile( path + headerPath + sep, headerFile )
else:
parseFile( rootPath + headerPath + sep, headerFile )
elif not guardParser.match( line ):
print line.rstrip()
elif defineParser.match( line ):
print line.rstrip()
elif not guardParser.match( line ) and not commentParser1.match( line )and not commentParser2.match( line ):
if blankParser.match( line ):
blanks = blanks + 1
else:
blanks = 0
if blanks < 2:
print line.rstrip()
print "// This file has been merged from multiple headers. Please don't edit it directly"
print
print '#ifndef TWOBLUECUBES_CATCH_HPP_INCLUDED'
print '#define TWOBLUECUBES_CATCH_HPP_INCLUDED'
print "/*"
print " * This file has been merged from multiple headers. Please don't edit it directly"
print " * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved."
print " *"
print " * Distributed under the Boost Software License, Version 1.0. (See accompanying"
print " * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)"
print " */"
print '#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
print '#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
parseFile( rootPath, 'catch.hpp' )
print '#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED'
print
print '#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
print