GNU Octave  9.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-2024 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 #include "version.h"
56 
57 static void
58 check_hg_versions ()
59 {
60  bool ok = true;
61 
62  // Each library and executable has its own definition of the hg
63  // id. They should always match but may be different because of a
64  // botched installation or incorrect LD_LIBRARY_PATH or some other
65  // unusual problem.
66 
67  std::string octave_id = octave_hg_id ();
68  std::string liboctave_id = liboctave_hg_id ();
69  std::string liboctinterp_id = liboctinterp_hg_id ();
70  std::string liboctgui_id = liboctgui_hg_id ();
71 
72  if (octave_id != liboctave_id)
73  {
74  std::cerr << "octave hg id ("
75  << octave_id
76  << ") does not match liboctave hg id ("
77  << liboctave_id
78  << ')' << std::endl;
79  ok = false;
80  }
81 
82  if (octave_id != liboctinterp_id)
83  {
84  std::cerr << "octave hg id ("
85  << octave_id
86  << ") does not match liboctinterp hg id ("
87  << liboctinterp_id
88  << ')' << std::endl;
89  ok = false;
90  }
91 
92  if (octave_id != liboctgui_id)
93  {
94  std::cerr << "octave hg id ("
95  << octave_id
96  << ") does not match liboctgui hg id ("
97  << liboctgui_id
98  << ')' << std::endl;
99  ok = false;
100  }
101 
102  if (! ok)
103  exit (1);
104 }
105 
106 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
107 extern "C"
108 int
109 wmain (int argc, wchar_t **wargv)
110 {
111  static char **argv = new char * [argc + 1];
112  std::vector<std::string> argv_str;
113 
114  // convert wide character strings to multibyte UTF-8 strings
115  std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
116  for (int i_arg = 0; i_arg < argc; i_arg++)
117  argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
118 
119  // Get pointers to C strings not before vector is stable.
120  for (int i_arg = 0; i_arg < argc; i_arg++)
121  argv[i_arg] = &argv_str[i_arg][0];
122  argv[argc] = nullptr;
123 
124  unsigned int old_console_codepage = 0;
125  unsigned int old_console_output_codepage = 0;
126 
127  if (IsWindows7OrGreater ())
128  {
129  // save old console input and output codepages
130  old_console_codepage = GetConsoleCP ();
131  old_console_output_codepage = GetConsoleOutputCP ();
132 
133  // set console input and output codepages to UTF-8
134  SetConsoleCP (65001);
135  SetConsoleOutputCP (65001);
136  }
137 
138 #else
139 int
140 main (int argc, char **argv)
141 {
142 #endif
143  check_hg_versions ();
144 
145  octave::sys::env::set_program_name (argv[0]);
146 
147  octave::qt_application app ("octave", "octave-gui", OCTAVE_VERSION,
148  argc, argv);
149 
150  int ret = app.execute ();
151 
152 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
153  if (IsWindows7OrGreater ())
154  {
155  // restore previous console input and output codepages
156  if (old_console_codepage)
157  SetConsoleCP (old_console_codepage);
158  if (old_console_output_codepage)
159  SetConsoleOutputCP (old_console_output_codepage);
160  }
161 #endif
162 
163  return ret;
164 }
std::string liboctave_hg_id()
std::string liboctinterp_hg_id()
int main(int argc, char **argv)
Definition: main-gui.cc:140
#define OCTAVE_VERSION
Definition: main.cc:63
std::string octave_hg_id()