aboutsummaryrefslogtreecommitdiff
path: root/scan4dups.py
diff options
context:
space:
mode:
Diffstat (limited to 'scan4dups.py')
-rwxr-xr-xscan4dups.py74
1 files changed, 36 insertions, 38 deletions
diff --git a/scan4dups.py b/scan4dups.py
index 9ce6193..a80bf94 100755
--- a/scan4dups.py
+++ b/scan4dups.py
@@ -6,42 +6,40 @@ import re
listing={}
-try:
+for line in sys.stdin:
+ # print "((%s))"%line
+ startpos=0
+ name=''
+ dupsfound=[]
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)
+ m=re.match("\s*<(\w+)>",line[startpos:])
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]"%(name, val)
- else:
- listing[name]=val
-except StopIteration:
- print "hit end"
+ 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.keys():
+print("Checking prefixes.")
+for key in listing:
# print "Key: (%s)"%key
pref=''
# Careful when splitting. The key always starts with a space.
@@ -51,9 +49,9 @@ for key in listing.keys():
continue
pref+=" "+word
# print "checking (%s)"%pref
- if listing.has_key(pref):
- print "Prefix conflict found: " \
- "(%s )[%s] vs (%s )[%s]"%(pref, listing[pref],
- key, listing[key])
+ if pref in listing:
+ print("Prefix conflict found: "
+ "(%s )[%s] vs (%s )[%s]"%(pref, listing[pref],
+ key, listing[key]))
+
-