changeset 8041:a14bdf90be55

Add a search for Contents.m files to the help function
author David Bateman <dbateman@free.fr>
date Tue, 19 Aug 2008 16:15:52 -0400
parents 5511929874da
children 827d4f24ec6c
files src/ChangeLog src/help.cc src/load-path.cc src/load-path.h src/utils.cc src/utils.h
diffstat 6 files changed, 101 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/ChangeLog	Tue Aug 19 16:15:52 2008 -0400
@@ -1,5 +1,18 @@
 2008-08-19  David Bateman  <dbateman@free.fr>
 
+	* load-path.cc (load-path::do_find_dir (const std:string&) const)):
+	Method to find a directory on the load-path corresponding to the
+	argument.
+	* load-path.h (load-path::do_find_dir (const std:string&) const),
+	load-path::find_dir (const std::string&) const): New methods.
+	* utils.cc (std::string contents_file_in_path (const std::string&)):
+	New function.
+	* utils.h  (std::string contents_file_in_path (const std::string&)): 
+	Declare it.
+	* help.cc (static bool raw_help_from_file (const std::string&,
+	std::string&, std::string&, bool&)): Also check is requested
+	argument is a directory and contains the file Contents.m.
+
 	* OPERATORS/op-int-conv.cc (DEFINTCONVFN): New macro that warn
 	for integer conversion issues. Use it to replace DEFCONVFN.
 	* OPERATORS/op-int.h (DEFINTBINOP_OP, DEFINTNDBINOP_OP,
--- a/src/help.cc	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/help.cc	Tue Aug 19 16:15:52 2008 -0400
@@ -1005,6 +1005,18 @@
 
   if (h.length () > 0)
     retval = true;
+  else if (! symbol_found)
+    {
+      file = contents_file_in_path (nm);
+      
+      if (! file.empty ())
+	{
+	  h = get_help_from_file (file, symbol_found);
+
+	  if (h.length () > 0)
+	    retval = true;
+	}
+    }
 
   return retval;
 }
--- a/src/load-path.cc	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/load-path.cc	Tue Aug 19 16:15:52 2008 -0400
@@ -1054,6 +1054,50 @@
 }
 
 std::string
+load_path::do_find_dir (const std::string& dir) const
+{
+  std::string retval;
+
+  if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos
+      && (octave_env::absolute_pathname (dir)
+	  || octave_env::rooted_relative_pathname (dir)))
+    {
+      file_stat fs (dir);
+
+      if (fs.exists () && fs.is_dir ())
+	return dir;
+    }
+  else
+    {
+      for (const_dir_info_list_iterator p = dir_info_list.begin ();
+	   p != dir_info_list.end ();
+	   p++)
+	{
+	  std::string dname = p->dir_name;
+
+	  size_t dname_len = dname.length ();
+
+	  if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ())
+	    dname = dname.substr (0, dname_len - 1);
+
+	  size_t dir_len = dir.length ();
+
+	  if (dname_len >= dir_len
+	      && file_ops::is_dir_sep (dname[dname_len - dir_len - 1])
+	      && dir.compare (dname.substr (dname_len - dir_len)) == 0)
+	    {
+	      file_stat fs (p->dir_name);
+
+	      if (fs.exists () && fs.is_dir ())
+		return p->dir_name;
+	    }
+	}
+    }
+
+  return retval;
+}
+
+std::string
 load_path::do_find_first_of (const string_vector& flist) const
 {
   std::string retval;
--- a/src/load-path.h	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/load-path.h	Tue Aug 19 16:15:52 2008 -0400
@@ -156,6 +156,12 @@
       ? instance->do_find_file (file) : std::string ();
   }
 
+  static std::string find_dir (const std::string& dir)
+  {
+    return instance_ok ()
+      ? instance->do_find_dir (dir) : std::string ();
+  }
+
   static std::string find_first_of (const string_vector& files)
   {
     return instance_ok () ?
@@ -438,6 +444,8 @@
 
   std::string do_find_file (const std::string& file) const;
 
+  std::string do_find_dir (const std::string& dir) const;
+
   std::string do_find_first_of (const string_vector& files) const;
 
   string_vector do_find_all_first_of (const string_vector& files) const;
--- a/src/utils.cc	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/utils.cc	Tue Aug 19 16:15:52 2008 -0400
@@ -448,6 +448,28 @@
   return retval;
 }
 
+// See if there is a directory called "name" in the path and if it
+// contains a Contents.m file return the full path to this file.
+
+std::string
+contents_file_in_path (const std::string& dir)
+{
+  std::string retval;
+
+  if (dir.length () > 0)
+    {
+      std::string tcontents = file_ops::concat (load_path::find_dir (dir), 
+						std::string ("Contents.m"));
+
+      file_stat fs (tcontents);
+
+      if (fs.exists ())
+	retval = octave_env::make_absolute (tcontents, octave_env::getcwd ());
+    }
+
+  return retval;
+}
+
 // See if there is a .oct file in the path.  If so, return the
 // full path to the file.
 
--- a/src/utils.h	Tue Aug 19 14:55:03 2008 -0400
+++ b/src/utils.h	Tue Aug 19 16:15:52 2008 -0400
@@ -64,6 +64,8 @@
 extern OCTINTERP_API std::string
 file_in_path (const std::string&, const std::string&);
 
+extern OCTINTERP_API std::string contents_file_in_path (const std::string&);
+
 extern OCTINTERP_API std::string fcn_file_in_path (const std::string&);
 extern OCTINTERP_API std::string oct_file_in_path (const std::string&);
 extern OCTINTERP_API std::string mex_file_in_path (const std::string&);