GNU Octave  9.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-2024 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 ();
44 
45 public:
46 
47  OCTAVE_DISABLE_COPY_MOVE (env)
48 
49  ~env () = default;
50 
51  static std::string polite_directory_format (const std::string& name);
52 
53  static bool absolute_pathname (const std::string& s);
54 
55  static bool rooted_relative_pathname (const std::string& s);
56 
57  static std::string base_pathname (const std::string& s);
58 
59  static std::string
60  make_absolute (const std::string& s,
61  const std::string& dot_path = get_current_directory ());
62 
63  static std::string get_current_directory ();
64 
65  static std::string get_home_directory ();
66 
67  static std::string get_temp_directory ();
68 
69  static std::string get_user_config_directory ();
70 
71  static std::string get_user_data_directory ();
72 
73  static std::string get_program_name ();
74 
75  static std::string get_program_invocation_name ();
76 
77  static std::string get_user_name ();
78 
79  static std::string get_host_name ();
80 
81  static std::string getenv (const std::string& name);
82 
83  static bool isenv (const std::string& name);
84 
85  static void putenv (const std::string& name, const std::string& value);
86 
87  static bool have_x11_display ();
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 ();
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 ();
109 
110  std::string do_get_home_directory ();
111 
112  std::string do_get_temp_directory () const;
113 
114  std::string do_get_user_config_directory ();
115 
116  std::string do_get_user_data_directory ();
117 
118  std::string do_get_user_name ();
119 
120  std::string do_get_host_name ();
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 *s_instance;
138 
139  static void cleanup_instance ()
140  { delete s_instance; s_instance = nullptr; }
141 
142  // TRUE means follow symbolic links that point to directories just
143  // as if they are real directories.
144  bool m_follow_symbolic_links;
145 
146  // TRUE means that pwd always give verbatim directory, regardless
147  // of symbolic link following.
148  bool m_verbatim_pwd;
149 
150  // Where are we?
151  std::string m_current_directory;
152 
153  // Etc.
154  std::string m_prog_name;
155 
156  std::string m_prog_invocation_name;
157 
158  std::string m_user_name;
159 
160  std::string m_host_name;
161 };
162 
163 OCTAVE_END_NAMESPACE(sys)
164 OCTAVE_END_NAMESPACE(octave)
165 
166 #endif
Definition: oct-env.h:40
~env()=default
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void() error(const char *fmt,...)
Definition: error.cc:988
int chdir(const std::string &path_arg)
Definition: lo-sysdep.cc:107
#define OCTAVE_API
Definition: main.cc:55
octave_idx_type n
Definition: mx-inlines.cc:761