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