Mercurial > octave-nkf
comparison src/error.cc @ 12100:38f3c198ba63 release-3-2-x
error: improve compatibility for calls with no arguments or empty format
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 24 Nov 2009 07:58:44 +0100 |
parents | ba7f45642ffe |
children |
comparison
equal
deleted
inserted
replaced
12099:b8fa8cba212f | 12100:38f3c198ba63 |
---|---|
281 { | 281 { |
282 if (fmt) | 282 if (fmt) |
283 { | 283 { |
284 if (*fmt) | 284 if (*fmt) |
285 { | 285 { |
286 int len = strlen (fmt); | 286 size_t len = strlen (fmt); |
287 if (fmt[len - 1] == '\n') | 287 |
288 { | 288 if (len > 0) |
289 if (len > 1) | 289 { |
290 { | 290 if (fmt[len - 1] == '\n') |
291 char *tmp_fmt = strsave (fmt); | 291 { |
292 tmp_fmt[len - 1] = '\0'; | 292 if (len > 1) |
293 verror (true, os, name, id, tmp_fmt, args); | 293 { |
294 delete [] tmp_fmt; | 294 char *tmp_fmt = strsave (fmt); |
295 } | 295 tmp_fmt[len - 1] = '\0'; |
296 | 296 verror (true, os, name, id, tmp_fmt, args); |
297 error_state = -2; | 297 delete [] tmp_fmt; |
298 } | 298 } |
299 else | 299 |
300 verror (true, os, name, id, fmt, args); | 300 error_state = -2; |
301 } | |
302 else | |
303 { | |
304 verror (true, os, name, id, fmt, args); | |
305 | |
306 if (! error_state) | |
307 error_state = 1; | |
308 } | |
309 } | |
301 } | 310 } |
302 } | 311 } |
303 else | 312 else |
304 panic ("error_1: invalid format"); | 313 panic ("error_1: invalid format"); |
305 | |
306 if (! error_state) | |
307 error_state = 1; | |
308 } | 314 } |
309 } | 315 } |
310 | 316 |
311 void | 317 void |
312 vmessage (const char *name, const char *fmt, va_list args) | 318 vmessage (const char *name, const char *fmt, va_list args) |
381 { | 387 { |
382 if (fmt) | 388 if (fmt) |
383 { | 389 { |
384 if (*fmt) | 390 if (*fmt) |
385 { | 391 { |
386 int len = strlen (fmt); | 392 size_t len = strlen (fmt); |
387 if (fmt[len - 1] == '\n') | 393 |
394 if (len > 0) | |
388 { | 395 { |
389 if (len > 1) | 396 if (fmt[len - 1] == '\n') |
390 { | 397 { |
391 char *tmp_fmt = strsave (fmt); | 398 if (len > 1) |
392 tmp_fmt[len - 1] = '\0'; | 399 { |
393 verror (false, std::cerr, 0, "", tmp_fmt, args); | 400 char *tmp_fmt = strsave (fmt); |
394 delete [] tmp_fmt; | 401 tmp_fmt[len - 1] = '\0'; |
395 } | 402 verror (false, std::cerr, 0, "", tmp_fmt, args); |
403 delete [] tmp_fmt; | |
404 } | |
405 } | |
406 else | |
407 verror (false, std::cerr, 0, "", fmt, args); | |
396 } | 408 } |
397 else | |
398 verror (false, std::cerr, 0, "", fmt, args); | |
399 } | 409 } |
400 } | 410 } |
401 else | 411 else |
402 panic ("pr_where_2: invalid format"); | 412 panic ("pr_where_2: invalid format"); |
403 } | 413 } |
761 } | 771 } |
762 } | 772 } |
763 | 773 |
764 // Ugh. | 774 // Ugh. |
765 | 775 |
766 int len = strlen (msg); | 776 size_t len = strlen (msg); |
767 if (msg[len - 1] == '\n') | 777 |
768 { | 778 if (len > 0) |
769 if (len > 1) | 779 { |
770 { | 780 if (msg[len - 1] == '\n') |
771 char *tmp_msg = strsave (msg); | 781 { |
772 tmp_msg[len - 1] = '\0'; | 782 if (len > 1) |
773 f (id, "%s\n", tmp_msg); | 783 { |
774 retval = tmp_msg; | 784 char *tmp_msg = strsave (msg); |
775 delete [] tmp_msg; | 785 tmp_msg[len - 1] = '\0'; |
776 } | 786 f (id, "%s\n", tmp_msg); |
777 } | 787 retval = tmp_msg; |
778 else | 788 delete [] tmp_msg; |
779 { | 789 } |
780 f (id, "%s", msg); | 790 } |
781 retval = msg; | 791 else |
792 { | |
793 f (id, "%s", msg); | |
794 retval = msg; | |
795 } | |
782 } | 796 } |
783 | 797 |
784 return retval; | 798 return retval; |
785 } | 799 } |
786 | 800 |
983 | 997 |
984 octave_value_list nargs = args; | 998 octave_value_list nargs = args; |
985 | 999 |
986 std::string id; | 1000 std::string id; |
987 | 1001 |
988 if (nargin > 1) | 1002 if (nargin == 0) |
989 { | 1003 print_usage (); |
990 std::string arg1 = args(0).string_value (); | 1004 else |
991 | 1005 { |
992 if (! error_state) | 1006 if (nargin > 1) |
993 { | 1007 { |
994 if (arg1.find ('%') == std::string::npos) | 1008 std::string arg1 = args(0).string_value (); |
1009 | |
1010 if (! error_state) | |
995 { | 1011 { |
996 id = arg1; | 1012 if (arg1.find ('%') == std::string::npos) |
997 | 1013 { |
998 nargs.resize (nargin-1); | 1014 id = arg1; |
999 | 1015 |
1000 for (int i = 1; i < nargin; i++) | 1016 nargs.resize (nargin-1); |
1001 nargs(i-1) = args(i); | 1017 |
1018 for (int i = 1; i < nargin; i++) | |
1019 nargs(i-1) = args(i); | |
1020 } | |
1002 } | 1021 } |
1003 } | 1022 else |
1004 else | 1023 return retval; |
1005 return retval; | 1024 } |
1006 } | 1025 else if (nargin == 1 && args(0).is_map ()) |
1007 else if (nargin == 1 && args(0).is_map ()) | 1026 { |
1008 { | 1027 octave_value_list tmp; |
1009 octave_value_list tmp; | 1028 |
1010 | 1029 Octave_map m = args(0).map_value (); |
1011 Octave_map m = args(0).map_value (); | 1030 |
1012 | 1031 if (m.numel () == 1) |
1013 if (m.numel () == 1) | |
1014 { | |
1015 if (m.contains ("message")) | |
1016 { | 1032 { |
1017 Cell c = m.contents ("message"); | 1033 if (m.contains ("message")) |
1018 | 1034 { |
1019 if (! c.is_empty () && c(0).is_string ()) | 1035 Cell c = m.contents ("message"); |
1020 nargs(0) = c(0).string_value (); | 1036 |
1037 if (! c.is_empty () && c(0).is_string ()) | |
1038 nargs(0) = c(0).string_value (); | |
1039 } | |
1040 | |
1041 if (m.contains ("identifier")) | |
1042 { | |
1043 Cell c = m.contents ("identifier"); | |
1044 | |
1045 if (! c.is_empty () && c(0).is_string ()) | |
1046 id = c(0).string_value (); | |
1047 } | |
1048 | |
1049 // FIXME -- also need to handle "stack" field in error | |
1050 // structure, but that will require some more significant | |
1051 // surgery on handle_message, error_with_id, etc. | |
1021 } | 1052 } |
1022 | 1053 } |
1023 if (m.contains ("identifier")) | 1054 |
1024 { | 1055 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); |
1025 Cell c = m.contents ("identifier"); | 1056 } |
1026 | |
1027 if (! c.is_empty () && c(0).is_string ()) | |
1028 id = c(0).string_value (); | |
1029 } | |
1030 | |
1031 // FIXME -- also need to handle "stack" field in error | |
1032 // structure, but that will require some more significant | |
1033 // surgery on handle_message, error_with_id, etc. | |
1034 } | |
1035 } | |
1036 | |
1037 handle_message (error_with_id, id.c_str (), "unspecified error", nargs); | |
1038 | 1057 |
1039 return retval; | 1058 return retval; |
1040 } | 1059 } |
1041 | 1060 |
1042 DEFUN (warning, args, nargout, | 1061 DEFUN (warning, args, nargout, |