changeset 31630:ae0aa570c907

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 03 Dec 2022 13:44:21 +0100
parents 2fbbf9c07327 (current diff) ea0b06534a37 (diff)
children 4c040e1edb4b
files src/main-gui.cc
diffstat 2 files changed, 60 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 <vector>
 #  include <locale>
 #  include <codecvt>
+#  include <windows.h>
+#  include <versionhelpers.h>
 #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;
 }
--- 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 <vector>
 #  include <locale>
 #  include <codecvt>
+#  include <windows.h>
+#  include <versionhelpers.h>
 #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;
 }