Mercurial > hg > octave-terminal
changeset 11814:2ca993580aca release-3-0-x
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 | 22876f8e0f17 |
children | 72ceeae0f6b2 |
files | src/ChangeLog src/help.cc src/load-path.cc src/load-path.h src/utils.cc src/utils.h |
diffstat | 6 files changed, 103 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +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. + 2008-08-19 Jaroslav Hajek <highegg@gmail.com> * pt-assign.h (tree_simple_assignment::first_execution): New
--- a/src/help.cc +++ b/src/help.cc @@ -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; }
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -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;
--- a/src/load-path.h +++ b/src/load-path.h @@ -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;
--- a/src/utils.cc +++ b/src/utils.cc @@ -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
--- a/src/utils.h +++ b/src/utils.h @@ -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&);