Mercurial > octave
annotate src/shared-fcns.h @ 33552:129d335e4b78 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Wed, 08 May 2024 15:17:17 -0400 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
3 // Copyright (C) 2008-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
26 // These functions are also defined in liboctave or libinterp. They |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
27 // are repeated here to avoid having to link the main Octave program |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
28 // with the Octave libraries. |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
29 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
30 #if ! defined (octave_shared_fcns_h) |
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
31 #define octave_shared_fcns_h 1 |
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
32 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
33 #include <cctype> |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
34 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21960
diff
changeset
|
35 #if defined (OCTAVE_USE_WINDOWS_API) |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
29537
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
37 # include <windows.h> |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
38 # include <tlhelp32.h> |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
39 # include <locale> |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
40 # include <codecvt> |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
29537
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
42 # if defined (_MSC_VER) |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
43 # define popen _popen |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
44 # define pclose _pclose |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
45 # endif |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 static std::string |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
48 w32_get_octave_home () |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 { |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 std::string retval; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 std::string bin_dir; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 |
29537
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
54 wchar_t namebuf[MAX_PATH+1]; |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
55 DWORD n_size |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
56 = GetModuleFileNameW (GetModuleHandle (nullptr), namebuf, MAX_PATH); |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
57 if (n_size < MAX_PATH) |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 { |
29537
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
59 // convert wide character string to multibyte UTF-8 string |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
60 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv; |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
61 std::string exe_name |
93a751f468d9
Windows: Allow non-ASCII characters in Octave home directory.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
62 = wchar_conv.to_bytes (std::wstring (namebuf, n_size)); |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
64 std::size_t pos = exe_name.rfind ('\\'); |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
23003
d591b38e3410
Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents:
22412
diff
changeset
|
66 if (pos != std::string::npos) |
d591b38e3410
Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents:
22412
diff
changeset
|
67 bin_dir = exe_name.substr (0, pos + 1); |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 } |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 if (! bin_dir.empty ()) |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
72 std::size_t pos = bin_dir.rfind (R"(\bin\)"); |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 if (pos != std::string::npos) |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 retval = bin_dir.substr (0, pos); |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 } |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 return retval; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 } |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 #endif |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 // Find the directory where the octave binary is supposed to be |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 // installed. |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21979
diff
changeset
|
86 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 static const char dir_sep_char = '\\'; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 #else |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 static const char dir_sep_char = '/'; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 #endif |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
93 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23791
diff
changeset
|
94 static std::string dir_sep_chars = R"(/\)"; |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
95 #else |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
96 static std::string dir_sep_chars = "/"; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
97 #endif |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
98 |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 static std::string |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 octave_getenv (const std::string& name) |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 { |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 char *value = ::getenv (name.c_str ()); |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 return value ? value : ""; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 } |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
107 static std::string Voctave_home; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
108 static std::string Voctave_exec_home; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
109 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
110 static void |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
111 set_octave_home () |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 { |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
113 std::string op = OCTAVE_PREFIX; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
114 std::string oep = OCTAVE_EXEC_PREFIX; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
115 |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 std::string oh = octave_getenv ("OCTAVE_HOME"); |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
117 std::string oeh = octave_getenv ("OCTAVE_EXEC_HOME"); |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21960
diff
changeset
|
119 #if defined (OCTAVE_USE_WINDOWS_API) |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 if (oh.empty ()) |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 oh = w32_get_octave_home (); |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 #endif |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
124 // If OCTAVE_HOME is set in the environment, use that. Otherwise, |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
125 // default to ${prefix} from configure. |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
126 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
127 Voctave_home = (oh.empty () ? op : oh); |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
128 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
129 // If OCTAVE_EXEC_HOME is set in the environment, use that. |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
130 // Otherwise, if ${prefix} and ${exec_prefix} from configure are set |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
131 // to the same value, use OCTAVE_HOME from the environment if it is set. |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
132 // Otherwise, default to ${exec_prefix} from configure. |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
133 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
134 if (! oeh.empty ()) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
135 Voctave_exec_home = oeh; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
136 else if (op == oep && ! oh.empty ()) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
137 Voctave_exec_home = oh; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
138 else |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
139 Voctave_exec_home = oep; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
140 } |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
141 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
142 static bool is_dir_sep (char c) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
143 { |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
144 return dir_sep_chars.find (c) != std::string::npos; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
145 } |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
146 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
147 static bool |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
148 absolute_pathname (const std::string& s) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
149 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
150 std::size_t len = s.length (); |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
151 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
152 if (len == 0) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
153 return false; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
154 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
155 if (is_dir_sep (s[0])) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
156 return true; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
157 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
158 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
159 if ((len == 2 && isalpha (s[0]) && s[1] == ':') |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
160 || (len > 2 && isalpha (s[0]) && s[1] == ':' |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
161 && is_dir_sep (s[2]))) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
162 return true; |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
163 #endif |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
164 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
165 return false; |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 } |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 static std::string |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
169 prepend_home_dir (const std::string& hd, const std::string& s) |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
170 { |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
171 std::string retval = s; |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
173 if (! absolute_pathname (retval)) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
174 retval = hd + dir_sep_char + s; |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 if (dir_sep_char != '/') |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 std::replace (retval.begin (), retval.end (), '/', dir_sep_char); |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 return retval; |
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 } |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
181 |
23791
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
182 // prepend_octave_home is used in mkoctfile.in.cc and |
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
183 // octave-config.in.cc but not in main.in.cc. Tagging it as unused |
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
184 // avoids warnings from GCC about an unused function but should not |
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
185 // cause trouble in the event that it actually is used. |
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
186 |
e5a1c8eb1d5b
* shared-fcns.h (prepend_octave_home): Tag with unused attribute.
John W. Eaton <jwe@octave.org>
parents:
23712
diff
changeset
|
187 OCTAVE_UNUSED |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
188 static std::string |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
189 prepend_octave_home (const std::string& s) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
190 { |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
191 return prepend_home_dir (Voctave_home, s); |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
192 } |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
193 |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
194 static std::string |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
195 prepend_octave_exec_home (const std::string& s) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
196 { |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
197 return prepend_home_dir (Voctave_exec_home, s); |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
198 } |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
199 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
200 #endif |