aboutsummaryrefslogtreecommitdiff
path: root/scan4dups.py
blob: a80bf94967102f3e9e3a48a8c3bba93a60602a82 (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
#!/usr/bin/env python 
 
import sys
import re
 
 
listing={}
 
for line in sys.stdin:
    # 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 name in listing:
        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
 
print("hit end")
# NOW check for prefix conflicts: 
print("Checking prefixes.")
for key in listing:
    # 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 pref in listing:
            print("Prefix conflict found: "
                  "(%s )[%s] vs (%s )[%s]"%(preflisting[pref],
                                            keylisting[key]))