# HG changeset patch # User David Bateman # Date 1219176952 14400 # Node ID 2ca993580acaf32d052b08ef8d9d4baa0dae72cc # Parent 22876f8e0f1790aeefee069cec99428a721a97bb Add a search for Contents.m files to the help function diff -r 22876f8e0f17 -r 2ca993580aca src/ChangeLog --- a/src/ChangeLog Tue Aug 19 14:19:14 2008 -0400 +++ b/src/ChangeLog Tue Aug 19 16:15:52 2008 -0400 @@ -1,3 +1,18 @@ +2008-08-19 David Bateman + + * 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. + 2008-08-19 Jaroslav Hajek * pt-assign.h (tree_simple_assignment::first_execution): New diff -r 22876f8e0f17 -r 2ca993580aca src/help.cc --- a/src/help.cc Tue Aug 19 14:19:14 2008 -0400 +++ b/src/help.cc Tue Aug 19 16:15:52 2008 -0400 @@ -1063,6 +1063,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; } diff -r 22876f8e0f17 -r 2ca993580aca src/load-path.cc --- a/src/load-path.cc Tue Aug 19 14:19:14 2008 -0400 +++ b/src/load-path.cc Tue Aug 19 16:15:52 2008 -0400 @@ -794,6 +794,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; diff -r 22876f8e0f17 -r 2ca993580aca src/load-path.h --- a/src/load-path.h Tue Aug 19 14:19:14 2008 -0400 +++ b/src/load-path.h Tue Aug 19 16:15:52 2008 -0400 @@ -116,6 +116,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 () ? @@ -322,6 +328,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; diff -r 22876f8e0f17 -r 2ca993580aca src/utils.cc --- a/src/utils.cc Tue Aug 19 14:19:14 2008 -0400 +++ b/src/utils.cc Tue Aug 19 16:15:52 2008 -0400 @@ -746,6 +746,28 @@ error ("errno: expecting integer argument"); } } + + 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 ()); + } else if (nargin == 0) retval = octave_errno::get (); else diff -r 22876f8e0f17 -r 2ca993580aca src/utils.h --- a/src/utils.h Tue Aug 19 14:19:14 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&);