30 #if ! defined (octave_shared_fcns_h)
31 #define octave_shared_fcns_h 1
35 #if defined (OCTAVE_USE_WINDOWS_API)
38 # include <tlhelp32.h>
42 # if defined (_MSC_VER)
44 # define pclose _pclose
48 w32_get_octave_home ()
54 wchar_t namebuf[MAX_PATH+1];
56 = GetModuleFileNameW (GetModuleHandle (
nullptr), namebuf, MAX_PATH);
57 if (n_size < MAX_PATH)
60 std::wstring_convert<std::codecvt_utf8<wchar_t>,
wchar_t> wchar_conv;
62 = wchar_conv.to_bytes (std::wstring (namebuf, n_size));
64 std::size_t pos = exe_name.rfind (
'\\');
66 if (pos != std::string::npos)
67 bin_dir = exe_name.substr (0, pos + 1);
72 std::size_t pos =
bin_dir.rfind (R
"(\bin\)");
74 if (pos != std::string::npos)
75 retval =
bin_dir.substr (0, pos);
86 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
87 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
93 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
100 octave_getenv (
const std::string& name)
102 char *value = ::getenv (name.c_str ());
104 return value ? value :
"";
107 static std::string Voctave_home;
108 static std::string Voctave_exec_home;
116 std::string oh = octave_getenv (
"OCTAVE_HOME");
117 std::string oeh = octave_getenv (
"OCTAVE_EXEC_HOME");
119 #if defined (OCTAVE_USE_WINDOWS_API)
121 oh = w32_get_octave_home ();
127 Voctave_home = (oh.empty () ? op : oh);
135 Voctave_exec_home = oeh;
136 else if (op == oep && ! oh.empty ())
137 Voctave_exec_home = oh;
139 Voctave_exec_home = oep;
148 absolute_pathname (
const std::string& s)
150 std::size_t
len = s.length ();
158 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
159 if ((
len == 2 && isalpha (s[0]) && s[1] ==
':')
160 || (
len > 2 && isalpha (s[0]) && s[1] ==
':'
169 prepend_home_dir (
const std::string& hd,
const std::string& s)
171 std::string retval = s;
173 if (! absolute_pathname (retval))
177 std::replace (retval.begin (), retval.end (),
'/',
dir_sep_char);
191 return prepend_home_dir (Voctave_home, s);
197 return prepend_home_dir (Voctave_exec_home, s);
std::string prepend_octave_home(const std::string &s)
std::string prepend_octave_exec_home(const std::string &s)
std::string dir_sep_chars()
#define OCTAVE_EXEC_PREFIX