# Non-string variables # # This is script is rather fragile, and tuned to the MacOS 10.1 header-files. # # We should probably use bgen, but how does one use that tool? import re import os from dupfile import * IDENT='[A-Za-z_][A-Za-z0-9_]*' attribute_unused=re.compile(r'__attribute__\s*\(\(_?_?unused_?_?\)\)') attribute_const=re.compile(r'__attribute__\s*\(\(_?_?const_?_?\)\)') def process_file(outfp, filename, match_prefix='', ignore_list=()): MATCH_RE=re.compile('%(match_prefix)s(.+\s+.+\([^);{]+\))\s*(?:AVAILABLE_MAC_OS_X_VERSION_10_\d_AND_LATER\w*\s*)?(?:[;{]|$)'%{ 'match_prefix':match_prefix, 'IDENT':IDENT}) fp = open(filename, 'r') outfp.write("\n# From: %s\n"%os.path.basename(filename)) in_class = 0 saved_line = None for ln in fp.xreadlines(): ln = attribute_unused.sub(' ', ln) ln = attribute_const.sub(' ', ln) # Skip declarations in objective-C class definitions if not in_class: if ln.startswith("@interface"): saved_line=None in_class = 1 continue else: if ln.startswith("@end"): in_class = 0 continue if saved_line is not None: ln = saved_line.rstrip() + ' ' + ln i = ln.find('//') if i != -1: ln = ln[:i] m = MATCH_RE.match(ln) if not m: if saved_line is None and ln.startswith(match_prefix): saved_line=ln else: saved_line=None continue prototype=m.group(1).strip() ign = 0 for i in ignore_list: if prototype.find(i) != -1: ign=1 break if not ign: outfp.write('%s\n'%prototype) def generate(dirname, fn = None, match_prefix='', ignore_list=()): if fn: fp = dupfile(fn, 'w') else: import sys fp = sys.stdout del sys fp.write("#\n") fp.write("# List of functions. Generated from files in \n") fp.write("# %s\n"%dirname) fp.write("# \n") fp.write("# Used to check for new functions\n") fp.write("# \n") fnames = [ os.path.join(dirname, fn) for fn in os.listdir(dirname) if fn.endswith('.h') ] fnames.sort() for f in fnames: process_file(fp, f, match_prefix, ignore_list) fp.close() if __name__ == "__main__": import sys generate(sys.argv[1], match_prefix=sys.argv[2])