From ecd9d0b6aeca72de7e6fa91c1948829d18cd1a73 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 10 Aug 2019 20:32:47 -0400 Subject: [PATCH] allow hex numbers --- string_compiler.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/string_compiler.py b/string_compiler.py index 6682a06..42337ca 100644 --- a/string_compiler.py +++ b/string_compiler.py @@ -162,7 +162,7 @@ def read_data(f, name): if line == "" : continue if line[0] == "#" : continue - m = re.match(r'^"([^"]*)"\s+(\d+)$', line) + m = re.match(r'^"([^"]*)"\s+(\d+|0x[A-Fa-f0-9]+)$', line) if not m: err = "{}:{}: Bad data: {}".format(name,ln,line) raise Exception(err) @@ -170,7 +170,12 @@ def read_data(f, name): if flag_i: k = k.lower() k = decode_string(k) - v = int(m[2]) + + tmp = m[2] + base = 10 + if tmp.startswith("0x"): base = 16 + v = int(tmp, base) + if flag_l: if v > 255 or len(orig_k) > 255: err = "{}:{} Value too large: {}".format(name, ln, v)