[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mex Extensions
From: |
John W. Eaton |
Subject: |
Re: Mex Extensions |
Date: |
Wed, 24 Jan 2007 13:16:00 -0500 |
On 11-Jan-2007, David Bateman wrote:
| John W. Eaton wrote:
| > On 10-Jan-2007, David Bateman wrote:
| >
| > | If no help is found in an oct-file it shouldn't go looking for it in an
| > | m-file...
| >
| > Octave already does this.
| Does it? If the doc string is empty then (help.cc)help_from_symbol_table
| returns false and then if an m-file is found (help.cc)help_from_file
| takes the help from there.
|
| > One case where this behavior makes sense is
| > if you have both .oct and .mex versions of a function (you need .mex
| > for Matlab and you want to use .oct for Octave so that you avoid the
| > data copying issues with using .mex in Octave) and you only want to
| > store the doc string in one place. In that case, you should omit it
| > from the .oct file and store it in a corresponding .m file and then it
| > will work for both Octave and Matlab without having to have two copies
| > of the doc string.
| >
| So the current behavior is desired, and you see a reason to look in a
| m-file for the doc string if the oct-file doesn't have help?
|
| However, that isn't the only situation my previous suggestion addressed.
| It also fixed the header to state where the function was defined not
| where the help came from. To get the behavior you want help_from_file
| should look something like
|
|
| static bool
| help_from_file (std::ostream& os, const std::string& nm, bool& symbol_found)
| {
| bool retval = false;
|
| std::string file;
|
| std::string header;
|
| if (symbol_found)
| {
| symbol_record *sym_rec = lookup_by_name (nm, 0);
|
| if (sym_rec && sym_rec->is_defined ())
| {
| header = sym_rec->which();
| }
| else
| symbol_found = false;
| }
|
| if (! symbol_found)
| header = nm + " is the file " + file + "\n\n";
|
| std::string h = get_help_from_file (nm, symbol_found, file);
|
| if (h.length () > 0)
| {
| os << header;
| display_help_text (os, h);
| os << "\n";
| retval = true;
| }
|
| return retval;
| }
I was thinking of something more like this:
src/ChangeLog:
2007-01-24 John W. Eaton <address@hidden>
* help.cc (help_from_file): Show .oct or .mex file name if one
exists in the same directory as the .m file.
Index: src/help.cc
===================================================================
RCS file: /cvs/octave/src/help.cc,v
retrieving revision 1.168
diff -u -u -r1.168 help.cc
--- src/help.cc 17 Jan 2007 21:47:50 -0000 1.168
+++ src/help.cc 24 Jan 2007 18:11:02 -0000
@@ -43,6 +43,7 @@
#include "cmd-edit.h"
#include "file-ops.h"
+#include "file-stat.h"
#include "oct-env.h"
#include "str-vec.h"
@@ -1078,6 +1079,18 @@
{
if (h.length () > 0)
{
+ // Strip extension
+ size_t l = file.length ();
+ if (l > 2 && file.substr (l-2) == ".m")
+ {
+ std::string tmp = file.substr (0, l - 2);
+
+ if (file_stat (tmp + ".oct"))
+ file = tmp + ".oct";
+ else if (file_stat (tmp + ".mex"))
+ file = tmp + ".mex";
+ }
+
os << nm << " is the file " << file << "\n\n";
display_help_text (os, h);
jwe