GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
shared-fcns.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_shared_fcns_h)
24 #define octave_shared_fcns_h 1
25 
26 #if defined (OCTAVE_USE_WINDOWS_API)
27 
28 #include <windows.h>
29 #include <tlhelp32.h>
30 
31 #if defined (_MSC_VER)
32 # define popen _popen
33 # define pclose _pclose
34 #endif
35 
36 static std::string
37 w32_get_octave_home (void)
38 {
40 
41  std::string bin_dir;
42 
43  char namebuf[MAX_PATH+1];
44  if (GetModuleFileName (GetModuleHandle (NULL), namebuf, MAX_PATH))
45  {
46  namebuf[MAX_PATH] = '\0';
47 
48  std::string exe_name = namebuf;
49  size_t pos = exe_name.rfind ("\\");
50 
51  if (pos != std::string::npos)
52  bin_dir = exe_name.substr (0, pos + 1);
53  }
54 
55  if (! bin_dir.empty ())
56  {
57  size_t pos = bin_dir.rfind ("\\bin\\");
58 
59  if (pos != std::string::npos)
60  retval = bin_dir.substr (0, pos);
61  }
62 
63  return retval;
64 }
65 
66 #endif
67 
68 // Find the directory where the octave binary is supposed to be
69 // installed.
70 
71 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
72  && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
73 static const char dir_sep_char = '\\';
74 #else
75 static const char dir_sep_char = '/';
76 #endif
77 
78 static std::string
80 {
81  char *value = ::getenv (name.c_str ());
82 
83  return value ? value : "";
84 }
85 
86 static std::string
88 {
89  std::string oh = octave_getenv ("OCTAVE_HOME");
90 
91 #if defined (OCTAVE_USE_WINDOWS_API)
92  if (oh.empty ())
93  oh = w32_get_octave_home ();
94 #endif
95 
96  return oh.empty () ? std::string (OCTAVE_PREFIX) : oh;
97 }
98 
99 static std::string
101 {
103 
104  std::string octave_home = get_octave_home ();
105 
106  std::string prefix = OCTAVE_PREFIX;
107 
108  retval = s;
109 
110  if (octave_home != prefix)
111  {
112  size_t len = prefix.length ();
113 
114  if (s.substr (0, len) == prefix)
115  retval.replace (0, len, octave_home);
116  }
117 
118  if (dir_sep_char != '/')
119  std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
120 
121  return retval;
122 }
123 
124 #endif
static std::string get_octave_home(void)
Definition: shared-fcns.h:87
static std::string subst_octave_home(const std::string &s)
Definition: shared-fcns.h:100
s
Definition: file-io.cc:2682
#define OCTAVE_PREFIX
Definition: main.cc:61
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
static void replace(QString &text, const QRegExp &re, const QString &after)
Definition: parser.cc:561
octave_value retval
Definition: data.cc:6294
static const char dir_sep_char
Definition: shared-fcns.h:75
static std::string octave_getenv(const std::string &name)
Definition: shared-fcns.h:79
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854