mm/tools/rename_global_asm.py
EllipticEllipsis 823281291b
Script fixes, Type 1 cylinders fixed, rename main (#256)
* Fix actor_symbols.py

* Temporary fix to rename_sym.sh

* Fix the few Type1 cylinders

* Rename main -> Main

* chmod rename_global_asm, fix asm in rename_syms

* Format
2021-08-08 23:01:51 -04:00

33 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
#
# Rename non_matching files whose name does not match the glabel function name
#
import os
to_rename = {}
for root, dirs, files in os.walk("asm/non_matchings/"):
for f in [f for f in files if f.endswith(".s")]:
full_path = os.path.join(root,f)
contents = ""
with open(full_path,"r") as infile:
contents = infile.read()
text_lines = []
if ".text\n" in contents:
text_lines = contents.split(".text\n")[1].split("\n")
else:
text_lines = contents.split("\n")
for line in text_lines:
if line.startswith("glabel "):
if f.replace(".s","") != line.replace("glabel ",""):
to_rename.update({full_path : full_path.replace(f.replace(".s",""),line.replace("glabel ",""))})
break
if any([list(to_rename.values()).count(x) > 1 for x in to_rename]):
print("Rename collision, aborting!")
else:
for old_path,new_path in to_rename.items():
print(f"{old_path} --> {new_path}")
os.rename(old_path, new_path)