1#!/usr/bin/env python 2 3from __future__ import print_function 4import re 5import sys 6 7categories = [] 8defines = [] 9excludes = [] 10bases = [] 11 12if __name__ == '__main__': 13 out = sys.stdout 14 filenames = sys.argv[1:] 15 16 while filenames and filenames[0].startswith('-'): 17 option = filenames.pop(0) 18 if option == '-o': out = open(filenames.pop(0), 'w') 19 elif option.startswith('-C'): categories += option[2:].split(',') 20 elif option.startswith('-D'): defines += option[2:].split(',') 21 elif option.startswith('-X'): excludes += option[2:].split(',') 22 elif option.startswith('-B'): bases += option[2:].split(',') 23 24 excludes = [re.compile(exclude) for exclude in excludes] 25 exported = [] 26 27 for filename in filenames: 28 for line in open(filename).readlines(): 29 name, _, _, meta, _ = re.split('\s+', line) 30 if any(p.match(name) for p in excludes): continue 31 meta = meta.split(':') 32 assert meta[0] in ('EXIST', 'NOEXIST') 33 assert meta[2] in ('FUNCTION', 'VARIABLE') 34 if meta[0] != 'EXIST': continue 35 if meta[2] != 'FUNCTION': continue 36 def satisfy(expr, rules): 37 def test(expr): 38 if expr.startswith('!'): return not expr[1:] in rules 39 return expr == '' or expr in rules 40 return all(map(test, expr.split(','))) 41 if not satisfy(meta[1], defines): continue 42 if not satisfy(meta[3], categories): continue 43 exported.append(name) 44 45 for filename in bases: 46 for line in open(filename).readlines(): 47 line = line.strip() 48 if line == 'EXPORTS': continue 49 if line[0] == ';': continue 50 exported.append(line) 51 52 print('EXPORTS', file=out) 53 for name in sorted(exported): print(' ', name, file=out) 54