From 09dcdb3d140893bfbc86511c2c5e40c29b8114f7 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sat, 29 Feb 2020 16:49:26 -0800 Subject: [PATCH] tools: fix iconv issues on Windows Need to use libiconv on Windows. libiconv doesn't accept all of the same encoding names as the glibc iconv. In particular, CP932 needs to be used instead of SJIS-WIN. --- src/tools/aindump/aindump.c | 6 +++--- src/tools/aindump/meson.build | 2 +- src/tools/ainedit/ainedit.c | 8 ++++---- src/tools/ainedit/meson.build | 2 +- src/tools/ar/meson.build | 2 +- src/tools/ex/exbuild.c | 4 ++-- src/tools/ex/exdump.c | 4 ++-- src/tools/ex/meson.build | 4 ++-- src/tools/meson.build | 7 +++++++ 9 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/tools/aindump/aindump.c b/src/tools/aindump/aindump.c index 65bfd0b..17a837f 100644 --- a/src/tools/aindump/aindump.c +++ b/src/tools/aindump/aindump.c @@ -115,7 +115,7 @@ static void usage(void) puts(" -d, --decrypt Dump decrypted AIN file"); puts(" --map Dump AIN file map"); puts(" --inline-strings Dump code in inline-strings mode"); - puts(" --input-encoding Specify the text encoding of the AIN file (default: SJIS-WIN)"); + puts(" --input-encoding Specify the text encoding of the AIN file (default: CP932)"); puts(" --output-encoding Specify the text encoding of the output file (default: UTF-8)"); } @@ -515,7 +515,7 @@ int main(int argc, char *argv[]) bool decrypt = false; char *output_file = NULL; FILE *output = stdout; - char *input_encoding = "SJIS-WIN"; + char *input_encoding = "CP932"; char *output_encoding = "UTF-8"; int err = AIN_SUCCESS; unsigned int flags = DASM_NO_STRINGS; @@ -672,7 +672,7 @@ int main(int argc, char *argv[]) if ((output_conv = iconv_open(output_encoding, input_encoding)) == (iconv_t)-1) { ERROR("iconv_open: %s", strerror(errno)); } - if ((utf8_conv = iconv_open("utf8", input_encoding)) == (iconv_t)-1) { + if ((utf8_conv = iconv_open("UTF-8", input_encoding)) == (iconv_t)-1) { ERROR("iconv_open: %s", strerror(errno)); } diff --git a/src/tools/aindump/meson.build b/src/tools/aindump/meson.build index 2c17e25..e22e582 100644 --- a/src/tools/aindump/meson.build +++ b/src/tools/aindump/meson.build @@ -7,6 +7,6 @@ aindump = ['../../cJSON.c', ] executable('aindump', aindump, - dependencies : [libm, zlib], + dependencies : tool_deps, include_directories : incdir, link_with : libsys4) diff --git a/src/tools/ainedit/ainedit.c b/src/tools/ainedit/ainedit.c index 92f0314..0ea7afe 100644 --- a/src/tools/ainedit/ainedit.c +++ b/src/tools/ainedit/ainedit.c @@ -39,7 +39,7 @@ static void usage(void) puts(" --raw Read code in raw mode"); puts(" --inline-strings Read code in inline-strings mode"); puts(" --input-encoding Specify the text encoding of the input file(s) (default: UTF-8)"); - puts(" --output-encoding Specify the text encoding of the output file (default: SJIS-WIN)"); + puts(" --output-encoding Specify the text encoding of the output file (default: CP932)"); //puts(" -p,--project Build AIN from project file"); } @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) const char *text_file = NULL; const char *output_file = NULL; const char *input_encoding = "UTF-8"; - const char *output_encoding = "SJIS-WIN"; + const char *output_encoding = "CP932"; bool transcode = false; uint32_t flags = ASM_NO_STRINGS; while (1) { @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) break; case LOPT_TRANSCODE: transcode = true; - input_encoding = "SJIS-WIN"; + input_encoding = "CP932"; output_encoding = optarg; break; case 'o': @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) if ((ain_conv = iconv_open(output_encoding, input_encoding)) == (iconv_t)-1) { ERROR("iconv_open: %s", strerror(errno)); } - if ((print_conv = iconv_open("utf8", output_encoding)) == (iconv_t)-1) { + if ((print_conv = iconv_open("UTF-8", output_encoding)) == (iconv_t)-1) { ERROR("iconv_open: %s", strerror(errno)); } diff --git a/src/tools/ainedit/meson.build b/src/tools/ainedit/meson.build index 8995700..bc79bd2 100644 --- a/src/tools/ainedit/meson.build +++ b/src/tools/ainedit/meson.build @@ -23,7 +23,7 @@ endif executable('ainedit', ainedit, lfiles, pfiles, - dependencies : [libm, zlib], + dependencies : tool_deps, c_args : ['-Wno-unused-parameter'], include_directories : incdir, link_with : libsys4) diff --git a/src/tools/ar/meson.build b/src/tools/ar/meson.build index 6609b77..cd8fd29 100644 --- a/src/tools/ar/meson.build +++ b/src/tools/ar/meson.build @@ -2,7 +2,7 @@ alicear = ['alice-ar.c', ] executable('alice-ar', alicear, - dependencies: [libm, zlib], + dependencies: tool_deps, c_args : ['-Wno-unused-parameter'], include_directories : incdir, link_with : libsys4) diff --git a/src/tools/ex/exbuild.c b/src/tools/ex/exbuild.c index 2d5eb79..671b10e 100644 --- a/src/tools/ex/exbuild.c +++ b/src/tools/ex/exbuild.c @@ -46,7 +46,7 @@ static void usage(void) puts(" -o, --output Set the output file path"); puts(" --old Use this for pre-Evenicle .ex files"); puts(" --input-encoding Specify the encoding of the input file (default: UTF-8)"); - puts(" --output-encoding Specify the encoding of the output file (default: SJIS-WIN)"); + puts(" --output-encoding Specify the encoding of the output file (default: CP932)"); } enum { @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { const char *output_file = NULL; const char *input_encoding = "UTF-8"; - const char *output_encoding = "SJIS-WIN"; + const char *output_encoding = "CP932"; while (1) { static struct option long_options[] = { diff --git a/src/tools/ex/exdump.c b/src/tools/ex/exdump.c index 44b2315..22e9828 100644 --- a/src/tools/ex/exdump.c +++ b/src/tools/ex/exdump.c @@ -55,7 +55,7 @@ static void usage(void) puts(" -d, --decrypt Decrypt the EX file only"); puts(" -o, --output Set the output file path"); puts(" -s, --split Split output into multiple files"); - puts(" --input-encoding Specify the encoding of the EX file (default: SJIS-WIN)"); + puts(" --input-encoding Specify the encoding of the EX file (default: CP932)"); puts(" --output-encoding Specify the encoding of the output file (default UTF-8)"); } @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) bool decrypt = false; bool split = false; char *output_file = NULL; - char *input_encoding = "SJIS-WIN"; + char *input_encoding = "CP932"; char *output_encoding = "UTF-8"; while (1) { diff --git a/src/tools/ex/meson.build b/src/tools/ex/meson.build index e1e6e64..dea43b4 100644 --- a/src/tools/ex/meson.build +++ b/src/tools/ex/meson.build @@ -13,13 +13,13 @@ exbuild = ['../conv.c', ] executable('exdump', exdump, - dependencies : [libm, zlib], + dependencies : tool_deps, c_args : ['-Wno-unused-parameter'], include_directories : incdir, link_with : libsys4) executable('exbuild', exbuild, lfiles, pfiles, - dependencies : [libm, zlib], + dependencies : tool_deps, c_args : ['-Wno-unused-parameter'], include_directories : incdir, link_with : libsys4) diff --git a/src/tools/meson.build b/src/tools/meson.build index 78eebac..d9632f6 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -14,6 +14,13 @@ if bison.found() arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) endif +if build_machine.system() == 'windows' + iconv = dependency('iconv') + tool_deps = [libm, zlib, iconv] +else + tool_deps = [libm, zlib] +endif + subdir('aindump') subdir('ainedit') subdir('ar')