GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
main-gui.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2012-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdlib>
31 
32 #include <iostream>
33 #include <string>
34 
35 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
36 # include <vector>
37 # include <locale>
38 # include <codecvt>
39 # include <windows.h>
40 # include <versionhelpers.h>
41 #endif
42 
43 #include "liboctave-build-info.h"
44 
46 
47 #include "liboctgui-build-info.h"
48 
49 #include "oct-env.h"
50 
51 #include "octave.h"
52 #include "octave-build-info.h"
53 #include "qt-application.h"
54 #include "sysdep.h"
55 
56 static void
58 {
59  bool ok = true;
60 
61  // Each library and executable has its own definition of the hg
62  // id. They should always match but may be different because of a
63  // botched installation or incorrect LD_LIBRARY_PATH or some other
64  // unusual problem.
65 
66  std::string octave_id = octave_hg_id ();
67  std::string liboctave_id = liboctave_hg_id ();
68  std::string liboctinterp_id = liboctinterp_hg_id ();
69  std::string liboctgui_id = liboctgui_hg_id ();
70 
71  if (octave_id != liboctave_id)
72  {
73  std::cerr << "octave hg id ("
74  << octave_id
75  << ") does not match liboctave hg id ("
76  << liboctave_id
77  << ')' << std::endl;
78  ok = false;
79  }
80 
81  if (octave_id != liboctinterp_id)
82  {
83  std::cerr << "octave hg id ("
84  << octave_id
85  << ") does not match liboctinterp hg id ("
86  << liboctinterp_id
87  << ')' << std::endl;
88  ok = false;
89  }
90 
91  if (octave_id != liboctgui_id)
92  {
93  std::cerr << "octave hg id ("
94  << octave_id
95  << ") does not match liboctgui hg id ("
96  << liboctgui_id
97  << ')' << std::endl;
98  ok = false;
99  }
100 
101  if (! ok)
102  exit (1);
103 }
104 
105 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
106 extern "C"
107 int
108 wmain (int argc, wchar_t **wargv)
109 {
110  static char **argv = new char * [argc + 1];
111  std::vector<std::string> argv_str;
112 
113  // convert wide character strings to multibyte UTF-8 strings
114  std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
115  for (int i_arg = 0; i_arg < argc; i_arg++)
116  argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
117 
118  // Get pointers to C strings not before vector is stable.
119  for (int i_arg = 0; i_arg < argc; i_arg++)
120  argv[i_arg] = &argv_str[i_arg][0];
121  argv[argc] = nullptr;
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 
137 #else
138 int
139 main (int argc, char **argv)
140 {
141 #endif
143 
144  octave::sys::env::set_program_name (argv[0]);
145 
146  octave::qt_application app (argc, argv);
147 
148  int ret = app.execute ();
149 
150 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
151  if (IsWindows7OrGreater ())
152  {
153  // restore previous console input and output codepages
154  if (old_console_codepage)
155  SetConsoleCP (old_console_codepage);
156  if (old_console_output_codepage)
157  SetConsoleOutputCP (old_console_output_codepage);
158  }
159 #endif
160 
161  return ret;
162 }
OCTAVE_API std::string liboctave_hg_id(void)
OCTGUI_API std::string liboctgui_hg_id(void)
OCTINTERP_API std::string liboctinterp_hg_id(void)
int main(int argc, char **argv)
Definition: main-gui.cc:139
static void check_hg_versions(void)
Definition: main-gui.cc:57
std::string octave_hg_id(void)