# HG changeset patch # User John W. Eaton # Date 1259045924 -3600 # Node ID 38f3c198ba630c26880db38bc978703e5fdbd426 # Parent b8fa8cba212f8afd565411f6273a34e284bec096 error: improve compatibility for calls with no arguments or empty format diff -r b8fa8cba212f -r 38f3c198ba63 src/ChangeLog --- a/src/ChangeLog Fri Nov 20 10:49:17 2009 +0100 +++ b/src/ChangeLog Tue Nov 24 07:58:44 2009 +0100 @@ -1,3 +1,9 @@ +2009-09-30 John W. Eaton + + * error.cc (error_1, pr_where_2, handle_message): + Don't do anything if fmt is empty. + (Ferror): Call print_usage if nargin == 0. + 2009-09-18 Jaroslav Hajek Version 3.2.3 released. diff -r b8fa8cba212f -r 38f3c198ba63 src/error.cc --- a/src/error.cc Fri Nov 20 10:49:17 2009 +0100 +++ b/src/error.cc Tue Nov 24 07:58:44 2009 +0100 @@ -283,28 +283,34 @@ { if (*fmt) { - int len = strlen (fmt); - if (fmt[len - 1] == '\n') + size_t len = strlen (fmt); + + if (len > 0) { - if (len > 1) + if (fmt[len - 1] == '\n') { - char *tmp_fmt = strsave (fmt); - tmp_fmt[len - 1] = '\0'; - verror (true, os, name, id, tmp_fmt, args); - delete [] tmp_fmt; + if (len > 1) + { + char *tmp_fmt = strsave (fmt); + tmp_fmt[len - 1] = '\0'; + verror (true, os, name, id, tmp_fmt, args); + delete [] tmp_fmt; + } + + error_state = -2; } + else + { + verror (true, os, name, id, fmt, args); - error_state = -2; + if (! error_state) + error_state = 1; + } } - else - verror (true, os, name, id, fmt, args); } } else panic ("error_1: invalid format"); - - if (! error_state) - error_state = 1; } } @@ -383,19 +389,23 @@ { if (*fmt) { - int len = strlen (fmt); - if (fmt[len - 1] == '\n') + size_t len = strlen (fmt); + + if (len > 0) { - if (len > 1) + if (fmt[len - 1] == '\n') { - char *tmp_fmt = strsave (fmt); - tmp_fmt[len - 1] = '\0'; - verror (false, std::cerr, 0, "", tmp_fmt, args); - delete [] tmp_fmt; + if (len > 1) + { + char *tmp_fmt = strsave (fmt); + tmp_fmt[len - 1] = '\0'; + verror (false, std::cerr, 0, "", tmp_fmt, args); + delete [] tmp_fmt; + } } + else + verror (false, std::cerr, 0, "", fmt, args); } - else - verror (false, std::cerr, 0, "", fmt, args); } } else @@ -763,22 +773,26 @@ // Ugh. - int len = strlen (msg); - if (msg[len - 1] == '\n') + size_t len = strlen (msg); + + if (len > 0) { - if (len > 1) + if (msg[len - 1] == '\n') { - char *tmp_msg = strsave (msg); - tmp_msg[len - 1] = '\0'; - f (id, "%s\n", tmp_msg); - retval = tmp_msg; - delete [] tmp_msg; + if (len > 1) + { + char *tmp_msg = strsave (msg); + tmp_msg[len - 1] = '\0'; + f (id, "%s\n", tmp_msg); + retval = tmp_msg; + delete [] tmp_msg; + } } - } - else - { - f (id, "%s", msg); - retval = msg; + else + { + f (id, "%s", msg); + retval = msg; + } } return retval; @@ -985,56 +999,61 @@ std::string id; - if (nargin > 1) + if (nargin == 0) + print_usage (); + else { - std::string arg1 = args(0).string_value (); + if (nargin > 1) + { + std::string arg1 = args(0).string_value (); + + if (! error_state) + { + if (arg1.find ('%') == std::string::npos) + { + id = arg1; - if (! error_state) + nargs.resize (nargin-1); + + for (int i = 1; i < nargin; i++) + nargs(i-1) = args(i); + } + } + else + return retval; + } + else if (nargin == 1 && args(0).is_map ()) { - if (arg1.find ('%') == std::string::npos) + octave_value_list tmp; + + Octave_map m = args(0).map_value (); + + if (m.numel () == 1) { - id = arg1; + if (m.contains ("message")) + { + Cell c = m.contents ("message"); - nargs.resize (nargin-1); + if (! c.is_empty () && c(0).is_string ()) + nargs(0) = c(0).string_value (); + } + + if (m.contains ("identifier")) + { + Cell c = m.contents ("identifier"); - for (int i = 1; i < nargin; i++) - nargs(i-1) = args(i); + if (! c.is_empty () && c(0).is_string ()) + id = c(0).string_value (); + } + + // FIXME -- also need to handle "stack" field in error + // structure, but that will require some more significant + // surgery on handle_message, error_with_id, etc. } } - else - return retval; + + handle_message (error_with_id, id.c_str (), "unspecified error", nargs); } - else if (nargin == 1 && args(0).is_map ()) - { - octave_value_list tmp; - - Octave_map m = args(0).map_value (); - - if (m.numel () == 1) - { - if (m.contains ("message")) - { - Cell c = m.contents ("message"); - - if (! c.is_empty () && c(0).is_string ()) - nargs(0) = c(0).string_value (); - } - - if (m.contains ("identifier")) - { - Cell c = m.contents ("identifier"); - - if (! c.is_empty () && c(0).is_string ()) - id = c(0).string_value (); - } - - // FIXME -- also need to handle "stack" field in error - // structure, but that will require some more significant - // surgery on handle_message, error_with_id, etc. - } - } - - handle_message (error_with_id, id.c_str (), "unspecified error", nargs); return retval; }