From da9918431d37f85a38c0e1ab7e4479996b757695 Mon Sep 17 00:00:00 2001 From: "Mark E. Shoulson" Date: Thu, 19 Dec 2019 09:21:19 -0500 Subject: Fixed some .py utils to use python3; added a few chars. After all, Python2 reaches EOL very soon! More emoji added. Also improved the Makefile. A few additions, improvements to translator. --- scan4dups.py | 74 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'scan4dups.py') 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])) + - -- cgit v1.2.3