2020-11-29 17:52:16 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
2021-08-18 18:28:32 +02:00
|
|
|
import re
|
2020-11-29 17:52:16 +01:00
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
root_dir = script_dir + "/../"
|
|
|
|
src_dir = root_dir + "src/"
|
2021-02-22 10:21:23 +01:00
|
|
|
asm_dir = root_dir + "ver/current/asm/"
|
2020-11-29 17:52:16 +01:00
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
renames = {}
|
|
|
|
deletes = []
|
|
|
|
|
|
|
|
def handle_file(f_path, try_rename_file=False):
|
|
|
|
with open(f_path) as f:
|
|
|
|
f_text_orig = f.read()
|
|
|
|
|
|
|
|
if try_rename_file:
|
|
|
|
extless = f_path.split("/")[-1][:-2]
|
|
|
|
if extless in renames:
|
|
|
|
deletes.append(f_path)
|
|
|
|
f_path = f_path.replace(extless, renames[extless])
|
|
|
|
|
|
|
|
f_text = f_text_orig
|
|
|
|
for rename in renames:
|
2021-08-18 18:28:32 +02:00
|
|
|
f_text = re.sub(r"(?:\b)" + rename + r"(?:\b)", renames[rename], f_text)
|
2021-06-30 04:27:12 +02:00
|
|
|
|
2021-10-22 16:01:27 +02:00
|
|
|
with open(f_path, "w", newline="\n") as f:
|
|
|
|
f.write(f_text)
|
2021-06-30 04:27:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Read Star Rod's output file
|
|
|
|
with open(os.path.join(script_dir, "to_rename.txt")) as f:
|
2020-11-29 17:52:16 +01:00
|
|
|
renames_text = f.readlines()
|
|
|
|
|
2021-06-30 04:27:12 +02:00
|
|
|
# Create dict of old -> new names
|
|
|
|
for line in renames_text:
|
|
|
|
split = line.split()
|
2021-08-17 13:24:26 +02:00
|
|
|
renames[split[0]] = split[1]
|
2021-06-30 04:27:12 +02:00
|
|
|
|
|
|
|
# Walk through asm files and rename stuff
|
|
|
|
print("Walking through asm files")
|
2020-11-29 17:52:16 +01:00
|
|
|
for root, dirs, files in os.walk(asm_dir):
|
|
|
|
for f_name in files:
|
|
|
|
if f_name.endswith(".s"):
|
|
|
|
f_path = os.path.join(root, f_name)
|
2021-06-30 04:27:12 +02:00
|
|
|
|
|
|
|
handle_file(f_path, True)
|
|
|
|
|
2021-10-22 16:01:27 +02:00
|
|
|
# Delete old versions of newly saved asm files
|
2021-06-30 04:27:12 +02:00
|
|
|
print("Deleting old asm files")
|
|
|
|
for d in deletes:
|
|
|
|
os.remove(d)
|
|
|
|
|
|
|
|
# Walk through src files and rename stuff
|
|
|
|
print("Walking through src files")
|
|
|
|
for root, dirs, files in os.walk(src_dir):
|
|
|
|
for f_name in files:
|
|
|
|
if f_name.endswith(".c") or f_name.endswith(".h"):
|
|
|
|
f_path = os.path.join(root, f_name)
|
|
|
|
|
|
|
|
handle_file(f_path)
|
|
|
|
|
|
|
|
# Walk through include files and rename stuff
|
|
|
|
print("Walking through include files")
|
|
|
|
for root, dirs, files in os.walk(os.path.join(root_dir, "include")):
|
|
|
|
for f_name in files:
|
|
|
|
f_path = os.path.join(root, f_name)
|
|
|
|
|
|
|
|
handle_file(f_path)
|
|
|
|
|
|
|
|
# Rename stuff in symbol_addrs.txt
|
|
|
|
handle_file(os.path.join(root_dir, "ver", "current", "symbol_addrs.txt"))
|
|
|
|
|