30#if ! defined (octave_shared_fcns_h)
31#define octave_shared_fcns_h 1
35#if defined (OCTAVE_USE_WINDOWS_API)
42# if defined (_MSC_VER)
44# define pclose _pclose
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))
88static const char dir_sep_char =
'\\';
90static const char dir_sep_char =
'/';
93#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
94static std::string dir_sep_chars = R
"(/\)";
96static std::string dir_sep_chars =
"/";
100octave_getenv (
const std::string& name)
102 char *value = ::getenv (name.c_str ());
104 return value ? value :
"";
107static std::string Voctave_home;
108static 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;
142static bool is_dir_sep (
char c)
144 return dir_sep_chars.find (c) != std::string::npos;
148absolute_pathname (
const std::string& s)
150 std::size_t
len = s.length ();
155 if (is_dir_sep (s[0]))
158#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
159 if ((
len == 2 && isalpha (s[0]) && s[1] ==
':')
160 || (
len > 2 && isalpha (s[0]) && s[1] ==
':'
161 && is_dir_sep (s[2])))
169prepend_home_dir (
const std::string& hd,
const std::string& s)
171 std::string retval = s;
173 if (! absolute_pathname (retval))
174 retval = hd + dir_sep_char + s;
176 if (dir_sep_char !=
'/')
177 std::replace (retval.begin (), retval.end (),
'/', dir_sep_char);
189prepend_octave_home (
const std::string& s)
191 return prepend_home_dir (Voctave_home, s);
195prepend_octave_exec_home (
const std::string& s)
197 return prepend_home_dir (Voctave_exec_home, s);
#define OCTAVE_EXEC_PREFIX