1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-11 03:39:59 +00:00
oot/tools/create_actor_headers.py

72 lines
2 KiB
Python
Raw Normal View History

2020-03-17 04:31:30 +00:00
#!/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 + "/../"
asm_dir = root_dir + "asm/non_matchings/overlays/actors"
src_dir = root_dir + "src/overlays/actors"
include_dir = root_dir + "include"
indent = " "
includes = "#include <ultra64.h>\n#include <global.h>\n\n"
def remove_struct(root, filename):
with open(os.path.join(root, filename)) as f:
c_text = f.read()
2020-03-17 04:31:30 +00:00
struct_start = c_text.find("typedef")
struct_end = c_text.find("#define")
struct = c_text[struct_start:struct_end]
2020-03-17 04:31:30 +00:00
newfile_text = "#include \"" + filename[:-2] + ".h\"" + "\n\n" + c_text[struct_end:]
with open(os.path.join(root, filename), "w", newline="\n") as f:
f.write(newfile_text)
return struct
def handle_file(root, filename):
guard_name = "_" + filename[:-2].upper() + "_H_"
top_guard = "#ifndef " + guard_name + "\n#define " + guard_name + "\n\n"
header_text = top_guard
header_text += includes
struct = remove_struct(root, filename)
header_text += struct
u_split = filename[:-2].split("_")
init_vars_name = ""
for part in u_split[1:]:
init_vars_name += part[0].upper()
if len(part) > 1:
init_vars_name += part[1:]
init_vars_name += "_"
init_vars_name += "InitVars"
header_text += "extern ActorInit " + init_vars_name + ";\n\n"
2020-03-17 04:31:30 +00:00
header_text += "#endif\n"
2020-03-17 04:31:30 +00:00
with open(os.path.join(root, filename[:-2] + ".h"), "w", newline="\n") as f:
f.write(header_text)
def main():
for root, dirs, files in os.walk(src_dir):
for filename in files:
if filename.endswith(".c"):
file_path = os.path.join(root, filename)
with open(file_path) as f:
file_text = f.read()
brace_count = file_text.count("{")
if brace_count == 2:
handle_file(root, filename)
dog = 5
main()