Mercurial > octave
comparison src/main-cli.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 | 597f3ee61a48 |
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" |
103 // Get pointers to C strings not before vector is stable. | 105 // Get pointers to C strings not before vector is stable. |
104 for (int i_arg = 0; i_arg < argc; i_arg++) | 106 for (int i_arg = 0; i_arg < argc; i_arg++) |
105 argv[i_arg] = &argv_str[i_arg][0]; | 107 argv[i_arg] = &argv_str[i_arg][0]; |
106 argv[argc] = nullptr; | 108 argv[argc] = nullptr; |
107 | 109 |
110 unsigned int old_console_codepage = 0; | |
111 unsigned int old_console_output_codepage = 0; | |
112 | |
113 if (IsWindows7OrGreater ()) | |
114 { | |
115 // save old console input and output codepages | |
116 old_console_codepage = GetConsoleCP (); | |
117 old_console_output_codepage = GetConsoleOutputCP (); | |
118 | |
119 // set console input and output codepages to UTF-8 | |
120 SetConsoleCP (65001); | |
121 SetConsoleOutputCP (65001); | |
122 } | |
123 | |
108 #else | 124 #else |
109 int | 125 int |
110 main (int argc, char **argv) | 126 main (int argc, char **argv) |
111 { | 127 { |
112 #endif | 128 #endif |
116 | 132 |
117 octave::sys::env::set_program_name (argv[0]); | 133 octave::sys::env::set_program_name (argv[0]); |
118 | 134 |
119 octave::cli_application app (argc, argv); | 135 octave::cli_application app (argc, argv); |
120 | 136 |
121 return app.execute (); | 137 int ret = app.execute (); |
138 | |
139 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE) | |
140 if (IsWindows7OrGreater ()) | |
141 { | |
142 // restore previous console input and output codepages | |
143 if (old_console_codepage) | |
144 SetConsoleCP (old_console_codepage); | |
145 if (old_console_output_codepage) | |
146 SetConsoleOutputCP (old_console_output_codepage); | |
147 } | |
148 #endif | |
149 | |
150 return ret; | |
122 } | 151 } |