-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathscan4dups.py
executable file
·57 lines (50 loc) · 1.53 KB
/
scan4dups.py
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
#!/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]"%(name, val))
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]"%(pref, listing[pref],
key, listing[key]))