#! /usr/bin/python import os import re re_probename = re.compile('struct\s+platform_driver\s+(?P\S+)\s*=\s*{.*\.probe\s*=\s*(?P[A-Za-z0-9_]*)', re.S) for dirpath, dirnames, filenames in os.walk('.'): for f in filter(lambda s: s.endswith('.c'), filenames): fullf = os.path.join(dirpath, f) content = open(fullf).read() matchdict = dict(filename=fullf) mo = re_probename.search(content) if mo: matchdict.update(mo.groupdict()) else: continue re_section = re.compile('int\s+(?:(?P__(?:dev)?(?:init|exit)+)\s+)?%(probefunction)s\s*\(' % matchdict) mo = re_section.search(content) if mo: matchdict.update(mo.groupdict()) else: matchdict['probesection'] = '' if matchdict['probesection'] != '__devinit': print 'probe function %(probefunction)r for %(drivername)r (%(filename)s) defined in section %(probesection)r' % matchdict