Mercurial > hg > octave-avbm
changeset 10131:30817aa3889a
allow print_usage to print backtrace if called from functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 19 Jan 2010 07:19:00 +0100 |
parents | 0c3609dd34cf |
children | aa0f575cf39b |
files | scripts/ChangeLog scripts/help/print_usage.m |
diffstat | 2 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-01-19 Jaroslav Hajek <highegg@gmail.com> + + * help/print_usage.m: Try determining whether called from top level. + If not, don't print additional help and enable backtrace instead. + 2010-01-18 John W. Eaton <jwe@octave.org> * testfun/test.m: Undo previous change.
--- a/scripts/help/print_usage.m +++ b/scripts/help/print_usage.m @@ -24,10 +24,10 @@ ## @end deftypefn function print_usage (name) + x = dbstack (); ## Handle input if (nargin == 0) ## Determine the name of the calling function - x = dbstack (); if (numel (x) > 1) name = x (2).name; else @@ -43,6 +43,9 @@ fullname = name; endif + ## Determine if we're called from top level. + at_toplev = length (x) < 2 || (length (x) == 2 && strcmp (x(2).name, name)); + ## Do the actual work [text, format] = get_help_text (fullname); max_len = 80; @@ -67,8 +70,21 @@ warning ("print_usage: raw Texinfo source of help text follows...\n"); endif - error ("Invalid call to %s. Correct usage is:\n\n%s\n%s", - name, usage_string, __additional_help_message__ ()); + if (at_toplev) + error ("Invalid call to %s. Correct usage is:\n\n%s\n%s", + name, usage_string, __additional_help_message__ ()); + else + msg = sprintf ("Invalid call to %s. Correct usage is:\n\n%s", + name, usage_string); + ## Ensure that the error doesn't end up with a newline, as that disables + ## backtraces. + if (msg(end) == "\n") + msg(end) = " "; + endif + + error (msg); + endif + endfunction function [retval, status] = get_usage_plain_text (help_text, max_len)