aboutsummaryrefslogtreecommitdiff
path: root/scan4dups.py
blob: 9ce619354f031e435cc8a38f53b2da6cca726c8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python 
 
import sys
import re
 
 
listing={}
 
try:
    while True:
        line=sys.stdin.next()
        # print "((%s))"%line 
        startpos=0
        name=''
        dupsfound=[]
        while True:
            m=re.match("\s*<(\w+)>",line[startpos:])
            if not m:
                break
            word=m.group(1)
            name+=' '+word
            startpos+=m.end()
        if startpos<=0:
            continue
        m=re.match(r'[^"]*"(.+)"',line)
        if not m:
            # shouldn't happen, but just in case 
            val='???'
            print "couldn't make sense of line: "+line
        else:
            val=m.group(1)
        if listing.has_key(name):
            if val != listing[name]:
                print "Exact conflict found: (%s )[%s][%s]"%(name
                                                             listing[name]val)
            else:   # It's easier to read if lines have different indentations 
                print "\tRedundant definition: (%s )[%s]"%(nameval)
        else:
            listing[name]=val
except StopIteration:
    print "hit end"
# NOW check for prefix conflicts: 
print "Checking prefixes."
for key in listing.keys():
    # print "Key: (%s)"%key 
    pref=''
    # Careful when splitting.  The key always starts with a space. 
    for word in key.split(" ")[:-1]# chop the last one; that'll always match. 
        # Skip the empty first entry 
        if not word:
            continue
        pref+=" "+word
        # print "checking (%s)"%pref 
        if listing.has_key(pref):
            print "Prefix conflict found: " \ 
                "(%s )[%s] vs (%s )[%s]"%(preflisting[pref],
                                          keylisting[key])