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