Mercurial > octave
annotate libinterp/corefcn/environment.cc @ 25103:078b795c5219 stable
maint: style check C++ ahead of 4.4 release.
* ButtonGroup.cc, Canvas.cc, Figure.cc, GLCanvas.cc, GLCanvas.h,
ListBoxControl.cc, ObjectProxy.cc, QTerminal.h, dialog.cc, documentation.cc,
files-dock-widget.cc, history-dock-widget.cc, file-editor-tab.cc,
file-editor.h, find-dialog.cc, marker.h, octave-qscintilla.cc,
octave-qscintilla.h, main-window.cc, webinfo.cc, resource-manager.h,
settings-dialog.cc, shortcut-manager.cc, shortcut-manager.h,
variable-editor.cc, workspace-view.cc, build-env.in.cc, __ilu__.cc, cellfun.cc,
data.cc, dirfns.cc, dynamic-ld.h, environment.cc, error.cc, fcn-info.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, help.cc,
interpreter.cc, load-path.cc, load-save.cc, ls-mat5.cc, mex.cc, oct-stream.cc,
oct-stream.h, qz.cc, sighandlers.cc, sparse-xpow.cc, svd.cc, symscope.h,
symtab.cc, symtab.h, sysdep.cc, url-handle-manager.h, utils.cc, variables.cc,
__init_fltk__.cc, __ode15__.cc, gzip.cc, ov-base.cc, ov-builtin.h, ov-cell.cc,
ov-class.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-java.cc, ov-re-diag.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc,
op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc,
op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcs-fcm.cc, op-fcs-fcs.cc,
op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc,
op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc,
op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc,
op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc,
op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc,
op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc,
op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc,
op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc,
bp-table.cc, comment-list.h, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, lex.h,
parse.h, pt-binop.h, pt-decl.h, pt-eval.cc, pt-jit.cc, pt-jit.h, pt-misc.h,
token.h, CMatrix.cc, CMatrix.h, CSparse.cc, CSparse.h, dMatrix.h, fCMatrix.cc,
fCMatrix.h, fMatrix.h, Faddeeva.cc, gepbalance.cc, hess.cc, oct-fftw.cc,
oct-fftw.h, file-stat.cc, lo-sysinfo.cc, action-container.h, f77-fcn.h,
lo-regexp.cc, oct-mutex.h, oct-shlib.cc:
Use Octave coding conventions in C++ files.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 03 Apr 2018 13:52:07 -0700 |
parents | 6652d3823428 |
children | 389757b7b6af |
rev | line source |
---|---|
23719 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2017-2018 John W. Eaton |
23719 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23719
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
23719 | 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:
23719
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
23719 | 10 (at your option) any later version. |
11 | |
12 Octave is distributed in the hope that it will be useful, but | |
13 WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License 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 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23719
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
23719 | 20 |
21 */ | |
22 | |
23 #if defined (HAVE_CONFIG_H) | |
24 # include "config.h" | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
29 #include "dir-ops.h" | |
30 #include "oct-env.h" | |
31 #include "file-stat.h" | |
32 #include "pathsearch.h" | |
33 #include "str-vec.h" | |
34 | |
35 #include "defaults.h" | |
36 #include "defun.h" | |
37 #include "environment.h" | |
38 #include "interpreter.h" | |
39 #include "variables.h" | |
40 | |
41 static void append_to_shell_path (const std::string& exec_path) | |
42 { | |
43 // FIXME: should there be a way to remove a previous setting from | |
44 // PATH? | |
45 | |
46 if (exec_path.empty ()) | |
47 return; | |
48 | |
49 // FIXME: should we really be modifying PATH in the environment? | |
50 | |
51 std::string shell_path = octave::sys::env::getenv ("PATH"); | |
52 | |
53 if (shell_path.empty ()) | |
54 octave::sys::env::putenv ("PATH", exec_path); | |
55 else | |
56 { | |
57 // If PATH doesn't already have exec_path, append it. | |
58 // FIXME: should we search for the elements individually, and | |
59 // only append those that are missing? | |
60 | |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
61 std::string path_sep = octave::directory_path::path_sep_str (); |
23719 | 62 |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
63 if (shell_path.find (exec_path) == std::string::npos) |
23719 | 64 octave::sys::env::putenv ("PATH", shell_path + path_sep + exec_path); |
65 } | |
66 } | |
67 | |
68 namespace octave | |
69 { | |
70 octave_value | |
71 environment::editor (const octave_value_list& args, int nargout) | |
72 { | |
73 return set_internal_variable (m_editor, args, nargout, "EDITOR", false); | |
74 } | |
75 | |
76 | |
77 octave_value | |
78 environment::exec_path (const octave_value_list& args, int nargout) | |
79 { | |
80 octave_value retval | |
81 = set_internal_variable (m_exec_path, args, nargout, "EXEC_PATH", false); | |
82 | |
83 append_to_shell_path (m_exec_path); | |
84 | |
85 return retval; | |
86 } | |
87 | |
88 std::string environment::exec_path (const std::string& path) | |
89 { | |
90 std::string old_val = set (m_exec_path, path); | |
91 | |
92 append_to_shell_path (m_exec_path); | |
93 | |
94 return old_val; | |
95 } | |
96 | |
97 octave_value | |
98 environment::image_path (const octave_value_list& args, int nargout) | |
99 { | |
100 return set_internal_variable (m_image_path, args, nargout, "IMAGE_PATH", | |
101 false); | |
102 } | |
103 | |
104 std::string environment::init_editor (void) | |
105 { | |
106 std::string retval = "emacs"; | |
107 | |
108 std::string env_editor = octave::sys::env::getenv ("EDITOR"); | |
109 | |
110 if (! env_editor.empty ()) | |
111 retval = env_editor; | |
112 | |
113 return retval; | |
114 } | |
115 | |
116 std::string environment::init_exec_path (void) | |
117 { | |
118 std::string exec_path = octave::sys::env::getenv ("OCTAVE_EXEC_PATH"); | |
119 | |
120 std::string path_sep = octave::directory_path::path_sep_str (); | |
121 | |
122 if (exec_path.empty ()) | |
123 exec_path = (config::local_ver_arch_lib_dir () + path_sep | |
124 + config::local_api_arch_lib_dir () + path_sep | |
125 + config::local_arch_lib_dir () + path_sep | |
126 + config::arch_lib_dir () + path_sep | |
127 + config::bin_dir ()); | |
128 | |
129 append_to_shell_path (exec_path); | |
130 | |
131 return exec_path; | |
132 } | |
133 | |
134 std::string environment::init_image_path (void) | |
135 { | |
136 std::string image_path = "."; | |
137 | |
138 std::string path_sep = octave::directory_path::path_sep_str (); | |
139 | |
140 std::string env_path = octave::sys::env::getenv ("OCTAVE_IMAGE_PATH"); | |
141 | |
142 if (! env_path.empty ()) | |
143 image_path += path_sep + env_path; | |
144 | |
145 std::string gen_path = octave::genpath (config::image_dir (), ""); | |
146 | |
147 if (! gen_path.empty ()) | |
148 image_path += path_sep + gen_path; | |
149 | |
150 return image_path; | |
151 } | |
152 } | |
153 | |
154 DEFMETHOD (EDITOR, interp, args, nargout, | |
155 doc: /* -*- texinfo -*- | |
156 @deftypefn {} {@var{val} =} EDITOR () | |
157 @deftypefnx {} {@var{old_val} =} EDITOR (@var{new_val}) | |
158 @deftypefnx {} {} EDITOR (@var{new_val}, "local") | |
159 Query or set the internal variable that specifies the default text editor. | |
160 | |
161 The default value is taken from the environment variable @w{@env{EDITOR}} | |
162 when Octave starts. If the environment variable is not initialized, | |
163 @w{@env{EDITOR}} will be set to @qcode{"emacs"}. | |
164 | |
165 When called from inside a function with the @qcode{"local"} option, the | |
166 variable is changed locally for the function and any subroutines it calls. | |
167 The original variable value is restored when exiting the function. | |
168 | |
169 @seealso{edit, edit_history} | |
170 @end deftypefn */) | |
171 { | |
172 octave::environment& env = interp.get_environment (); | |
173 | |
174 return env.editor (args, nargout); | |
175 } | |
176 | |
177 /* | |
178 %!test | |
179 %! orig_val = EDITOR (); | |
180 %! old_val = EDITOR ("X"); | |
181 %! assert (orig_val, old_val); | |
182 %! assert (EDITOR (), "X"); | |
183 %! EDITOR (orig_val); | |
184 %! assert (EDITOR (), orig_val); | |
185 | |
186 %!error (EDITOR (1, 2)) | |
187 */ | |
188 | |
189 DEFMETHOD (EXEC_PATH, interp, args, nargout, | |
190 doc: /* -*- texinfo -*- | |
191 @deftypefn {} {@var{val} =} EXEC_PATH () | |
192 @deftypefnx {} {@var{old_val} =} EXEC_PATH (@var{new_val}) | |
193 @deftypefnx {} {} EXEC_PATH (@var{new_val}, "local") | |
194 Query or set the internal variable that specifies a colon separated | |
195 list of directories to append to the shell PATH when executing external | |
196 programs. | |
197 | |
198 The initial value of is taken from the environment variable | |
199 @w{@env{OCTAVE_EXEC_PATH}}, but that value can be overridden by the command | |
200 line argument @option{--exec-path PATH}. | |
201 | |
202 When called from inside a function with the @qcode{"local"} option, the | |
203 variable is changed locally for the function and any subroutines it calls. | |
204 The original variable value is restored when exiting the function. | |
205 | |
206 @seealso{IMAGE_PATH, OCTAVE_HOME, OCTAVE_EXEC_HOME} | |
207 @end deftypefn */) | |
208 { | |
209 octave::environment& env = interp.get_environment (); | |
210 | |
211 return env.exec_path (args, nargout); | |
212 } | |
213 | |
214 /* | |
215 %!test | |
216 %! orig_val = EXEC_PATH (); | |
217 %! old_val = EXEC_PATH ("X"); | |
218 %! assert (orig_val, old_val); | |
219 %! assert (EXEC_PATH (), "X"); | |
220 %! EXEC_PATH (orig_val); | |
221 %! assert (EXEC_PATH (), orig_val); | |
222 | |
223 %!error (EXEC_PATH (1, 2)) | |
224 */ | |
225 | |
226 DEFMETHOD (IMAGE_PATH, interp, args, nargout, | |
227 doc: /* -*- texinfo -*- | |
228 @deftypefn {} {@var{val} =} IMAGE_PATH () | |
229 @deftypefnx {} {@var{old_val} =} IMAGE_PATH (@var{new_val}) | |
230 @deftypefnx {} {} IMAGE_PATH (@var{new_val}, "local") | |
231 Query or set the internal variable that specifies a colon separated | |
232 list of directories in which to search for image files. | |
233 | |
234 When called from inside a function with the @qcode{"local"} option, the | |
235 variable is changed locally for the function and any subroutines it calls. | |
236 The original variable value is restored when exiting the function. | |
237 | |
238 @seealso{EXEC_PATH, OCTAVE_HOME, OCTAVE_EXEC_HOME} | |
239 @end deftypefn */) | |
240 { | |
241 octave::environment& env = interp.get_environment (); | |
242 | |
243 return env.image_path (args, nargout); | |
244 } | |
245 | |
246 /* | |
247 %!test | |
248 %! orig_val = IMAGE_PATH (); | |
249 %! old_val = IMAGE_PATH ("X"); | |
250 %! assert (orig_val, old_val); | |
251 %! assert (IMAGE_PATH (), "X"); | |
252 %! IMAGE_PATH (orig_val); | |
253 %! assert (IMAGE_PATH (), orig_val); | |
254 | |
255 %!error (IMAGE_PATH (1, 2)) | |
256 */ |