Mercurial > octave
annotate liboctave/system/oct-env.h @ 27832:8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
* oct-env.[cc,h] (get_user_config_directory, do_get_user_config_directory):
New functions.
* interpreter.cc (execute_startup_files): Try to execute the octaverc file at
a platform dependent location.
* doc/interpreter/basics.txi: Document new location for startup file.
* NEWS: Announce change.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 06 Mar 2019 14:54:38 -0800 |
parents | 00f796120a6d |
children | b442ec6dda5c |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25147
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2926 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
2926 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
2926 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2926 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_oct_env_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 #define octave_oct_env_h 1 |
2926 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 |
2926 | 28 #include <string> |
29 | |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
30 namespace octave |
2926 | 31 { |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
32 namespace sys |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
33 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
34 class |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
35 OCTAVE_API |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
36 env |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
37 { |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
38 protected: |
2926 | 39 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
40 env (void); |
2926 | 41 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 public: |
2926 | 43 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
44 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
45 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
46 env (const env&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
47 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
48 env& operator = (const env&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
49 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
50 static std::string polite_directory_format (const std::string& name); |
6838 | 51 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
52 static bool absolute_pathname (const std::string& s); |
2926 | 53 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
54 static bool rooted_relative_pathname (const std::string& s); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
55 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
56 static std::string base_pathname (const std::string& s); |
2926 | 57 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
58 static std::string |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
59 make_absolute (const std::string& s, |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
60 const std::string& dot_path = get_current_directory ()); |
2926 | 61 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
62 static std::string get_current_directory (void); |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17822
diff
changeset
|
63 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
64 static std::string get_home_directory (void); |
2926 | 65 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
66 static std::string get_temp_directory (void); |
2926 | 67 |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
68 static std::string get_user_config_directory (void); |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
69 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
70 static std::string get_program_name (void); |
2926 | 71 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
72 static std::string get_program_invocation_name (void); |
2926 | 73 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
74 static std::string get_user_name (void); |
2926 | 75 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
76 static std::string get_host_name (void); |
2926 | 77 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
78 static std::string getenv (const std::string& name); |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
79 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
80 static void putenv (const std::string& name, const std::string& value); |
5489 | 81 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
82 static bool have_x11_display (void); |
2926 | 83 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
84 static bool chdir (const std::string& newdir); |
2926 | 85 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
86 static void set_program_name (const std::string& s); |
2926 | 87 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
88 private: |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
89 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
90 static bool instance_ok (void); |
2926 | 91 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
92 std::string do_polite_directory_format (const std::string& name) const; |
2926 | 93 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
94 bool do_absolute_pathname (const std::string& s) const; |
2926 | 95 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
96 bool do_rooted_relative_pathname (const std::string& s) const; |
6838 | 97 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
98 std::string do_base_pathname (const std::string& s) const; |
2926 | 99 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
100 std::string do_make_absolute (const std::string& s, |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
101 const std::string& dot_path) const; |
2926 | 102 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
103 std::string do_getcwd (void) const; |
2926 | 104 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
105 std::string do_get_home_directory (void) const; |
2926 | 106 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
107 std::string do_get_temp_directory (void) const; |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
17822
diff
changeset
|
108 |
27832
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
109 std::string do_get_user_config_directory (void) const; |
8fd7d1d2a4ca
Read startup files from XDG_CONFIG_HOME or LOCALAPPDATA (bug #36477).
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
110 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
111 std::string do_get_user_name (void) const; |
2926 | 112 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
113 std::string do_get_host_name (void) const; |
2926 | 114 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
115 std::string do_getenv (const std::string& name) const; |
2926 | 116 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
117 void do_putenv (const std::string& name, const std::string& value) const; |
2926 | 118 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
119 bool do_chdir (const std::string& newdir); |
2926 | 120 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
121 void do_set_program_name (const std::string& s) const; |
2926 | 122 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
123 void pathname_backup (std::string& path, int n) const; |
2926 | 124 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
125 void error (int) const; |
2926 | 126 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
127 void error (const std::string&) const; |
2926 | 128 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
129 // The real thing. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
130 static env *instance; |
2926 | 131 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23615
diff
changeset
|
132 static void cleanup_instance (void) { delete instance; instance = nullptr; } |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
133 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
134 // TRUE means follow symbolic links that point to directories just |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
135 // as if they are real directories. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
136 bool follow_symbolic_links; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
137 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
138 // TRUE means that pwd always give verbatim directory, regardless |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
139 // of symbolic link following. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
140 bool verbatim_pwd; |
2926 | 141 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
142 // Where are we? |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
143 mutable std::string current_directory; |
2926 | 144 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
145 // Etc. |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
146 mutable std::string prog_name; |
2926 | 147 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
148 mutable std::string prog_invocation_name; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
149 |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
150 mutable std::string user_name; |
2926 | 151 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
152 mutable std::string host_name; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
153 }; |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
154 } |
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
155 } |
2926 | 156 |
157 #endif |