#!/usr/bin/env python import sys import re files = sys.argv[1:] sht_re = re.compile('.*struct\s*scsi_host_template\s*(\w+)\s*(=|$)', re.M); ops_re = re.compile('.*struct\s*ata_port_operations\s*(\w+)\s*(=|$)', re.M); init_re = re.compile('^\s*module_init\s*\(\s*(\w*)\s*\)\s*;', re.M); for f in files: srcf = open(f, 'r+') src = srcf.read() code = '{\n' match = init_re.search(src) initfn_pattern = '^[^\n]*\s*%s\s*\(\s*void\s*\).*(return[^;]*;)\s*^}' \ % match.group(1); match = re.compile(initfn_pattern, re.M|re.DOTALL).search(src) pos = match.start(1) match = sht_re.findall(src) for m in match: code += '\t\tata_dump_sht(DRV_NAME, &%s);\n' % m[0] match = ops_re.findall(src) for m in match: code += '\t\tata_dump_ops(DRV_NAME, &%s);\n' % m[0] code += '\t}\n\t' srcf.seek(0) srcf.truncate() srcf.write(src[:pos] + code + src[pos:])