GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
main-gui.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2025 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
44
46
47#include "liboctgui-build-info.h"
48
49#include "liboctmex-build-info.h"
50
51#include "oct-env.h"
52
53#include "octave.h"
54#include "octave-build-info.h"
55#include "qt-application.h"
56#include "sysdep.h"
57#include "version.h"
58
59static void
60check_hg_versions ()
61{
62 bool ok = true;
63
64 // Each library and executable has its own definition of the hg
65 // id. They should always match but may be different because of a
66 // botched installation or incorrect LD_LIBRARY_PATH or some other
67 // unusual problem.
68
69 std::string octave_id = octave_hg_id ();
70 std::string liboctave_id = liboctave_hg_id ();
71 std::string liboctinterp_id = liboctinterp_hg_id ();
72 std::string liboctgui_id = liboctgui_hg_id ();
73 std::string liboctmex_id = liboctmex_hg_id ();
74
75 if (octave_id != liboctave_id)
76 {
77 std::cerr << "octave hg id ("
78 << octave_id
79 << ") does not match liboctave hg id ("
80 << liboctave_id
81 << ')' << std::endl;
82 ok = false;
83 }
84
85 if (octave_id != liboctinterp_id)
86 {
87 std::cerr << "octave hg id ("
88 << octave_id
89 << ") does not match liboctinterp hg id ("
90 << liboctinterp_id
91 << ')' << std::endl;
92 ok = false;
93 }
94
95 if (octave_id != liboctgui_id)
96 {
97 std::cerr << "octave hg id ("
98 << octave_id
99 << ") does not match liboctgui hg id ("
100 << liboctgui_id
101 << ')' << std::endl;
102 ok = false;
103 }
104
105 if (octave_id != liboctmex_id)
106 {
107 std::cerr << "octave hg id ("
108 << octave_id
109 << ") does not match liboctmex hg id ("
110 << liboctmex_id
111 << ')' << std::endl;
112 ok = false;
113 }
114
115 if (! ok)
116 exit (1);
117}
118
119#if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
120extern "C"
121int
122wmain (int argc, wchar_t **wargv)
123{
124 static char **argv = new char * [argc + 1];
125 std::vector<std::string> argv_str;
126
127 // convert wide character strings to multibyte UTF-8 strings
128 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
129 for (int i_arg = 0; i_arg < argc; i_arg++)
130 argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
131
132 // Get pointers to C strings not before vector is stable.
133 for (int i_arg = 0; i_arg < argc; i_arg++)
134 argv[i_arg] = &argv_str[i_arg][0];
135 argv[argc] = nullptr;
136
137 unsigned int old_console_codepage = 0;
138 unsigned int old_console_output_codepage = 0;
139
140 if (IsWindows7OrGreater ())
141 {
142 // save old console input and output codepages
143 old_console_codepage = GetConsoleCP ();
144 old_console_output_codepage = GetConsoleOutputCP ();
145
146 // set console input and output codepages to UTF-8
147 SetConsoleCP (65001);
148 SetConsoleOutputCP (65001);
149 }
150
151#else
152int
153main (int argc, char **argv)
154{
155#endif
156 check_hg_versions ();
157
158 octave::sys::env::set_program_name (argv[0]);
159
160 std::string app_name ("octave-gui");
161 std::string settings_file = octave::sys::env::getenv ("OCTAVE_GUI_SETTINGS");
162 if (! settings_file.empty ())
163 app_name = settings_file;
164
165 octave::qt_application app ("octave", app_name, OCTAVE_VERSION,
166 argc, argv);
167
168 int ret = app.execute ();
169
170#if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
171 if (IsWindows7OrGreater ())
172 {
173 // restore previous console input and output codepages
174 if (old_console_codepage)
175 SetConsoleCP (old_console_codepage);
176 if (old_console_output_codepage)
177 SetConsoleOutputCP (old_console_output_codepage);
178 }
179#endif
180
181 return ret;
182}
program main
std::string liboctave_hg_id()
std::string liboctinterp_hg_id()
#define OCTAVE_VERSION
Definition main.in.cc:63
std::string octave_hg_id()