diff src/help.cc @ 9806:8e345f2fe4d6

improved support for Contents.m files
author John W. Eaton <jwe@octave.org>
date Wed, 11 Nov 2009 15:11:14 -0500
parents 2cc47338e427
children 2cd940306a06
line wrap: on
line diff
--- a/src/help.cc
+++ b/src/help.cc
@@ -705,7 +705,7 @@
 }
 
 static void
-do_get_help_text (const std::string name, std::string& text,
+do_get_help_text (const std::string& name, std::string& text,
 		  std::string& format)
 {
   bool symbol_found = false;
@@ -774,6 +774,80 @@
   return retval;
 }
 
+static void
+do_get_help_text_from_file (const std::string& fname, std::string& text,
+			    std::string& format)
+{
+  bool symbol_found = false;
+
+  std::string f;
+
+  raw_help_from_file (fname, text, f, symbol_found);
+
+  format = "Not found";
+  if (symbol_found)
+    {
+      size_t idx = -1;
+      if (text.empty ())
+        {
+          format = "Not documented";
+        }
+      else if (looks_like_texinfo (text, idx))
+        {
+          format = "texinfo";
+          text.erase (0, idx);
+        }
+      else if (looks_like_html (text))
+        {
+          format = "html";
+        }
+      else
+        {
+          format = "plain text";
+        }
+    }
+}
+
+DEFUN (get_help_text_from_file, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text_from_file (@var{fname})\n\
+Returns the help text from the given file.\n\
+\n\
+This function returns the raw help text @var{text} and an indication of\n\
+its format for the function @var{name}.  The format indication @var{format}\n\
+is a string that can be either @t{\"texinfo\"}, @t{\"html\"}, or\n\
+@t{\"plain text\"}.\n\
+\n\
+To convert the help text to other formats, use the @code{makeinfo} function.\n\
+\n\
+@seealso{makeinfo}\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  if (args.length () == 1)
+    {
+      const std::string fname = args(0).string_value ();
+
+      if (! error_state)
+	{
+	  std::string text;
+	  std::string format;
+
+	  do_get_help_text_from_file (fname, text, format);
+  
+	  retval(1) = format;
+	  retval(0) = text;
+	}
+      else
+	error ("get_help_text_from_file: invalid input");
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
 // Return a cell array of strings containing the names of all
 // operators.