changeset 4217:301cc4cf87e9

[project @ 2002-12-05 03:33:01 by jwe]
author jwe
date Thu, 05 Dec 2002 03:33:01 +0000
parents e613ffa9f0e6
children 4a392a01e51a
files src/ChangeLog src/defaults.cc src/defaults.h.in src/octave.cc src/toplev.cc src/toplev.h
diffstat 6 files changed, 127 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/ChangeLog	Thu Dec 05 03:33:01 2002 +0000
@@ -1,5 +1,12 @@
 2002-12-04  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* 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.
--- a/src/defaults.cc	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/defaults.cc	Thu Dec 05 03:33:01 2002 +0000
@@ -37,7 +37,9 @@
 #endif
 
 #include "oct-env.h"
+#include "file-stat.h"
 #include "pathsearch.h"
+#include "str-vec.h"
 
 #include <defaults.h>
 #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 <version.h>
 
@@ -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\
--- a/src/defaults.h.in	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/defaults.h.in	Thu Dec 05 03:33:01 2002 +0000
@@ -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);
--- a/src/octave.cc	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/octave.cc	Thu Dec 05 03:33:01 2002 +0000
@@ -513,6 +513,10 @@
   if (traditional)
     maximum_braindamage ();
 
+  octave_interpreter_ready = true;
+
+  execute_default_pkg_add_files ();
+
   execute_startup_files ();
 
   command_history::read (false);
--- a/src/toplev.cc	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/toplev.cc	Thu Dec 05 03:33:01 2002 +0000
@@ -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;
 
--- a/src/toplev.h	Wed Dec 04 17:37:09 2002 +0000
+++ b/src/toplev.h	Thu Dec 05 03:33:01 2002 +0000
@@ -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;