# HG changeset patch # User jwe # Date 1039059181 0 # Node ID 301cc4cf87e9eb1819bb6049488b682693f37b2a # Parent e613ffa9f0e6a5064ef88bd5fef3bcbb7560a64a [project @ 2002-12-05 03:33:01 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2002-12-04 John W. Eaton + * defaults.cc (maybe_add_or_del_packages, default_load_path, + update_load_path_dir_path): New static functions. + (set_default_path, loadpath): Call update_load_path_dir_path. + (symbols_of_defaults): Use DEFVAR, not DEFCONST for DEFAULT_LOADPATH. + (execute_default_pkg_add_files): New function. + * defaults.h.in: Provide decl. + * utils.cc (search_path_for_all_files): New function. (Ffile_in_loadpath, Ffile_in_path): Allow search to return all files in the path. diff --git a/src/defaults.cc b/src/defaults.cc --- a/src/defaults.cc +++ b/src/defaults.cc @@ -37,7 +37,9 @@ #endif #include "oct-env.h" +#include "file-stat.h" #include "pathsearch.h" +#include "str-vec.h" #include #include "defun.h" @@ -47,7 +49,9 @@ #include "help.h" #include "oct-obj.h" #include "ov.h" +#include "parse.h" #include "toplev.h" +#include "unwind-prot.h" #include "variables.h" #include @@ -84,6 +88,83 @@ std::string Vlocal_site_defaults_file; std::string Vsite_defaults_file; +// Each element of A and B should be directory names. For each +// element of A not in the list B, execute SCRIPT_FILE in that +// directory if it exists. + +static void +maybe_add_or_del_packages (const string_vector& a, + const string_vector& b, + const std::string script_file) +{ + if (! octave_interpreter_ready) + return; + + unwind_protect::begin_frame ("maybe_add_or_del_packages"); + + unwind_protect_bool (input_from_startup_file); + + input_from_startup_file = true; + + int a_len = a.length (); + int b_len = b.length (); + + for (int i = 0; i < a_len; i++) + { + std::string a_dir = a[i]; + + bool found = false; + + for (int j = 0; j < b_len; j++) + { + if (b[j] == a_dir) + { + found = true; + break; + } + } + + if (! found) + { + std::string file = a_dir + file_ops::dir_sep_str + script_file; + + file_stat fs = file_stat (file); + + if (fs.exists ()) + parse_and_execute (file); + + if (error_state) + return; + } + } + + unwind_protect::run_frame ("maybe_add_or_del_packages"); +} + +static void +update_load_path_dir_path (void) +{ + string_vector old_dirs = Vload_path_dir_path.all_directories (); + + Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); + + string_vector new_dirs = Vload_path_dir_path.all_directories (); + + maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL"); + + if (! error_state) + maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); +} + +void +execute_default_pkg_add_files (void) +{ + string_vector old_dirs; + string_vector new_dirs = Vload_path_dir_path.all_directories (); + + maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD"); +} + static std::string subst_octave_home (const std::string& s) { @@ -191,7 +272,7 @@ Vload_path = oct_path.empty () ? std::string (":") : oct_path; - Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); + update_load_path_dir_path (); } static void @@ -423,7 +504,29 @@ Vload_path = s; - Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); + update_load_path_dir_path (); + } + + return status; +} + +static int +default_load_path (void) +{ + int status = 0; + + std::string s = builtin_string_variable ("DEFAULT_LOADPATH"); + + if (s.empty ()) + { + gripe_invalid_value_specified ("DEFAULT_LOADPATH"); + status = -1; + } + else + { + Vdefault_load_path = s; + + update_load_path_dir_path (); } return status; @@ -496,7 +599,7 @@ directories that are distributed with Octave.\n\ @end defvr"); - DEFCONST (DEFAULT_LOADPATH, Vdefault_load_path, + DEFVAR (DEFAULT_LOADPATH, Vdefault_load_path, default_load_path, "-*- texinfo -*-\n\ @defvr {Built-in Variable} DEFAULT_LOADPATH\n\ A colon separated list of directories in which to search for function\n\ diff --git a/src/defaults.h.in b/src/defaults.h.in --- a/src/defaults.h.in +++ b/src/defaults.h.in @@ -186,6 +186,8 @@ extern std::string Vlocal_site_defaults_file; extern std::string Vsite_defaults_file; +extern void execute_default_pkg_add_files (void); + extern std::string maybe_add_default_load_path (const std::string& pathstring); extern void install_defaults (void); diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -513,6 +513,10 @@ if (traditional) maximum_braindamage (); + octave_interpreter_ready = true; + + execute_default_pkg_add_files (); + execute_startup_files (); command_history::read (false); diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -78,6 +78,10 @@ // TRUE means we are exiting via the builtin exit or quit functions. static bool quitting_gracefully = false; +// TRUE means we are ready to interpret commands, but not everything +// is ready for interactive use. +bool octave_interpreter_ready = false; + // TRUE means we've processed all the init code and we are good to go. bool octave_initialized = false; diff --git a/src/toplev.h b/src/toplev.h --- a/src/toplev.h +++ b/src/toplev.h @@ -51,6 +51,10 @@ // Original value of TEXMFDBS environment variable. extern std::string octave_original_texmfdbs; +// TRUE means we are ready to interpret commands, but not everything +// is ready for interactive use. +extern bool octave_interpreter_ready; + // TRUE means we've processed all the init code and we are good to go. extern bool octave_initialized;