Mercurial > hg > octave-lyh
diff scripts/help/print_usage.m @ 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 | 936734e15a4d |
children | be55736a0783 |
line wrap: on
line diff
--- 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)