LSR: Update.
[lilypond.git] / buildscripts / find-superfluous-includes.py
blobded1087da78fbb27f4e283a092914771187c79d1
1 #!/usr/bin/python
2 import sys
3 import re
4 import os
7 full_paths = {}
8 incs = {}
9 inc_re = re.compile ('^#include "([^"]+)"')
10 def parse_file (fn):
11 lst = []
13 lc = 0
14 for l in open (fn).readlines():
15 lc += 1
16 m = inc_re.search (l)
17 if m:
18 lst.append ((lc, m.group (1)))
20 base = os.path.split (fn)[1]
21 full_paths[base] = fn
22 incs[base] = lst
25 def has_include (f, name):
26 try:
27 return name in [b for (a,b) in incs[f]]
28 except KeyError:
29 return False
31 for a in sys.argv:
32 parse_file (a)
34 print '-*-compilation-*-'
35 for (f, lst) in incs.items ():
36 for (n, inc) in lst:
37 for (n2, inc2) in lst:
38 if has_include (inc2, inc):
39 print "%s:%d: already have %s from %s" % (full_paths[f], n,
40 inc, inc2)
41 break