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 |
5814
|
40 #include "dir-ops.h" |
2926
|
41 #include "oct-env.h" |
4217
|
42 #include "file-stat.h" |
3174
|
43 #include "pathsearch.h" |
4217
|
44 #include "str-vec.h" |
2926
|
45 |
2492
|
46 #include <defaults.h> |
2203
|
47 #include "defun.h" |
|
48 #include "error.h" |
3040
|
49 #include "file-ops.h" |
2203
|
50 #include "gripes.h" |
|
51 #include "help.h" |
5395
|
52 #include "input.h" |
3185
|
53 #include "oct-obj.h" |
2390
|
54 #include "ov.h" |
4217
|
55 #include "parse.h" |
2203
|
56 #include "toplev.h" |
4217
|
57 #include "unwind-prot.h" |
2203
|
58 #include "variables.h" |
2492
|
59 #include <version.h> |
2203
|
60 |
3523
|
61 std::string Voctave_home; |
2203
|
62 |
3523
|
63 std::string Vbin_dir; |
|
64 std::string Vinfo_dir; |
|
65 std::string Vdata_dir; |
|
66 std::string Vlibexec_dir; |
|
67 std::string Varch_lib_dir; |
|
68 std::string Vlocal_arch_lib_dir; |
3597
|
69 std::string Vlocal_ver_arch_lib_dir; |
5814
|
70 |
|
71 std::string Vlocal_ver_oct_file_dir; |
|
72 std::string Vlocal_api_oct_file_dir; |
|
73 std::string Vlocal_oct_file_dir; |
2203
|
74 |
5814
|
75 std::string Vlocal_ver_fcn_file_dir; |
|
76 std::string Vlocal_api_fcn_file_dir; |
|
77 std::string Vlocal_fcn_file_dir; |
|
78 |
|
79 std::string Voct_file_dir; |
|
80 std::string Vfcn_file_dir; |
|
81 |
|
82 std::string Vimage_dir; |
4447
|
83 |
2203
|
84 // The path that will be searched for programs that we execute. |
|
85 // (--exec-path path) |
5794
|
86 static std::string VEXEC_PATH; |
2203
|
87 |
|
88 // Load path specified on command line. |
|
89 // (--path path; -p path) |
5794
|
90 static std::string VLOADPATH; |
2203
|
91 |
3192
|
92 // The default load path with OCTAVE_HOME appropriately substituted. |
5794
|
93 static std::string VDEFAULT_LOADPATH; |
3192
|
94 |
3174
|
95 // And the cached directory path corresponding to Vload_path. |
|
96 dir_path Vload_path_dir_path; |
|
97 |
2203
|
98 // Name of the editor to be invoked by the edit_history command. |
5794
|
99 std::string VEDITOR; |
2203
|
100 |
5814
|
101 static std::string VIMAGE_PATH; |
2203
|
102 |
3523
|
103 std::string Vlocal_site_defaults_file; |
|
104 std::string Vsite_defaults_file; |
2203
|
105 |
4776
|
106 // Name of the FFTW wisdom program. |
5794
|
107 std::string Vfftw_wisdom_program; |
4773
|
108 |
4217
|
109 // Each element of A and B should be directory names. For each |
|
110 // element of A not in the list B, execute SCRIPT_FILE in that |
|
111 // directory if it exists. |
|
112 |
|
113 static void |
|
114 maybe_add_or_del_packages (const string_vector& a, |
|
115 const string_vector& b, |
4247
|
116 const std::string& script_file) |
4217
|
117 { |
|
118 if (! octave_interpreter_ready) |
|
119 return; |
|
120 |
|
121 unwind_protect::begin_frame ("maybe_add_or_del_packages"); |
|
122 |
|
123 unwind_protect_bool (input_from_startup_file); |
|
124 |
|
125 input_from_startup_file = true; |
|
126 |
5275
|
127 octave_idx_type a_len = a.length (); |
|
128 octave_idx_type b_len = b.length (); |
4217
|
129 |
5275
|
130 for (octave_idx_type i = 0; i < a_len; i++) |
4217
|
131 { |
|
132 std::string a_dir = a[i]; |
|
133 |
|
134 bool found = false; |
|
135 |
5275
|
136 for (octave_idx_type j = 0; j < b_len; j++) |
4217
|
137 { |
|
138 if (b[j] == a_dir) |
|
139 { |
|
140 found = true; |
|
141 break; |
|
142 } |
|
143 } |
|
144 |
|
145 if (! found) |
|
146 { |
|
147 std::string file = a_dir + file_ops::dir_sep_str + script_file; |
|
148 |
|
149 file_stat fs = file_stat (file); |
|
150 |
|
151 if (fs.exists ()) |
4486
|
152 source_file (file); |
4217
|
153 |
|
154 if (error_state) |
|
155 return; |
|
156 } |
|
157 } |
|
158 |
|
159 unwind_protect::run_frame ("maybe_add_or_del_packages"); |
|
160 } |
|
161 |
|
162 static void |
|
163 update_load_path_dir_path (void) |
|
164 { |
|
165 string_vector old_dirs = Vload_path_dir_path.all_directories (); |
|
166 |
5814
|
167 Vload_path_dir_path = dir_path (VLOADPATH, ""); |
4217
|
168 |
|
169 string_vector new_dirs = Vload_path_dir_path.all_directories (); |
|
170 |
|
171 maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL"); |
|
172 |
|
173 if (! error_state) |
|
174 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); |
|
175 } |
|
176 |
|
177 void |
|
178 execute_default_pkg_add_files (void) |
|
179 { |
|
180 string_vector old_dirs; |
|
181 string_vector new_dirs = Vload_path_dir_path.all_directories (); |
|
182 |
|
183 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); |
|
184 } |
|
185 |
3535
|
186 static std::string |
3523
|
187 subst_octave_home (const std::string& s) |
2203
|
188 { |
3523
|
189 std::string retval; |
2203
|
190 |
3523
|
191 std::string prefix = OCTAVE_PREFIX; |
2203
|
192 |
|
193 retval = s; |
|
194 |
|
195 if (Voctave_home != prefix) |
|
196 { |
5275
|
197 octave_idx_type len = prefix.length (); |
2203
|
198 size_t start = 0; |
2522
|
199 while ((start = retval.find (prefix, start)) != NPOS) |
2203
|
200 { |
|
201 retval.replace (start, len, Voctave_home); |
2522
|
202 start += len; |
2203
|
203 } |
|
204 } |
|
205 |
|
206 return retval; |
|
207 } |
|
208 |
|
209 static void |
|
210 set_octave_home (void) |
|
211 { |
3523
|
212 std::string oh = octave_env::getenv ("OCTAVE_HOME"); |
2203
|
213 |
3523
|
214 Voctave_home = oh.empty () ? std::string (OCTAVE_PREFIX) : oh; |
2203
|
215 } |
|
216 |
|
217 static void |
|
218 set_default_info_dir (void) |
|
219 { |
|
220 Vinfo_dir = subst_octave_home (OCTAVE_INFODIR); |
|
221 } |
|
222 |
|
223 static void |
3141
|
224 set_default_data_dir (void) |
|
225 { |
|
226 Vdata_dir = subst_octave_home (OCTAVE_DATADIR); |
|
227 } |
|
228 |
|
229 static void |
|
230 set_default_libexec_dir (void) |
|
231 { |
|
232 Vlibexec_dir = subst_octave_home (OCTAVE_LIBEXECDIR); |
|
233 } |
|
234 |
|
235 static void |
2203
|
236 set_default_arch_lib_dir (void) |
|
237 { |
|
238 Varch_lib_dir = subst_octave_home (OCTAVE_ARCHLIBDIR); |
|
239 } |
|
240 |
|
241 static void |
2439
|
242 set_default_local_arch_lib_dir (void) |
|
243 { |
|
244 Vlocal_arch_lib_dir = subst_octave_home (OCTAVE_LOCALARCHLIBDIR); |
|
245 } |
|
246 |
|
247 static void |
3597
|
248 set_default_local_ver_arch_lib_dir (void) |
|
249 { |
|
250 Vlocal_ver_arch_lib_dir = subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR); |
|
251 } |
|
252 |
|
253 static void |
5814
|
254 set_default_local_ver_oct_file_dir (void) |
|
255 { |
|
256 Vlocal_ver_oct_file_dir = subst_octave_home (OCTAVE_LOCALVEROCTFILEDIR); |
|
257 } |
|
258 |
|
259 static void |
|
260 set_default_local_api_oct_file_dir (void) |
|
261 { |
|
262 Vlocal_api_oct_file_dir = subst_octave_home (OCTAVE_LOCALAPIOCTFILEDIR); |
|
263 } |
|
264 |
|
265 static void |
|
266 set_default_local_oct_file_dir (void) |
|
267 { |
|
268 Vlocal_oct_file_dir = subst_octave_home (OCTAVE_LOCALOCTFILEDIR); |
|
269 } |
|
270 |
|
271 static void |
|
272 set_default_local_ver_fcn_file_dir (void) |
|
273 { |
|
274 Vlocal_ver_fcn_file_dir = subst_octave_home (OCTAVE_LOCALVERFCNFILEDIR); |
|
275 } |
|
276 |
|
277 static void |
|
278 set_default_local_api_fcn_file_dir (void) |
|
279 { |
|
280 Vlocal_api_fcn_file_dir = subst_octave_home (OCTAVE_LOCALAPIFCNFILEDIR); |
|
281 } |
|
282 |
|
283 static void |
|
284 set_default_local_fcn_file_dir (void) |
|
285 { |
|
286 Vlocal_fcn_file_dir = subst_octave_home (OCTAVE_LOCALFCNFILEDIR); |
|
287 } |
|
288 |
|
289 static void |
2203
|
290 set_default_fcn_file_dir (void) |
|
291 { |
|
292 Vfcn_file_dir = subst_octave_home (OCTAVE_FCNFILEDIR); |
|
293 } |
|
294 |
|
295 static void |
5814
|
296 set_default_image_dir (void) |
|
297 { |
|
298 Vimage_dir = subst_octave_home (OCTAVE_IMAGEDIR); |
|
299 } |
|
300 |
|
301 static void |
5397
|
302 set_default_oct_file_dir (void) |
|
303 { |
|
304 Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); |
|
305 } |
|
306 |
|
307 static void |
2203
|
308 set_default_bin_dir (void) |
|
309 { |
|
310 Vbin_dir = subst_octave_home (OCTAVE_BINDIR); |
|
311 } |
|
312 |
5814
|
313 void |
|
314 set_exec_path (const std::string& path) |
4447
|
315 { |
5814
|
316 VEXEC_PATH = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str |
5777
|
317 + Vlocal_arch_lib_dir + dir_path::path_sep_str |
|
318 + Varch_lib_dir + dir_path::path_sep_str |
4447
|
319 + Vbin_dir; |
5814
|
320 |
|
321 // This is static so that even if set_exec_path is called more than |
|
322 // once, shell_path is the original PATH from the environment, |
|
323 // before we start modifying it. |
|
324 static std::string shell_path = octave_env::getenv ("PATH"); |
|
325 |
|
326 if (! shell_path.empty ()) |
|
327 VEXEC_PATH += dir_path::path_sep_str + shell_path; |
|
328 |
|
329 std::string tpath = path; |
|
330 |
|
331 if (tpath.empty ()) |
|
332 tpath = octave_env::getenv ("OCTAVE_EXEC_PATH"); |
|
333 |
|
334 if (! tpath.empty ()) |
|
335 VEXEC_PATH = tpath + dir_path::path_sep_str + VEXEC_PATH; |
|
336 |
|
337 octave_env::putenv ("PATH", VEXEC_PATH); |
|
338 } |
|
339 |
|
340 static std::string |
|
341 genpath (const std::string& dirname) |
|
342 { |
|
343 std::string retval; |
|
344 |
|
345 std::string full_dirname = file_ops::tilde_expand (dirname); |
|
346 |
|
347 dir_entry dir (full_dirname); |
|
348 |
|
349 if (dir) |
|
350 { |
|
351 retval = dirname; |
|
352 |
|
353 string_vector dirlist = dir.read (); |
|
354 |
|
355 octave_idx_type len = dirlist.length (); |
|
356 |
|
357 for (octave_idx_type i = 0; i < len; i++) |
|
358 { |
|
359 std::string elt = dirlist[i]; |
|
360 |
|
361 if (elt != "." && elt != ".." && elt != "private") |
|
362 { |
|
363 std::string nm = full_dirname + file_ops::dir_sep_str + elt; |
|
364 |
|
365 file_stat fs (nm); |
|
366 |
|
367 if (fs && fs.is_dir ()) |
|
368 retval += dir_path::path_sep_str + genpath (nm); |
|
369 } |
|
370 } |
|
371 } |
|
372 |
|
373 return retval; |
4447
|
374 } |
|
375 |
|
376 static void |
5814
|
377 maybe_add_path_elts (std::string& pathvar, const std::string& dir) |
2203
|
378 { |
5814
|
379 std::string tpath = genpath (dir); |
2203
|
380 |
5814
|
381 if (! tpath.empty ()) |
|
382 pathvar += dir_path::path_sep_str + tpath; |
2203
|
383 } |
|
384 |
5814
|
385 void |
|
386 set_load_path (const std::string& path) |
2203
|
387 { |
5814
|
388 VDEFAULT_LOADPATH = ":"; |
|
389 |
|
390 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_ver_oct_file_dir); |
|
391 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_api_oct_file_dir); |
|
392 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_oct_file_dir); |
|
393 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_ver_fcn_file_dir); |
|
394 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_api_fcn_file_dir); |
|
395 maybe_add_path_elts (VDEFAULT_LOADPATH, Vlocal_fcn_file_dir); |
|
396 maybe_add_path_elts (VDEFAULT_LOADPATH, Voct_file_dir); |
|
397 maybe_add_path_elts (VDEFAULT_LOADPATH, Vfcn_file_dir); |
2203
|
398 |
5814
|
399 std::string tpath = path; |
|
400 |
|
401 if (tpath.empty ()) |
|
402 tpath = octave_env::getenv ("OCTAVE_LOADPATH"); |
2203
|
403 |
5814
|
404 VLOADPATH = "."; |
|
405 |
|
406 if (! tpath.empty ()) |
|
407 VLOADPATH += dir_path::path_sep_str + tpath; |
|
408 |
|
409 if (VDEFAULT_LOADPATH != ":") |
|
410 VLOADPATH += VDEFAULT_LOADPATH; |
3174
|
411 |
4217
|
412 update_load_path_dir_path (); |
2203
|
413 } |
|
414 |
5814
|
415 void |
|
416 set_image_path (const std::string& path) |
|
417 { |
|
418 VIMAGE_PATH = "."; |
|
419 |
|
420 std::string tpath = path; |
|
421 |
|
422 if (tpath.empty ()) |
|
423 tpath = octave_env::getenv ("OCTAVE_IMAGE_PATH"); |
|
424 |
|
425 if (! tpath.empty ()) |
|
426 VIMAGE_PATH += dir_path::path_sep_str + tpath; |
|
427 |
|
428 maybe_add_path_elts (VIMAGE_PATH, Vimage_dir); |
|
429 } |
|
430 |
2203
|
431 static void |
|
432 set_default_info_file (void) |
|
433 { |
3523
|
434 std::string std_info_file = subst_octave_home (OCTAVE_INFOFILE); |
2512
|
435 |
3523
|
436 std::string oct_info_file = octave_env::getenv ("OCTAVE_INFO_FILE"); |
2203
|
437 |
2926
|
438 Vinfo_file = oct_info_file.empty () ? std_info_file : oct_info_file; |
2203
|
439 } |
|
440 |
|
441 static void |
|
442 set_default_info_prog (void) |
|
443 { |
3523
|
444 std::string oct_info_prog = octave_env::getenv ("OCTAVE_INFO_PROGRAM"); |
2203
|
445 |
2926
|
446 if (oct_info_prog.empty ()) |
5794
|
447 Vinfo_program = "info"; |
2926
|
448 else |
5794
|
449 Vinfo_program = std::string (oct_info_prog); |
2203
|
450 } |
|
451 |
4773
|
452 static void |
4776
|
453 set_default_fftw_wisdom_prog (void) |
4773
|
454 { |
4776
|
455 std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_FFTW_WISDOM_PROGRAM"); |
4773
|
456 |
|
457 if (oct_wisdom_prog.empty ()) |
5794
|
458 Vfftw_wisdom_program = "fftw-wisdom"; |
4773
|
459 else |
5794
|
460 Vfftw_wisdom_program = std::string (oct_wisdom_prog); |
4773
|
461 } |
|
462 |
2203
|
463 static void |
|
464 set_default_editor (void) |
|
465 { |
5794
|
466 VEDITOR = "emacs"; |
2203
|
467 |
3523
|
468 std::string env_editor = octave_env::getenv ("EDITOR"); |
2203
|
469 |
2926
|
470 if (! env_editor.empty ()) |
5794
|
471 VEDITOR = env_editor; |
2203
|
472 } |
|
473 |
|
474 static void |
|
475 set_local_site_defaults_file (void) |
|
476 { |
5781
|
477 std::string lsf = octave_env::getenv ("OCTAVE_LOCAL_SITE_INITFILE"); |
|
478 |
|
479 if (lsf.empty ()) |
|
480 { |
|
481 Vlocal_site_defaults_file = subst_octave_home (OCTAVE_LOCALSTARTUPFILEDIR); |
|
482 Vlocal_site_defaults_file.append ("/octaverc"); |
|
483 } |
|
484 else |
|
485 Vlocal_site_defaults_file = lsf; |
2203
|
486 } |
|
487 |
|
488 static void |
|
489 set_site_defaults_file (void) |
|
490 { |
5781
|
491 std::string sf = octave_env::getenv ("OCTAVE_SITE_INITFILE"); |
|
492 |
|
493 if (sf.empty ()) |
|
494 { |
|
495 Vsite_defaults_file = subst_octave_home (OCTAVE_STARTUPFILEDIR); |
|
496 Vsite_defaults_file.append ("/octaverc"); |
|
497 } |
|
498 else |
|
499 Vsite_defaults_file = sf; |
2203
|
500 } |
|
501 |
|
502 void |
|
503 install_defaults (void) |
|
504 { |
|
505 // OCTAVE_HOME must be set first! |
|
506 |
|
507 set_octave_home (); |
|
508 |
|
509 set_default_info_dir (); |
|
510 |
3141
|
511 set_default_data_dir (); |
|
512 |
|
513 set_default_libexec_dir (); |
|
514 |
2203
|
515 set_default_arch_lib_dir (); |
|
516 |
2439
|
517 set_default_local_arch_lib_dir (); |
|
518 |
3597
|
519 set_default_local_ver_arch_lib_dir (); |
|
520 |
5814
|
521 set_default_local_ver_oct_file_dir (); |
|
522 set_default_local_api_oct_file_dir (); |
|
523 set_default_local_oct_file_dir (); |
2203
|
524 |
5814
|
525 set_default_local_ver_fcn_file_dir (); |
|
526 set_default_local_api_fcn_file_dir (); |
|
527 set_default_local_fcn_file_dir (); |
|
528 |
|
529 set_default_fcn_file_dir (); |
5397
|
530 set_default_oct_file_dir (); |
|
531 |
5814
|
532 set_default_image_dir (); |
|
533 |
2203
|
534 set_default_bin_dir (); |
|
535 |
5814
|
536 set_exec_path (); |
4447
|
537 |
5814
|
538 set_load_path (); |
2203
|
539 |
5814
|
540 set_image_path (); |
2203
|
541 |
|
542 set_default_info_file (); |
|
543 |
|
544 set_default_info_prog (); |
|
545 |
4776
|
546 set_default_fftw_wisdom_prog (); |
4773
|
547 |
2203
|
548 set_default_editor (); |
|
549 |
|
550 set_local_site_defaults_file (); |
|
551 |
|
552 set_site_defaults_file (); |
|
553 } |
|
554 |
5814
|
555 DEFUN (genpath, args, , |
|
556 "-*- texinfo -*-\n\ |
|
557 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ |
|
558 Return a path constructed from @var{dir} and all its subdiretories.\n\ |
|
559 @end deftypefn") |
|
560 { |
|
561 octave_value retval; |
|
562 |
|
563 if (args.length () == 1) |
|
564 { |
|
565 std::string dirname = args(0).string_value (); |
|
566 |
|
567 if (! error_state) |
|
568 retval = genpath (dirname); |
|
569 else |
|
570 error ("genpath: expecting argument to be a character string"); |
|
571 } |
|
572 else |
5823
|
573 print_usage (); |
5814
|
574 |
|
575 return retval; |
|
576 } |
|
577 |
4264
|
578 DEFUN (rehash, , , |
|
579 "-*- texinfo -*-\n\ |
|
580 @deftypefn {Built-in Function} {} rehash ()\n\ |
|
581 Reinitialize Octave's @code{LOADPATH} directory cache.\n\ |
|
582 @end deftypefn") |
|
583 { |
|
584 octave_value_list retval; |
|
585 |
|
586 Vload_path_dir_path.rehash (); |
|
587 |
|
588 return retval; |
|
589 } |
|
590 |
5794
|
591 DEFUN (EDITOR, args, nargout, |
|
592 "-*- texinfo -*-\n\ |
|
593 @deftypefn {Built-in Function} {@var{val} =} EDITOR ()\n\ |
|
594 @deftypefnx {Built-in Function} {@var{old_val} =} EDITOR (@var{new_val})\n\ |
|
595 Query or set the internal variable that specifies the editor to\n\ |
|
596 use with the @code{edit_history} command. If the environment\n\ |
|
597 variable @code{EDITOR} is set when Octave starts, its\n\ |
|
598 value is used as the default. Otherwise, @code{EDITOR} is set to\n\ |
|
599 @code{\"emacs\"}.\n\ |
|
600 @seealso{edit_history}\n\ |
|
601 @end deftypefn") |
2203
|
602 { |
5794
|
603 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); |
2203
|
604 } |
|
605 |
5794
|
606 DEFUN (EXEC_PATH, args, nargout, |
|
607 "-*- texinfo -*-\n\ |
|
608 @deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ |
|
609 @deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\ |
|
610 Query or set the internal variable that specifies a colon separated\n\ |
|
611 list of directories to search when executing external programs.\n\ |
|
612 Its initial value is taken from the environment variable\n\ |
|
613 @code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ |
|
614 value can be overridden by the command line argument\n\ |
5814
|
615 @code{--exec-path PATH}. At startup, an additional set of\n\ |
|
616 directories (including the shell PATH) is appended to the path\n\ |
|
617 specified in the environment or on the command line. If you use\n\ |
|
618 the @code{EXEC_PATH} function to modify the path, you should take\n\ |
|
619 care to preserve these additional directories.\n\ |
5794
|
620 @end deftypefn") |
4217
|
621 { |
5794
|
622 std::string saved_exec_path = VEXEC_PATH; |
4217
|
623 |
5794
|
624 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); |
4217
|
625 |
5794
|
626 if (VEXEC_PATH != saved_exec_path) |
5814
|
627 octave_env::putenv ("PATH", VEXEC_PATH); |
2203
|
628 |
5794
|
629 return retval; |
2203
|
630 } |
|
631 |
5794
|
632 DEFUN (fftw_wisdom_program, args, nargout, |
3301
|
633 "-*- texinfo -*-\n\ |
5794
|
634 @deftypefn {Built-in Function} {@var{val} =} FFTW_WISDOM_PROGRAM ()\n\ |
|
635 @deftypefnx {Built-in Function} {@var{old_val} =} FFTW_WISDOM_PROGRAM (@var{new_val})\n\ |
|
636 Query or set the internal variable that specifies the FFTW wisdom\n\ |
|
637 program to use to create wisdom data to accelerate Fourier transforms.\n\ |
|
638 If the environment variable @code{OCTAVE_WISDOM_PROGRAM} is set when\n\ |
|
639 Octave starts, its value is used as the default. Otherwise,\n\ |
|
640 @code{WISDOM_PROGRAM} is set to @code{\"fftw-wisdom\"}.\n\ |
|
641 @end deftypefn") |
|
642 { |
|
643 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); |
|
644 } |
2203
|
645 |
5814
|
646 DEFUN (IMAGE_PATH, args, nargout, |
5794
|
647 "-*- texinfo -*-\n\ |
5814
|
648 @deftypefn {Built-in Function} {@var{val} =} IMAGE_PATH ()\n\ |
|
649 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGE_PATH (@var{new_val})\n\ |
5794
|
650 Query or set the internal variable that specifies a colon separated\n\ |
|
651 list of directories in which to search for image files.\n\ |
|
652 @end deftypefn") |
|
653 { |
5814
|
654 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGE_PATH); |
5794
|
655 } |
|
656 |
5814
|
657 DEFUN (path, args, nargout, |
3371
|
658 "-*- texinfo -*-\n\ |
5814
|
659 @deftypefn {Function File} {} path (@dots{})\n\ |
|
660 Modify or display Octave's @code{LOADPATH}.\n\ |
3371
|
661 \n\ |
5814
|
662 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ |
|
663 Octave's @code{LOADPATH} in an easy to read format.\n\ |
3371
|
664 \n\ |
5814
|
665 If @var{nargin} is zero and nargout is greater than zero, return the\n\ |
|
666 current value of @code{LOADPATH}.\n\ |
3371
|
667 \n\ |
5814
|
668 If @var{nargin} is greater than zero, concatenate the arguments,\n\ |
|
669 separating them with @code{pathsep()}. Set the internal search path\n\ |
|
670 to the result and return it.\n\ |
3371
|
671 \n\ |
5814
|
672 No checks are made for duplicate elements.\n\ |
|
673 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
5794
|
674 @end deftypefn") |
|
675 { |
5814
|
676 octave_value retval; |
|
677 |
|
678 int argc = args.length () + 1; |
5794
|
679 |
5814
|
680 string_vector argv = args.make_argv ("path"); |
2203
|
681 |
5814
|
682 if (! error_state) |
5794
|
683 { |
5814
|
684 if (argc > 1) |
|
685 { |
|
686 std::string path = argv[1]; |
|
687 |
|
688 for (int i = 2; i < argc; i++) |
|
689 path += dir_path::path_sep_str; |
|
690 |
|
691 size_t plen = path.length (); |
|
692 |
|
693 if (! ((plen == 1 && path[0] == ':') |
|
694 || (plen > 1 |
|
695 && path.substr (0, 2) == ("." + dir_path::path_sep_str)))) |
|
696 path = "." + dir_path::path_sep_str + path; |
|
697 |
|
698 VLOADPATH = path; |
|
699 |
|
700 // By resetting the last prompt time variable, we will force |
|
701 // checks for out of date symbols even if the change to |
|
702 // LOADPATH and subsequent function calls happen between |
|
703 // prompts. |
5794
|
704 |
5814
|
705 // FIXME -- maybe we should rename |
|
706 // Vlast_prompt_time_stamp since the new usage doesn't really |
|
707 // fit with the current name? |
|
708 |
|
709 Vlast_prompt_time.stamp (); |
|
710 |
|
711 update_load_path_dir_path (); |
|
712 } |
5794
|
713 |
5814
|
714 if (nargout > 0) |
|
715 retval = VLOADPATH; |
|
716 else if (argc == 1 && nargout == 0) |
|
717 { |
|
718 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; |
5794
|
719 |
5814
|
720 string_vector sv = Vload_path_dir_path.all_directories (); |
|
721 |
|
722 sv.list_in_columns (octave_stdout); |
|
723 |
|
724 octave_stdout << "\n"; |
|
725 } |
5794
|
726 } |
|
727 |
|
728 return retval; |
5780
|
729 } |
2203
|
730 |
5814
|
731 DEFUN (pathdef, , , |
5794
|
732 "-*- texinfo -*-\n\ |
|
733 @deftypefn {Built-in Function} {@var{val} =} DEFAULT_LOADPATH ()\n\ |
5814
|
734 Return the default list of directories in which to search for function\n\ |
|
735 files.\n\ |
5794
|
736 @seealso{LOADPATH}\n\ |
|
737 @end deftypefn") |
|
738 { |
5814
|
739 return octave_value (VDEFAULT_LOADPATH); |
5794
|
740 } |
|
741 |
5780
|
742 DEFUN (OCTAVE_HOME, args, , |
|
743 "-*- texinfo -*-\n\ |
|
744 @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ |
|
745 Return the name of the top-level Octave installation directory.\n\ |
|
746 @end deftypefn") |
|
747 { |
|
748 octave_value retval; |
2831
|
749 |
5780
|
750 if (args.length () == 0) |
|
751 retval = Voctave_home; |
|
752 else |
5823
|
753 print_usage (); |
5780
|
754 |
|
755 return retval; |
5749
|
756 } |
3446
|
757 |
5749
|
758 DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, , |
|
759 "-*- texinfo -*-\n\ |
|
760 @deftypefn {Built-in Function} {} OCTAVE_VERSION ()\n\ |
|
761 Return the version number of Octave, as a string.\n\ |
|
762 @end deftypefn") |
|
763 { |
|
764 octave_value retval; |
|
765 |
|
766 int nargin = args.length (); |
|
767 |
|
768 if (nargin == 0) |
|
769 retval = OCTAVE_VERSION; |
|
770 else |
5823
|
771 print_usage (); |
5749
|
772 |
|
773 return retval; |
2203
|
774 } |
|
775 |
|
776 /* |
|
777 ;;; Local Variables: *** |
|
778 ;;; mode: C++ *** |
|
779 ;;; End: *** |
|
780 */ |