comparison src/main-gui.cc @ 31629:ea0b06534a37 stable

Windows: Set console input and output codepages to UTF-8 if supported. * src/main-cli.cc (main), src/main-gui.cc (main): Temporary set the input and output codepage for the console to UTF-8. That is needed so that non-ASCII characters entered at the CLI are correctly stored as UTF-8 in Octave character arrays, and so that UTF-8 encoded character arrays are correctly displayed in the CLI.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 03 Dec 2022 13:41:42 +0100
parents 796f54d4ddbf
children ae0aa570c907 ec1f34091635
comparison
equal deleted inserted replaced
31623:59422a6fbd91 31629:ea0b06534a37
34 34
35 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE) 35 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
36 # include <vector> 36 # include <vector>
37 # include <locale> 37 # include <locale>
38 # include <codecvt> 38 # include <codecvt>
39 # include <windows.h>
40 # include <versionhelpers.h>
39 #endif 41 #endif
40 42
41 #include "liboctave-build-info.h" 43 #include "liboctave-build-info.h"
42 44
43 #include "liboctinterp-build-info.h" 45 #include "liboctinterp-build-info.h"
116 // Get pointers to C strings not before vector is stable. 118 // Get pointers to C strings not before vector is stable.
117 for (int i_arg = 0; i_arg < argc; i_arg++) 119 for (int i_arg = 0; i_arg < argc; i_arg++)
118 argv[i_arg] = &argv_str[i_arg][0]; 120 argv[i_arg] = &argv_str[i_arg][0];
119 argv[argc] = nullptr; 121 argv[argc] = nullptr;
120 122
123 unsigned int old_console_codepage = 0;
124 unsigned int old_console_output_codepage = 0;
125
126 if (IsWindows7OrGreater ())
127 {
128 // save old console input and output codepages
129 old_console_codepage = GetConsoleCP ();
130 old_console_output_codepage = GetConsoleOutputCP ();
131
132 // set console input and output codepages to UTF-8
133 SetConsoleCP (65001);
134 SetConsoleOutputCP (65001);
135 }
136
121 #else 137 #else
122 int 138 int
123 main (int argc, char **argv) 139 main (int argc, char **argv)
124 { 140 {
125 #endif 141 #endif
126 check_hg_versions (); 142 check_hg_versions ();
127 143
128 octave::sys::env::set_program_name (argv[0]); 144 octave::sys::env::set_program_name (argv[0]);
129 145
130 octave::qt_application app (argc, argv); 146 octave::qt_application app ("octave", "octave-gui", OCTAVE_VERSION,
147 argc, argv);
131 148
132 return app.execute (); 149 int ret = app.execute ();
150
151 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
152 if (IsWindows7OrGreater ())
153 {
154 // restore previous console input and output codepages
155 if (old_console_codepage)
156 SetConsoleCP (old_console_codepage);
157 if (old_console_output_codepage)
158 SetConsoleOutputCP (old_console_output_codepage);
159 }
160 #endif
161
162 return ret;
133 } 163 }