GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
main-cli.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 "liboctmex-build-info.h"
48
49#include "oct-env.h"
50#include "signal-wrappers.h"
51
52#include "octave.h"
53#include "octave-build-info.h"
54#include "sysdep.h"
55
56static void
57check_hg_versions ()
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 liboctmex_id = liboctmex_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 != liboctmex_id)
92 {
93 std::cerr << "octave hg id ("
94 << octave_id
95 << ") does not match liboctmex hg id ("
96 << liboctmex_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)
106extern "C"
107int
108wmain (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
138int
139main (int argc, char **argv)
140{
141#endif
142 check_hg_versions ();
143
145
146 octave::sys::env::set_program_name (argv[0]);
147
148 octave::cli_application app (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}
void octave_block_async_signals()
program main
std::string liboctave_hg_id()
std::string liboctinterp_hg_id()
std::string octave_hg_id()