import re import sys import clint class headers(clint.Rule): def initialize(self): self.pattern = re.compile("^#\W*include\W*<(?P
.*\.h)>") self.headers = { 'iostream.h' : 'iostream', 'ctype.h': 'cctype', 'vector.h': 'vector', 'deque.h': 'deque', 'math.h': 'cmath', 'string.h': 'cstring', 'stdlib.h': 'cstdlib', 'stdarg.h': 'cstdarg', 'assert.h': 'cassert', 'ctype.h':'cctype', 'errno': 'cerrno', 'time.h': 'ctime', 'stdio.h': 'cstdio', 'map.h': 'map', 'iomanip.h':'iomanip', 'fstream.h':'fstream', 'limits.h':'climits', 'locale.h':'clocale', 'setjmp.h':'csetjmp' } def pre_cpp(self,line): match = self.pattern.match(line) if match: old_header = match.group('header') if self.headers.has_key(old_header): self.message( "Old style header detected: Change <" + old_header + "> to <" + self.headers[old_header] + ">") def finalize(self): pass if __name__ == "__main__": lineno=0 rule = new_headers() file = open(sys.argv[1]) for line in file.readlines(): lineno = lineno + 1 rule.parse(line)