Skip to content

Instantly share code, notes, and snippets.

@rjwalsh
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjwalsh/d85b898fa27a54034a22 to your computer and use it in GitHub Desktop.
Save rjwalsh/d85b898fa27a54034a22 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# List the duplicate entries in the minipro devices.h file
import re
o = open('devices.h', 'r')
prog = re.compile("^\s*\.(\S+)\s*=\s*\"?(.+?)\"?\s*,\s*$")
current = {}
entries = []
def newentry():
global current
global entries
if current:
keys = current.keys()
keys.sort()
val = current["name"] + ":"
for i in keys:
if i != "name":
val = val + current[i] + ":"
entries.append(val)
def stash(field, value):
global current
if field == "name":
newentry()
current = {}
current[field] = value
for i in o:
ret = prog.match(i)
if ret:
field = ret.group(1)
value = ret.group(2)
stash(field, value)
newentry()
current = {}
o.close()
entries.sort()
p = ""
founddup = False
for i in entries:
if i == p:
founddup = True
continue
if founddup:
founddup = False
print i
p = i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment