# HG changeset patch # User Markus Mützel # Date 1670071461 -3600 # Node ID ae0aa570c90733ad2b917fe7b4edbc3c077120d7 # Parent 2fbbf9c073278f25986f41f3c8684616708d55b2# Parent ea0b06534a370ad65bd1b8ec0140289eef153585 maint: Merge stable to default. diff -r 2fbbf9c07327 -r ae0aa570c907 src/main-cli.cc --- a/src/main-cli.cc Sat Dec 03 13:29:27 2022 +0100 +++ b/src/main-cli.cc Sat Dec 03 13:44:21 2022 +0100 @@ -36,6 +36,8 @@ # include # include # include +# include +# include #endif #include "liboctave-build-info.h" @@ -105,6 +107,20 @@ argv[i_arg] = &argv_str[i_arg][0]; argv[argc] = nullptr; + unsigned int old_console_codepage = 0; + unsigned int old_console_output_codepage = 0; + + if (IsWindows7OrGreater ()) + { + // save old console input and output codepages + old_console_codepage = GetConsoleCP (); + old_console_output_codepage = GetConsoleOutputCP (); + + // set console input and output codepages to UTF-8 + SetConsoleCP (65001); + SetConsoleOutputCP (65001); + } + #else int main (int argc, char **argv) @@ -118,5 +134,18 @@ octave::cli_application app (argc, argv); - return app.execute (); + int ret = app.execute (); + +#if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE) + if (IsWindows7OrGreater ()) + { + // restore previous console input and output codepages + if (old_console_codepage) + SetConsoleCP (old_console_codepage); + if (old_console_output_codepage) + SetConsoleOutputCP (old_console_output_codepage); + } +#endif + + return ret; } diff -r 2fbbf9c07327 -r ae0aa570c907 src/main-gui.cc --- a/src/main-gui.cc Sat Dec 03 13:29:27 2022 +0100 +++ b/src/main-gui.cc Sat Dec 03 13:44:21 2022 +0100 @@ -36,6 +36,8 @@ # include # include # include +# include +# include #endif #include "liboctave-build-info.h" @@ -119,6 +121,20 @@ argv[i_arg] = &argv_str[i_arg][0]; argv[argc] = nullptr; + unsigned int old_console_codepage = 0; + unsigned int old_console_output_codepage = 0; + + if (IsWindows7OrGreater ()) + { + // save old console input and output codepages + old_console_codepage = GetConsoleCP (); + old_console_output_codepage = GetConsoleOutputCP (); + + // set console input and output codepages to UTF-8 + SetConsoleCP (65001); + SetConsoleOutputCP (65001); + } + #else int main (int argc, char **argv) @@ -131,5 +147,18 @@ octave::qt_application app ("octave", "octave-gui", OCTAVE_VERSION, argc, argv); - return app.execute (); + int ret = app.execute (); + +#if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE) + if (IsWindows7OrGreater ()) + { + // restore previous console input and output codepages + if (old_console_codepage) + SetConsoleCP (old_console_codepage); + if (old_console_output_codepage) + SetConsoleOutputCP (old_console_output_codepage); + } +#endif + + return ret; }