changeset 9261:95445f9f5976

omit file extensions from __list_functions__ output
author John W. Eaton <jwe@octave.org>
date Tue, 26 May 2009 12:00:00 -0400
parents 9c2349a51218
children de255681c85f
files src/ChangeLog src/help.cc src/load-path.cc src/load-path.h
diffstat 4 files changed, 34 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue May 26 11:20:40 2009 -0400
+++ b/src/ChangeLog	Tue May 26 12:00:00 2009 -0400
@@ -1,5 +1,10 @@
 2009-05-26  John W. Eaton  <jwe@octave.org>
 
+	* load-path.h, load-path.cc (load_path::files, load_path::do_files): 
+	New arg, OMIT_EXTS.
+	* help.cc (F__list_functions__): Call load_path::files with
+	omit_exts set to true.
+
 	* symtab.h
 	(symbol_table::symbol_record::symbol_record_rep::is_variable):
 	Use "! is_local ()" instead of storage_class != local.
--- a/src/help.cc	Tue May 26 11:20:40 2009 -0400
+++ b/src/help.cc	Tue May 26 12:00:00 2009 -0400
@@ -957,10 +957,17 @@
 
       if (! error_state)
 	{
-	  string_vector fl = load_path::files (dir);
+	  string_vector fl = load_path::files (dir, true);
 
 	  if (! error_state)
-	    retval = Cell (fl);
+	    {
+	      // Return a sorted list with unique entries (in case of
+	      // .m and .oct versions of the same function in a given
+	      // directory, for example).
+	      fl.sort (true);
+
+	      retval = Cell (fl);
+	    }
 	}
       else
         error ("__list_functions__: input must be a string");
--- a/src/load-path.cc	Tue May 26 11:20:40 2009 -0400
+++ b/src/load-path.cc	Tue May 26 12:00:00 2009 -0400
@@ -1337,7 +1337,7 @@
 }
 
 string_vector
-load_path::do_files (const std::string& dir) const
+load_path::do_files (const std::string& dir, bool omit_exts) const
 {
   string_vector retval;
 
@@ -1346,6 +1346,21 @@
   if (i != dir_info_list.end ())
     retval = i->fcn_files;
 
+  if (omit_exts)
+    {
+      octave_idx_type len = retval.length ();
+
+      for (octave_idx_type i = 0; i < len; i++)
+	{
+	  std::string fname = retval[i];
+
+	  size_t pos = fname.rfind ('.');
+
+	  if (pos != std::string::npos)
+	    retval[i] = fname.substr (0, pos);
+	}
+    }
+
   return retval;
 }
 
--- a/src/load-path.h	Tue May 26 11:20:40 2009 -0400
+++ b/src/load-path.h	Tue May 26 12:00:00 2009 -0400
@@ -186,9 +186,10 @@
       ? instance->do_dir_list () : std::list<std::string> ();
   }
 
-  static string_vector files (const std::string& dir)
+  static string_vector files (const std::string& dir, bool omit_exts = false)
   {
-    return instance_ok () ? instance->do_files (dir) : string_vector ();
+    return instance_ok ()
+      ? instance->do_files (dir, omit_exts) : string_vector ();
   }
 
   static string_vector fcn_names (void)
@@ -490,7 +491,7 @@
 
   std::list<std::string> do_dir_list (void) const;
 
-  string_vector do_files (const std::string& dir) const;
+  string_vector do_files (const std::string& dir, bool omit_exts) const;
 
   string_vector do_fcn_names (void) const;