1 2# Copyright 2017 Peter Dimov. 3# 4# Distributed under the Boost Software License, Version 1.0. 5# 6# See accompanying file LICENSE_1_0.txt or copy at 7# http://www.boost.org/LICENSE_1_0.txt 8 9import os.path 10import re 11import sys 12 13included = [] 14 15def scan_header( prefix, dir, fn ): 16 17 path = os.path.join( prefix, dir, fn ) 18 19 if path in included: 20 21 return 22 23 included.append( path ) 24 25 with open( path, 'r' ) as header: 26 27 for line in header: 28 29 m = re.match( '[ \t]*#[ \t]*include[ \t]*(["<])([^">]*)[">]', line ) 30 31 r = False 32 33 if m: 34 35 h = m.group( 2 ) 36 37 hfn1 = os.path.join( prefix, h ) 38 hfn2 = os.path.join( prefix, dir, h ) 39 40 if m.group( 1 ) == '"' and os.path.exists( hfn2 ): 41 42 scan_header( prefix, os.path.join( dir, os.path.dirname( hfn2 ) ), os.path.basename( hfn2 ) ) 43 r = True 44 45 elif os.path.exists( hfn1 ): 46 47 scan_header( prefix, os.path.dirname( h ), os.path.basename( h ) ) 48 r = True 49 50 if not r: 51 52 sys.stdout.write( line ) 53 54scan_header( 'include', 'boost', 'mp11.hpp' ) 55