From b90d7119d4140754d3b1485ba3de9f434269de2e Mon Sep 17 00:00:00 2001 From: bumbread Date: Sun, 31 Jul 2022 05:06:15 +1100 Subject: [PATCH] Add UTF-8 codepage support --- .gitmodules | 3 +++ bake-test.cmd | 2 +- src/_win/stdio.c | 3 +++ src/libwinsane | 1 + test/test_os.c | 10 ---------- test/test_windows_utf8.c | 20 ++++++++++++++++++++ 6 files changed, 28 insertions(+), 11 deletions(-) create mode 160000 src/libwinsane delete mode 100644 test/test_os.c create mode 100644 test/test_windows_utf8.c diff --git a/.gitmodules b/.gitmodules index c172b1a..20c22da 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "fdec64"] path = src/fdec64 url = https://github.com/bumbread/fdec64.git +[submodule "src/libwinsane"] + path = src/libwinsane + url = https://github.com/flysand7/libwinsane.git diff --git a/bake-test.cmd b/bake-test.cmd index cf939f5..b0bc3c5 100644 --- a/bake-test.cmd +++ b/bake-test.cmd @@ -1 +1 @@ -clang test\test_%test%.c -Iinc -g -lkernel32 -lDbghelp -lciabatta.lib \ No newline at end of file +clang test\test_%test%.c src\libwinsane\libwinsane.obj -Iinc -g -lkernel32 -lDbghelp -lciabatta.lib \ No newline at end of file diff --git a/src/_win/stdio.c b/src/_win/stdio.c index 232a3b3..3d4aa4f 100644 --- a/src/_win/stdio.c +++ b/src/_win/stdio.c @@ -123,6 +123,9 @@ void _setup_io() { stdin->buffer = (stream_buffer_t){1, _IOLBF, BUFSIZ, in_buf}; stdout->buffer = (stream_buffer_t){1, _IOLBF, BUFSIZ, out_buf}; stderr->buffer = (stream_buffer_t){1, _IONBF, 0, NULL}; + + SetConsoleCP(CP_UTF8); // maybe will work someday + SetConsoleOutputCP(CP_UTF8); } int win_parse_mode( diff --git a/src/libwinsane b/src/libwinsane new file mode 160000 index 0000000..c229735 --- /dev/null +++ b/src/libwinsane @@ -0,0 +1 @@ +Subproject commit c22973570de5d75eff0f03a823536e781ebdac4c diff --git a/test/test_os.c b/test/test_os.c deleted file mode 100644 index 44d71c5..0000000 --- a/test/test_os.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include - -int main(int argc, char **argv) { - for(int i = 0; i != argc; ++i) { - char *arg = argv[i]; - printf("% 2d: %s\n", i, arg); - } - return 0; -} diff --git a/test/test_windows_utf8.c b/test/test_windows_utf8.c new file mode 100644 index 0000000..cd53d04 --- /dev/null +++ b/test/test_windows_utf8.c @@ -0,0 +1,20 @@ + +#include +#include + +#pragma comment(lib, "user32.lib") + +int main(int argc, char **argv) { + // Print args: + printf("Arguments:\n"); + for(int i = 0; i != argc; ++i) { + char *arg = argv[i]; + printf(" %s\n", arg); + } + // Test UTF-8 support: + printf(u8"Привет, мир!\n"); + printf(u8"こんにちくわ世界!\n"); + // Try UTF-8 in winapi (doesn't use UTF-8 without manifest) + MessageBoxA(NULL, u8"Успех", u8"Ошибка", MB_OK); + return 0; +}