GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
main-cli.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 "oct-env.h"
48 #include "signal-wrappers.h"
49 
50 #include "octave.h"
51 #include "octave-build-info.h"
52 #include "sysdep.h"
53 
54 static void
55 check_hg_versions ()
56 {
57  bool ok = true;
58 
59  // Each library and executable has its own definition of the hg
60  // id. They should always match but may be different because of a
61  // botched installation or incorrect LD_LIBRARY_PATH or some other
62  // unusual problem.
63 
64  std::string octave_id = octave_hg_id ();
65  std::string liboctave_id = liboctave_hg_id ();
66  std::string liboctinterp_id = liboctinterp_hg_id ();
67 
68  if (octave_id != liboctave_id)
69  {
70  std::cerr << "octave hg id ("
71  << octave_id
72  << ") does not match liboctave hg id ("
73  << liboctave_id
74  << ')' << std::endl;
75  ok = false;
76  }
77 
78  if (octave_id != liboctinterp_id)
79  {
80  std::cerr << "octave hg id ("
81  << octave_id
82  << ") does not match liboctinterp hg id ("
83  << liboctinterp_id
84  << ')' << std::endl;
85  ok = false;
86  }
87 
88  if (! ok)
89  exit (1);
90 }
91 
92 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
93 extern "C"
94 int
95 wmain (int argc, wchar_t **wargv)
96 {
97  static char **argv = new char * [argc + 1];
98  std::vector<std::string> argv_str;
99 
100  // convert wide character strings to multibyte UTF-8 strings
101  std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
102  for (int i_arg = 0; i_arg < argc; i_arg++)
103  argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
104 
105  // Get pointers to C strings not before vector is stable.
106  for (int i_arg = 0; i_arg < argc; i_arg++)
107  argv[i_arg] = &argv_str[i_arg][0];
108  argv[argc] = nullptr;
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 
124 #else
125 int
126 main (int argc, char **argv)
127 {
128 #endif
129  check_hg_versions ();
130 
132 
133  octave::sys::env::set_program_name (argv[0]);
134 
135  octave::cli_application app (argc, argv);
136 
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;
151 }
void octave_block_async_signals()
std::string liboctave_hg_id()
std::string liboctinterp_hg_id()
int main(int argc, char **argv)
Definition: main-cli.cc:126
std::string octave_hg_id()