changeset 12032:b59e304fe00a release-3-2-x

allow which look for files on path
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 02 Jul 2009 13:43:46 +0200
parents 3335e82622ba
children c477c7023698
files src/ChangeLog src/help.cc
diffstat 2 files changed, 36 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2009-07-02  Jaroslav Hajek  <highegg@gmail.com>
+
+	* help.cc (do_which): Also look for files.
+
 2009-07-02  Jaroslav Hajek  <highegg@gmail.com>
 
 	* Cell.cc (Cell::index): Use proper resize_fill_value.
--- a/src/help.cc
+++ b/src/help.cc
@@ -821,33 +821,47 @@
 
   octave_value val = symbol_table::find_function (name);
 
-  if (val.is_defined ())
+  if (name.find_first_of ('.') == std::string::npos)
     {
-      octave_function *fcn = val.function_value ();
+      if (val.is_defined ())
+        {
+          octave_function *fcn = val.function_value ();
 
-      if (fcn)
-	{
-	  file = fcn->fcn_file_name ();
+          if (fcn)
+            {
+              file = fcn->fcn_file_name ();
 
-	  if (file.empty ())
-	    {
-	      if (fcn->is_user_function ())
-		type = "command-line function";
-	      else
-		type = "built-in function";
-	    }
-	  else
-	    type = val.is_user_script ()
-	      ? std::string ("script") : std::string ("function");
-	}
+              if (file.empty ())
+                {
+                  if (fcn->is_user_function ())
+                    type = "command-line function";
+                  else
+                    type = "built-in function";
+                }
+              else
+                type = val.is_user_script ()
+                  ? std::string ("script") : std::string ("function");
+            }
+        }
+      else
+        {
+          // We might find a file that contains only a doc string.
+
+          file = load_path::find_fcn_file (name);
+        }
     }
   else
     {
-      // We might find a file that contains only a doc string.
+      // File query.
 
-      file = load_path::find_fcn_file (name);
+      // For compatibility: "file." queries "file".
+      if (name.size () > 1 && name[name.size () - 1] == '.')
+        file = load_path::find_file (name.substr (0, name.size () - 1));
+      else
+        file = load_path::find_file (name);
     }
 
+
   return file;
 }