GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-env.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_oct_env_h)
27 #define octave_oct_env_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
34 
36 
37 class
39 env
40 {
41 protected:
42 
43  env (void);
44 
45 public:
46 
47  // No copying!
48 
49  env (const env&) = delete;
50 
51  env& operator = (const env&) = delete;
52 
53  static std::string polite_directory_format (const std::string& name);
54 
55  static bool absolute_pathname (const std::string& s);
56 
57  static bool rooted_relative_pathname (const std::string& s);
58 
59  static std::string base_pathname (const std::string& s);
60 
61  static std::string
62  make_absolute (const std::string& s,
63  const std::string& dot_path = get_current_directory ());
64 
65  static std::string get_current_directory (void);
66 
67  static std::string get_home_directory (void);
68 
69  static std::string get_temp_directory (void);
70 
71  static std::string get_user_config_directory (void);
72 
73  static std::string get_user_data_directory (void);
74 
75  static std::string get_program_name (void);
76 
77  static std::string get_program_invocation_name (void);
78 
79  static std::string get_user_name (void);
80 
81  static std::string get_host_name (void);
82 
83  static std::string getenv (const std::string& name);
84 
85  static void putenv (const std::string& name, const std::string& value);
86 
87  static bool have_x11_display (void);
88 
89  static bool chdir (const std::string& newdir);
90 
91  static void set_program_name (const std::string& s);
92 
93 private:
94 
95  static bool instance_ok (void);
96 
97  std::string do_polite_directory_format (const std::string& name);
98 
99  bool do_absolute_pathname (const std::string& s) const;
100 
101  bool do_rooted_relative_pathname (const std::string& s) const;
102 
103  std::string do_base_pathname (const std::string& s) const;
104 
105  std::string do_make_absolute (const std::string& s,
106  const std::string& dot_path) const;
107 
108  std::string do_getcwd (void);
109 
110  std::string do_get_home_directory (void);
111 
112  std::string do_get_temp_directory (void) const;
113 
114  std::string do_get_user_config_directory (void);
115 
116  std::string do_get_user_data_directory (void);
117 
118  std::string do_get_user_name (void);
119 
120  std::string do_get_host_name (void);
121 
122  std::string do_getenv (const std::string& name) const;
123 
124  void do_putenv (const std::string& name, const std::string& value) const;
125 
126  bool do_chdir (const std::string& newdir);
127 
128  void do_set_program_name (const std::string& s);
129 
130  void pathname_backup (std::string& path, int n) const;
131 
132  void error (int) const;
133 
134  void error (const std::string&) const;
135 
136  // The real thing.
137  static env *m_instance;
138 
139  static void cleanup_instance (void)
140  { delete m_instance; m_instance = nullptr; }
141 
142  // TRUE means follow symbolic links that point to directories just
143  // as if they are real directories.
145 
146  // TRUE means that pwd always give verbatim directory, regardless
147  // of symbolic link following.
149 
150  // Where are we?
151  std::string m_current_directory;
152 
153  // Etc.
154  std::string m_prog_name;
155 
157 
158  std::string m_user_name;
159 
160  std::string m_host_name;
161 };
162 
165 
166 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: oct-env.h:40
bool m_verbatim_pwd
Definition: oct-env.h:148
std::string m_prog_invocation_name
Definition: oct-env.h:156
env(const env &)=delete
std::string m_user_name
Definition: oct-env.h:158
static void cleanup_instance(void)
Definition: oct-env.h:139
std::string m_current_directory
Definition: oct-env.h:151
void do_putenv(const std::string &name, const std::string &value) const
std::string m_host_name
Definition: oct-env.h:160
std::string m_prog_name
Definition: oct-env.h:154
static env * m_instance
Definition: oct-env.h:137
bool m_follow_symbolic_links
Definition: oct-env.h:144
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
int chdir(const std::string &path_arg)
Definition: lo-sysdep.cc:106
#define OCTAVE_API
Definition: main.in.cc:55
static std::string get_temp_directory(void)
octave_idx_type n
Definition: mx-inlines.cc:753
static bool absolute_pathname(const std::string &s)
Definition: shared-fcns.h:148
static string_vector make_absolute(const string_vector &sv)
Definition: utils.cc:536