GNU Octave  6.2.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-2021 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 
33 namespace octave
34 {
35  namespace sys
36  {
37  class
38  OCTAVE_API
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_program_name (void);
74 
75  static std::string get_program_invocation_name (void);
76 
77  static std::string get_user_name (void);
78 
79  static std::string get_host_name (void);
80 
81  static std::string getenv (const std::string& name);
82 
83  static void putenv (const std::string& name, const std::string& value);
84 
85  static bool have_x11_display (void);
86 
87  static bool chdir (const std::string& newdir);
88 
89  static void set_program_name (const std::string& s);
90 
91  private:
92 
93  static bool instance_ok (void);
94 
95  std::string do_polite_directory_format (const std::string& name) const;
96 
97  bool do_absolute_pathname (const std::string& s) const;
98 
99  bool do_rooted_relative_pathname (const std::string& s) const;
100 
101  std::string do_base_pathname (const std::string& s) const;
102 
103  std::string do_make_absolute (const std::string& s,
104  const std::string& dot_path) const;
105 
106  std::string do_getcwd (void) const;
107 
108  std::string do_get_home_directory (void) const;
109 
110  std::string do_get_temp_directory (void) const;
111 
112  std::string do_get_user_config_directory (void) const;
113 
114  std::string do_get_user_name (void) const;
115 
116  std::string do_get_host_name (void) const;
117 
118  std::string do_getenv (const std::string& name) const;
119 
120  void do_putenv (const std::string& name, const std::string& value) const;
121 
122  bool do_chdir (const std::string& newdir);
123 
124  void do_set_program_name (const std::string& s) const;
125 
126  void pathname_backup (std::string& path, int n) const;
127 
128  void error (int) const;
129 
130  void error (const std::string&) const;
131 
132  // The real thing.
133  static env *instance;
134 
135  static void cleanup_instance (void) { delete instance; instance = nullptr; }
136 
137  // TRUE means follow symbolic links that point to directories just
138  // as if they are real directories.
140 
141  // TRUE means that pwd always give verbatim directory, regardless
142  // of symbolic link following.
144 
145  // Where are we?
146  mutable std::string current_directory;
147 
148  // Etc.
149  mutable std::string prog_name;
150 
151  mutable std::string prog_invocation_name;
152 
153  mutable std::string user_name;
154 
155  mutable std::string host_name;
156  };
157  }
158 }
159 
160 #endif
std::string prog_invocation_name
Definition: oct-env.h:151
bool follow_symbolic_links
Definition: oct-env.h:139
static void cleanup_instance(void)
Definition: oct-env.h:135
bool verbatim_pwd
Definition: oct-env.h:143
std::string current_directory
Definition: oct-env.h:146
std::string host_name
Definition: oct-env.h:155
void do_putenv(const std::string &name, const std::string &value) const
env(const env &)=delete
static env * instance
Definition: oct-env.h:133
std::string user_name
Definition: oct-env.h:153
std::string prog_name
Definition: oct-env.h:149
void error(const char *fmt,...)
Definition: error.cc:968
QString path
QString name
static std::string get_temp_directory(void)
octave_idx_type n
Definition: mx-inlines.cc:753
int chdir(const std::string &path_arg)
Definition: lo-sysdep.cc:88
static string_vector make_absolute(const string_vector &sv)
Definition: utils.cc:385
static bool absolute_pathname(const std::string &s)
Definition: shared-fcns.h:142