Mercurial > octave
comparison libinterp/corefcn/variables.cc @ 21224:2e64b5899d1f
maint: invert if/else/error pattern in variables.cc
variables.cc: invert if/else/error pattern.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 08 Feb 2016 21:29:57 -0800 |
parents | fcac5dbbf9ed |
children | 987c1a79d33f |
comparison
equal
deleted
inserted
replaced
21223:f6aab24ed82e | 21224:2e64b5899d1f |
---|---|
108 | 108 |
109 if (val.is_defined ()) | 109 if (val.is_defined ()) |
110 ans = val.function_value (true); | 110 ans = val.function_value (true); |
111 } | 111 } |
112 | 112 |
113 // FIXME: Should this be "err" and "error_for", rather than warn? | |
113 if (! ans && warn) | 114 if (! ans && warn) |
114 error ("%s: the symbol '%s' is not valid as a function", | 115 error ("%s: the symbol '%s' is not valid as a function", |
115 warn_for.c_str (), fcn_name.c_str ()); | 116 warn_for.c_str (), fcn_name.c_str ()); |
116 | 117 |
117 return ans; | 118 return ans; |
130 fcn_name = arg.string_value (); | 131 fcn_name = arg.string_value (); |
131 | 132 |
132 ans = is_valid_function (fcn_name, warn_for, warn); | 133 ans = is_valid_function (fcn_name, warn_for, warn); |
133 } | 134 } |
134 else if (warn) | 135 else if (warn) |
136 // FIXME: Should this be "err" and "error_for", rather than warn? | |
135 error ("%s: argument must be a string containing function name", warn_for.c_str ()); | 137 error ("%s: argument must be a string containing function name", warn_for.c_str ()); |
136 | 138 |
137 return ans; | 139 return ans; |
138 } | 140 } |
139 | 141 |
157 | 159 |
158 int parse_status; | 160 int parse_status; |
159 | 161 |
160 eval_string (cmd, true, parse_status, 0); | 162 eval_string (cmd, true, parse_status, 0); |
161 | 163 |
162 if (parse_status == 0) | 164 if (parse_status != 0) |
163 { | |
164 retval = is_valid_function (fname, warn_for, 0); | |
165 | |
166 if (! retval) | |
167 error ("%s: '%s' is not valid as a function", | |
168 warn_for.c_str (), fname.c_str ()); | |
169 | |
170 warning ("%s: passing function body as a string is obsolete; please use anonymous functions", | |
171 warn_for.c_str ()); | |
172 } | |
173 else | |
174 error ("%s: '%s' is not valid as a function", | 165 error ("%s: '%s' is not valid as a function", |
175 warn_for.c_str (), fname.c_str ()); | 166 warn_for.c_str (), fname.c_str ()); |
167 | |
168 retval = is_valid_function (fname, warn_for, 0); | |
169 | |
170 if (! retval) | |
171 error ("%s: '%s' is not valid as a function", | |
172 warn_for.c_str (), fname.c_str ()); | |
173 | |
174 warning ("%s: passing function body as a string is obsolete; please use anonymous functions", | |
175 warn_for.c_str ()); | |
176 } | 176 } |
177 | 177 |
178 return retval; | 178 return retval; |
179 } | 179 } |
180 | 180 |
720 { | 720 { |
721 bool retval = false; | 721 bool retval = false; |
722 | 722 |
723 if (nargin == 2) | 723 if (nargin == 2) |
724 { | 724 { |
725 if (args(1).is_string () && args(1).string_value () == "local") | 725 if (! args(1).is_string () || args(1).string_value () != "local") |
726 { | |
727 nargin = 1; | |
728 retval = true; | |
729 } | |
730 else | |
731 error_with_cfn ("second argument must be \"local\""); | 726 error_with_cfn ("second argument must be \"local\""); |
727 | |
728 nargin = 1; | |
729 retval = true; | |
732 } | 730 } |
733 | 731 |
734 return retval; | 732 return retval; |
735 } | 733 } |
736 | 734 |
846 { | 844 { |
847 int ival = args(0).xint_value ("%s: argument must be an integer value", nm); | 845 int ival = args(0).xint_value ("%s: argument must be an integer value", nm); |
848 | 846 |
849 if (ival < minval) | 847 if (ival < minval) |
850 error ("%s: arg must be greater than %d", nm, minval); | 848 error ("%s: arg must be greater than %d", nm, minval); |
851 else if (ival > maxval) | 849 if (ival > maxval) |
852 error ("%s: arg must be less than or equal to %d", nm, maxval); | 850 error ("%s: arg must be less than or equal to %d", nm, maxval); |
853 else | 851 |
854 var = ival; | 852 var = ival; |
855 } | 853 } |
856 | 854 |
857 return retval; | 855 return retval; |
858 } | 856 } |
859 | 857 |
882 { | 880 { |
883 double dval = args(0).xscalar_value ("%s: argument must be a scalar value", nm); | 881 double dval = args(0).xscalar_value ("%s: argument must be a scalar value", nm); |
884 | 882 |
885 if (dval < minval) | 883 if (dval < minval) |
886 error ("%s: argument must be greater than %g", minval); | 884 error ("%s: argument must be greater than %g", minval); |
887 else if (dval > maxval) | 885 if (dval > maxval) |
888 error ("%s: argument must be less than or equal to %g", maxval); | 886 error ("%s: argument must be less than or equal to %g", maxval); |
889 else | 887 |
890 var = dval; | 888 var = dval; |
891 } | 889 } |
892 | 890 |
893 return retval; | 891 return retval; |
894 } | 892 } |
895 | 893 |
915 | 913 |
916 if (nargin == 1) | 914 if (nargin == 1) |
917 { | 915 { |
918 std::string sval = args(0).xstring_value ("%s: first argument must be a string", nm); | 916 std::string sval = args(0).xstring_value ("%s: first argument must be a string", nm); |
919 | 917 |
920 if (empty_ok || ! sval.empty ()) | 918 if (! empty_ok && sval.empty ()) |
921 var = sval; | |
922 else | |
923 error ("%s: value must not be empty", nm); | 919 error ("%s: value must not be empty", nm); |
920 | |
921 var = sval; | |
924 } | 922 } |
925 | 923 |
926 return retval; | 924 return retval; |
927 } | 925 } |
928 | 926 |
1463 std::string cmd; | 1461 std::string cmd; |
1464 | 1462 |
1465 // Parse one command from whos_line_format | 1463 // Parse one command from whos_line_format |
1466 cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); | 1464 cmd = Vwhos_line_format.substr (idx, Vwhos_line_format.length ()); |
1467 pos = cmd.find (';'); | 1465 pos = cmd.find (';'); |
1468 if (pos != std::string::npos) | 1466 if (pos == std::string::npos) |
1469 cmd = cmd.substr (0, pos+1); | |
1470 else | |
1471 error ("parameter without ; in whos_line_format"); | 1467 error ("parameter without ; in whos_line_format"); |
1468 | |
1469 cmd = cmd.substr (0, pos+1); | |
1472 | 1470 |
1473 idx += cmd.length (); | 1471 idx += cmd.length (); |
1474 | 1472 |
1475 // FIXME: use iostream functions instead of sscanf! | 1473 // FIXME: use iostream functions instead of sscanf! |
1476 | 1474 |
1486 error ("whos_line_format: parameter structure without command in whos_line_format"); | 1484 error ("whos_line_format: parameter structure without command in whos_line_format"); |
1487 | 1485 |
1488 // Insert data into parameter | 1486 // Insert data into parameter |
1489 param.first_parameter_length = 0; | 1487 param.first_parameter_length = 0; |
1490 pos = param_string.find (param.command); | 1488 pos = param_string.find (param.command); |
1491 if (pos != std::string::npos) | 1489 if (pos == std::string::npos) |
1492 { | 1490 error ("whos_line_format: '%c' is not a command", param.command); |
1493 param.parameter_length = param_length(pos); | 1491 |
1494 param.text = param_names(pos); | 1492 param.parameter_length = param_length(pos); |
1495 param.line.assign (param_names(pos).length (), '='); | 1493 param.text = param_names(pos); |
1496 | 1494 param.line.assign (param_names(pos).length (), '='); |
1497 param.parameter_length = (a > param.parameter_length | 1495 |
1498 ? a : param.parameter_length); | 1496 param.parameter_length = (a > param.parameter_length |
1499 if (param.command == 's' && param.modifier == 'c' && b > 0) | 1497 ? a : param.parameter_length); |
1500 param.first_parameter_length = b; | 1498 if (param.command == 's' && param.modifier == 'c' && b > 0) |
1501 } | 1499 param.first_parameter_length = b; |
1502 else | |
1503 error ("whos_line_format: '%c' is not a command", | |
1504 param.command); | |
1505 | 1500 |
1506 if (param.command == 's') | 1501 if (param.command == 's') |
1507 { | 1502 { |
1508 // Have to calculate space needed for printing | 1503 // Have to calculate space needed for printing |
1509 // matrix dimensions Space needed for Size column is | 1504 // matrix dimensions Space needed for Size column is |
1937 void | 1932 void |
1938 mlock (void) | 1933 mlock (void) |
1939 { | 1934 { |
1940 octave_function *fcn = octave_call_stack::current (); | 1935 octave_function *fcn = octave_call_stack::current (); |
1941 | 1936 |
1942 if (fcn) | 1937 if (! fcn) |
1943 fcn->lock (); | |
1944 else | |
1945 error ("mlock: invalid use outside a function"); | 1938 error ("mlock: invalid use outside a function"); |
1939 | |
1940 fcn->lock (); | |
1946 } | 1941 } |
1947 | 1942 |
1948 void | 1943 void |
1949 munlock (const std::string& nm) | 1944 munlock (const std::string& nm) |
1950 { | 1945 { |