automatically fix deprecated section name 'HOME'
This commit is contained in:
parent
142b54de94
commit
ad3b974f91
|
@ -1,3 +1,4 @@
|
|||
home2rom0.py %1
|
||||
rgbasm -o%~n1.obj %1
|
||||
rgblink -m%~n1.map -n%~n1.sym -o%~n1.gb %~n1.obj
|
||||
rgbfix -p255 -v %~n1.gb
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
def get_includes(code):
|
||||
return re.findall(r'INCLUDE\s+"(.+\.z80)"', code, flags=re.IGNORECASE)
|
||||
|
||||
def fix_section_name(filename):
|
||||
with open(filename, 'r+') as f:
|
||||
fixed, n = re.subn(r'(SECTION\s+".+",\s+)HOME', r'\1ROM0', f.read(), flags=re.IGNORECASE)
|
||||
if n: # don't touch unchanged files
|
||||
f.seek(0)
|
||||
f.write(fixed)
|
||||
return n
|
||||
|
||||
def main(args):
|
||||
with open(args[0]) as code:
|
||||
filenames = get_includes(code.read())
|
||||
subs = sum((fix_section_name(file) for file in filenames))
|
||||
print("Fixed {} deprecated section name{}.".format(subs, '' if subs == 1 else 's'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
if not args:
|
||||
sys.exit("Usage: {} main_game_file.z80".format(os.path.basename('./' + __file__)))
|
||||
main(args)
|
Loading…
Reference in New Issue