# HG changeset patch # User David Bateman # Date 1219176952 14400 # Node ID a14bdf90be55ee97ef9916393ed3496f19014a98 # Parent 5511929874da1ce3ff657f4fe6a41ba106ab58e4 Add a search for Contents.m files to the help function diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +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. + * 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, diff --git a/src/help.cc b/src/help.cc --- a/src/help.cc +++ b/src/help.cc @@ -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; } diff --git a/src/load-path.cc b/src/load-path.cc --- a/src/load-path.cc +++ b/src/load-path.cc @@ -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; diff --git a/src/load-path.h b/src/load-path.h --- a/src/load-path.h +++ b/src/load-path.h @@ -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; diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -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. diff --git a/src/utils.h b/src/utils.h --- 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&);