annotate src/shared-fcns.h @ 23712:b95c430c0649

revamp insertion of config variables into binaries and eliminate some macros * subst-config-vals.in.sh, subst-cross-config-vals.in.sh, subst-default-vals.in.sh: Strip "^${prefix}/" or "^${exec_prefix} from directory and file variables before substitution. * defaults.h: Rename from defaults.in.h. * defaults.in.cc: Rename from defaults.cc. Move macro substitutions here from defaults.h * libinterp/corefcn/module.mk: Generate defaults.cc instead of defaults.in.h * defaults.h, defaults.in.cc (prepend_octave_home): Rename from subst_octave_home. Prepend instead of substitute OCTAVE_HOME. Skip absolute directory and file names. (prepend_octave_exec_home): New function to handle OCTAVE_EXEC_HOME separately from OCTAVE_HOME. (FOCTAVE_EXEC_HOME): New function. Expose more configuration variables as internal Octave variables. Change all uses of macros to use variables instead. * toplev.cc (F__octave_config_info__): Use std::map initializer to create structs. * shared-fcns.h (prepend_octave_home): Rename from subst_octave_home. Prepend instead of substitute OCTAVE_HOME. (prepend_octave_exec_home): Handle OCTAVE_EXEC_HOME separately from OCTAVE_HOME. Import additional support functions.
author John W. Eaton <jwe@octave.org>
date Wed, 28 Jun 2017 15:20:02 -0400
parents 092078913d54
children e5a1c8eb1d5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2008-2017 Michael Goffioul
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
10 (at your option) any later version.
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22412
diff changeset
15 GNU General Public License for more details.
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
23 // 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
24 // 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
25 // 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
26
21213
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 #if ! defined (octave_shared_fcns_h)
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
28 #define octave_shared_fcns_h 1
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
29
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
30 #include <cctype>
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
31
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21960
diff changeset
32 #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
33
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include <windows.h>
18400
e0b96a751afc Include tlhelp32.h in shared-fcns.h
John Donoghue <john.donoghue@ieee.org>
parents: 18360
diff changeset
35 #include <tlhelp32.h>
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
37 #if defined (_MSC_VER)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 19697
diff changeset
38 # define popen _popen
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 19697
diff changeset
39 # define pclose _pclose
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #endif
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 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
43 w32_get_octave_home (void)
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 {
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 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
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 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
48
23003
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
49 char namebuf[MAX_PATH+1];
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
50 if (GetModuleFileName (GetModuleHandle (NULL), namebuf, 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
51 {
23003
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
52 namebuf[MAX_PATH] = '\0';
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
23082
e8d64dce0afd maint: strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23003
diff changeset
54 std::string exe_name = namebuf;
23003
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
55 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
56
23003
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
57 if (pos != std::string::npos)
d591b38e3410 Use GetModuleFileName for getting octave path in windows (bug #48671)
John D
parents: 22412
diff changeset
58 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
59 }
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 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
62 {
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 size_t pos = bin_dir.rfind ("\\bin\\");
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 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
66 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
67 }
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 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
70 }
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 #endif
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 // 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
75 // installed.
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
77 #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
78 && ! 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
79 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
80 #else
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 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
82 #endif
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
84 #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
85 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
86 #else
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
87 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
88 #endif
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
89
18360
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 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
91 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
92 {
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 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
94
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 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
96 }
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
98 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
99 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
100
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
101 static void
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
102 set_octave_home (void)
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 {
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
104 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
105 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
106
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 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
108 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
109
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21960
diff changeset
110 #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
111 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
112 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
113 #endif
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
115 // If OCTAVE_HOME is set in the enviornment, use that. Otherwise,
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
116 // 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
117
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
118 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
119
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
120 // 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
121 // 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
122 // to the same value, use OCTAVE_HOME from the environment if it is set.
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
123 // Othewise, default to ${exec_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
124
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
125 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
126 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
127 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
128 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
129 else
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
130 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
131 }
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
132
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
133 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
134 {
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
135 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
136 }
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
137
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
138 static bool
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
139 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
140 {
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
141 size_t len = s.length ();
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
142
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
143 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
144 return false;
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 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
147 return true;
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
148
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
149 #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
150 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
151 || (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
152 && 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
153 return true;
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
154 #endif
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
155
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
156 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
157 }
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 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
160 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
161 {
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
162 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
163
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
164 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
165 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
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 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
168 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
169
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 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
171 }
21213
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
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 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
174 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
175 {
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
176 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
177 }
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
178
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
179 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
180 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
181 {
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
182 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
183 }
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
184
21213
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
185 #endif