1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-25 17:54:15 +00:00
oot/tools/format_s_files.py
Lucas Shaw 045a92d7c3
Big actor cleanup (fixed) (#69)
* Started doing cleanup

* did more work

* did more migration

* migrated more rodata and worked on some structs

* did more work

* Removal of ROOM field from initvars, some rodata migration, some string decompilation

* General update

* Decompiled vt strings

* Tool work

* Tool improvements

* 270 overlay rodata files remaining

* better float handling

* floats

* Many more floats

* migrated boss_mo

* assorted fixes

* Migrated 10

* tool improvements

* migrated 10

* 10 more

* 1 more

* did a few more

* fixes

* 10 more

* more floats

* Did some more, updated migrate-rodata.py to 'modify' the C file after processing in order to make to compiler process it as if it was changed.

* removed changes made to script by accident

* migrated largest rodata - ovl_fishing

* Did some more

* 114 remaining

* 99 left !

* almost done migrating rodata

* did some more, done for tonight

* almost done, tried add support to the script for z_player

* All possible rodata migrated in actor overlays

* update

* removed static from all overlays, ran format.sh

* Removed unknown actor structs

* converted a few floats

* Added new lines to header files that were missing them. Removed unused asm files

* Removed unused asm files

* Formatting newlines

Further formatting

spacing

.float spacing

More space formatting

More spacing formatting

Removing .balign 4 after floats

Co-authored-by: Ethan Roseman <ethteck@gmail.com>
2020-04-14 14:16:34 -04:00

86 lines
2.4 KiB
Python

#!/usr/bin/python3
import os
import sys
import re
from disassemble import get_z_name
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = script_dir + "/../"
src_dir = root_dir + "src/overlays/"
asm_dir = root_dir + "asm/non_matchings/overlays/"
def remove_empty_lines_after_glabel(file_text):
file_lines = file_text.splitlines()
last_glabel = False
to_remove = []
for i, line in enumerate(file_lines):
if "glabel" in line:
last_glabel = True
continue
if last_glabel and not line.strip():
to_remove.append(i)
last_glabel = False
if len(to_remove) > 0:
for line_num in reversed(to_remove):
del file_lines[line_num]
file_text = "\n".join(file_lines)
return file_text
def remove_balign_after_float(file_text):
file_lines = file_text.splitlines()
last_float = False
to_remove = []
for i, line in enumerate(file_lines):
if ".float" in line:
last_float = True
continue
if last_float and line == " .balign 4":
to_remove.append(i)
last_float = False
if len(to_remove) > 0:
for line_num in reversed(to_remove):
del file_lines[line_num]
file_text = "\n".join(file_lines)
return file_text
def format_file(file_path):
with open(file_path) as f:
orig_file_text = f.read()
file_text = orig_file_text
# Condense 2+ empty lines to 1
file_text = file_text.replace("\n\n\n+", "\n\n")
# Remove empty lines after section declarations
file_text = file_text.replace(".rdata\n\n", ".rdata\n")
file_text = file_text.replace(".late_rodata\n\n", ".late_rodata\n")
file_text = file_text.replace(".text\n\n", ".text\n")
# Remove dumb empty lines after glabel
file_text = remove_empty_lines_after_glabel(file_text)
# Remove dumb balign 4 lines after float
file_text = remove_balign_after_float(file_text)
# Make sure there's only one empty line at the end
file_text = file_text.rstrip("\n") + "\n"
if file_text != orig_file_text:
with open(file_path, "w", newline="\n") as f:
f.write(file_text)
return True
return False
def main():
for root, dirs, files in os.walk(asm_dir):
for f in files:
if f.endswith(".s"):
format_file(os.path.join(root, f))
main()