changeset 2233:0da2c91573d9

[project @ 1996-05-17 17:27:17 by jwe]
author jwe
date Fri, 17 May 1996 17:31:30 +0000
parents 834eab508368
children a174011c96f2
files src/fn-cache.cc src/fn-cache.h src/help.cc src/utils.cc src/utils.h src/variables.cc
diffstat 6 files changed, 24 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/src/fn-cache.cc	Fri May 17 17:11:40 1996 +0000
+++ b/src/fn-cache.cc	Fri May 17 17:31:30 1996 +0000
@@ -40,17 +40,15 @@
 
 // Update the cache.  Returns TRUE if something needed to be updated.
 
-// XXX FIXME XXX -- I suppose we could also keep track of the load
-// path.  Then if a directory is deleted from the load path, we could
-// also delete it from the cache.  Currently, we just accumulate all
-// directories ever referenced in the cache.
+// We just accumulate all directories ever referenced in the cache and
+// we don't delete any old ones.
 
 bool
-octave_fcn_file_name_cache::update (void)
+octave_fcn_file_name_cache::update (const string& path)
 {
   bool retval = false;
 
-  dir_path p (Vload_path);
+  dir_path p = path.empty () ? dir_path (Vload_path) : dir_path (path);
 
   string_vector dirs = p.all_directories ();
 
@@ -79,11 +77,11 @@
 // updated, then return the list of names in the cache.
 
 string_vector
-octave_fcn_file_name_cache::do_list (bool no_suffix)
+octave_fcn_file_name_cache::do_list (const string& path, bool no_suffix)
 {
   // Only recompute the cache if something has changed.
 
-  if (update ())
+  if (update (path))
     {
       int total_len = 0;
 
@@ -130,7 +128,7 @@
 }
 
 string_vector
-octave_fcn_file_name_cache::list (bool no_suffix = false)
+octave_fcn_file_name_cache::list (const string& path, bool no_suffix)
 {
   string_vector retval;
 
@@ -138,7 +136,7 @@
     instance = new octave_fcn_file_name_cache ();
 
   if (instance)
-    retval = instance->do_list (no_suffix);
+    retval = instance->do_list (path, no_suffix);
   else
     panic_impossible ();
 
--- a/src/fn-cache.h	Fri May 17 17:11:40 1996 +0000
+++ b/src/fn-cache.h	Fri May 17 17:31:30 1996 +0000
@@ -89,11 +89,18 @@
 
   ~octave_fcn_file_name_cache (void) { }
 
-  bool update (void);
+  bool update (const string& path = string ());
+
+  static string_vector list (bool no_suffix = false)
+    { return list (string (), no_suffix); }
 
-  static string_vector list (bool no_suffix = false);
+  static string_vector list (const string& path, bool no_suffix = false);
 
-  static string_vector list_no_suffix (void) { return list (true); }
+  static string_vector list_no_suffix (void)
+    { return list (true); }
+
+  static string_vector list_no_suffix (const string& path)
+    { return list (path, true); }
 
 private:
 
@@ -110,7 +117,7 @@
   // .oct suffixes.
   string_vector fcn_file_names_no_suffix;
 
-  string_vector do_list (bool no_suffix);
+  string_vector do_list (const string& path, bool no_suffix);
 };
 
 #endif
--- a/src/help.cc	Fri May 17 17:11:40 1996 +0000
+++ b/src/help.cc	Fri May 17 17:31:30 1996 +0000
@@ -44,6 +44,7 @@
 #include "defun.h"
 #include "dirfns.h"
 #include "error.h"
+#include "fn-cache.h"
 #include "gripes.h"
 #include "help.h"
 #include "input.h"
@@ -500,7 +501,7 @@
 
   for (int i = 0; i < len; i++)
     {
-      string_vector names = get_fcn_file_names (dirs[i]);
+      string_vector names = octave_fcn_file_name_cache::list (dirs[i]);
 
       if (! names.empty ())
 	{
--- a/src/utils.cc	Fri May 17 17:11:40 1996 +0000
+++ b/src/utils.cc	Fri May 17 17:31:30 1996 +0000
@@ -55,6 +55,7 @@
 
 #include "SLStack.h"
 
+#include "file-ops.h"
 #include "oct-cmplx.h"
 #include "str-vec.h"
 
@@ -207,123 +208,6 @@
   return status;
 }
 
-string_vector
-get_fcn_file_names (const string& name, int no_suffix)
-{
-  string_vector retval;
-
-  dir_entry dir (name);
-
-  if (dir)
-    {
-      string_vector tmp = dir.read ();
-
-      int max_len = tmp.length ();
-
-      retval.resize (max_len);
-
-      int k = 0;
-      int i;
-      for (i = 0; i < max_len; i++)
-	{
-	  string entry = tmp[i];
-
-	  int len = entry.length ();
-
-#if defined (WITH_DYNAMIC_LINKING)
-	  if ((len > 2
-	       && entry[len-2] == '.' && entry[len-1] == 'm')
-	      || (len > 4
-		  && entry[len-4] == '.' && entry[len-3] == 'o'
-		  && entry[len-2] == 'c' && entry[len-1] == 't'))
-#else
-	  if (len > 2
-	      && entry[len-2] == '.' && entry[len-1] == 'm')
-#endif
-	    {
-	      if (no_suffix)
-		{
-		  if (entry[len-1] == 'm')
-		    entry.resize (len-2);
-		  else
-		    entry.resize (len-4);
-		}
-
-	      retval[k++] = entry;
-	    }
-	}
-
-      retval.resize (k);
-    }
-
-  return retval;
-}
-
-string_vector
-get_fcn_file_names (int no_suffix)
-{
-  static int num_max = 1024;
-
-  string_vector retval (num_max);
-
-  dir_path p (Vload_path);
-
-  string_vector dirs = p.all_directories ();
-
-  int len = dirs.length ();
-
-  int k = 0;
-
-  for (int i = 0; i < len; i++)
-    {
-      string_vector names = get_fcn_file_names (dirs[i], no_suffix);
-
-      int tmp_num = names.length ();
-
-      if (k + tmp_num > num_max)
-	{
-	  num_max += tmp_num;
-	  retval.resize (num_max);
-	}
-
-      for (int j = 0; j < tmp_num; j++)
-	retval[k++] = names[j];
-    }
-
-  retval.resize (k);
-
-  return retval;
-}
-
-// Return non-zero if either NR or NC is zero.  Return -1 if this
-// should be considered fatal; return 1 if this is ok.
-
-int
-empty_arg (const char *name, int nr, int nc)
-{
-  int is_empty = 0;
-
-  if (nr == 0 || nc == 0)
-    {
-      int flag = Vpropagate_empty_matrices;
-
-      if (flag < 0)
-	{
-	  gripe_empty_arg (name, 0);
-	  is_empty = 1;
-	}
-      else if (flag == 0)
-	{
-	  gripe_empty_arg (name, 1);
-	  is_empty = -1;
-	}
-      else
-	is_empty = 1;
-    }
-
-  return is_empty;
-}
-
 // See if the given file is in the path.
 
 string
--- a/src/utils.h	Fri May 17 17:11:40 1996 +0000
+++ b/src/utils.h	Fri May 17 17:31:30 1996 +0000
@@ -50,10 +50,6 @@
 		      const string& s, int min_toks_to_match,
 		      int max_toks);
 
-extern string_vector get_fcn_file_names (const string&, int = 0);
-
-extern string_vector get_fcn_file_names (int = 0);
-
 extern int empty_arg (const char *name, int nr, int nc);
 
 extern const char *undo_string_escape (char c);
--- a/src/variables.cc	Fri May 17 17:11:40 1996 +0000
+++ b/src/variables.cc	Fri May 17 17:31:30 1996 +0000
@@ -53,6 +53,7 @@
 #include "dynamic-ld.h"
 #include "error.h"
 #include "file-io.h"
+#include "fn-cache.h"
 #include "gripes.h"
 #include "help.h"
 #include "input.h"
@@ -913,7 +914,7 @@
   if (top_level_sym_tab != curr_sym_tab)
     lcl = curr_sym_tab->list (lcl_len);
 
-  ffl = get_fcn_file_names (1);
+  ffl = octave_fcn_file_name_cache::list_no_suffix ();
   int ffl_len = ffl.length ();
 
   int total_len = key_len + glb_len + top_len + lcl_len + ffl_len;