1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-25 09:45:02 +00:00

m2ctx.py fixes (#681)

* adding a fix to m2ctx and adding argparse

* adding in some print statements
This commit is contained in:
Parker Burnett 2021-02-11 14:08:24 -05:00 committed by GitHub
parent f95a5aec68
commit a30b5bbb26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@
import os
import sys
import subprocess
import argparse
from pathlib import Path
script_dir = os.path.dirname(os.path.realpath(__file__))
@ -23,9 +24,10 @@ def get_c_file(directory):
if file.endswith(".c") and "data" not in file:
return file
def import_c_file(in_file):
in_file = os.path.relpath(in_file, root_dir)
cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C",
cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Iassets", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C",
"-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file]
try:
return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
@ -37,21 +39,26 @@ def import_c_file(in_file):
)
sys.exit(1)
def main():
if len(sys.argv) > 1:
arg = sys.argv[1]
if arg == "-h" or arg == "--help":
sys.exit("Usage: ./m2ctx.py path/to/file.c\n" \
"or ./m2ctx.py (from an actor or gamestate's asm dir)\n" \
"Output will be saved in oot/ctx.c")
c_file_path = Path.cwd() / sys.argv[1]
parser = argparse.ArgumentParser(usage="./m2ctx.py path/to/file.c or ./m2ctx.py (from an actor or gamestate's asm dir)",
description="Creates a ctx.c file for mips2c. "
"Output will be saved as oot/ctx.c")
parser.add_argument('filepath', help="path of c file to be processed")
args = parser.parse_args()
if args.filepath:
c_file_path = args.filepath
print("Using file: {}".format(c_file_path))
else:
this_dir = Path.cwd()
c_dir_path = get_c_dir(this_dir.name)
if c_dir_path is None:
sys.exit("Cannot find appropriate c file dir. In argumentless mode, run this script from the c file's corresponding asm dir.")
sys.exit(
"Cannot find appropriate c file dir. In argumentless mode, run this script from the c file's corresponding asm dir.")
c_file = get_c_file(c_dir_path)
c_file_path = os.path.join(c_dir_path, c_file)
print("Using file: {}".format(c_file_path))
output = import_c_file(c_file_path)