From fe518ecdf05f526fc3fe104dfa89dd54c3d15886 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 31 Mar 2019 09:01:21 +0100 Subject: More testing preparation --- z80count.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'z80count.py') diff --git a/z80count.py b/z80count.py index 54757d4..6c569f7 100755 --- a/z80count.py +++ b/z80count.py @@ -73,6 +73,16 @@ def z80count(line, table, total, total_cond, subt, update, tabstop=2, debug=Fals return (out, total, total_cond) +def init_table(table_file="z80table.json"): + table_file = path.join( + path.dirname(path.realpath(__file__)), table_file) + with open(table_file, "rt") as fd: + table = json.load(fd) + + for i in range(len(table)): + table[i]["cregex"] = re.compile(table[i]["regex"] + r"\s?(;.*)?", re.I) + + return sorted(table, key=lambda o: o["w"]) def main(): @@ -100,15 +110,7 @@ def main(): in_f = args.infile out_f = args.outfile - table_file = path.join( - path.dirname(path.realpath(__file__)), "z80table.json") - with open(table_file, "rt") as fd: - table = json.load(fd) - - for i in range(len(table)): - table[i]["cregex"] = re.compile(table[i]["regex"] + r"\s?(;.*)?", re.I) - - table = sorted(table, key=lambda o: o["w"]) + table = init_table() total = total_cond = 0 while True: line = in_f.readline() -- cgit v1.2.3