# HG changeset patch # User Rik # Date 1454995797 28800 # Node ID 2e64b5899d1f4be195b1081da6aefbfb84bd4e44 # Parent f6aab24ed82e5603df6e369ecb151db5d345caeb maint: invert if/else/error pattern in variables.cc variables.cc: invert if/else/error pattern. diff -r f6aab24ed82e -r 2e64b5899d1f libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Mon Feb 08 20:36:40 2016 -0800 +++ b/libinterp/corefcn/variables.cc Mon Feb 08 21:29:57 2016 -0800 @@ -110,6 +110,7 @@ ans = val.function_value (true); } + // FIXME: Should this be "err" and "error_for", rather than warn? if (! ans && warn) error ("%s: the symbol '%s' is not valid as a function", warn_for.c_str (), fcn_name.c_str ()); @@ -132,6 +133,7 @@ ans = is_valid_function (fcn_name, warn_for, warn); } else if (warn) + // FIXME: Should this be "err" and "error_for", rather than warn? error ("%s: argument must be a string containing function name", warn_for.c_str ()); return ans; @@ -159,20 +161,18 @@ eval_string (cmd, true, parse_status, 0); - if (parse_status == 0) - { - retval = is_valid_function (fname, warn_for, 0); - - if (! retval) - error ("%s: '%s' is not valid as a function", - warn_for.c_str (), fname.c_str ()); - - warning ("%s: passing function body as a string is obsolete; please use anonymous functions", - warn_for.c_str ()); - } - else + if (parse_status != 0) error ("%s: '%s' is not valid as a function", warn_for.c_str (), fname.c_str ()); + + retval = is_valid_function (fname, warn_for, 0); + + if (! retval) + error ("%s: '%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + + warning ("%s: passing function body as a string is obsolete; please use anonymous functions", + warn_for.c_str ()); } return retval; @@ -722,13 +722,11 @@ if (nargin == 2) { - if (args(1).is_string () && args(1).string_value () == "local") - { - nargin = 1; - retval = true; - } - else + if (! args(1).is_string () || args(1).string_value () != "local") error_with_cfn ("second argument must be \"local\""); + + nargin = 1; + retval = true; } return retval; @@ -848,10 +846,10 @@ if (ival < minval) error ("%s: arg must be greater than %d", nm, minval); - else if (ival > maxval) + if (ival > maxval) error ("%s: arg must be less than or equal to %d", nm, maxval); - else - var = ival; + + var = ival; } return retval; @@ -884,10 +882,10 @@ if (dval < minval) error ("%s: argument must be greater than %g", minval); - else if (dval > maxval) + if (dval > maxval) error ("%s: argument must be less than or equal to %g", maxval); - else - var = dval; + + var = dval; } return retval; @@ -917,10 +915,10 @@ { std::string sval = args(0).xstring_value ("%s: first argument must be a string", nm); - if (empty_ok || ! sval.empty ()) - var = sval; - else + if (! empty_ok && sval.empty ()) error ("%s: value must not be empty", nm); + + var = sval; } return retval; @@ -1465,11 +1463,11 @@ // Parse one command from whos_line_format cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); pos = cmd.find (';'); - if (pos != std::string::npos) - cmd = cmd.substr (0, pos+1); - else + if (pos == std::string::npos) error ("parameter without ; in whos_line_format"); + cmd = cmd.substr (0, pos+1); + idx += cmd.length (); // FIXME: use iostream functions instead of sscanf! @@ -1488,20 +1486,17 @@ // Insert data into parameter param.first_parameter_length = 0; pos = param_string.find (param.command); - if (pos != std::string::npos) - { - param.parameter_length = param_length(pos); - param.text = param_names(pos); - param.line.assign (param_names(pos).length (), '='); - - param.parameter_length = (a > param.parameter_length - ? a : param.parameter_length); - if (param.command == 's' && param.modifier == 'c' && b > 0) - param.first_parameter_length = b; - } - else - error ("whos_line_format: '%c' is not a command", - param.command); + if (pos == std::string::npos) + error ("whos_line_format: '%c' is not a command", param.command); + + param.parameter_length = param_length(pos); + param.text = param_names(pos); + param.line.assign (param_names(pos).length (), '='); + + param.parameter_length = (a > param.parameter_length + ? a : param.parameter_length); + if (param.command == 's' && param.modifier == 'c' && b > 0) + param.first_parameter_length = b; if (param.command == 's') { @@ -1939,10 +1934,10 @@ { octave_function *fcn = octave_call_stack::current (); - if (fcn) - fcn->lock (); - else + if (! fcn) error ("mlock: invalid use outside a function"); + + fcn->lock (); } void