From bug-octave-request at bevo dot che dot wisc dot edu Mon Feb 2 15:17:27 2004 Subject: lasterr not set for usage From: "John W. Eaton" To: Paul Kienzle Cc: bug-octave at bevo dot che dot wisc dot edu Date: Mon, 2 Feb 2004 15:15:56 -0600 On 28-Jan-2004, Paul Kienzle wrote: | usage() in scripts and print_usage() in oct-files do not | go through normal octave error processing. | | e.g., | try kron; catch end | should not print anything, but it does. | | e.g., | try is_siso; catch lasterr, end | should print "usage: SISO = is_siso (sys) | | This affects all 2.1.x that I have used. Please try the following patch, to be applied after the patch I sent earlier to the octave-maintainers mailing list. Thanks, jwe src/ChangeLog: 2004-02-02 John W. Eaton * error.cc (verror, error_1): New arg, os. Use this instead of always printing to std:cerr. Change all callers. * error.cc (defun_usage_message): New function. * error.h: Provide decl. * defun.cc (print_usage): Use it to display error message. Index: src/defun.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/defun.cc,v retrieving revision 1.19 diff -u -r1.19 defun.cc --- src/defun.cc 8 Jul 2003 19:14:55 -0000 1.19 +++ src/defun.cc 2 Feb 2004 21:15:07 -0000 at @ -51,14 +51,22 @@ if (h.length () > 0) { - octave_stdout << "\n*** " << nm << ":\n\n"; + OSSTREAM buf; - display_help_text (octave_stdout, h); + buf << "\n*** " << nm << ":\n\n"; - octave_stdout << "\n"; + display_help_text (buf, h); + + buf << "\n"; if (! just_usage) - additional_help_message (octave_stdout); + additional_help_message (buf); + + buf << OSSTREAM_ENDS; + + defun_usage_message (OSSTREAM_C_STR (buf)); + + OSSTREAM_FREEZE (buf); } } else Index: src/error.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/error.cc,v retrieving revision 1.95 diff -u -r1.95 error.cc --- src/error.cc 2 Feb 2004 20:27:15 -0000 1.95 +++ src/error.cc 2 Feb 2004 21:15:07 -0000 at @ -154,7 +154,8 @@ } static void -verror (bool save_last_error, const char *name, const char *fmt, va_list args) +verror (bool save_last_error, std::ostream& os, + const char *name, const char *fmt, va_list args) { if (discard_error_messages) return; at @ -216,7 +217,7 @@ else { octave_diary << msg_string; - std::cerr << msg_string; + os << msg_string; } } at @ -225,7 +226,7 @@ // just set the error state. static void -error_1 (const char *name, const char *fmt, va_list args) +error_1 (std::ostream& os, const char *name, const char *fmt, va_list args) { if (error_state != -2) { at @ -240,14 +241,14 @@ { char *tmp_fmt = strsave (fmt); tmp_fmt[len - 1] = '\0'; - verror (true, name, tmp_fmt, args); + verror (true, os, name, tmp_fmt, args); delete [] tmp_fmt; } error_state = -2; } else - verror (true, name, fmt, args); + verror (true, os, name, fmt, args); } } else at @ -263,7 +264,7 @@ { va_list args; va_start (args, fmt); - verror (false, name, fmt, args); + verror (false, std::cerr, name, fmt, args); va_end (args); } at @ -272,7 +273,7 @@ { va_list args; va_start (args, fmt); - verror (true, "usage", fmt, args); + verror (true, std::cerr, "usage", fmt, args); error_state = -1; va_end (args); } at @ -291,12 +292,12 @@ { char *tmp_fmt = strsave (fmt); tmp_fmt[len - 1] = '\0'; - verror (false, 0, tmp_fmt, args); + verror (false, std::cerr, 0, tmp_fmt, args); delete [] tmp_fmt; } } else - verror (false, 0, fmt, args); + verror (false, std::cerr, 0, fmt, args); } } else at @ -398,7 +399,7 @@ va_list args; va_start (args, fmt); - error_1 ("error", fmt, args); + error_1 (std::cerr, "error", fmt, args); va_end (args); if ((interactive || forced_interactive) at @ -422,7 +423,7 @@ { va_list args; va_start (args, fmt); - error_1 (0, fmt, args); + error_1 (std::cerr, 0, fmt, args); va_end (args); } at @ -433,11 +434,20 @@ va_start (args, fmt); buffer_error_messages = 0; discard_error_messages = false; - verror (false, "panic", fmt, args); + verror (false, std::cerr, "panic", fmt, args); va_end (args); abort (); } +void +defun_usage_message (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + error_1 (octave_stdout, 0, fmt, args); + va_end (args); +} + typedef void (*error_fun)(const char *, ...); extern octave_value_list Fsprintf (const octave_value_list&, int); Index: src/error.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/error.h,v retrieving revision 1.33 diff -u -r1.33 error.h --- src/error.h 20 Jan 2004 23:04:46 -0000 1.33 +++ src/error.h 2 Feb 2004 21:15:07 -0000 at @ -38,6 +38,9 @@ extern void parse_error (const char *fmt, ...); extern void panic (const char *fmt, ...) GCC_ATTR_NORETURN; +// Helper function for print_usage defined in defun.cc. +extern void defun_usage_message (const char *fmt, ...); + // Current error state. extern int error_state; ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------