From bug-octave-request at bevo dot che dot wisc dot edu Thu Jan 22 22:09:16 2004 Subject: m-file warning() could be more useful From: "John W. Eaton" To: Paul Kienzle Cc: bug-octave at bevo dot che dot wisc dot edu Date: Thu, 22 Jan 2004 22:08:11 -0600 On 11-Dec-2003, Paul Kienzle wrote: | octave:35> C('c',2) | warning: in C near line 10, column 1: | | >>> warning ("Replacing definition of constant %s", varargin {i}); | | | warning: Replacing definition of constant c | | Should be: | | octave:35> C('c',2) | warning: Replacing definition of constant c | | E.g., | | octave:36> function f, C('c',3); end | octave:37> f | warning: in C near line 10, column 1: | | >>> warning ("Replacing definition of constant %s", varargin {i}); | | | warning: Replacing definition of constant c | | Should be: | | octave:37> f | warning: in f near line 1, column 1: | >>> C('c',3); | Replacing definition of constant c OK, I agree that printing out the warning twice is not too useful. The following patch fixes that, but preserves the location information, which I think is useful -- you might like to know precisely which warning call was made when there could be several of the same format in a given .m file or set of .m files. Of course it would be more useful if we could get more complete traceback information, but that is not currently easy to get. jwe 2004-01-22 John W. Eaton * error.cc (pr_where): New arg, print_code with default value true. (warning): Call pr_where with second arg false. Index: src/error.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/error.cc,v retrieving revision 1.93 diff -u -r1.93 error.cc --- src/error.cc 20 Jan 2004 23:04:46 -0000 1.93 +++ src/error.cc 23 Jan 2004 04:07:44 -0000 at @ -313,7 +313,7 @@ } static void -pr_where (const char *name) +pr_where (const char *name, bool print_code = true) { if (curr_statement) { at @ -335,25 +335,28 @@ else pr_where_1 ("%s: near line %d, column %d:", name, l, c); - // XXX FIXME XXX -- Note that the column number is probably not - // going to mean much here since the code is being reproduced - // from the parse tree, and we are only showing one statement - // even if there were multiple statements on the original source - // line. + if (print_code) + { + // XXX FIXME XXX -- Note that the column number is probably + // not going to mean much here since the code is being + // reproduced from the parse tree, and we are only showing + // one statement even if there were multiple statements on + // the original source line. - OSSTREAM output_buf; + OSSTREAM output_buf; - output_buf << std::endl; + output_buf << std::endl; - tree_print_code tpc (output_buf, ">>> "); + tree_print_code tpc (output_buf, ">>> "); - curr_statement->accept (tpc); + curr_statement->accept (tpc); - output_buf << std::endl << OSSTREAM_ENDS; + output_buf << std::endl << OSSTREAM_ENDS; - pr_where_1 ("%s", OSSTREAM_C_STR (output_buf)); + pr_where_1 ("%s", OSSTREAM_C_STR (output_buf)); - OSSTREAM_FREEZE (output_buf); + OSSTREAM_FREEZE (output_buf); + } } } at @ -366,7 +369,7 @@ && Vwarning_option == "backtrace" && ! warning_state && ! discard_warning_messages) - pr_where ("warning"); + pr_where ("warning", false); va_list args; va_start (args, fmt); ------------------------------------------------------------- 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 -------------------------------------------------------------