help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Changeset]; Re: feature request / Matlab incompatability


From: David Bateman
Subject: [Changeset]; Re: feature request / Matlab incompatability
Date: Tue, 19 Aug 2008 15:49:18 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080725)

Peter L. Søndergaard wrote:
Hi,

I develop the ltfat toolbox available at http://ltfat.sourceforge.net. I
try to keep the toolbox working equally well in Octave and Matlab.

The toolbox is organized in subdirectories, each containing a
"Contents.m" file.

In Matlab the user can type "help gabor" and this will display the
Contents.m file in the "gabor" directory. This does not work in Octave.
In Octave the user has to change the directory to the "gabor" directory
and then type "help Contents" to get the same listing.

Other third-party toolboxes like WaveLab use the same system for
documentation and suffer from the same problem in Octave.

So I humbly ask if it is possible to add this functionality to the
"help" command.

Cheers,

Peter.
What about something like the attached?

D.

--
David Bateman                                address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary

# HG changeset patch
# User David Bateman <address@hidden>
# Date 1219153661 -7200
# Node ID 3c34b7d61a59a01a75bb116d641f48eb08f5fd41
# Parent  02bdc652e429d6c667a7b58909c7cc1014154821
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,4 +1,17 @@ 2008-08-19  David Bateman  <address@hidden
 2008-08-19  David Bateman  <address@hidden>
+
+       * 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.
diff --git a/src/help.cc b/src/help.cc
--- a/src/help.cc
+++ b/src/help.cc
@@ -1005,6 +1005,18 @@ raw_help_from_file (const std::string& n
 
   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
@@ -1046,6 +1046,46 @@ load_path::do_find_file (const std::stri
            {
              if (all_files[i] == file)
                return file_ops::concat (p->dir_name, file);
+           }
+       }
+    }
+
+  return retval;
+}
+
+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;
+
+         if (dname.substr (dname.length () - 1) == file_ops::dir_sep_str ())
+           dname = dname.substr (0, dname.length () - 1);
+
+
+         if (dname.length() >= dir.length() && 
+             dir.compare (dname.substr (dname.length() - dir.length ())) == 0)
+           {
+             file_stat fs (p->dir_name);
+
+             if (fs.exists () && fs.is_dir ())
+               return p->dir_name;
            }
        }
     }
diff --git a/src/load-path.h b/src/load-path.h
--- a/src/load-path.h
+++ b/src/load-path.h
@@ -154,6 +154,12 @@ public:
   {
     return instance_ok ()
       ? 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)
@@ -438,6 +444,8 @@ private:
 
   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
@@ -239,10 +239,6 @@ search_path_for_file (const std::string&
 search_path_for_file (const std::string& path, const string_vector& names)
 {
   dir_path p (path);
-
-  return octave_env::make_absolute (p.find_first_of (names),
-                                   octave_env::getcwd ());
-}
 
 // Find all locations of the given file in the path.
 
@@ -443,6 +439,28 @@ fcn_file_in_path (const std::string& nam
 
          retval = load_path::find_fcn_file (fname);
        }
+    }
+
+  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;
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
 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&);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]