Mercurial > octave-nkf
comparison src/defaults.cc @ 5814:67bf9b4f2ae2
[project @ 2006-05-11 21:58:34 by jwe]
author | jwe |
---|---|
date | Thu, 11 May 2006 21:58:34 +0000 |
parents | 1138ced03f14 |
children | 080c08b192d8 |
comparison
equal
deleted
inserted
replaced
5813:dfef2f909f34 | 5814:67bf9b4f2ae2 |
---|---|
35 #include <sys/types.h> | 35 #include <sys/types.h> |
36 #endif | 36 #endif |
37 #include <unistd.h> | 37 #include <unistd.h> |
38 #endif | 38 #endif |
39 | 39 |
40 #include "dir-ops.h" | |
40 #include "oct-env.h" | 41 #include "oct-env.h" |
41 #include "file-stat.h" | 42 #include "file-stat.h" |
42 #include "pathsearch.h" | 43 #include "pathsearch.h" |
43 #include "str-vec.h" | 44 #include "str-vec.h" |
44 | 45 |
64 std::string Vdata_dir; | 65 std::string Vdata_dir; |
65 std::string Vlibexec_dir; | 66 std::string Vlibexec_dir; |
66 std::string Varch_lib_dir; | 67 std::string Varch_lib_dir; |
67 std::string Vlocal_arch_lib_dir; | 68 std::string Vlocal_arch_lib_dir; |
68 std::string Vlocal_ver_arch_lib_dir; | 69 std::string Vlocal_ver_arch_lib_dir; |
70 | |
71 std::string Vlocal_ver_oct_file_dir; | |
72 std::string Vlocal_api_oct_file_dir; | |
73 std::string Vlocal_oct_file_dir; | |
74 | |
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; | |
69 std::string Vfcn_file_dir; | 80 std::string Vfcn_file_dir; |
70 std::string Voct_file_dir; | 81 |
71 | 82 std::string Vimage_dir; |
72 // The default path that will be searched for programs that we | |
73 // execute (in addition to the user-specified --exec-path). | |
74 static std::string VDEFAULT_EXEC_PATH; | |
75 | 83 |
76 // The path that will be searched for programs that we execute. | 84 // The path that will be searched for programs that we execute. |
77 // (--exec-path path) | 85 // (--exec-path path) |
78 static std::string VEXEC_PATH; | 86 static std::string VEXEC_PATH; |
79 | 87 |
88 dir_path Vload_path_dir_path; | 96 dir_path Vload_path_dir_path; |
89 | 97 |
90 // Name of the editor to be invoked by the edit_history command. | 98 // Name of the editor to be invoked by the edit_history command. |
91 std::string VEDITOR; | 99 std::string VEDITOR; |
92 | 100 |
93 static std::string VIMAGEPATH; | 101 static std::string VIMAGE_PATH; |
94 | 102 |
95 std::string Vlocal_site_defaults_file; | 103 std::string Vlocal_site_defaults_file; |
96 std::string Vsite_defaults_file; | 104 std::string Vsite_defaults_file; |
97 | 105 |
98 // Name of the FFTW wisdom program. | 106 // Name of the FFTW wisdom program. |
154 static void | 162 static void |
155 update_load_path_dir_path (void) | 163 update_load_path_dir_path (void) |
156 { | 164 { |
157 string_vector old_dirs = Vload_path_dir_path.all_directories (); | 165 string_vector old_dirs = Vload_path_dir_path.all_directories (); |
158 | 166 |
159 Vload_path_dir_path = dir_path (VLOADPATH, VDEFAULT_LOADPATH); | 167 Vload_path_dir_path = dir_path (VLOADPATH, ""); |
160 | 168 |
161 string_vector new_dirs = Vload_path_dir_path.all_directories (); | 169 string_vector new_dirs = Vload_path_dir_path.all_directories (); |
162 | 170 |
163 maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL"); | 171 maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL"); |
164 | 172 |
241 { | 249 { |
242 Vlocal_ver_arch_lib_dir = subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR); | 250 Vlocal_ver_arch_lib_dir = subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR); |
243 } | 251 } |
244 | 252 |
245 static void | 253 static void |
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 | |
246 set_default_fcn_file_dir (void) | 290 set_default_fcn_file_dir (void) |
247 { | 291 { |
248 Vfcn_file_dir = subst_octave_home (OCTAVE_FCNFILEDIR); | 292 Vfcn_file_dir = subst_octave_home (OCTAVE_FCNFILEDIR); |
249 } | 293 } |
250 | 294 |
251 static void | 295 static void |
296 set_default_image_dir (void) | |
297 { | |
298 Vimage_dir = subst_octave_home (OCTAVE_IMAGEDIR); | |
299 } | |
300 | |
301 static void | |
252 set_default_oct_file_dir (void) | 302 set_default_oct_file_dir (void) |
253 { | 303 { |
254 Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); | 304 Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); |
255 } | 305 } |
256 | 306 |
258 set_default_bin_dir (void) | 308 set_default_bin_dir (void) |
259 { | 309 { |
260 Vbin_dir = subst_octave_home (OCTAVE_BINDIR); | 310 Vbin_dir = subst_octave_home (OCTAVE_BINDIR); |
261 } | 311 } |
262 | 312 |
263 static void | 313 void |
264 set_default_default_exec_path (void) | 314 set_exec_path (const std::string& path) |
265 { | 315 { |
266 VDEFAULT_EXEC_PATH | 316 VEXEC_PATH = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str |
267 = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str | |
268 + Vlocal_arch_lib_dir + dir_path::path_sep_str | 317 + Vlocal_arch_lib_dir + dir_path::path_sep_str |
269 + Varch_lib_dir + dir_path::path_sep_str | 318 + Varch_lib_dir + dir_path::path_sep_str |
270 + Vbin_dir; | 319 + Vbin_dir; |
271 } | 320 |
272 | 321 // This is static so that even if set_exec_path is called more than |
273 static void | 322 // once, shell_path is the original PATH from the environment, |
274 set_default_exec_path (void) | 323 // before we start modifying it. |
275 { | 324 static std::string shell_path = octave_env::getenv ("PATH"); |
276 std::string octave_exec_path = octave_env::getenv ("OCTAVE_EXEC_PATH"); | 325 |
277 | 326 if (! shell_path.empty ()) |
278 if (octave_exec_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) | |
279 { | 350 { |
280 std::string shell_path = octave_env::getenv ("PATH"); | 351 retval = dirname; |
281 | 352 |
282 if (! shell_path.empty ()) | 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++) | |
283 { | 358 { |
284 VEXEC_PATH = dir_path::path_sep_str; | 359 std::string elt = dirlist[i]; |
285 VEXEC_PATH.append (shell_path); | 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 } | |
286 } | 370 } |
287 } | 371 } |
288 else | 372 |
289 VEXEC_PATH = std::string (octave_exec_path); | 373 return retval; |
290 } | 374 } |
291 | 375 |
292 static void | 376 static void |
293 set_default_path (void) | 377 maybe_add_path_elts (std::string& pathvar, const std::string& dir) |
294 { | 378 { |
295 VDEFAULT_LOADPATH = subst_octave_home (OCTAVE_FCNFILEPATH); | 379 std::string tpath = genpath (dir); |
296 | 380 |
297 std::string oct_path = octave_env::getenv ("OCTAVE_PATH"); | 381 if (! tpath.empty ()) |
298 | 382 pathvar += dir_path::path_sep_str + tpath; |
299 VLOADPATH = oct_path.empty () ? dir_path::path_sep_str : oct_path; | 383 } |
384 | |
385 void | |
386 set_load_path (const std::string& path) | |
387 { | |
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); | |
398 | |
399 std::string tpath = path; | |
400 | |
401 if (tpath.empty ()) | |
402 tpath = octave_env::getenv ("OCTAVE_LOADPATH"); | |
403 | |
404 VLOADPATH = "."; | |
405 | |
406 if (! tpath.empty ()) | |
407 VLOADPATH += dir_path::path_sep_str + tpath; | |
408 | |
409 if (VDEFAULT_LOADPATH != ":") | |
410 VLOADPATH += VDEFAULT_LOADPATH; | |
300 | 411 |
301 update_load_path_dir_path (); | 412 update_load_path_dir_path (); |
413 } | |
414 | |
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); | |
302 } | 429 } |
303 | 430 |
304 static void | 431 static void |
305 set_default_info_file (void) | 432 set_default_info_file (void) |
306 { | 433 { |
370 } | 497 } |
371 else | 498 else |
372 Vsite_defaults_file = sf; | 499 Vsite_defaults_file = sf; |
373 } | 500 } |
374 | 501 |
375 std::string | |
376 maybe_add_default_load_path (const std::string& pathstring) | |
377 { | |
378 std::string retval; | |
379 | |
380 if (! pathstring.empty ()) | |
381 { | |
382 if (dir_path::is_path_sep (pathstring[0])) | |
383 { | |
384 retval = VDEFAULT_LOADPATH; | |
385 retval.append (pathstring); | |
386 } | |
387 else | |
388 retval = pathstring; | |
389 | |
390 if (dir_path::is_path_sep (pathstring[pathstring.length () - 1])) | |
391 retval.append (VDEFAULT_LOADPATH); | |
392 | |
393 size_t pos = 0; | |
394 do | |
395 { | |
396 pos = retval.find (dir_path::path_sep_str + dir_path::path_sep_str); | |
397 | |
398 if (pos != NPOS) | |
399 retval.insert (pos+1, VDEFAULT_LOADPATH); | |
400 } | |
401 while (pos != NPOS); | |
402 } | |
403 | |
404 return retval; | |
405 } | |
406 | |
407 void | 502 void |
408 install_defaults (void) | 503 install_defaults (void) |
409 { | 504 { |
410 // OCTAVE_HOME must be set first! | 505 // OCTAVE_HOME must be set first! |
411 | 506 |
421 | 516 |
422 set_default_local_arch_lib_dir (); | 517 set_default_local_arch_lib_dir (); |
423 | 518 |
424 set_default_local_ver_arch_lib_dir (); | 519 set_default_local_ver_arch_lib_dir (); |
425 | 520 |
521 set_default_local_ver_oct_file_dir (); | |
522 set_default_local_api_oct_file_dir (); | |
523 set_default_local_oct_file_dir (); | |
524 | |
525 set_default_local_ver_fcn_file_dir (); | |
526 set_default_local_api_fcn_file_dir (); | |
527 set_default_local_fcn_file_dir (); | |
528 | |
426 set_default_fcn_file_dir (); | 529 set_default_fcn_file_dir (); |
427 | |
428 set_default_oct_file_dir (); | 530 set_default_oct_file_dir (); |
429 | 531 |
532 set_default_image_dir (); | |
533 | |
430 set_default_bin_dir (); | 534 set_default_bin_dir (); |
431 | 535 |
432 set_default_default_exec_path (); | 536 set_exec_path (); |
433 | 537 |
434 set_default_exec_path (); | 538 set_load_path (); |
435 | 539 |
436 set_default_path (); | 540 set_image_path (); |
437 | 541 |
438 set_default_info_file (); | 542 set_default_info_file (); |
439 | 543 |
440 set_default_info_prog (); | 544 set_default_info_prog (); |
441 | 545 |
444 set_default_editor (); | 548 set_default_editor (); |
445 | 549 |
446 set_local_site_defaults_file (); | 550 set_local_site_defaults_file (); |
447 | 551 |
448 set_site_defaults_file (); | 552 set_site_defaults_file (); |
553 } | |
554 | |
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 | |
573 print_usage ("genpath"); | |
574 | |
575 return retval; | |
449 } | 576 } |
450 | 577 |
451 DEFUN (rehash, , , | 578 DEFUN (rehash, , , |
452 "-*- texinfo -*-\n\ | 579 "-*- texinfo -*-\n\ |
453 @deftypefn {Built-in Function} {} rehash ()\n\ | 580 @deftypefn {Built-in Function} {} rehash ()\n\ |
474 @end deftypefn") | 601 @end deftypefn") |
475 { | 602 { |
476 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); | 603 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); |
477 } | 604 } |
478 | 605 |
479 static void | |
480 update_exec_path (void) | |
481 { | |
482 std::string path; | |
483 | |
484 int eplen = VEXEC_PATH.length (); | |
485 | |
486 if (eplen > 0) | |
487 { | |
488 bool prepend = (VEXEC_PATH[0] == ':'); | |
489 bool append = (eplen > 1 && VEXEC_PATH[eplen-1] == ':'); | |
490 | |
491 if (prepend) | |
492 { | |
493 path = VDEFAULT_EXEC_PATH + VEXEC_PATH; | |
494 } | |
495 else | |
496 { | |
497 path = VEXEC_PATH; | |
498 | |
499 if (append) | |
500 path.append (VDEFAULT_EXEC_PATH); | |
501 } | |
502 } | |
503 else | |
504 path = VDEFAULT_EXEC_PATH; | |
505 | |
506 octave_env::putenv ("PATH", path); | |
507 } | |
508 | |
509 DEFUN (EXEC_PATH, args, nargout, | 606 DEFUN (EXEC_PATH, args, nargout, |
510 "-*- texinfo -*-\n\ | 607 "-*- texinfo -*-\n\ |
511 @deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ | 608 @deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ |
512 @deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\ | 609 @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\ | 610 Query or set the internal variable that specifies a colon separated\n\ |
514 list of directories to search when executing external programs.\n\ | 611 list of directories to search when executing external programs.\n\ |
515 Its initial value is taken from the environment variable\n\ | 612 Its initial value is taken from the environment variable\n\ |
516 @code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ | 613 @code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ |
517 value can be overridden by the command line argument\n\ | 614 value can be overridden by the command line argument\n\ |
518 @code{--exec-path PATH}. Any leading, trailing, or doubled colon in\n\ | 615 @code{--exec-path PATH}. At startup, an additional set of\n\ |
519 the value of @code{EXEC_PATH} are replaced by by the value of\n\ | 616 directories (including the shell PATH) is appended to the path\n\ |
520 @code{DEFAULT_EXEC_PATH}.\n\ | 617 specified in the environment or on the command line. If you use\n\ |
521 @seealso{DEFAULT_EXEC_PATH}\n\ | 618 the @code{EXEC_PATH} function to modify the path, you should take\n\ |
619 care to preserve these additional directories.\n\ | |
522 @end deftypefn") | 620 @end deftypefn") |
523 { | 621 { |
524 std::string saved_exec_path = VEXEC_PATH; | 622 std::string saved_exec_path = VEXEC_PATH; |
525 | 623 |
526 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); | 624 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); |
527 | 625 |
528 if (VEXEC_PATH != saved_exec_path) | 626 if (VEXEC_PATH != saved_exec_path) |
529 update_exec_path (); | 627 octave_env::putenv ("PATH", VEXEC_PATH); |
530 | 628 |
531 return retval; | 629 return retval; |
532 } | 630 } |
533 | 631 |
534 DEFUN (fftw_wisdom_program, args, nargout, | 632 DEFUN (fftw_wisdom_program, args, nargout, |
543 @end deftypefn") | 641 @end deftypefn") |
544 { | 642 { |
545 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); | 643 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); |
546 } | 644 } |
547 | 645 |
548 DEFUN (DEFAULT_EXEC_PATH, args, nargout, | 646 DEFUN (IMAGE_PATH, args, nargout, |
549 "-*- texinfo -*-\n\ | |
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\ | |
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\ | |
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 } | |
570 | |
571 DEFUN (IMAGEPATH, args, nargout, | |
572 "-*- texinfo -*-\n\ | 647 "-*- texinfo -*-\n\ |
573 @deftypefn {Built-in Function} {@var{val} =} IMAGEPATH ()\n\ | 648 @deftypefn {Built-in Function} {@var{val} =} IMAGE_PATH ()\n\ |
574 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGEPATH (@var{new_val})\n\ | 649 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGE_PATH (@var{new_val})\n\ |
575 Query or set the internal variable that specifies a colon separated\n\ | 650 Query or set the internal variable that specifies a colon separated\n\ |
576 list of directories in which to search for image files.\n\ | 651 list of directories in which to search for image files.\n\ |
577 @end deftypefn") | 652 @end deftypefn") |
578 { | 653 { |
579 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGEPATH); | 654 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGE_PATH); |
580 } | 655 } |
581 | 656 |
582 DEFUN (LOADPATH, args, nargout, | 657 DEFUN (path, args, nargout, |
583 "-*- texinfo -*-\n\ | 658 "-*- texinfo -*-\n\ |
584 @deftypefn {Built-in Function} {@var{val} =} LOADPATH ()\n\ | 659 @deftypefn {Function File} {} path (@dots{})\n\ |
585 @deftypefnx {Built-in Function} {@var{old_val} =} LOADPATH (@var{new_val})\n\ | 660 Modify or display Octave's @code{LOADPATH}.\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\ | |
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\ | 661 \n\ |
591 Leading, trailing, or doubled colons that appear in\n\ | 662 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ |
592 @code{LOADPATH} are replaced by the value of @code{DEFAULT_LOADPATH}.\n\ | 663 Octave's @code{LOADPATH} in an easy to read format.\n\ |
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\ | |
597 \n\ | 664 \n\ |
598 In addition, if any path element ends in @samp{//}, that directory and\n\ | 665 If @var{nargin} is zero and nargout is greater than zero, return the\n\ |
599 all subdirectories it contains are searched recursively for function\n\ | 666 current value of @code{LOADPATH}.\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\ | 667 \n\ |
605 To improve performance of recursive directory searching, it is best for\n\ | 668 If @var{nargin} is greater than zero, concatenate the arguments,\n\ |
606 each directory that is to be searched recursively to contain\n\ | 669 separating them with @code{pathsep()}. Set the internal search path\n\ |
607 @emph{either} additional subdirectories @emph{or} function files, but\n\ | 670 to the result and return it.\n\ |
608 not a mixture of both.\n\ | |
609 \n\ | 671 \n\ |
610 @xref{Organization of Functions}, for a description of the function file\n\ | 672 No checks are made for duplicate elements.\n\ |
611 directories that are distributed with Octave.\n\ | 673 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
612 @seealso{DEFAULT_LOADPATH}\n\ | 674 @end deftypefn") |
613 @end deftypefn") | 675 { |
614 { | 676 octave_value retval; |
615 std::string saved_loadpath = VLOADPATH; | 677 |
616 | 678 int argc = args.length () + 1; |
617 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (LOADPATH); | 679 |
618 | 680 string_vector argv = args.make_argv ("path"); |
619 if (VLOADPATH != saved_loadpath) | 681 |
682 if (! error_state) | |
620 { | 683 { |
621 // By resetting the last prompt time variable, we will force | 684 if (argc > 1) |
622 // checks for out of date symbols even if the change to LOADPATH | 685 { |
623 // and subsequent function calls happen between prompts. | 686 std::string path = argv[1]; |
624 | 687 |
625 // FIXME -- maybe we should rename | 688 for (int i = 2; i < argc; i++) |
626 // Vlast_prompt_time_stamp since the new usage doesn't really | 689 path += dir_path::path_sep_str; |
627 // fit with the current name? | 690 |
628 | 691 size_t plen = path.length (); |
629 Vlast_prompt_time.stamp (); | 692 |
630 | 693 if (! ((plen == 1 && path[0] == ':') |
631 update_load_path_dir_path (); | 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. | |
704 | |
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 } | |
713 | |
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"; | |
719 | |
720 string_vector sv = Vload_path_dir_path.all_directories (); | |
721 | |
722 sv.list_in_columns (octave_stdout); | |
723 | |
724 octave_stdout << "\n"; | |
725 } | |
632 } | 726 } |
633 | 727 |
634 return retval; | 728 return retval; |
635 } | 729 } |
636 | 730 |
637 DEFUN (DEFAULT_LOADPATH, args, nargout, | 731 DEFUN (pathdef, , , |
638 "-*- texinfo -*-\n\ | 732 "-*- texinfo -*-\n\ |
639 @deftypefn {Built-in Function} {@var{val} =} DEFAULT_LOADPATH ()\n\ | 733 @deftypefn {Built-in Function} {@var{val} =} DEFAULT_LOADPATH ()\n\ |
640 @deftypefnx {Built-in Function} {@var{old_val} =} DEFAULT_LOADPATH (@var{new_val})\n\ | 734 Return the default list of directories in which to search for function\n\ |
641 Query or set the internal variable that specifies the colon separated\n\ | 735 files.\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\ | 736 @seealso{LOADPATH}\n\ |
646 @end deftypefn") | 737 @end deftypefn") |
647 { | 738 { |
648 std::string saved_default_loadpath = VDEFAULT_LOADPATH; | 739 return octave_value (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 } | 740 } |
658 | 741 |
659 DEFUN (OCTAVE_HOME, args, , | 742 DEFUN (OCTAVE_HOME, args, , |
660 "-*- texinfo -*-\n\ | 743 "-*- texinfo -*-\n\ |
661 @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ | 744 @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ |