Mercurial > octave-nkf
annotate libinterp/corefcn/error.cc @ 20216:aa36fb998a4d stable
maint: Remove unnecessary whitespace at end of lines.
* libgui/Makefile.am, libgui/graphics/Canvas.cc,
libgui/graphics/EditControl.cc, libgui/graphics/Figure.cc,
libgui/graphics/MouseModeActionGroup.cc, libgui/graphics/annotation-dialog.cc,
libgui/graphics/annotation-dialog.h, libgui/graphics/gl-select.cc,
libgui/graphics/module.mk, libgui/kb-layouts/default.keytab,
libgui/kb-layouts/linux.keytab, libgui/kb-layouts/vt420pc.keytab,
libgui/src/m-editor/find-dialog.cc, libgui/src/main-window.cc,
libgui/src/octave-qt-link.cc, libgui/src/octave-qt-link.h,
libgui/src/shortcut-manager.h, libinterp/corefcn/error.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gl2ps-renderer.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h,
libinterp/corefcn/octave-link.cc, libinterp/corefcn/quadcc.cc,
libinterp/corefcn/strfns.cc, libinterp/corefcn/syscalls.cc,
libinterp/corefcn/sysdep.cc, libinterp/corefcn/urlwrite.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/ccolamd.cc,
libinterp/dldfcn/colamd.cc, libinterp/octave-value/ov-bool-sparse.cc,
libinterp/octave-value/ov-classdef.cc, libinterp/octave-value/ov-re-sparse.cc,
libinterp/octave-value/ov-struct.cc, libinterp/parse-tree/pt-arg-list.cc,
scripts/audio/@audiorecorder/play.m, scripts/audio/wavwrite.m,
scripts/general/cart2sph.m, scripts/geometry/inpolygon.m,
scripts/gui/listdlg.m, scripts/gui/msgbox.m,
scripts/gui/private/message_dialog.m, scripts/help/get_first_help_sentence.m,
scripts/help/lookfor.m, scripts/image/imshow.m, scripts/io/strread.m,
scripts/java/javamem.m, scripts/miscellaneous/dir.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/genvarname.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/private/__w2mpth__.m,
scripts/plot/appearance/annotation.m, scripts/plot/draw/colorbar.m,
scripts/plot/draw/quiver3.m, scripts/plot/util/hold.m,
scripts/plot/util/print.m, scripts/polynomial/mkpp.m,
scripts/polynomial/polyder.m, scripts/polynomial/spline.m,
scripts/polynomial/unmkpp.m, scripts/signal/arma_rnd.m, scripts/sparse/gplot.m,
scripts/statistics/tests/t_test.m,
scripts/statistics/tests/t_test_regression.m, scripts/strings/mat2str.m,
scripts/strings/strsplit.m, scripts/strings/strtrunc.m,
scripts/strings/untabify.m, scripts/testfun/assert.m:
maint: Remove unnecessary whitespace at end of lines.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 12 May 2015 09:22:01 -0700 |
parents | 4f45eaf83908 |
children | 9502e0142c19 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19631
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
1343 | 27 #include <cstdarg> |
1633 | 28 #include <cstring> |
1343 | 29 |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
30 #include <iomanip> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 #include <iostream> |
5765 | 32 #include <sstream> |
1728 | 33 #include <string> |
34 | |
1352 | 35 #include "defun.h" |
1 | 36 #include "error.h" |
3707 | 37 #include "input.h" |
1742 | 38 #include "pager.h" |
1352 | 39 #include "oct-obj.h" |
5567 | 40 #include "oct-map.h" |
1352 | 41 #include "utils.h" |
2370 | 42 #include "ov.h" |
3707 | 43 #include "ov-usr-fcn.h" |
18776
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
44 #include "pt-eval.h" |
3707 | 45 #include "pt-pr-code.h" |
46 #include "pt-stmt.h" | |
47 #include "toplev.h" | |
48 #include "unwind-prot.h" | |
2370 | 49 #include "variables.h" |
1 | 50 |
2174 | 51 // TRUE means that Octave will try to beep obnoxiously before printing |
52 // error messages. | |
5794 | 53 static bool Vbeep_on_error = false; |
2174 | 54 |
3707 | 55 // TRUE means that Octave will try to enter the debugger when an error |
56 // is encountered. This will also inhibit printing of the normal | |
57 // traceback message (you will only see the top-level error message). | |
7353 | 58 bool Vdebug_on_error = false; |
3707 | 59 |
60 // TRUE means that Octave will try to enter the debugger when a warning | |
61 // is encountered. | |
7353 | 62 bool Vdebug_on_warning = false; |
3707 | 63 |
5567 | 64 // TRUE means that Octave will try to display a stack trace when a |
65 // warning is encountered. | |
18127
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
66 static bool Vbacktrace_on_warning = true; |
5567 | 67 |
68 // TRUE means that Octave will print a verbose warning. Currently unused. | |
69 static bool Vverbose_warning; | |
70 | |
18776
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
71 // TRUE means that Octave will print no warnings, but lastwarn will be updated |
5582 | 72 static bool Vquiet_warning = false; |
73 | |
5567 | 74 // A structure containing (most of) the current state of warnings. |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
75 static octave_map warning_options; |
5567 | 76 |
3935 | 77 // The text of the last error message. |
78 static std::string Vlast_error_message; | |
79 | |
3934 | 80 // The text of the last warning message. |
81 static std::string Vlast_warning_message; | |
82 | |
5567 | 83 // The last warning message id. |
84 static std::string Vlast_warning_id; | |
3934 | 85 |
5567 | 86 // The last error message id. |
87 static std::string Vlast_error_id; | |
3934 | 88 |
6361 | 89 // The last file in which an error occured |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
90 static octave_map Vlast_error_stack; |
6361 | 91 |
143 | 92 // Current error state. |
3935 | 93 // |
94 // Valid values: | |
95 // | |
96 // -2: an error has occurred, but don't print any messages. | |
97 // -1: an error has occurred, we are printing a traceback | |
98 // 0: no error | |
99 // 1: an error has occurred | |
100 // | |
672 | 101 int error_state = 0; |
102 | |
3489 | 103 // Current warning state. |
3935 | 104 // |
105 // Valid values: | |
106 // | |
107 // 0: no warning | |
108 // 1: a warning has occurred | |
109 // | |
3489 | 110 int warning_state = 0; |
111 | |
1489 | 112 // Tell the error handler whether to print messages, or just store |
113 // them for later. Used for handling errors in eval() and | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
114 // the 'unwind_protect' statement. |
4699 | 115 int buffer_error_messages = 0; |
1489 | 116 |
3815 | 117 // TRUE means error messages are turned off. |
118 bool discard_error_messages = false; | |
119 | |
4452 | 120 // TRUE means warning messages are turned off. |
121 bool discard_warning_messages = false; | |
122 | |
4318 | 123 void |
124 reset_error_handler (void) | |
125 { | |
126 error_state = 0; | |
127 warning_state = 0; | |
4699 | 128 buffer_error_messages = 0; |
4318 | 129 discard_error_messages = false; |
130 } | |
131 | |
5567 | 132 static void |
5794 | 133 initialize_warning_options (const std::string& state) |
5567 | 134 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
135 octave_scalar_map initw; |
5567 | 136 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
137 initw.setfield ("identifier", "all"); |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
138 initw.setfield ("state", state); |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
139 |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
140 warning_options = initw; |
5567 | 141 } |
142 | |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
143 static octave_map |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
144 initialize_last_error_stack (void) |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
145 { |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
146 return octave_call_stack::empty_backtrace (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
147 } |
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
148 |
3491 | 149 // Warning messages are never buffered. |
150 | |
151 static void | |
5567 | 152 vwarning (const char *name, const char *id, const char *fmt, va_list args) |
3491 | 153 { |
4452 | 154 if (discard_warning_messages) |
155 return; | |
156 | |
3491 | 157 flush_octave_stdout (); |
158 | |
5765 | 159 std::ostringstream output_buf; |
3491 | 160 |
3761 | 161 octave_vformat (output_buf, fmt, args); |
162 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
163 // FIXME: we really want to capture the message before it has all the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
164 // formatting goop attached to it. We probably also want just the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
165 // message, not the traceback information. |
3935 | 166 |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
167 std::string base_msg = output_buf.str (); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
168 std::string msg_string; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
169 |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
170 if (name) |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
171 msg_string = std::string (name) + ": "; |
20216
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
172 |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
173 msg_string += base_msg + "\n"; |
3934 | 174 |
19478
3f29b433bd5d
do a better job of preserving warning state when running tests
John W. Eaton <jwe@octave.org>
parents:
19473
diff
changeset
|
175 Vlast_warning_id = id; |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
176 Vlast_warning_message = base_msg; |
3934 | 177 |
5582 | 178 if (! Vquiet_warning) |
179 { | |
180 octave_diary << msg_string; | |
3935 | 181 |
5582 | 182 std::cerr << msg_string; |
183 } | |
3491 | 184 } |
185 | |
1 | 186 static void |
4732 | 187 verror (bool save_last_error, std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 const char *name, const char *id, const char *fmt, va_list args, |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
189 bool with_cfn = false) |
1 | 190 { |
3815 | 191 if (discard_error_messages) |
192 return; | |
193 | |
3585 | 194 if (! buffer_error_messages) |
195 flush_octave_stdout (); | |
914 | 196 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 // FIXME: we really want to capture the message before it has all the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
198 // formatting goop attached to it. We probably also want just the |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
199 // message, not the traceback information. |
3935 | 200 |
7877 | 201 std::ostringstream output_buf; |
202 | |
203 octave_vformat (output_buf, fmt, args); | |
204 | |
205 std::string base_msg = output_buf.str (); | |
206 | |
207 bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; | |
208 | |
209 std::string msg_string; | |
210 | |
211 if (to_beep_or_not_to_beep_p) | |
212 msg_string = "\a"; | |
213 | |
214 if (name) | |
215 msg_string += std::string (name) + ": "; | |
216 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
217 // If with_fcn is specified, we'll attempt to prefix the message with the name |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
218 // of the current executing function. But we'll do so only if: |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
219 // 1. the name is not empty (anonymous function) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
220 // 2. it is not already there (including the following colon) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
221 if (with_cfn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
222 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
223 octave_function *curfcn = octave_call_stack::current (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
224 if (curfcn) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
225 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
226 std::string cfn = curfcn->name (); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
227 if (! cfn.empty ()) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
228 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
229 cfn += ':'; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
230 if (cfn.length () > base_msg.length () |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 || base_msg.compare (0, cfn.length (), cfn) != 0) |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
232 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
233 msg_string += cfn + ' '; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
234 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
235 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
236 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
237 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
238 |
7880 | 239 msg_string += base_msg + "\n"; |
3935 | 240 |
4731 | 241 if (! error_state && save_last_error) |
3935 | 242 { |
243 // This is the first error in a possible series. | |
5567 | 244 |
245 Vlast_error_id = id; | |
7877 | 246 Vlast_error_message = base_msg; |
6361 | 247 |
7877 | 248 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
6361 | 249 |
7877 | 250 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 octave_idx_type curr_frame = -1; |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
253 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 Vlast_error_stack = octave_call_stack::backtrace (0, curr_frame); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
255 } |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
256 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
257 Vlast_error_stack = initialize_last_error_stack (); |
3935 | 258 } |
259 | |
13987
2c0765c14e4f
eliminate unused error message buffer
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
260 if (! buffer_error_messages) |
1489 | 261 { |
3935 | 262 octave_diary << msg_string; |
4732 | 263 os << msg_string; |
1489 | 264 } |
1 | 265 } |
266 | |
19455
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
267 static void |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
268 pr_where_2 (const char *fmt, va_list args) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
269 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
270 if (fmt) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
271 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
272 if (*fmt) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
273 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
274 size_t len = strlen (fmt); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
275 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
276 if (len > 0) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
277 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
278 if (fmt[len - 1] == '\n') |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
279 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
280 if (len > 1) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
281 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
282 char *tmp_fmt = strsave (fmt); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
283 tmp_fmt[len - 1] = '\0'; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
284 verror (false, std::cerr, 0, "", tmp_fmt, args); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
285 delete [] tmp_fmt; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
286 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
287 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
288 else |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
289 verror (false, std::cerr, 0, "", fmt, args); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
290 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
291 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
292 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
293 else |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
294 panic ("pr_where_2: invalid format"); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
295 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
296 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
297 static void |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
298 pr_where_1 (const char *fmt, ...) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
299 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
300 va_list args; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
301 va_start (args, fmt); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
302 pr_where_2 (fmt, args); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
303 va_end (args); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
304 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
305 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
306 static void |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
307 pr_where (const char *who) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
308 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
309 std::list<octave_call_stack::stack_frame> frames |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
310 = octave_call_stack::backtrace_frames (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
311 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
312 size_t nframes = frames.size (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
313 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
314 if (nframes > 0) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
315 pr_where_1 ("%s: called from\n", who); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
316 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
317 for (std::list<octave_call_stack::stack_frame>::const_iterator p = frames.begin (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
318 p != frames.end (); p++) |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
319 { |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
320 const octave_call_stack::stack_frame& elt = *p; |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
321 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
322 std::string fcn_name = elt.fcn_name (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
323 int line = elt.line (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
324 int column = elt.column (); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
325 |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
326 pr_where_1 (" %s at line %d column %d\n", |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
327 fcn_name.c_str (), line, column); |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
328 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
329 } |
8b785ca93de7
don't print stack trace on errors if error_state is -2
John W. Eaton <jwe@octave.org>
parents:
19449
diff
changeset
|
330 |
1266 | 331 // Note that we don't actually print any message if the error string |
332 // is just "" or "\n". This allows error ("") and error ("\n") to | |
333 // just set the error state. | |
334 | |
1005 | 335 static void |
5567 | 336 error_1 (std::ostream& os, const char *name, const char *id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 const char *fmt, va_list args, bool with_cfn = false) |
1005 | 338 { |
339 if (error_state != -2) | |
340 { | |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
341 if (fmt && *fmt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 { |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
343 size_t len = strlen (fmt); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
344 |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
345 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 { |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
347 if (fmt[len - 1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 { |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
349 if (len > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 { |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
351 // Strip newline before issuing error |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
352 std::string tmp_fmt (fmt, len - 1); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
353 verror (true, os, name, id, tmp_fmt.c_str (), |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
354 args, with_cfn); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
355 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
356 |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
357 error_state = -2; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
358 } |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
359 else |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
360 { |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
361 verror (true, os, name, id, fmt, args, with_cfn); |
1423 | 362 |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
363 if (! error_state) |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
364 error_state = 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 } |
1489 | 368 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 panic ("error_1: invalid format"); |
1005 | 370 } |
371 } | |
372 | |
1 | 373 void |
6338 | 374 vmessage (const char *name, const char *fmt, va_list args) |
375 { | |
376 verror (false, std::cerr, name, "", fmt, args); | |
377 } | |
378 | |
379 void | |
1 | 380 message (const char *name, const char *fmt, ...) |
381 { | |
382 va_list args; | |
383 va_start (args, fmt); | |
6338 | 384 vmessage (name, fmt, args); |
1 | 385 va_end (args); |
386 } | |
387 | |
388 void | |
6338 | 389 vmessage_with_id (const char *name, const char *id, const char *fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
390 va_list args) |
6338 | 391 { |
392 verror (false, std::cerr, name, id, fmt, args); | |
393 } | |
394 | |
395 void | |
5567 | 396 message_with_id (const char *name, const char *id, const char *fmt, ...) |
397 { | |
398 va_list args; | |
399 va_start (args, fmt); | |
6338 | 400 vmessage_with_id (name, id, fmt, args); |
5567 | 401 va_end (args); |
402 } | |
403 | |
404 void | |
405 usage_1 (const char *id, const char *fmt, va_list args) | |
406 { | |
407 verror (true, std::cerr, "usage", id, fmt, args); | |
408 error_state = -1; | |
409 } | |
410 | |
411 void | |
6338 | 412 vusage (const char *fmt, va_list args) |
413 { | |
414 usage_1 ("", fmt, args); | |
415 } | |
416 | |
417 void | |
1 | 418 usage (const char *fmt, ...) |
419 { | |
420 va_list args; | |
421 va_start (args, fmt); | |
6338 | 422 vusage (fmt, args); |
5567 | 423 va_end (args); |
424 } | |
425 | |
426 void | |
6338 | 427 vusage_with_id (const char *id, const char *fmt, va_list args) |
428 { | |
429 usage_1 (id, fmt, args); | |
430 } | |
431 | |
432 void | |
5567 | 433 usage_with_id (const char *id, const char *fmt, ...) |
434 { | |
435 va_list args; | |
436 va_start (args, fmt); | |
6338 | 437 vusage_with_id (id, fmt, args); |
1 | 438 va_end (args); |
439 } | |
440 | |
3707 | 441 static void |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
442 error_2 (const char *id, const char *fmt, va_list args, bool with_cfn = false) |
6000 | 443 { |
444 int init_state = error_state; | |
445 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
446 error_1 (std::cerr, "error", id, fmt, args, with_cfn); |
6000 | 447 |
20162
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
448 bool in_user_code = octave_call_stack::caller_user_code () != 0; |
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
449 |
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
450 if (error_state != -2 && in_user_code && ! discard_error_messages) |
19449
972abb60c30f
emit stack trace immediately at point of error
John W. Eaton <jwe@octave.org>
parents:
19437
diff
changeset
|
451 pr_where ("error"); |
972abb60c30f
emit stack trace immediately at point of error
John W. Eaton <jwe@octave.org>
parents:
19437
diff
changeset
|
452 |
20162
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
453 if (interactive && Vdebug_on_error && init_state == 0 && in_user_code) |
6000 | 454 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
455 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
456 frame.protect_var (Vdebug_on_error); |
6000 | 457 Vdebug_on_error = false; |
458 | |
8973 | 459 error_state = 0; |
6000 | 460 |
18776
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
461 tree_evaluator::debug_mode = true; |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
462 |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
463 tree_evaluator::current_frame = octave_call_stack::current_frame (); |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
464 |
6000 | 465 do_keyboard (octave_value_list ()); |
466 } | |
467 } | |
468 | |
469 void | |
6338 | 470 verror (const char *fmt, va_list args) |
471 { | |
472 error_2 ("", fmt, args); | |
473 } | |
474 | |
475 void | |
6000 | 476 error (const char *fmt, ...) |
477 { | |
478 va_list args; | |
479 va_start (args, fmt); | |
6338 | 480 verror (fmt, args); |
6000 | 481 va_end (args); |
482 } | |
483 | |
484 void | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
485 verror_with_cfn (const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
486 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
487 error_2 ("", fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
488 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
489 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
490 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
491 error_with_cfn (const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
492 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
493 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
494 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
495 verror_with_cfn (fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
496 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
497 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
498 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
499 void |
6338 | 500 verror_with_id (const char *id, const char *fmt, va_list args) |
501 { | |
502 error_2 (id, fmt, args); | |
503 } | |
504 | |
505 void | |
6000 | 506 error_with_id (const char *id, const char *fmt, ...) |
507 { | |
508 va_list args; | |
509 va_start (args, fmt); | |
6338 | 510 verror_with_id (id, fmt, args); |
6000 | 511 va_end (args); |
512 } | |
513 | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
514 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
515 verror_with_id_cfn (const char *id, const char *fmt, va_list args) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
516 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
517 error_2 (id, fmt, args, true); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
518 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
519 |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
520 void |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
521 error_with_id_cfn (const char *id, const char *fmt, ...) |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
522 { |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
523 va_list args; |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
524 va_start (args, fmt); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
525 verror_with_id_cfn (id, fmt, args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
526 va_end (args); |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
527 } |
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9675
diff
changeset
|
528 |
5567 | 529 static int |
530 check_state (const std::string& state) | |
531 { | |
532 // -1: not found | |
533 // 0: found, "off" | |
534 // 1: found, "on" | |
535 // 2: found, "error" | |
536 | |
537 if (state == "off") | |
538 return 0; | |
539 else if (state == "on") | |
540 return 1; | |
541 else if (state == "error") | |
542 return 2; | |
543 else | |
544 return -1; | |
545 } | |
546 | |
547 // For given warning ID, return 0 if warnings are disabled, 1 if | |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
548 // enabled, and 2 if the given ID should be an error instead of a |
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
549 // warning. |
5567 | 550 |
5781 | 551 int |
5567 | 552 warning_enabled (const std::string& id) |
1 | 553 { |
5567 | 554 int retval = 0; |
555 | |
556 int all_state = -1; | |
557 int id_state = -1; | |
558 | |
559 octave_idx_type nel = warning_options.numel (); | |
560 | |
561 if (nel > 0) | |
562 { | |
563 Cell identifier = warning_options.contents ("identifier"); | |
564 Cell state = warning_options.contents ("state"); | |
565 | |
566 bool all_found = false; | |
567 bool id_found = false; | |
568 | |
569 for (octave_idx_type i = 0; i < nel; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 octave_value ov = identifier(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 std::string ovs = ov.string_value (); |
5567 | 573 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 if (! all_found && ovs == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
576 all_state = check_state (state(i).string_value ()); |
5567 | 577 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
578 if (all_state >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
579 all_found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
580 } |
5567 | 581 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
582 if (! id_found && ovs == id) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 id_state = check_state (state(i).string_value ()); |
5567 | 585 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
586 if (id_state >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 id_found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 } |
5567 | 589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 if (all_found && id_found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 } |
5567 | 593 } |
594 | |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
595 // If "all" is not present, assume warnings are enabled. |
5567 | 596 if (all_state == -1) |
14042
57e19c30b7d6
assume "all" "on" if "all" is not present in warning_state structure (bug #35050)
John W. Eaton <jwe@octave.org>
parents:
13987
diff
changeset
|
597 all_state = 1; |
5567 | 598 |
599 if (all_state == 0) | |
600 { | |
601 if (id_state >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
602 retval = id_state; |
5567 | 603 } |
604 else if (all_state == 1) | |
605 { | |
606 if (id_state == 0 || id_state == 2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
607 retval = id_state; |
5567 | 608 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
609 retval = all_state; |
5567 | 610 } |
611 else if (all_state == 2) | |
7206 | 612 { |
613 if (id_state == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
614 retval= id_state; |
7206 | 615 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
616 retval = all_state; |
7206 | 617 } |
5567 | 618 |
619 return retval; | |
620 } | |
621 | |
622 static void | |
623 warning_1 (const char *id, const char *fmt, va_list args) | |
624 { | |
625 int warn_opt = warning_enabled (id); | |
626 | |
627 if (warn_opt == 2) | |
628 { | |
629 // Handle this warning as an error. | |
630 | |
5998 | 631 error_2 (id, fmt, args); |
5567 | 632 } |
633 else if (warn_opt == 1) | |
3934 | 634 { |
20175
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
635 bool fmt_suppresses_backtrace = false; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
636 size_t fmt_len = fmt ? strlen (fmt) : 0; |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
637 fmt_suppresses_backtrace = (fmt_len > 0 && fmt[fmt_len-1] == '\n'); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
638 |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
639 if (fmt_suppresses_backtrace && fmt_len > 1) |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
640 { |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
641 // Strip newline before issuing warning |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
642 std::string tmp_fmt (fmt, fmt_len - 1); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
643 vwarning ("warning", id, tmp_fmt.c_str (), args); |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
644 } |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
645 else |
64a2d4c87ecb
Don't save "warning: " prefix in lastwarn() message.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
646 vwarning ("warning", id, fmt, args); |
8973 | 647 |
20162
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
648 bool in_user_code = octave_call_stack::caller_user_code () != 0; |
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
649 |
20165
0aed244dbdb3
don't print stack trace if warning format ends with newline character
John W. Eaton <jwe@octave.org>
parents:
20162
diff
changeset
|
650 |
0aed244dbdb3
don't print stack trace if warning format ends with newline character
John W. Eaton <jwe@octave.org>
parents:
20162
diff
changeset
|
651 if (! fmt_suppresses_backtrace && in_user_code |
0aed244dbdb3
don't print stack trace if warning format ends with newline character
John W. Eaton <jwe@octave.org>
parents:
20162
diff
changeset
|
652 && Vbacktrace_on_warning && ! warning_state |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
653 && ! discard_warning_messages) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 pr_where ("warning"); |
3707 | 655 |
3935 | 656 warning_state = 1; |
657 | |
3934 | 658 if ((interactive || forced_interactive) |
20162
a42de4173533
also provide stack traces for errors in script files (bug #44862)
John W. Eaton <jwe@octave.org>
parents:
20136
diff
changeset
|
659 && Vdebug_on_warning && in_user_code) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
660 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
661 unwind_protect frame; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
662 frame.protect_var (Vdebug_on_warning); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
663 Vdebug_on_warning = false; |
3707 | 664 |
18776
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
665 tree_evaluator::debug_mode = true; |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
666 |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
667 tree_evaluator::current_frame = octave_call_stack::current_frame (); |
bd334b6af257
Enter true debug mode after debug_on_(warning|error) (bug #37574).
Rik <rik@octave.org>
parents:
18221
diff
changeset
|
668 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 do_keyboard (octave_value_list ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 } |
3707 | 671 } |
1 | 672 } |
673 | |
674 void | |
6338 | 675 vwarning (const char *fmt, va_list args) |
676 { | |
677 warning_1 ("", fmt, args); | |
678 } | |
679 | |
680 void | |
5567 | 681 warning (const char *fmt, ...) |
682 { | |
683 va_list args; | |
684 va_start (args, fmt); | |
6338 | 685 vwarning (fmt, args); |
5567 | 686 va_end (args); |
687 } | |
688 | |
689 void | |
6338 | 690 vwarning_with_id (const char *id, const char *fmt, va_list args) |
691 { | |
692 warning_1 (id, fmt, args); | |
693 } | |
694 | |
695 void | |
5567 | 696 warning_with_id (const char *id, const char *fmt, ...) |
697 { | |
698 va_list args; | |
699 va_start (args, fmt); | |
6338 | 700 vwarning_with_id (id, fmt, args); |
5567 | 701 va_end (args); |
702 } | |
703 | |
704 void | |
6338 | 705 vparse_error (const char *fmt, va_list args) |
706 { | |
707 error_1 (std::cerr, 0, "", fmt, args); | |
708 } | |
709 | |
710 void | |
1005 | 711 parse_error (const char *fmt, ...) |
712 { | |
713 va_list args; | |
714 va_start (args, fmt); | |
6338 | 715 vparse_error (fmt, args); |
5567 | 716 va_end (args); |
717 } | |
718 | |
719 void | |
6338 | 720 vparse_error_with_id (const char *id, const char *fmt, va_list args) |
721 { | |
722 error_1 (std::cerr, 0, id, fmt, args); | |
723 } | |
724 | |
725 void | |
5567 | 726 parse_error_with_id (const char *id, const char *fmt, ...) |
727 { | |
728 va_list args; | |
729 va_start (args, fmt); | |
6338 | 730 vparse_error_with_id (id, fmt, args); |
1 | 731 va_end (args); |
732 } | |
733 | |
189 | 734 void |
6361 | 735 rethrow_error (const char *id, const char *fmt, ...) |
736 { | |
737 va_list args; | |
738 va_start (args, fmt); | |
6640 | 739 error_1 (std::cerr, 0, id, fmt, args); |
6361 | 740 va_end (args); |
741 } | |
742 | |
743 void | |
1 | 744 panic (const char *fmt, ...) |
745 { | |
746 va_list args; | |
747 va_start (args, fmt); | |
4699 | 748 buffer_error_messages = 0; |
3815 | 749 discard_error_messages = false; |
5567 | 750 verror (false, std::cerr, "panic", "", fmt, args); |
1 | 751 va_end (args); |
752 abort (); | |
753 } | |
754 | |
4732 | 755 static void |
756 defun_usage_message_1 (const char *fmt, ...) | |
757 { | |
758 va_list args; | |
759 va_start (args, fmt); | |
5567 | 760 error_1 (octave_stdout, 0, "", fmt, args); |
4732 | 761 va_end (args); |
762 } | |
763 | |
764 void | |
765 defun_usage_message (const std::string& msg) | |
766 { | |
767 defun_usage_message_1 ("%s", msg.c_str ()); | |
768 } | |
769 | |
5567 | 770 typedef void (*error_fun)(const char *, const char *, ...); |
1489 | 771 |
2086 | 772 extern octave_value_list Fsprintf (const octave_value_list&, int); |
1489 | 773 |
3934 | 774 static std::string |
5567 | 775 handle_message (error_fun f, const char *id, const char *msg, |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
776 const octave_value_list& args, bool have_fmt) |
528 | 777 { |
3934 | 778 std::string retval; |
528 | 779 |
3523 | 780 std::string tstr; |
1728 | 781 |
528 | 782 int nargin = args.length (); |
783 | |
2745 | 784 if (nargin > 0) |
528 | 785 { |
3066 | 786 octave_value arg; |
787 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
788 if (have_fmt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
789 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 octave_value_list tmp = Fsprintf (args, 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 arg = tmp(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
792 } |
3066 | 793 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
794 arg = args(0); |
2745 | 795 |
796 if (arg.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 if (arg.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
799 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 tstr = arg.string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 msg = tstr.c_str (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
802 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
803 if (! msg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
804 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
806 else if (arg.is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
807 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 } |
528 | 809 } |
810 | |
1489 | 811 // Ugh. |
812 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
813 size_t len = strlen (msg); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
814 |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
815 if (len > 0) |
1489 | 816 { |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
817 if (msg[len - 1] == '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
819 if (len > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
820 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
821 char *tmp_msg = strsave (msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
822 tmp_msg[len - 1] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
823 f (id, "%s\n", tmp_msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
824 retval = tmp_msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
825 delete [] tmp_msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
826 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
827 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
828 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
829 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
830 f (id, "%s", msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
831 retval = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
832 } |
3934 | 833 } |
528 | 834 |
835 return retval; | |
836 } | |
837 | |
6361 | 838 DEFUN (rethrow, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
839 "-*- texinfo -*-\n\ |
6361 | 840 @deftypefn {Built-in Function} {} rethrow (@var{err})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
841 Reissue a previous error as defined by @var{err}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
842 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
843 @var{err} is a structure that must contain at least the @qcode{\"message\"}\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
844 and @qcode{\"identifier\"} fields. @var{err} can also contain a field\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
845 @qcode{\"stack\"} that gives information on the assumed location of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
846 error. Typically @var{err} is returned from @code{lasterror}.\n\ |
6361 | 847 @seealso{lasterror, lasterr, error}\n\ |
848 @end deftypefn") | |
849 { | |
850 octave_value retval; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
851 int nargin = args.length (); |
6361 | 852 |
853 if (nargin != 1) | |
6959 | 854 print_usage (); |
6361 | 855 else |
856 { | |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
857 const octave_scalar_map err = args(0).scalar_map_value (); |
6361 | 858 |
6483 | 859 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
861 if (err.contains ("message") && err.contains ("identifier")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
863 std::string msg = err.contents ("message").string_value (); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
864 std::string id = err.contents ("identifier").string_value (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
865 int len = msg.length (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
866 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 std::string file; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 std::string nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 int l = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 int c = -1; |
6361 | 871 |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10605
diff
changeset
|
872 octave_map err_stack = initialize_last_error_stack (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
873 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 if (err.contains ("stack")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
876 err_stack = err.contents ("stack").map_value (); |
6483 | 877 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 if (err_stack.numel () > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 if (err_stack.contains ("file")) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
881 file = err_stack.contents ("file")(0).string_value (); |
6483 | 882 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 if (err_stack.contains ("name")) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
884 nm = err_stack.contents ("name")(0).string_value (); |
6483 | 885 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 if (err_stack.contains ("line")) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
887 l = err_stack.contents ("line")(0).nint_value (); |
6640 | 888 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 if (err_stack.contains ("column")) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
890 c = err_stack.contents ("column")(0).nint_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
891 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 } |
6361 | 893 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 // Ugh. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
895 char *tmp_msg = strsave (msg.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 if (tmp_msg[len-1] == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
898 if (len > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
900 tmp_msg[len - 1] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 rethrow_error (id.c_str (), "%s\n", tmp_msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
902 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
905 rethrow_error (id.c_str (), "%s", tmp_msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
906 delete [] tmp_msg; |
6361 | 907 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
908 // FIXME: is this the right thing to do for Vlast_error_stack? |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
909 // Should it be saved and restored with unwind_protect? |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
910 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 Vlast_error_stack = err_stack; |
6361 | 912 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 if (err.contains ("stack")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 if (file.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
916 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 if (nm.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
918 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
919 if (l > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 if (c > 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
922 pr_where_1 ("error: near line %d, column %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
924 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 pr_where_1 ("error: near line %d", l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
926 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
927 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
928 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
929 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
930 if (l > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
931 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 if (c > 0) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
933 pr_where_1 ("error: called from '%s' near line %d, column %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
934 nm.c_str (), l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
935 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
936 pr_where_1 ("error: called from '%d' near line %d", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
937 nm.c_str (), l); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
938 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
940 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
941 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
942 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
943 if (nm.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
944 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
945 if (l > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
946 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
947 if (c > 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
948 pr_where_1 ("error: in file %s near line %d, column %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
949 file.c_str (), l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
950 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
951 pr_where_1 ("error: in file %s near line %d", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
952 file.c_str (), l); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
953 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
954 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
955 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
956 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
957 if (l > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
958 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
959 if (c > 0) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
960 pr_where_1 ("error: called from '%s' in file %s near line %d, column %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
961 nm.c_str (), file.c_str (), l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
962 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
963 pr_where_1 ("error: called from '%d' in file %s near line %d", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
964 nm.c_str (), file.c_str (), l); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
965 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
966 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
967 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
968 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
969 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
971 error ("rethrow: ERR structure must contain the fields 'message and 'identifier'"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 } |
6361 | 973 } |
974 return retval; | |
975 } | |
976 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
977 // Determine whether the first argument to error or warning function |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
978 // should be handled as the message identifier or as the format string. |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
979 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
980 static bool |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
981 maybe_extract_message_id (const std::string& caller, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
982 const octave_value_list& args, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
983 octave_value_list& nargs, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
984 std::string& id) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
985 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
986 nargs = args; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
987 id = std::string (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
988 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
989 int nargin = args.length (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
990 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
991 bool have_fmt = nargin > 1; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
992 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
993 if (nargin > 0) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
994 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
995 std::string arg1 = args(0).string_value (); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
996 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
997 if (! error_state) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
998 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
999 // For compatibility with Matlab, an identifier must contain |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1000 // ':', but not at the beginning or the end, and it must not |
14559
90c51d8797cc
also require that warning and error message identifiers do not contain whitespace
John W. Eaton <jwe@octave.org>
parents:
14558
diff
changeset
|
1001 // contain '%' (even if it is not a valid conversion |
90c51d8797cc
also require that warning and error message identifiers do not contain whitespace
John W. Eaton <jwe@octave.org>
parents:
14558
diff
changeset
|
1002 // operator) or whitespace. |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1003 |
14559
90c51d8797cc
also require that warning and error message identifiers do not contain whitespace
John W. Eaton <jwe@octave.org>
parents:
14558
diff
changeset
|
1004 if (arg1.find_first_of ("% \f\n\r\t\v") == std::string::npos |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1005 && arg1.find (':') != std::string::npos |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1006 && arg1[0] != ':' |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1007 && arg1[arg1.length ()-1] != ':') |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1008 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1009 if (nargin > 1) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1010 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1011 id = arg1; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1012 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1013 nargs.resize (nargin-1); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1014 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1015 for (int i = 1; i < nargin; i++) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1016 nargs(i-1) = args(i); |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1017 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1018 else |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1019 nargs(0) = "call to " + caller |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1020 + " with message identifier requires message"; |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1021 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1022 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1023 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1024 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1025 return have_fmt; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1026 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1027 |
1957 | 1028 DEFUN (error, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1029 "-*- texinfo -*-\n\ |
10840 | 1030 @deftypefn {Built-in Function} {} error (@var{template}, @dots{})\n\ |
7252 | 1031 @deftypefnx {Built-in Function} {} error (@var{id}, @var{template}, @dots{})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1032 Display an error message and stop m-file execution.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1033 \n\ |
5781 | 1034 Format the optional arguments under the control of the template string\n\ |
1035 @var{template} using the same rules as the @code{printf} family of\n\ | |
1036 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1037 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1038 string @samp{error: }.\n\ | |
3373 | 1039 \n\ |
1040 Calling @code{error} also sets Octave's internal error state such that\n\ | |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1041 control will return to the top level without evaluating any further\n\ |
3373 | 1042 commands. This is useful for aborting from functions or scripts.\n\ |
897 | 1043 \n\ |
19368
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18125
diff
changeset
|
1044 If the error message does not end with a newline character, Octave will\n\ |
3373 | 1045 print a traceback of all the function calls leading to the error. For\n\ |
1046 example, given the following function definitions:\n\ | |
1047 \n\ | |
1048 @example\n\ | |
1049 @group\n\ | |
6671 | 1050 function f () g (); end\n\ |
1051 function g () h (); end\n\ | |
3373 | 1052 function h () nargin == 1 || error (\"nargin != 1\"); end\n\ |
1053 @end group\n\ | |
1054 @end example\n\ | |
1489 | 1055 \n\ |
3373 | 1056 @noindent\n\ |
1057 calling the function @code{f} will result in a list of messages that\n\ | |
1058 can help you to quickly locate the exact location of the error:\n\ | |
1489 | 1059 \n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1060 @example\n\ |
3373 | 1061 @group\n\ |
1062 f ()\n\ | |
1063 error: nargin != 1\n\ | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1064 error: called from:\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1065 error: error at line -1, column -1\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1066 error: h at line 1, column 27\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1067 error: g at line 1, column 15\n\ |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7977
diff
changeset
|
1068 error: f at line 1, column 15\n\ |
3373 | 1069 @end group\n\ |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1070 @end example\n\ |
3373 | 1071 \n\ |
19368
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18125
diff
changeset
|
1072 If the error message ends in a newline character, Octave will print the\n\ |
3373 | 1073 message but will not display any traceback messages as it returns\n\ |
1074 control to the top level. For example, modifying the error message\n\ | |
19368
1213af866a89
doc: Fix backslash not showing in error/warning docs due to escape processing.
Rik <rik@octave.org>
parents:
18125
diff
changeset
|
1075 in the previous example to end in a newline causes Octave to only print\n\ |
3373 | 1076 a single message:\n\ |
1077 \n\ | |
1078 @example\n\ | |
1079 @group\n\ | |
1080 function h () nargin == 1 || error (\"nargin != 1\\n\"); end\n\ | |
1081 f ()\n\ | |
1082 error: nargin != 1\n\ | |
1083 @end group\n\ | |
1084 @end example\n\ | |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1085 \n\ |
16770
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1086 A null string (\"\") input to @code{error} will be ignored and the code\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1087 will continue running as if the statement were a NOP@. This is for\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1088 compatibility with @sc{matlab}. It also makes it possible to write code such\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1089 as\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1090 \n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1091 @example\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1092 @group\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1093 err_msg = \"\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1094 if (CONDITION 1)\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1095 err_msg = \"CONDITION 1 found\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1096 elseif (CONDITION2)\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1097 err_msg = \"CONDITION 2 found\";\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1098 @dots{}\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1099 endif\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1100 error (err_msg);\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1101 @end group\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1102 @end example\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1103 \n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1104 @noindent\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1105 which will only stop execution if an error has been found.\n\ |
2b86cb4e172b
doc: clarify docstring regarding null input to error() (bug #39271).
Rik <rik@octave.org>
parents:
16492
diff
changeset
|
1106 \n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1107 Implementation Note: For compatibility with @sc{matlab}, escape\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1108 sequences in @var{template} (e.g., @qcode{\"@xbackslashchar{}n\"} =>\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1109 newline) are processed regardless of whether @var{template} has been defined\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1110 with single quotes, as long as there are two or more input arguments. To\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1111 disable escape sequence expansion use a second backslash before the sequence\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1112 (e.g., @qcode{\"@xbackslashchar{}@xbackslashchar{}n\"}) or use the\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1113 @code{regexptranslate} function.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1114 @seealso{warning, lasterror}\n\ |
3373 | 1115 @end deftypefn") |
897 | 1116 { |
7252 | 1117 octave_value retval; |
1118 | |
1119 int nargin = args.length (); | |
1120 | |
1121 octave_value_list nargs = args; | |
1122 | |
1123 std::string id; | |
1124 | |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1125 if (nargin == 0) |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1126 print_usage (); |
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1127 else |
7252 | 1128 { |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1129 bool have_fmt = false; |
5567 | 1130 |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1131 if (nargin == 1 && args(0).is_map ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1132 { |
13709
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1133 // empty struct is not an error. return and resume calling function. |
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1134 if (args(0).is_empty ()) |
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1135 return retval; |
a0875c6cab7e
error.cc: Don't complain if error struct input is empty (Matlab compatability)
Rik <octave@nomad.inbox5.com>
parents:
12705
diff
changeset
|
1136 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1137 octave_value_list tmp; |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1138 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1139 octave_scalar_map m = args(0).scalar_map_value (); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1140 |
12705
4972eb61c6d6
Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents:
12704
diff
changeset
|
1141 // empty struct is not an error. return and resume calling function. |
4972eb61c6d6
Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents:
12704
diff
changeset
|
1142 if (m.nfields () == 0) |
4972eb61c6d6
Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents:
12704
diff
changeset
|
1143 return retval; |
4972eb61c6d6
Fix bug with error() not accepting an empty struct input (Bug #33428).
Rik <octave@nomad.inbox5.com>
parents:
12704
diff
changeset
|
1144 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1145 if (m.contains ("message")) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1146 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1147 octave_value c = m.getfield ("message"); |
7252 | 1148 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1149 if (c.is_string ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1150 nargs(0) = c.string_value (); |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1151 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1152 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1153 if (m.contains ("identifier")) |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1154 { |
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1155 octave_value c = m.getfield ("identifier"); |
7252 | 1156 |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1157 if (c.is_string ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1158 id = c.string_value (); |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1159 } |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1160 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1161 // FIXME: also need to handle "stack" field in error structure, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1162 // but that will require some more significant surgery on |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1163 // handle_message, error_with_id, etc. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1164 } |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1165 else |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1166 { |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1167 have_fmt = maybe_extract_message_id ("error", args, nargs, id); |
9675
ef45d191d833
error: improve compatibility for calls with no arguments or empty format
John W. Eaton <jwe@octave.org>
parents:
9588
diff
changeset
|
1168 |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1169 if (error_state) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1170 return retval; |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1171 } |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1172 |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1173 handle_message (error_with_id, id.c_str (), "unspecified error", |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1174 nargs, have_fmt); |
7252 | 1175 } |
1176 | |
3934 | 1177 return retval; |
1489 | 1178 } |
897 | 1179 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1180 static octave_scalar_map |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1181 warning_query (const std::string& id_arg) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1182 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1183 octave_scalar_map retval; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1184 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1185 std::string id = id_arg; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1186 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1187 if (id == "last") |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1188 id = Vlast_warning_id; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1189 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1190 Cell ident = warning_options.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1191 Cell state = warning_options.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1192 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1193 octave_idx_type nel = ident.numel (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1194 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1195 bool found = false; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1196 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1197 std::string val; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1198 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1199 for (octave_idx_type i = 0; i < nel; i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1200 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1201 if (ident(i).string_value () == id) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1202 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1203 val = state(i).string_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1204 found = true; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1205 break; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1206 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1207 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1208 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1209 if (! found) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1210 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1211 for (octave_idx_type i = 0; i < nel; i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1212 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1213 if (ident(i).string_value () == "all") |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1214 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1215 val = state(i).string_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1216 found = true; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1217 break; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1218 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1219 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1220 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1221 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1222 if (found) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1223 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1224 retval.assign ("identifier", id); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1225 retval.assign ("state", val); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1226 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1227 else |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1228 error ("warning: unable to find default warning state!"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1229 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1230 return retval; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1231 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1232 |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1233 static std::string |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1234 default_warning_state (void) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1235 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1236 std::string retval = "on"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1237 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1238 Cell ident = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1239 Cell state = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1240 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1241 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1242 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1243 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1244 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1245 if (ident(i).string_value () == "all") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1246 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1247 retval = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1248 break; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1249 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1250 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1251 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1252 return retval; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1253 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1254 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1255 static void |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1256 display_warning_options (std::ostream& os) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1257 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1258 Cell ident = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1259 Cell state = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1260 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1261 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1262 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1263 std::string all_state = default_warning_state (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1264 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1265 if (all_state == "on") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1266 os << "By default, warnings are enabled."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1267 else if (all_state == "off") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1268 os << "By default, warnings are disabled."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1269 else if (all_state == "error") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1270 os << "By default, warnings are treated as errors."; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1271 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1272 panic_impossible (); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19478
diff
changeset
|
1273 |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1274 if (nel > 1) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1275 os << "\n\n"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1276 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1277 // The state for all is always supposed to be first in the list. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1278 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1279 for (octave_idx_type i = 1; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1280 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1281 std::string tid = ident(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1282 std::string tst = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1283 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1284 os << std::setw (7) << tst << " " << tid << "\n"; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1285 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1286 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1287 os << std::endl; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1288 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1289 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1290 static void |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1291 set_warning_option (const std::string& state, const std::string& ident) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1292 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1293 if (ident == "all") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1294 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1295 initialize_warning_options (state); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1296 return; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1297 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1298 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1299 std::string all_state = default_warning_state (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1300 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1301 if (state != "on" && state != "off" && state != "error") |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1302 error ("invalid warning state: %s", state.c_str ()); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1303 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1304 Cell tid = warning_options.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1305 Cell tst = warning_options.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1306 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1307 octave_idx_type nel = tid.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1308 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1309 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1310 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1311 if (tid(i).string_value () == ident) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1312 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1313 // We found it in the current list of options. If the state |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1314 // for "all" is same as arg1, we can simply remove the item |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1315 // from the list. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1316 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1317 if (state == all_state) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1318 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1319 for (i = i + 1; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1320 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1321 tid(i-1) = tid(i); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1322 tst(i-1) = tst(i); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1323 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1324 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1325 tid.resize (dim_vector (1, nel-1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1326 tst.resize (dim_vector (1, nel-1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1327 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1328 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1329 tst(i) = state; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1330 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1331 warning_options.clear (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1332 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1333 warning_options.assign ("identifier", tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1334 warning_options.assign ("state", tst); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1335 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1336 return; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1337 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1338 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1339 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1340 // The option wasn't already in the list. Append it. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1341 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1342 tid.resize (dim_vector (1, nel+1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1343 tst.resize (dim_vector (1, nel+1)); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1344 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1345 tid(nel) = ident; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1346 tst(nel) = state; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1347 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1348 warning_options.clear (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1349 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1350 warning_options.assign ("identifier", tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1351 warning_options.assign ("state", tst); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1352 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1353 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
1354 DEFUN (warning, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1355 "-*- texinfo -*-\n\ |
10840 | 1356 @deftypefn {Built-in Function} {} warning (@var{template}, @dots{})\n\ |
7252 | 1357 @deftypefnx {Built-in Function} {} warning (@var{id}, @var{template}, @dots{})\n\ |
14072
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1358 @deftypefnx {Built-in Function} {} warning (\"on\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1359 @deftypefnx {Built-in Function} {} warning (\"off\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1360 @deftypefnx {Built-in Function} {} warning (\"query\", @var{id})\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1361 @deftypefnx {Built-in Function} {} warning (\"error\", @var{id})\n\ |
18127
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1362 @deftypefnx {Built-in Function} {} warning (@var{state}, \"backtrace\")\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1363 @deftypefnx {Built-in Function} {} warning (@var{state}, @var{id}, \"local\")\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1364 Display a warning message or control the behavior of Octave's warning system.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1365 \n\ |
5781 | 1366 Format the optional arguments under the control of the template string\n\ |
1367 @var{template} using the same rules as the @code{printf} family of\n\ | |
1368 functions (@pxref{Formatted Output}) and print the resulting message\n\ | |
1369 on the @code{stderr} stream. The message is prefixed by the character\n\ | |
1370 string @samp{warning: }.\n\ | |
1371 You should use this function when you want to notify the user\n\ | |
3600 | 1372 of an unusual condition, but only when it makes sense for your program\n\ |
1373 to go on.\n\ | |
5781 | 1374 \n\ |
1375 The optional message identifier allows users to enable or disable\n\ | |
15524
15628a84a4fa
Document form of warning IDs is NAMESPACE:WARNING-NAME (bug #37559)
Rik <rik@octave.org>
parents:
15466
diff
changeset
|
1376 warnings tagged by @var{id}. A message identifier is of the form\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1377 \"NAMESPACE:WARNING-NAME\". Octave's own warnings use the @qcode{\"Octave\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1378 namespace (@pxref{XREFwarning_ids}). The special identifier @qcode{\"all\"}\n\ |
15524
15628a84a4fa
Document form of warning IDs is NAMESPACE:WARNING-NAME (bug #37559)
Rik <rik@octave.org>
parents:
15466
diff
changeset
|
1379 may be used to set the state of all warnings.\n\ |
5781 | 1380 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1381 If the first argument is @qcode{\"on\"} or @qcode{\"off\"},\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1382 set the state of a particular warning using the identifier @var{id}. If the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1383 first argument is @qcode{\"query\"}, query the state of this warning\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1384 instead. If the identifier is omitted, a value of @qcode{\"all\"} is\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1385 assumed. If you set the state of a warning to @qcode{\"error\"}, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1386 warning named by @var{id} is handled as if it were an error instead. So,\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1387 for example, the following handles all warnings as errors:\n\ |
14072
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1388 \n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1389 @example\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1390 @group\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1391 warning (\"error\");\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1392 @end group\n\ |
d0d9c5d2e434
doc: Reformat and clarify warning's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14055
diff
changeset
|
1393 @end example\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1394 \n\ |
18127
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1395 If the state is @qcode{\"on\"} or @qcode{\"off\"} and the third argument\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1396 is @qcode{\"backtrace\"}, then a stack trace is printed along with the\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1397 warning message when warnings occur inside function calls. This option\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1398 is enabled by default.\n\ |
d96747f74b1e
enable "backtrace" warning by default and document option
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1399 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1400 If the state is @qcode{\"on\"}, @qcode{\"off\"}, or @qcode{\"error\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1401 and the third argument is @qcode{\"local\"}, then the warning state\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1402 will be set temporarily, until the end of the current function.\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1403 Changes to warning states that are set locally affect the current\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1404 function and all functions called from the current scope. The\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1405 previous warning state is restored on return from the current\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1406 function. The @qcode{\"local\"} option is ignored if used in the top-level\n\ |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1407 workspace.\n\ |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1408 \n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1409 Implementation Note: For compatibility with @sc{matlab}, escape\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1410 sequences in @var{template} (e.g., @qcode{\"@xbackslashchar{}n\"} =>\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1411 newline) are processed regardless of whether @var{template} has been defined\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1412 with single quotes, as long as there are two or more input arguments. To\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1413 disable escape sequence expansion use a second backslash before the sequence\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1414 (e.g., @qcode{\"@xbackslashchar{}@xbackslashchar{}n\"}) or use the\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20076
diff
changeset
|
1415 @code{regexptranslate} function.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1416 @seealso{warning_ids, lastwarn, error}\n\ |
3373 | 1417 @end deftypefn") |
1489 | 1418 { |
5567 | 1419 octave_value retval; |
3934 | 1420 |
5567 | 1421 int nargin = args.length (); |
1422 int argc = nargin + 1; | |
3934 | 1423 |
3935 | 1424 bool done = false; |
3934 | 1425 |
5567 | 1426 if (argc > 1 && args.all_strings_p ()) |
3935 | 1427 { |
1428 string_vector argv = args.make_argv ("warning"); | |
1429 | |
1430 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1431 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1432 std::string arg1 = argv(1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1433 std::string arg2 = "all"; |
5567 | 1434 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1435 if (argc >= 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1436 arg2 = argv(2); |
5567 | 1437 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1438 if (arg1 == "on" || arg1 == "off" || arg1 == "error") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1439 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1440 octave_map old_warning_options = warning_options; |
5567 | 1441 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1442 if (argc == 4 && argv(3) == "local" |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1443 && ! symbol_table::at_top_level ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1444 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1445 symbol_table::scope_id scope |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1446 = octave_call_stack::current_scope (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1447 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1448 symbol_table::context_id context |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1449 = octave_call_stack::current_context (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1450 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1451 octave_scalar_map val = warning_query (arg2); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1452 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1453 octave_value curr_state = val.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1454 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1455 // FIXME: this might be better with a dictionary object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1456 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1457 octave_value curr_warning_states |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1458 = symbol_table::varval (".saved_warning_states.", |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1459 scope, context); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1460 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1461 octave_map m; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1462 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1463 if (curr_warning_states.is_defined ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1464 m = curr_warning_states.map_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1465 else |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1466 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1467 string_vector fields (2); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1468 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1469 fields(0) = "identifier"; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1470 fields(1) = "state"; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1471 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1472 m = octave_map (dim_vector (0, 1), fields); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1473 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1474 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1475 if (error_state) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1476 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1477 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1478 Cell ids = m.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1479 Cell states = m.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1480 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1481 octave_idx_type nel = states.numel (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1482 bool found = false; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1483 octave_idx_type i; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1484 for (i = 0; i < nel; i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1485 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1486 std::string id = ids(i).string_value (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1487 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1488 if (error_state) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1489 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1490 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1491 if (id == arg2) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1492 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1493 states(i) = curr_state; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1494 found = true; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1495 break; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1496 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1497 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1498 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1499 if (! found) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1500 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1501 m.resize (dim_vector (nel+1, 1)); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1502 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1503 ids.resize (dim_vector (nel+1, 1)); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1504 states.resize (dim_vector (nel+1, 1)); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1505 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1506 ids(nel) = arg2; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1507 states(nel) = curr_state; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1508 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1509 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1510 m.contents ("identifier") = ids; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1511 m.contents ("state") = states; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1512 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15624
diff
changeset
|
1513 symbol_table::assign |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15624
diff
changeset
|
1514 (".saved_warning_states.", m, scope, context); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1515 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1516 // Now ignore the "local" argument and continue to |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1517 // handle the current setting. |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1518 argc--; |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1519 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1520 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1521 if (arg2 == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1522 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1523 octave_map tmp; |
3934 | 1524 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1525 Cell id (1, 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1526 Cell st (1, 1); |
7202 | 1527 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1528 id(0) = arg2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1529 st(0) = arg1; |
7202 | 1530 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1531 // Since internal Octave functions are not |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1532 // compatible, turning all warnings into errors |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1533 // should leave the state of |
19886
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19883
diff
changeset
|
1534 // Octave:language-extension alone. |
7202 | 1535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1536 if (arg1 == "error" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1537 && warning_options.contains ("identifier")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1538 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1539 octave_idx_type n = 1; |
7206 | 1540 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1541 Cell tid = warning_options.contents ("identifier"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1542 Cell tst = warning_options.contents ("state"); |
7202 | 1543 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1544 for (octave_idx_type i = 0; i < tid.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1546 octave_value vid = tid(i); |
7202 | 1547 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1548 if (vid.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1549 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1550 std::string key = vid.string_value (); |
7202 | 1551 |
19886
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19883
diff
changeset
|
1552 if (key == "Octave:language-extension" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1553 || key == "Octave:single-quote-string") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1554 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1555 id.resize (dim_vector (1, n+1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1556 st.resize (dim_vector (1, n+1)); |
7202 | 1557 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1558 id(n) = tid(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1559 st(n) = tst(i); |
7206 | 1560 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1561 n++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1562 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1563 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1564 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1565 } |
7202 | 1566 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1567 tmp.assign ("identifier", id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1568 tmp.assign ("state", st); |
5567 | 1569 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1570 warning_options = tmp; |
5567 | 1571 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1572 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1573 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1574 else if (arg2 == "backtrace") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1575 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1576 if (arg1 != "error") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1577 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1578 Vbacktrace_on_warning = (arg1 == "on"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1579 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1580 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1581 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1582 else if (arg2 == "debug") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1583 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1584 if (arg1 != "error") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1585 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1586 Vdebug_on_warning = (arg1 == "on"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1587 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1588 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1589 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1590 else if (arg2 == "verbose") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1591 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1592 if (arg1 != "error") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1593 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1594 Vverbose_warning = (arg1 == "on"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1595 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1596 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1597 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1598 else if (arg2 == "quiet") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1599 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1600 if (arg1 != "error") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1601 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1602 Vquiet_warning = (arg1 == "on"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1603 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1604 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1606 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1607 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1608 if (arg2 == "last") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1609 arg2 = Vlast_warning_id; |
5567 | 1610 |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1611 set_warning_option (arg1, arg2); |
5567 | 1612 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1613 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1614 } |
5567 | 1615 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1616 if (done && nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1617 retval = old_warning_options; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1618 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1619 else if (arg1 == "query") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1620 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1621 if (arg2 == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1622 retval = warning_options; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1623 else if (arg2 == "backtrace" || arg2 == "debug" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1624 || arg2 == "verbose" || arg2 == "quiet") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1625 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1626 octave_scalar_map tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1627 tmp.assign ("identifier", arg2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1628 if (arg2 == "backtrace") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1629 tmp.assign ("state", Vbacktrace_on_warning ? "on" : "off"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1630 else if (arg2 == "debug") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1631 tmp.assign ("state", Vdebug_on_warning ? "on" : "off"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1632 else if (arg2 == "verbose") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1633 tmp.assign ("state", Vverbose_warning ? "on" : "off"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1634 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1635 tmp.assign ("state", Vquiet_warning ? "on" : "off"); |
5582 | 1636 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1637 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1638 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1639 else |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
1640 retval = warning_query (arg2); |
5567 | 1641 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1642 done = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1643 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1644 } |
3934 | 1645 } |
5567 | 1646 else if (argc == 1) |
1647 { | |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1648 if (nargout > 0) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1649 retval = warning_options; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1650 else |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1651 display_warning_options (octave_stdout); |
3934 | 1652 |
5567 | 1653 done = true; |
1654 } | |
1655 else if (argc == 2) | |
1656 { | |
1657 octave_value arg = args(0); | |
1658 | |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1659 octave_map old_warning_options = warning_options; |
5567 | 1660 |
1661 if (arg.is_map ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1662 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1663 octave_map m = arg.map_value (); |
5567 | 1664 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1665 if (m.contains ("identifier") && m.contains ("state")) |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1666 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1667 // Simply step through the struct elements one at a time. |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1668 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1669 Cell ident = m.contents ("identifier"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1670 Cell state = m.contents ("state"); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1671 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1672 octave_idx_type nel = ident.numel (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1673 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1674 for (octave_idx_type i = 0; i < nel; i++) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1675 { |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1676 std::string tst = state(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1677 std::string tid = ident(i).string_value (); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1678 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1679 if (error_state) |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1680 return retval; |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1681 |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1682 set_warning_option (tst, tid); |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1683 } |
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1684 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1685 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1686 error ("warning: expecting structure with fields 'identifier' and 'state'"); |
5567 | 1687 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1688 done = true; |
5567 | 1689 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1690 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1691 retval = old_warning_options; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1692 } |
5567 | 1693 } |
1694 | |
1695 if (! (error_state || done)) | |
3935 | 1696 { |
5567 | 1697 octave_value_list nargs = args; |
1698 | |
1699 std::string id; | |
1700 | |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1701 bool have_fmt = maybe_extract_message_id ("warning", args, nargs, id); |
5567 | 1702 |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1703 if (error_state) |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1704 return retval; |
5567 | 1705 |
3935 | 1706 std::string prev_msg = Vlast_warning_message; |
1707 | |
5567 | 1708 std::string curr_msg = handle_message (warning_with_id, id.c_str (), |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1709 "unspecified warning", nargs, |
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
1710 have_fmt); |
3935 | 1711 |
1712 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1713 retval = prev_msg; |
3935 | 1714 } |
1715 | |
3934 | 1716 return retval; |
1717 } | |
1718 | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1719 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1720 set_warning_state (const std::string& id, const std::string& state) |
5794 | 1721 { |
1722 octave_value_list args; | |
1723 | |
1724 args(1) = id; | |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1725 args(0) = state; |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1726 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1727 return Fwarning (args, 1); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1728 } |
5794 | 1729 |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1730 octave_value_list |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1731 set_warning_state (const octave_value_list& args) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1732 { |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1733 return Fwarning (args, 1); |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1734 } |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1735 |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1736 void |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1737 disable_warning (const std::string& id) |
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10405
diff
changeset
|
1738 { |
19473
93fbdbcb3349
fix handling of options struct passed to warning function (bug #36393)
John W. Eaton <jwe@octave.org>
parents:
19455
diff
changeset
|
1739 set_warning_option ("off", id); |
5794 | 1740 } |
1741 | |
1742 void | |
1743 initialize_default_warning_state (void) | |
1744 { | |
1745 initialize_warning_options ("on"); | |
1746 | |
1747 // Most people will want to have the following disabled. | |
1748 | |
1749 disable_warning ("Octave:array-to-scalar"); | |
1750 disable_warning ("Octave:array-to-vector"); | |
1751 disable_warning ("Octave:imag-to-real"); | |
19886
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19883
diff
changeset
|
1752 disable_warning ("Octave:language-extension"); |
5794 | 1753 disable_warning ("Octave:missing-semicolon"); |
1754 disable_warning ("Octave:neg-dim-as-zero"); | |
1755 disable_warning ("Octave:resize-on-range-error"); | |
1756 disable_warning ("Octave:separator-insert"); | |
1757 disable_warning ("Octave:single-quote-string"); | |
1758 disable_warning ("Octave:str-to-num"); | |
13841
0a158dbdb04a
Remove 3 unused warning ids
Rik <octave@nomad.inbox5.com>
parents:
13709
diff
changeset
|
1759 disable_warning ("Octave:mixed-string-concat"); |
5794 | 1760 disable_warning ("Octave:variable-switch-label"); |
1761 } | |
1762 | |
6361 | 1763 DEFUN (lasterror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1764 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1765 @deftypefn {Built-in Function} {@var{lasterr} =} lasterror ()\n\ |
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1766 @deftypefnx {Built-in Function} {} lasterror (@var{err})\n\ |
14361
8de863b7126b
doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1767 @deftypefnx {Built-in Function} {} lasterror (\"reset\")\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1768 Query or set the last error message structure.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1769 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1770 When called without arguments, return a structure containing the last error\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1771 message and other information related to this error. The elements of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1772 structure are:\n\ |
6361 | 1773 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1774 @table @code\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1775 @item message\n\ |
6361 | 1776 The text of the last error message\n\ |
10840 | 1777 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1778 @item identifier\n\ |
6361 | 1779 The message identifier of this error message\n\ |
10840 | 1780 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1781 @item stack\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1782 A structure containing information on where the message occurred. This may\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1783 be an empty structure if the information cannot be obtained. The fields of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1784 the structure are:\n\ |
6361 | 1785 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1786 @table @code\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1787 @item file\n\ |
6361 | 1788 The name of the file where the error occurred\n\ |
10840 | 1789 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1790 @item name\n\ |
7001 | 1791 The name of function in which the error occurred\n\ |
10840 | 1792 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1793 @item line\n\ |
7001 | 1794 The line number at which the error occurred\n\ |
10840 | 1795 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1796 @item column\n\ |
6361 | 1797 An optional field with the column number at which the error occurred\n\ |
1798 @end table\n\ | |
1799 @end table\n\ | |
1800 \n\ | |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1801 The last error structure may be set by passing a scalar structure, @var{err},\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1802 as input. Any fields of @var{err} that match those above are set while any\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1803 unspecified fields are initialized with default values.\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1804 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1805 If @code{lasterror} is called with the argument @qcode{\"reset\"}, all\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
1806 fields are set to their default values.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1807 @seealso{lasterr, error, lastwarn}\n\ |
6361 | 1808 @end deftypefn") |
1809 { | |
1810 octave_value retval; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1811 int nargin = args.length (); |
6361 | 1812 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1813 unwind_protect frame; |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1814 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1815 frame.protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1816 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1817 |
6361 | 1818 if (nargin < 2) |
1819 { | |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1820 octave_scalar_map err; |
6361 | 1821 |
1822 err.assign ("message", Vlast_error_message); | |
1823 err.assign ("identifier", Vlast_error_id); | |
1824 | |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1825 err.assign ("stack", octave_value (Vlast_error_stack)); |
6361 | 1826 |
1827 if (nargin == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1828 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1829 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1830 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1831 if (args(0).string_value () == "reset") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1832 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1833 Vlast_error_message = std::string (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14559
diff
changeset
|
1834 Vlast_error_id = std::string (); |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1835 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1836 Vlast_error_stack = initialize_last_error_stack (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1837 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1838 else |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1839 error ("lasterror: unrecognized string argument"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1840 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1841 else if (args(0).is_map ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1842 { |
11058
3329616444f0
replace Octave_map in debug.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
11029
diff
changeset
|
1843 octave_scalar_map new_err = args(0).scalar_map_value (); |
16492
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1844 octave_scalar_map new_err_stack; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1845 std::string new_error_message; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1846 std::string new_error_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1847 std::string new_error_file; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1848 std::string new_error_name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1849 int new_error_line = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1850 int new_error_column = -1; |
6361 | 1851 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1852 if (! error_state && new_err.contains ("message")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1853 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1854 const std::string tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1855 new_err.getfield ("message").string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1856 new_error_message = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1857 } |
6361 | 1858 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1859 if (! error_state && new_err.contains ("identifier")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1861 const std::string tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1862 new_err.getfield ("identifier").string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1863 new_error_id = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1864 } |
6361 | 1865 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1866 if (! error_state && new_err.contains ("stack")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1868 new_err_stack = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1869 new_err.getfield ("stack").scalar_map_value (); |
6361 | 1870 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1871 if (! error_state && new_err_stack.contains ("file")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1872 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1873 const std::string tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1874 new_err_stack.getfield ("file").string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1875 new_error_file = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1876 } |
6361 | 1877 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1878 if (! error_state && new_err_stack.contains ("name")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1879 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1880 const std::string tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1881 new_err_stack.getfield ("name").string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1882 new_error_name = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1883 } |
6361 | 1884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1885 if (! error_state && new_err_stack.contains ("line")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1886 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1887 const int tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1888 new_err_stack.getfield ("line").nint_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1889 new_error_line = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1890 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1892 if (! error_state && new_err_stack.contains ("column")) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1893 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1894 const int tmp = |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1895 new_err_stack.getfield ("column").nint_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1896 new_error_column = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1897 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1898 } |
6361 | 1899 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1900 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1901 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1902 Vlast_error_message = new_error_message; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1903 Vlast_error_id = new_error_id; |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1904 |
16492
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1905 if (new_err.contains ("stack")) |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1906 { |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1907 new_err_stack.setfield ("file", new_error_file); |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1908 new_err_stack.setfield ("name", new_error_name); |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1909 new_err_stack.setfield ("line", new_error_line); |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1910 new_err_stack.setfield ("column", new_error_column); |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1911 Vlast_error_stack = new_err_stack; |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1912 } |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1913 else |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1914 { |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1915 // No stack field. Fill it in with backtrace info. |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1916 octave_idx_type curr_frame = -1; |
9166
69088b7b139c
use complete stack trace information for lasterror
John W. Eaton <jwe@octave.org>
parents:
9153
diff
changeset
|
1917 |
16492
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1918 Vlast_error_stack |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1919 = octave_call_stack::backtrace (0, curr_frame); |
91c32a702284
Correctly fill stack field in lasterror() when given as input.
Rik <rik@octave.org>
parents:
16442
diff
changeset
|
1920 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1921 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1922 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1923 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1924 error ("lasterror: argument must be a structure or a string"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1925 } |
6361 | 1926 |
6483 | 1927 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1928 retval = err; |
6361 | 1929 } |
1930 else | |
1931 print_usage (); | |
1932 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1933 return retval; |
6361 | 1934 } |
1935 | |
5567 | 1936 DEFUN (lasterr, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1937 "-*- texinfo -*-\n\ |
12692
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1938 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lasterr ()\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1939 @deftypefnx {Built-in Function} {} lasterr (@var{msg})\n\ |
e7b03b8662a2
doc: Update docstrings for a few functions
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1940 @deftypefnx {Built-in Function} {} lasterr (@var{msg}, @var{msgid})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1941 Query or set the last error message.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1942 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1943 When called without input arguments, return the last error message and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1944 message identifier.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1945 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1946 With one argument, set the last error message to @var{msg}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1947 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1948 With two arguments, also set the last message identifier.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1949 @seealso{lasterror, error, lastwarn}\n\ |
3935 | 1950 @end deftypefn") |
1951 { | |
1952 octave_value_list retval; | |
1953 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1954 unwind_protect frame; |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1955 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9753
diff
changeset
|
1956 frame.protect_var (error_state); |
7976
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1957 error_state = 0; |
736124a4fa3d
lasterr, lasterror: unwind-protect error_state
John W. Eaton <jwe@octave.org>
parents:
7882
diff
changeset
|
1958 |
3935 | 1959 int argc = args.length () + 1; |
1960 | |
5567 | 1961 if (argc < 4) |
5335 | 1962 { |
1963 string_vector argv = args.make_argv ("lasterr"); | |
3935 | 1964 |
5335 | 1965 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1966 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1967 std::string prev_error_id = Vlast_error_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1968 std::string prev_error_message = Vlast_error_message; |
5567 | 1969 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1970 if (argc > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1971 Vlast_error_id = argv(2); |
5567 | 1972 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1973 if (argc > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1974 Vlast_error_message = argv(1); |
5567 | 1975 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1976 if (argc == 1 || nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1977 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1978 retval(1) = prev_error_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1979 retval(0) = prev_error_message; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1980 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1981 } |
5567 | 1982 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19380
diff
changeset
|
1983 error ("lasterr: all arguments must be strings"); |
5335 | 1984 } |
3935 | 1985 else |
5823 | 1986 print_usage (); |
3935 | 1987 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1988 return retval; |
3935 | 1989 } |
1990 | |
5567 | 1991 DEFUN (lastwarn, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1992 "-*- texinfo -*-\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1993 @deftypefn {Built-in Function} {[@var{msg}, @var{msgid}] =} lastwarn ()\n\ |
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1994 @deftypefnx {Built-in Function} {} lastwarn (@var{msg})\n\ |
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
1995 @deftypefnx {Built-in Function} {} lastwarn (@var{msg}, @var{msgid})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1996 Query or set the last warning message.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1997 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1998 When called without input arguments, return the last warning message and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
1999 message identifier.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2000 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2001 With one argument, set the last warning message to @var{msg}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2002 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2003 With two arguments, also set the last message identifier.\n\ |
15173
8593bed236f1
doc: Document escape character processing within single quotes for regexp, warning, error.
Rik <rik@octave.org>
parents:
15088
diff
changeset
|
2004 @seealso{warning, lasterror, lasterr}\n\ |
3934 | 2005 @end deftypefn") |
2006 { | |
2007 octave_value_list retval; | |
2008 | |
2009 int argc = args.length () + 1; | |
2010 | |
5567 | 2011 if (argc < 4) |
2012 { | |
2013 string_vector argv = args.make_argv ("lastwarn"); | |
2014 | |
2015 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2016 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2017 std::string prev_warning_id = Vlast_warning_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2018 std::string prev_warning_message = Vlast_warning_message; |
5567 | 2019 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2020 if (argc > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2021 Vlast_warning_id = argv(2); |
3934 | 2022 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2023 if (argc > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2024 Vlast_warning_message = argv(1); |
5567 | 2025 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2026 if (argc == 1 || nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2027 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2028 warning_state = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2029 retval(1) = prev_warning_id; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2030 retval(0) = prev_warning_message; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2031 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2032 } |
5567 | 2033 else |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19380
diff
changeset
|
2034 error ("lastwarn: all arguments must be strings"); |
5567 | 2035 } |
3934 | 2036 else |
5823 | 2037 print_usage (); |
3934 | 2038 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2039 return retval; |
897 | 2040 } |
2041 | |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2042 /* FIXME: Deprecated in 4.0 and scheduled for removal in 4.4 */ |
19145 | 2043 DEFUN (__usage__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2044 "-*- texinfo -*-\n\ |
3373 | 2045 @deftypefn {Built-in Function} {} usage (@var{msg})\n\ |
2046 Print the message @var{msg}, prefixed by the string @samp{usage: }, and\n\ | |
2047 set Octave's internal error state such that control will return to the\n\ | |
2048 top level without evaluating any more commands. This is useful for\n\ | |
2049 aborting from functions.\n\ | |
2050 \n\ | |
2051 After @code{usage} is evaluated, Octave will print a traceback of all\n\ | |
2052 the function calls leading to the usage message.\n\ | |
899 | 2053 \n\ |
3373 | 2054 You should use this function for reporting problems errors that result\n\ |
2055 from an improper call to a function, such as calling a function with an\n\ | |
2056 incorrect number of arguments, or with arguments of the wrong type. For\n\ | |
2057 example, most functions distributed with Octave begin with code like\n\ | |
2058 this\n\ | |
2059 \n\ | |
2060 @example\n\ | |
2061 @group\n\ | |
2062 if (nargin != 2)\n\ | |
2063 usage (\"foo (a, b)\");\n\ | |
2064 endif\n\ | |
2065 @end group\n\ | |
2066 @end example\n\ | |
2067 \n\ | |
2068 @noindent\n\ | |
2069 to check for the proper number of arguments.\n\ | |
2070 @end deftypefn") | |
899 | 2071 { |
3934 | 2072 octave_value_list retval; |
14558
0c9c85e702ca
better compatibility for error/warning message IDs and format specifiers
John W. Eaton <jwe@octave.org>
parents:
14361
diff
changeset
|
2073 handle_message (usage_with_id, "", "unknown", args, true); |
3934 | 2074 return retval; |
899 | 2075 } |
2076 | |
5794 | 2077 DEFUN (beep_on_error, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2078 "-*- texinfo -*-\n\ |
10840 | 2079 @deftypefn {Built-in Function} {@var{val} =} beep_on_error ()\n\ |
5794 | 2080 @deftypefnx {Built-in Function} {@var{old_val} =} beep_on_error (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2081 @deftypefnx {Built-in Function} {} beep_on_error (@var{new_val}, \"local\")\n\ |
5794 | 2082 Query or set the internal variable that controls whether Octave will try\n\ |
2083 to ring the terminal bell before printing an error message.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2084 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2085 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2086 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2087 The original variable value is restored when exiting the function.\n\ |
5794 | 2088 @end deftypefn") |
3707 | 2089 { |
5794 | 2090 return SET_INTERNAL_VARIABLE (beep_on_error); |
3707 | 2091 } |
2092 | |
5794 | 2093 DEFUN (debug_on_error, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2094 "-*- texinfo -*-\n\ |
10840 | 2095 @deftypefn {Built-in Function} {@var{val} =} debug_on_error ()\n\ |
5794 | 2096 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_error (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2097 @deftypefnx {Built-in Function} {} debug_on_error (@var{new_val}, \"local\")\n\ |
5794 | 2098 Query or set the internal variable that controls whether Octave will try\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2099 to enter the debugger when an error is encountered.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2100 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2101 This will also inhibit printing of the normal traceback message (you will\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2102 only see the top-level error message).\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2103 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2104 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2105 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2106 The original variable value is restored when exiting the function.\n\ |
15573
63d024333bee
doc: Add seealso links between debug_on_XXX functions (bug #37576)
Rik <rik@octave.org>
parents:
15524
diff
changeset
|
2107 @seealso{debug_on_warning, debug_on_interrupt}\n\ |
5794 | 2108 @end deftypefn") |
2109 { | |
2110 return SET_INTERNAL_VARIABLE (debug_on_error); | |
2111 } | |
3707 | 2112 |
5794 | 2113 DEFUN (debug_on_warning, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2114 "-*- texinfo -*-\n\ |
10840 | 2115 @deftypefn {Built-in Function} {@var{val} =} debug_on_warning ()\n\ |
5794 | 2116 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_warning (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2117 @deftypefnx {Built-in Function} {} debug_on_warning (@var{new_val}, \"local\")\n\ |
5794 | 2118 Query or set the internal variable that controls whether Octave will try\n\ |
2119 to enter the debugger when a warning is encountered.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13841
diff
changeset
|
2120 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2121 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20175
diff
changeset
|
2122 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
2123 The original variable value is restored when exiting the function.\n\ |
15573
63d024333bee
doc: Add seealso links between debug_on_XXX functions (bug #37576)
Rik <rik@octave.org>
parents:
15524
diff
changeset
|
2124 @seealso{debug_on_error, debug_on_interrupt}\n\ |
5794 | 2125 @end deftypefn") |
2126 { | |
2127 return SET_INTERNAL_VARIABLE (debug_on_warning); | |
2174 | 2128 } |
2129 | |
7977
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2130 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2131 last_error_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2132 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2133 return Vlast_error_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2134 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2135 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2136 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2137 last_error_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2138 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2139 return Vlast_error_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2140 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2141 |
18221
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2142 octave_map |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2143 last_error_stack (void) |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2144 { |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2145 return Vlast_error_stack; |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2146 } |
6ef8b920a7d6
include stack in exception variable (bug #41117)
Stefan Mahr <dac922@gmx.de>
parents:
18129
diff
changeset
|
2147 |
7977
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2148 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2149 last_warning_message (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2150 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2151 return Vlast_warning_message; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2152 } |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2153 |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2154 std::string |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2155 last_warning_id (void) |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2156 { |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2157 return Vlast_warning_id; |
065c28e1c368
Modify Fcellfun to directly access the error message/id rather than use a call to Flasterr
David Bateman <dbateman@free.fr>
parents:
7976
diff
changeset
|
2158 } |
11029
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2159 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2160 void |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2161 interpreter_try (unwind_protect& frame) |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2162 { |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2163 frame.protect_var (error_state); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2164 frame.protect_var (buffer_error_messages); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2165 frame.protect_var (Vdebug_on_error); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2166 frame.protect_var (Vdebug_on_warning); |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2167 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2168 buffer_error_messages++; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2169 Vdebug_on_error = false; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2170 Vdebug_on_warning = false; |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2171 } |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2172 |
4ab04ea74b08
make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
2173 |