2019-08-03 07:43:22 +03:00
|
|
|
def hexify(v):
|
|
|
|
return hex(v)[2:]
|
|
|
|
|
2019-07-28 00:44:53 +03:00
|
|
|
prohibit = [ ]
|
|
|
|
|
|
|
|
table = None
|
|
|
|
for line in file("table.c.txt"):
|
|
|
|
line = line.strip()
|
|
|
|
if line.startswith("#"): continue
|
|
|
|
if line.startswith("---"):
|
|
|
|
if line.find("Start") >= 0:
|
|
|
|
table = line.replace("-", "").replace("Start", "").strip().replace(" ", "_").replace(".", "_")
|
|
|
|
print table
|
|
|
|
continue
|
|
|
|
comps = [ c.strip() for c in line.split(";") ]
|
|
|
|
if len(comps) != 2: raise Exception("hmmm")
|
|
|
|
comps = comps[0].split("-")
|
|
|
|
if len(comps) == 1:
|
|
|
|
start = int(comps[0], 16)
|
|
|
|
prohibit.append(start)
|
|
|
|
elif len(comps) == 2:
|
|
|
|
start = int(comps[0], 16)
|
|
|
|
end = int(comps[1], 16)
|
|
|
|
for i in xrange(start, end + 1):
|
|
|
|
prohibit.append(i)
|
|
|
|
else:
|
|
|
|
raise Exception("hmmm")
|
|
|
|
print prohibit
|
|
|
|
|
|
|
|
# Dedup and sort
|
|
|
|
prohibit = list(dict([(p, True) for p in prohibit]).keys())
|
|
|
|
prohibit.sort()
|
|
|
|
|
2019-08-03 07:43:22 +03:00
|
|
|
output = [ dict(lo = prohibit[0], hi = prohibit[0]) ]
|
2019-07-28 00:44:53 +03:00
|
|
|
|
2019-08-03 07:43:22 +03:00
|
|
|
for p in prohibit[1:]:
|
|
|
|
if p - 1 == output[-1]["hi"]:
|
|
|
|
output[-1]["hi"] = p
|
2019-07-28 00:44:53 +03:00
|
|
|
else:
|
2019-08-03 07:43:22 +03:00
|
|
|
output.append(dict(lo = p, hi = p))
|
2019-07-28 00:44:53 +03:00
|
|
|
|
2019-08-03 07:43:22 +03:00
|
|
|
print output
|
2019-08-02 09:10:58 +03:00
|
|
|
|
|
|
|
last = 0
|
2019-08-03 07:43:22 +03:00
|
|
|
for r in output:
|
|
|
|
r["h"] = r["hi"] - r["lo"]
|
|
|
|
r["l"] = r["lo"] - last
|
|
|
|
last = r["hi"]
|
|
|
|
|
|
|
|
r["range"] = hexify(r["l"])
|
|
|
|
if r["h"] > 1:
|
|
|
|
r["range"] += "-" + hexify(r["h"])
|
|
|
|
elif r["h"] > 0:
|
|
|
|
r["range"] += "-"
|
|
|
|
|
|
|
|
print 'const Table_C_ranges = "' + ",".join(x["range"] for x in output) + '";'
|
|
|
|
|