2203
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2203
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2203
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cstdlib> |
|
29 |
3503
|
30 #include <iostream> |
2203
|
31 #include <string> |
|
32 |
|
33 #ifdef HAVE_UNISTD_H |
2442
|
34 #ifdef HAVE_SYS_TYPES_H |
2203
|
35 #include <sys/types.h> |
2442
|
36 #endif |
2203
|
37 #include <unistd.h> |
|
38 #endif |
|
39 |
2926
|
40 #include "oct-env.h" |
4217
|
41 #include "file-stat.h" |
3174
|
42 #include "pathsearch.h" |
4217
|
43 #include "str-vec.h" |
2926
|
44 |
2492
|
45 #include <defaults.h> |
2203
|
46 #include "defun.h" |
|
47 #include "error.h" |
3040
|
48 #include "file-ops.h" |
2203
|
49 #include "gripes.h" |
|
50 #include "help.h" |
5395
|
51 #include "input.h" |
3185
|
52 #include "oct-obj.h" |
2390
|
53 #include "ov.h" |
4217
|
54 #include "parse.h" |
2203
|
55 #include "toplev.h" |
4217
|
56 #include "unwind-prot.h" |
2203
|
57 #include "variables.h" |
2492
|
58 #include <version.h> |
2203
|
59 |
3523
|
60 std::string Voctave_home; |
2203
|
61 |
3523
|
62 std::string Vbin_dir; |
|
63 std::string Vinfo_dir; |
|
64 std::string Vdata_dir; |
|
65 std::string Vlibexec_dir; |
|
66 std::string Varch_lib_dir; |
|
67 std::string Vlocal_arch_lib_dir; |
3597
|
68 std::string Vlocal_ver_arch_lib_dir; |
3523
|
69 std::string Vfcn_file_dir; |
5397
|
70 std::string Voct_file_dir; |
2203
|
71 |
4447
|
72 // The default path that will be searched for programs that we |
|
73 // execute (in addition to the user-specified --exec-path). |
5794
|
74 static std::string VDEFAULT_EXEC_PATH; |
4447
|
75 |
2203
|
76 // The path that will be searched for programs that we execute. |
|
77 // (--exec-path path) |
5794
|
78 static std::string VEXEC_PATH; |
2203
|
79 |
|
80 // Load path specified on command line. |
|
81 // (--path path; -p path) |
5794
|
82 static std::string VLOADPATH; |
2203
|
83 |
3192
|
84 // The default load path with OCTAVE_HOME appropriately substituted. |
5794
|
85 static std::string VDEFAULT_LOADPATH; |
3192
|
86 |
3174
|
87 // And the cached directory path corresponding to Vload_path. |
|
88 dir_path Vload_path_dir_path; |
|
89 |
2203
|
90 // Name of the editor to be invoked by the edit_history command. |
5794
|
91 std::string VEDITOR; |
2203
|
92 |
5794
|
93 static std::string VIMAGEPATH; |
2203
|
94 |
3523
|
95 std::string Vlocal_site_defaults_file; |
|
96 std::string Vsite_defaults_file; |
2203
|
97 |
4776
|
98 // Name of the FFTW wisdom program. |
5794
|
99 std::string Vfftw_wisdom_program; |
4773
|
100 |
4217
|
101 // Each element of A and B should be directory names. For each |
|
102 // element of A not in the list B, execute SCRIPT_FILE in that |
|
103 // directory if it exists. |
|
104 |
|
105 static void |
|
106 maybe_add_or_del_packages (const string_vector& a, |
|
107 const string_vector& b, |
4247
|
108 const std::string& script_file) |
4217
|
109 { |
|
110 if (! octave_interpreter_ready) |
|
111 return; |
|
112 |
|
113 unwind_protect::begin_frame ("maybe_add_or_del_packages"); |
|
114 |
|
115 unwind_protect_bool (input_from_startup_file); |
|
116 |
|
117 input_from_startup_file = true; |
|
118 |
5275
|
119 octave_idx_type a_len = a.length (); |
|
120 octave_idx_type b_len = b.length (); |
4217
|
121 |
5275
|
122 for (octave_idx_type i = 0; i < a_len; i++) |
4217
|
123 { |
|
124 std::string a_dir = a[i]; |
|
125 |
|
126 bool found = false; |
|
127 |
5275
|
128 for (octave_idx_type j = 0; j < b_len; j++) |
4217
|
129 { |
|
130 if (b[j] == a_dir) |
|
131 { |
|
132 found = true; |
|
133 break; |
|
134 } |
|
135 } |
|
136 |
|
137 if (! found) |
|
138 { |
|
139 std::string file = a_dir + file_ops::dir_sep_str + script_file; |
|
140 |
|
141 file_stat fs = file_stat (file); |
|
142 |
|
143 if (fs.exists ()) |
4486
|
144 source_file (file); |
4217
|
145 |
|
146 if (error_state) |
|
147 return; |
|
148 } |
|
149 } |
|
150 |
|
151 unwind_protect::run_frame ("maybe_add_or_del_packages"); |
|
152 } |
|
153 |
|
154 static void |
|
155 update_load_path_dir_path (void) |
|
156 { |
|
157 string_vector old_dirs = Vload_path_dir_path.all_directories (); |
|
158 |
5794
|
159 Vload_path_dir_path = dir_path (VLOADPATH, VDEFAULT_LOADPATH); |
4217
|
160 |
|
161 string_vector new_dirs = Vload_path_dir_path.all_directories (); |
|
162 |
|
163 maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL"); |
|
164 |
|
165 if (! error_state) |
|
166 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); |
|
167 } |
|
168 |
|
169 void |
|
170 execute_default_pkg_add_files (void) |
|
171 { |
|
172 string_vector old_dirs; |
|
173 string_vector new_dirs = Vload_path_dir_path.all_directories (); |
|
174 |
|
175 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); |
|
176 } |
|
177 |
3535
|
178 static std::string |
3523
|
179 subst_octave_home (const std::string& s) |
2203
|
180 { |
3523
|
181 std::string retval; |
2203
|
182 |
3523
|
183 std::string prefix = OCTAVE_PREFIX; |
2203
|
184 |
|
185 retval = s; |
|
186 |
|
187 if (Voctave_home != prefix) |
|
188 { |
5275
|
189 octave_idx_type len = prefix.length (); |
2203
|
190 size_t start = 0; |
2522
|
191 while ((start = retval.find (prefix, start)) != NPOS) |
2203
|
192 { |
|
193 retval.replace (start, len, Voctave_home); |
2522
|
194 start += len; |
2203
|
195 } |
|
196 } |
|
197 |
|
198 return retval; |
|
199 } |
|
200 |
|
201 static void |
|
202 set_octave_home (void) |
|
203 { |
3523
|
204 std::string oh = octave_env::getenv ("OCTAVE_HOME"); |
2203
|
205 |
3523
|
206 Voctave_home = oh.empty () ? std::string (OCTAVE_PREFIX) : oh; |
2203
|
207 } |
|
208 |
|
209 static void |
|
210 set_default_info_dir (void) |
|
211 { |
|
212 Vinfo_dir = subst_octave_home (OCTAVE_INFODIR); |
|
213 } |
|
214 |
|
215 static void |
3141
|
216 set_default_data_dir (void) |
|
217 { |
|
218 Vdata_dir = subst_octave_home (OCTAVE_DATADIR); |
|
219 } |
|
220 |
|
221 static void |
|
222 set_default_libexec_dir (void) |
|
223 { |
|
224 Vlibexec_dir = subst_octave_home (OCTAVE_LIBEXECDIR); |
|
225 } |
|
226 |
|
227 static void |
2203
|
228 set_default_arch_lib_dir (void) |
|
229 { |
|
230 Varch_lib_dir = subst_octave_home (OCTAVE_ARCHLIBDIR); |
|
231 } |
|
232 |
|
233 static void |
2439
|
234 set_default_local_arch_lib_dir (void) |
|
235 { |
|
236 Vlocal_arch_lib_dir = subst_octave_home (OCTAVE_LOCALARCHLIBDIR); |
|
237 } |
|
238 |
|
239 static void |
3597
|
240 set_default_local_ver_arch_lib_dir (void) |
|
241 { |
|
242 Vlocal_ver_arch_lib_dir = subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR); |
|
243 } |
|
244 |
|
245 static void |
2203
|
246 set_default_fcn_file_dir (void) |
|
247 { |
|
248 Vfcn_file_dir = subst_octave_home (OCTAVE_FCNFILEDIR); |
|
249 } |
|
250 |
|
251 static void |
5397
|
252 set_default_oct_file_dir (void) |
|
253 { |
|
254 Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); |
|
255 } |
|
256 |
|
257 static void |
2203
|
258 set_default_bin_dir (void) |
|
259 { |
|
260 Vbin_dir = subst_octave_home (OCTAVE_BINDIR); |
|
261 } |
|
262 |
|
263 static void |
4447
|
264 set_default_default_exec_path (void) |
|
265 { |
5794
|
266 VDEFAULT_EXEC_PATH |
5777
|
267 = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str |
|
268 + Vlocal_arch_lib_dir + dir_path::path_sep_str |
|
269 + Varch_lib_dir + dir_path::path_sep_str |
4447
|
270 + Vbin_dir; |
|
271 } |
|
272 |
|
273 static void |
2203
|
274 set_default_exec_path (void) |
|
275 { |
3523
|
276 std::string octave_exec_path = octave_env::getenv ("OCTAVE_EXEC_PATH"); |
2203
|
277 |
2926
|
278 if (octave_exec_path.empty ()) |
2203
|
279 { |
3523
|
280 std::string shell_path = octave_env::getenv ("PATH"); |
2203
|
281 |
2926
|
282 if (! shell_path.empty ()) |
2203
|
283 { |
5794
|
284 VEXEC_PATH = dir_path::path_sep_str; |
|
285 VEXEC_PATH.append (shell_path); |
2203
|
286 } |
|
287 } |
2926
|
288 else |
5794
|
289 VEXEC_PATH = std::string (octave_exec_path); |
2203
|
290 } |
|
291 |
|
292 static void |
|
293 set_default_path (void) |
|
294 { |
5794
|
295 VDEFAULT_LOADPATH = subst_octave_home (OCTAVE_FCNFILEPATH); |
2203
|
296 |
3523
|
297 std::string oct_path = octave_env::getenv ("OCTAVE_PATH"); |
2203
|
298 |
5794
|
299 VLOADPATH = oct_path.empty () ? dir_path::path_sep_str : oct_path; |
3174
|
300 |
4217
|
301 update_load_path_dir_path (); |
2203
|
302 } |
|
303 |
|
304 static void |
|
305 set_default_info_file (void) |
|
306 { |
3523
|
307 std::string std_info_file = subst_octave_home (OCTAVE_INFOFILE); |
2512
|
308 |
3523
|
309 std::string oct_info_file = octave_env::getenv ("OCTAVE_INFO_FILE"); |
2203
|
310 |
2926
|
311 Vinfo_file = oct_info_file.empty () ? std_info_file : oct_info_file; |
2203
|
312 } |
|
313 |
|
314 static void |
|
315 set_default_info_prog (void) |
|
316 { |
3523
|
317 std::string oct_info_prog = octave_env::getenv ("OCTAVE_INFO_PROGRAM"); |
2203
|
318 |
2926
|
319 if (oct_info_prog.empty ()) |
5794
|
320 Vinfo_program = "info"; |
2926
|
321 else |
5794
|
322 Vinfo_program = std::string (oct_info_prog); |
2203
|
323 } |
|
324 |
4773
|
325 static void |
4776
|
326 set_default_fftw_wisdom_prog (void) |
4773
|
327 { |
4776
|
328 std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_FFTW_WISDOM_PROGRAM"); |
4773
|
329 |
|
330 if (oct_wisdom_prog.empty ()) |
5794
|
331 Vfftw_wisdom_program = "fftw-wisdom"; |
4773
|
332 else |
5794
|
333 Vfftw_wisdom_program = std::string (oct_wisdom_prog); |
4773
|
334 } |
|
335 |
2203
|
336 static void |
|
337 set_default_editor (void) |
|
338 { |
5794
|
339 VEDITOR = "emacs"; |
2203
|
340 |
3523
|
341 std::string env_editor = octave_env::getenv ("EDITOR"); |
2203
|
342 |
2926
|
343 if (! env_editor.empty ()) |
5794
|
344 VEDITOR = env_editor; |
2203
|
345 } |
|
346 |
|
347 static void |
|
348 set_local_site_defaults_file (void) |
|
349 { |
5781
|
350 std::string lsf = octave_env::getenv ("OCTAVE_LOCAL_SITE_INITFILE"); |
|
351 |
|
352 if (lsf.empty ()) |
|
353 { |
|
354 Vlocal_site_defaults_file = subst_octave_home (OCTAVE_LOCALSTARTUPFILEDIR); |
|
355 Vlocal_site_defaults_file.append ("/octaverc"); |
|
356 } |
|
357 else |
|
358 Vlocal_site_defaults_file = lsf; |
2203
|
359 } |
|
360 |
|
361 static void |
|
362 set_site_defaults_file (void) |
|
363 { |
5781
|
364 std::string sf = octave_env::getenv ("OCTAVE_SITE_INITFILE"); |
|
365 |
|
366 if (sf.empty ()) |
|
367 { |
|
368 Vsite_defaults_file = subst_octave_home (OCTAVE_STARTUPFILEDIR); |
|
369 Vsite_defaults_file.append ("/octaverc"); |
|
370 } |
|
371 else |
|
372 Vsite_defaults_file = sf; |
2203
|
373 } |
|
374 |
3534
|
375 std::string |
3523
|
376 maybe_add_default_load_path (const std::string& pathstring) |
2203
|
377 { |
3523
|
378 std::string retval; |
2203
|
379 |
|
380 if (! pathstring.empty ()) |
|
381 { |
5777
|
382 if (dir_path::is_path_sep (pathstring[0])) |
2203
|
383 { |
5794
|
384 retval = VDEFAULT_LOADPATH; |
2203
|
385 retval.append (pathstring); |
|
386 } |
|
387 else |
|
388 retval = pathstring; |
|
389 |
5777
|
390 if (dir_path::is_path_sep (pathstring[pathstring.length () - 1])) |
5794
|
391 retval.append (VDEFAULT_LOADPATH); |
3192
|
392 |
|
393 size_t pos = 0; |
|
394 do |
|
395 { |
5777
|
396 pos = retval.find (dir_path::path_sep_str + dir_path::path_sep_str); |
3192
|
397 |
|
398 if (pos != NPOS) |
5794
|
399 retval.insert (pos+1, VDEFAULT_LOADPATH); |
3192
|
400 } |
|
401 while (pos != NPOS); |
2203
|
402 } |
|
403 |
|
404 return retval; |
|
405 } |
|
406 |
|
407 void |
|
408 install_defaults (void) |
|
409 { |
|
410 // OCTAVE_HOME must be set first! |
|
411 |
|
412 set_octave_home (); |
|
413 |
|
414 set_default_info_dir (); |
|
415 |
3141
|
416 set_default_data_dir (); |
|
417 |
|
418 set_default_libexec_dir (); |
|
419 |
2203
|
420 set_default_arch_lib_dir (); |
|
421 |
2439
|
422 set_default_local_arch_lib_dir (); |
|
423 |
3597
|
424 set_default_local_ver_arch_lib_dir (); |
|
425 |
2203
|
426 set_default_fcn_file_dir (); |
|
427 |
5397
|
428 set_default_oct_file_dir (); |
|
429 |
2203
|
430 set_default_bin_dir (); |
|
431 |
4447
|
432 set_default_default_exec_path (); |
|
433 |
2203
|
434 set_default_exec_path (); |
|
435 |
|
436 set_default_path (); |
|
437 |
|
438 set_default_info_file (); |
|
439 |
|
440 set_default_info_prog (); |
|
441 |
4776
|
442 set_default_fftw_wisdom_prog (); |
4773
|
443 |
2203
|
444 set_default_editor (); |
|
445 |
|
446 set_local_site_defaults_file (); |
|
447 |
|
448 set_site_defaults_file (); |
|
449 } |
|
450 |
4264
|
451 DEFUN (rehash, , , |
|
452 "-*- texinfo -*-\n\ |
|
453 @deftypefn {Built-in Function} {} rehash ()\n\ |
|
454 Reinitialize Octave's @code{LOADPATH} directory cache.\n\ |
|
455 @end deftypefn") |
|
456 { |
|
457 octave_value_list retval; |
|
458 |
|
459 Vload_path_dir_path.rehash (); |
|
460 |
|
461 return retval; |
|
462 } |
|
463 |
5794
|
464 DEFUN (EDITOR, args, nargout, |
|
465 "-*- texinfo -*-\n\ |
|
466 @deftypefn {Built-in Function} {@var{val} =} EDITOR ()\n\ |
|
467 @deftypefnx {Built-in Function} {@var{old_val} =} EDITOR (@var{new_val})\n\ |
|
468 Query or set the internal variable that specifies the editor to\n\ |
|
469 use with the @code{edit_history} command. If the environment\n\ |
|
470 variable @code{EDITOR} is set when Octave starts, its\n\ |
|
471 value is used as the default. Otherwise, @code{EDITOR} is set to\n\ |
|
472 @code{\"emacs\"}.\n\ |
|
473 @seealso{edit_history}\n\ |
|
474 @end deftypefn") |
2203
|
475 { |
5794
|
476 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); |
2203
|
477 } |
|
478 |
5794
|
479 static void |
|
480 update_exec_path (void) |
2203
|
481 { |
5794
|
482 std::string path; |
2439
|
483 |
5794
|
484 int eplen = VEXEC_PATH.length (); |
2203
|
485 |
5794
|
486 if (eplen > 0) |
|
487 { |
|
488 bool prepend = (VEXEC_PATH[0] == ':'); |
|
489 bool append = (eplen > 1 && VEXEC_PATH[eplen-1] == ':'); |
2203
|
490 |
5794
|
491 if (prepend) |
|
492 { |
|
493 path = VDEFAULT_EXEC_PATH + VEXEC_PATH; |
2203
|
494 } |
|
495 else |
5794
|
496 { |
|
497 path = VEXEC_PATH; |
4773
|
498 |
5794
|
499 if (append) |
|
500 path.append (VDEFAULT_EXEC_PATH); |
|
501 } |
2203
|
502 } |
|
503 else |
5794
|
504 path = VDEFAULT_EXEC_PATH; |
2203
|
505 |
5794
|
506 octave_env::putenv ("PATH", path); |
4217
|
507 } |
|
508 |
5794
|
509 DEFUN (EXEC_PATH, args, nargout, |
|
510 "-*- texinfo -*-\n\ |
|
511 @deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ |
|
512 @deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\ |
|
513 Query or set the internal variable that specifies a colon separated\n\ |
|
514 list of directories to search when executing external programs.\n\ |
|
515 Its initial value is taken from the environment variable\n\ |
|
516 @code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ |
|
517 value can be overridden by the command line argument\n\ |
|
518 @code{--exec-path PATH}. Any leading, trailing, or doubled colon in\n\ |
|
519 the value of @code{EXEC_PATH} are replaced by by the value of\n\ |
|
520 @code{DEFAULT_EXEC_PATH}.\n\ |
|
521 @seealso{DEFAULT_EXEC_PATH}\n\ |
|
522 @end deftypefn") |
4217
|
523 { |
5794
|
524 std::string saved_exec_path = VEXEC_PATH; |
4217
|
525 |
5794
|
526 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); |
4217
|
527 |
5794
|
528 if (VEXEC_PATH != saved_exec_path) |
|
529 update_exec_path (); |
2203
|
530 |
5794
|
531 return retval; |
2203
|
532 } |
|
533 |
5794
|
534 DEFUN (fftw_wisdom_program, args, nargout, |
3301
|
535 "-*- texinfo -*-\n\ |
5794
|
536 @deftypefn {Built-in Function} {@var{val} =} FFTW_WISDOM_PROGRAM ()\n\ |
|
537 @deftypefnx {Built-in Function} {@var{old_val} =} FFTW_WISDOM_PROGRAM (@var{new_val})\n\ |
|
538 Query or set the internal variable that specifies the FFTW wisdom\n\ |
|
539 program to use to create wisdom data to accelerate Fourier transforms.\n\ |
|
540 If the environment variable @code{OCTAVE_WISDOM_PROGRAM} is set when\n\ |
|
541 Octave starts, its value is used as the default. Otherwise,\n\ |
|
542 @code{WISDOM_PROGRAM} is set to @code{\"fftw-wisdom\"}.\n\ |
|
543 @end deftypefn") |
|
544 { |
|
545 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); |
|
546 } |
2203
|
547 |
5794
|
548 DEFUN (DEFAULT_EXEC_PATH, args, nargout, |
4447
|
549 "-*- texinfo -*-\n\ |
5794
|
550 @deftypefn {Built-in Function} {@var{val} =} DEFAULT_EXEC_PATH ()\n\ |
|
551 @deftypefnx {Built-in Function} {@var{old_val} =} DEFAULT_EXEC_PATH (@var{new_val})\n\ |
|
552 Query or set the internal variable that specifies a colon separated\n\ |
|
553 list of directories in which to search when executing\n\ |
4447
|
554 external programs. The value of this variable is automatically\n\ |
|
555 substituted for leading, trailing, or doubled colons that appear in the\n\ |
|
556 built-in variable @code{EXEC_PATH}.\n\ |
5794
|
557 @seealso{EXEC_PATH}\n\ |
|
558 @end deftypefn") |
|
559 { |
|
560 std::string saved_default_exec_path = VDEFAULT_EXEC_PATH; |
|
561 |
|
562 octave_value retval |
|
563 = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (DEFAULT_EXEC_PATH); |
|
564 |
|
565 if (VDEFAULT_EXEC_PATH != saved_default_exec_path) |
|
566 update_exec_path (); |
|
567 |
|
568 return retval; |
|
569 } |
4773
|
570 |
5794
|
571 DEFUN (IMAGEPATH, args, nargout, |
|
572 "-*- texinfo -*-\n\ |
|
573 @deftypefn {Built-in Function} {@var{val} =} IMAGEPATH ()\n\ |
|
574 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGEPATH (@var{new_val})\n\ |
|
575 Query or set the internal variable that specifies a colon separated\n\ |
|
576 list of directories in which to search for image files.\n\ |
|
577 @end deftypefn") |
|
578 { |
|
579 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGEPATH); |
|
580 } |
|
581 |
|
582 DEFUN (LOADPATH, args, nargout, |
3371
|
583 "-*- texinfo -*-\n\ |
5794
|
584 @deftypefn {Built-in Function} {@var{val} =} LOADPATH ()\n\ |
|
585 @deftypefnx {Built-in Function} {@var{old_val} =} LOADPATH (@var{new_val})\n\ |
|
586 Query or set the internal variable that specifies a colon separated\n\ |
|
587 list of directories in which to search for function\n\ |
3371
|
588 files. @xref{Functions and Scripts}. The value of @code{LOADPATH}\n\ |
|
589 overrides the environment variable @code{OCTAVE_PATH}. @xref{Installation}.\n\ |
|
590 \n\ |
5794
|
591 Leading, trailing, or doubled colons that appear in\n\ |
3371
|
592 @code{LOADPATH} are replaced by the value of @code{DEFAULT_LOADPATH}.\n\ |
5451
|
593 The default value of @code{LOADPATH} is @code{\"\n" |
|
594 SEPCHAR_STR |
|
595 "\"}, which tells Octave to search in the directories specified by\n\ |
|
596 @code{DEFAULT_LOADPATH}.\n\ |
3371
|
597 \n\ |
|
598 In addition, if any path element ends in @samp{//}, that directory and\n\ |
|
599 all subdirectories it contains are searched recursively for function\n\ |
|
600 files. This can result in a slight delay as Octave caches the lists of\n\ |
|
601 files found in the @code{LOADPATH} the first time Octave searches for a\n\ |
|
602 function. After that, searching is usually much faster because Octave\n\ |
|
603 normally only needs to search its internal cache for files.\n\ |
|
604 \n\ |
|
605 To improve performance of recursive directory searching, it is best for\n\ |
|
606 each directory that is to be searched recursively to contain\n\ |
|
607 @emph{either} additional subdirectories @emph{or} function files, but\n\ |
|
608 not a mixture of both.\n\ |
|
609 \n\ |
3402
|
610 @xref{Organization of Functions}, for a description of the function file\n\ |
3371
|
611 directories that are distributed with Octave.\n\ |
5794
|
612 @seealso{DEFAULT_LOADPATH}\n\ |
|
613 @end deftypefn") |
|
614 { |
|
615 std::string saved_loadpath = VLOADPATH; |
|
616 |
|
617 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (LOADPATH); |
2203
|
618 |
5794
|
619 if (VLOADPATH != saved_loadpath) |
|
620 { |
|
621 // By resetting the last prompt time variable, we will force |
|
622 // checks for out of date symbols even if the change to LOADPATH |
|
623 // and subsequent function calls happen between prompts. |
|
624 |
|
625 // FIXME -- maybe we should rename |
|
626 // Vlast_prompt_time_stamp since the new usage doesn't really |
|
627 // fit with the current name? |
|
628 |
|
629 Vlast_prompt_time.stamp (); |
|
630 |
|
631 update_load_path_dir_path (); |
|
632 } |
|
633 |
|
634 return retval; |
5780
|
635 } |
2203
|
636 |
5794
|
637 DEFUN (DEFAULT_LOADPATH, args, nargout, |
|
638 "-*- texinfo -*-\n\ |
|
639 @deftypefn {Built-in Function} {@var{val} =} DEFAULT_LOADPATH ()\n\ |
|
640 @deftypefnx {Built-in Function} {@var{old_val} =} DEFAULT_LOADPATH (@var{new_val})\n\ |
|
641 Query or set the internal variable that specifies the colon separated\n\ |
|
642 list of directories in which to search for function files. The value\n\ |
|
643 of this variable is automatically substituted for leading, trailing,\n\ |
|
644 or doubled colons that appear in the internal @code{loadpath} variable.\n\ |
|
645 @seealso{LOADPATH}\n\ |
|
646 @end deftypefn") |
|
647 { |
|
648 std::string saved_default_loadpath = VDEFAULT_LOADPATH; |
|
649 |
|
650 octave_value retval |
|
651 = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (DEFAULT_LOADPATH); |
|
652 |
|
653 if (VDEFAULT_LOADPATH != saved_default_loadpath) |
|
654 update_load_path_dir_path (); |
|
655 |
|
656 return retval; |
|
657 } |
|
658 |
5780
|
659 DEFUN (OCTAVE_HOME, args, , |
|
660 "-*- texinfo -*-\n\ |
|
661 @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ |
|
662 Return the name of the top-level Octave installation directory.\n\ |
|
663 @end deftypefn") |
|
664 { |
|
665 octave_value retval; |
2831
|
666 |
5780
|
667 if (args.length () == 0) |
|
668 retval = Voctave_home; |
|
669 else |
|
670 print_usage ("OCTAVE_HOME"); |
|
671 |
|
672 return retval; |
5749
|
673 } |
3446
|
674 |
5749
|
675 DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, , |
|
676 "-*- texinfo -*-\n\ |
|
677 @deftypefn {Built-in Function} {} OCTAVE_VERSION ()\n\ |
|
678 Return the version number of Octave, as a string.\n\ |
|
679 @end deftypefn") |
|
680 { |
|
681 octave_value retval; |
|
682 |
|
683 int nargin = args.length (); |
|
684 |
|
685 if (nargin == 0) |
|
686 retval = OCTAVE_VERSION; |
|
687 else |
|
688 print_usage ("OCTAVE_VERSION"); |
|
689 |
|
690 return retval; |
2203
|
691 } |
|
692 |
|
693 /* |
|
694 ;;; Local Variables: *** |
|
695 ;;; mode: C++ *** |
|
696 ;;; End: *** |
|
697 */ |