diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-09-10 20:08:49 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-09-10 20:08:49 -0500 |
commit | e47308a1f88f19dfc0ee5cb42dc643a520d9175b (patch) | |
tree | 7ae7bb3ff46ceeab012869db3cbdad86545a0496 /textpre.py | |
parent | a684941cfcf88942cbecaecf997609acc3652a1a (diff) | |
parent | 37c80175368352710e20f752ebfdc1e9e3ac3e2b (diff) |
Merge branch kanzure/master into dannye-incbins
Conflicts:
extras
Diffstat (limited to 'textpre.py')
-rw-r--r-- | textpre.py | 82 |
1 files changed, 7 insertions, 75 deletions
@@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import extras.pokemontools.preprocessor as preprocessor + import sys chars = { @@ -254,81 +256,11 @@ chars = { "6": 0xFC, "7": 0xFD, "8": 0xFE, -"9": 0xFF - +"9": 0xFF, } -for l in sys.stdin: - - # strip comments - line = l.partition(";") - i = 0 - asm = "" - while i < len(line) and l[0] != ";": - asm = asm + line[i] - i = i + 1 - - # skip asm with no quotes - if "\"" not in asm: - sys.stdout.write(l) - continue - - # split by quotes - asms = asm.split("\"") - - # skip asm that actually does use ASCII in quotes - lowasm = asms[0].lower() - if "section" in lowasm \ - or "include" in lowasm \ - or "incbin" in lowasm: - sys.stdout.write(l) - continue - - even = False - i = 0 - for token in asms: - i = i + 1 - if even: - # token is a string to convert to byte values - - while len(token): - # read a single UTF-8 codepoint - char = token[0] - if ord(char) >= 0xFC: - char = char + token[1:6] - token = token[6:] - elif ord(char) >= 0xF8: - char = char + token[1:5] - token = token[5:] - elif ord(char) >= 0xF0: - char = char + token[1:4] - token = token[4:] - elif ord(char) >= 0xE0: - char = char + token[1:3] - token = token[3:] - elif ord(char) >= 0xC0: - char = char + token[1:2] - token = token[2:] - else: - token = token[1:] - - # certain apostrophe-letter pairs are only a single byte - if char == "'" and \ - (token[0] == "d" or \ - token[0] == "l" or \ - token[0] == "m" or \ - token[0] == "r" or \ - token[0] == "s" or \ - token[0] == "t" or \ - token[0] == "v"): - char = char + token[0] - token = token[1:] - - sys.stdout.write("${0:02X}".format(chars[char])) - - if len(token): - sys.stdout.write(", ") +preprocessor.chars = chars - else: - sys.stdout.write(token) - even = not even +macros = [] +macro_table = preprocessor.make_macro_table(macros) +preprocessor.preprocess(macro_table) |