mirror of
https://github.com/pmret/papermario.git
synced 2024-09-16 14:32:37 +02:00
Use python iconv if system iconv is broken (#1156)
* use python iconv if system iconv is broken * black
This commit is contained in:
parent
260b96faf9
commit
1d0c818088
@ -357,6 +357,24 @@ def write_ninja_for_tools(ninja: ninja_syntax.Writer):
|
||||
ninja.build(CRC_TOOL, "cc_tool", f"{BUILD_TOOLS}/rom/n64crc.c")
|
||||
|
||||
|
||||
def does_iconv_work() -> bool:
|
||||
# run iconv and see if it works
|
||||
stdin = "エリア OMO2_1".encode("utf-8")
|
||||
|
||||
def run(command, stdin):
|
||||
sub = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=stdin)
|
||||
return sub.stdout
|
||||
|
||||
expected_stdout = run(["tools/build/iconv.py", "UTF-8", "CP932"], stdin)
|
||||
actual_stdout = run(["iconv", "--from", "UTF-8", "--to", "CP932"], stdin)
|
||||
return expected_stdout == actual_stdout
|
||||
|
||||
|
||||
use_python_iconv = not does_iconv_work()
|
||||
if use_python_iconv:
|
||||
print("warning: iconv doesn't work, using python implementation")
|
||||
|
||||
|
||||
class Configure:
|
||||
def __init__(self, version: str):
|
||||
self.version = version
|
||||
@ -677,6 +695,9 @@ class Configure:
|
||||
if version == "ique":
|
||||
encoding = "EUC-JP"
|
||||
|
||||
if use_python_iconv:
|
||||
iconv = f"tools/build/iconv.py UTF-8 {encoding}"
|
||||
else:
|
||||
iconv = f"iconv --from UTF-8 --to {encoding}"
|
||||
|
||||
# use tools/sjis-escape.py for src/battle/area/tik2/area.c
|
||||
|
23
tools/build/iconv.py
Executable file
23
tools/build/iconv.py
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description="Convert a file from one encoding to another")
|
||||
parser.add_argument("f")
|
||||
parser.add_argument("t")
|
||||
parser.add_argument("infile", nargs="?", type=argparse.FileType("r"), default=sys.stdin)
|
||||
parser.add_argument("outfile", nargs="?", type=argparse.FileType("w"), default=sys.stdout)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def main(args):
|
||||
sys.stdin.reconfigure(encoding=args.f)
|
||||
in_data = args.infile.read()
|
||||
sys.stdout.reconfigure(encoding=args.t)
|
||||
args.outfile.write(in_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(parser.parse_args())
|
Loading…
Reference in New Issue
Block a user