# HG changeset patch # User John W. Eaton # Date 1444399599 14400 # Node ID ba2b07c13913e9dfe7cce172987ab268f46bea24 # Parent fd0efcdb37188ecf35870f4751129c334a926f10 use new string_value method to handle value extraction errors * __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc, graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc, spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc: Use new string_value method. diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/__dispatch__.cc --- a/libinterp/corefcn/__dispatch__.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/__dispatch__.cc Fri Oct 09 10:06:39 2015 -0400 @@ -46,39 +46,17 @@ int nargin = args.length (); - std::string f, r, t; - if (nargin > 0 && nargin < 4) { - f = args(0).string_value (); + std::string f, r, t; - if (error_state) - { - error ("__dispatch__: first argument must be a function name"); - return retval; - } + f = args(0).string_value ("__dispatch__: first argument must be a function name"); if (nargin > 1) - { - r = args(1).string_value (); - - if (error_state) - { - error ("__dispatch__: second argument must be a function name"); - return retval; - } - } + r = args(1).string_value ("__dispatch__: second argument must be a function name"); if (nargin > 2) - { - t = args(2).string_value (); - - if (error_state) - { - error ("__dispatch__: third argument must be a type name"); - return retval; - } - } + t = args(2).string_value ("__dispatch__: third argument must be a type name"); if (nargin == 1) { diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/balance.cc --- a/libinterp/corefcn/balance.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/balance.cc Fri Oct 09 10:06:39 2015 -0400 @@ -243,13 +243,8 @@ // Generalized eigenvalue problem. if (nargin == 2) bal_job = "B"; - else if (args(2).is_string ()) - bal_job = args(2).string_value (); else - { - error ("balance: OPT argument must be a string"); - return retval; - } + bal_job = args(2).string_value ("balance: OPT argument must be a string"); if ((nn != args(1).columns ()) || (nn != args(1).rows ())) { diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/colloc.cc --- a/libinterp/corefcn/colloc.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/colloc.cc Fri Oct 09 10:06:39 2015 -0400 @@ -80,35 +80,21 @@ for (int i = 1; i < nargin; i++) { - if (args(i).is_defined ()) - { - if (! args(i).is_string ()) - { - error ("colloc: expecting string argument \"left\" or \"right\""); - return retval; - } - - std::string s = args(i).string_value (); + std::string s = args(i).string_value ("colloc: expecting string argument \"left\" or \"right\""); - if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) - || s == "right") - { - right = 1; - } - else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) - || s == "left") - { - left = 1; - } - else - { - error ("colloc: unrecognized argument"); - return retval; - } + if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) + || s == "right") + { + right = 1; + } + else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) + || s == "left") + { + left = 1; } else { - error ("colloc: unexpected empty argument"); + error ("colloc: unrecognized argument"); return retval; } } diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/conv2.cc --- a/libinterp/corefcn/conv2.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/conv2.cc Fri Oct 09 10:06:39 2015 -0400 @@ -329,15 +329,7 @@ return retval; } else if (nargin == 3) - { - if (args(2).is_string ()) - shape = args(2).string_value (); - else - { - error ("convn: SHAPE must be a string"); - return retval; - } - } + shape = args(2).string_value ("convn: SHAPE must be a string"); if (shape == "full") ct = convn_full; diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/data.cc Fri Oct 09 10:06:39 2015 -0400 @@ -6641,12 +6641,8 @@ return retval; } - if (! args(2).is_string ()) - { - error ("sort: MODE must be a string"); - return retval; - } - std::string mode = args(2).string_value (); + std::string mode = args(2).string_value ("sort: MODE must be a string"); + if (mode == "ascend") smode = ASCENDING; else if (mode == "descend") @@ -6924,20 +6920,16 @@ // FIXME: shouldn't these modes be scoped inside a class? sortmode smode = UNSORTED; - if (arg.is_string ()) - { - std::string mode = arg.string_value (); - if (mode == "ascending") - smode = ASCENDING; - else if (mode == "descending") - smode = DESCENDING; - else if (mode == "either") - smode = UNSORTED; - else - error ("issorted: MODE must be \"ascending\", \"descending\", or \"either\""); - } + std::string mode = arg.string_value ("issorted: expecting %s argument to be a string", argn); + + if (mode == "ascending") + smode = ASCENDING; + else if (mode == "descending") + smode = DESCENDING; + else if (mode == "either") + smode = UNSORTED; else - error ("issorted: expecting %s argument to be a string", argn); + error ("issorted: MODE must be \"ascending\", \"descending\", or \"either\""); return smode; } @@ -6983,16 +6975,11 @@ if (nargin == 3) smode = get_sort_mode_option (args(2), "third"); - if (args(1).is_string ()) - { - std::string tmp = args(1).string_value (); - if (tmp == "rows") - by_rows = true; - else - smode = get_sort_mode_option (args(1), "second"); - } + std::string tmp = args(1).string_value ("issorted: second argument must be a string"); + if (tmp == "rows") + by_rows = true; else - error ("issorted: second argument must be a string"); + smode = get_sort_mode_option (args(1), "second"); } octave_value arg = args(0); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/debug.cc Fri Oct 09 10:06:39 2015 -0400 @@ -1417,38 +1417,33 @@ print_usage (); else if (nargin == 1) { - if (args(0).is_string ()) + std::string arg = args(0).string_value ("dbstep: input argument must be a string"); + + if (arg == "in") { - std::string arg = args(0).string_value (); + Vdebugging = false; - if (arg == "in") - { - Vdebugging = false; + tree_evaluator::dbstep_flag = -1; + } + else if (arg == "out") + { + Vdebugging = false; - tree_evaluator::dbstep_flag = -1; - } - else if (arg == "out") + tree_evaluator::dbstep_flag = -2; + } + else + { + int n = atoi (arg.c_str ()); + + if (n > 0) { Vdebugging = false; - tree_evaluator::dbstep_flag = -2; + tree_evaluator::dbstep_flag = n; } else - { - int n = atoi (arg.c_str ()); - - if (n > 0) - { - Vdebugging = false; - - tree_evaluator::dbstep_flag = n; - } - else - error ("dbstep: invalid argument"); - } + error ("dbstep: invalid argument"); } - else - error ("dbstep: input argument must be a string"); } else { diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/graphics.cc Fri Oct 09 10:06:39 2015 -0400 @@ -1673,17 +1673,12 @@ error ("addproperty: missing possible values for radio property"); else { - std::string sv = args(0).string_value (); - - if (! error_state) - { - retval = property (new radio_property (name, h, sv)); - - if (args.length () > 1) - retval.set (args(1)); - } - else - error ("addproperty: invalid argument for radio property, expected a string value"); + std::string sv = args(0).string_value ("addproperty: invalid argument for radio property, expected a string value"); + + retval = property (new radio_property (name, h, sv)); + + if (args.length () > 1) + retval.set (args(1)); } } else if (type.compare ("double")) @@ -10694,17 +10689,12 @@ if (h.ok ()) { - std::string name = args(1).string_value (); - - if (! error_state) - { - if (nargin == 2) - gh_manager::execute_callback (h, name); - else - gh_manager::execute_callback (h, name, args(2)); - } + std::string name = args(1).string_value ("__go_execute_callback__: invalid callback name"); + + if (nargin == 2) + gh_manager::execute_callback (h, name); else - error ("__go_execute_callback__: invalid callback name"); + gh_manager::execute_callback (h, name, args(2)); } else error ("__go_execute_callback__: invalid graphics object (= %g)", @@ -10873,13 +10863,9 @@ if (args.length () == 1) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); - gtk_manager::register_toolkit (name); - } - else - error ("register_graphics_toolkit: TOOLKIT must be a string"); + std::string name = args(0).string_value ("register_graphics_toolkit: TOOLKIT must be a string"); + + gtk_manager::register_toolkit (name); } else print_usage (); @@ -10991,97 +10977,86 @@ std::string term, file, debug_file; bool mono; - term = args(0).string_value (); - - if (! error_state) - { - file = args(1).string_value (); - - if (! error_state) + term = args(0).string_value ("drawnow: invalid terminal TERM, expected a string value"); + + file = args(1).string_value ("drawnow: invalid FILE, expected a string value"); + + size_t pos_p = file.find_first_of ("|"); + size_t pos_c = file.find_first_not_of ("| "); + + if (pos_p == std::string::npos && + pos_c == std::string::npos) + { + error ("drawnow: empty output ''"); + + gh_manager::unlock (); + + return retval; + } + else if (pos_c == std::string::npos) + { + error ("drawnow: empty pipe '|'"); + + gh_manager::unlock (); + + return retval; + } + else if (pos_p != std::string::npos && pos_p < pos_c) + { + // Strip leading pipe character + file = file.substr (pos_c); + } + else + { + size_t pos = file.find_last_of (file_ops::dir_sep_chars ()); + + if (pos != std::string::npos) { - size_t pos_p = file.find_first_of ("|"); - size_t pos_c = file.find_first_not_of ("| "); - - if (pos_p == std::string::npos && - pos_c == std::string::npos) + std::string dirname = file.substr (pos_c, pos+1); + + file_stat fs (dirname); + + if (! (fs && fs.is_dir ())) { - error ("drawnow: empty output ''"); - - gh_manager::unlock (); - - return retval; - } - else if (pos_c == std::string::npos) - { - error ("drawnow: empty pipe '|'"); + error ("drawnow: nonexistent directory '%s'", + dirname.c_str ()); gh_manager::unlock (); return retval; } - else if (pos_p != std::string::npos && pos_p < pos_c) + } + } + + mono = (args.length () >= 3 ? args(2).bool_value () : false); + + if (! error_state) + { + debug_file = (args.length () > 3 ? args(3).string_value () : ""); + + if (! error_state) + { + graphics_handle h = gcf (); + + if (h.ok ()) { - // Strip leading pipe character - file = file.substr (pos_c); + graphics_object go = gh_manager::get_object (h); + + gh_manager::unlock (); + + go.get_toolkit ().print_figure (go, term, file, + mono, debug_file); + + gh_manager::lock (); } else - { - size_t pos = file.find_last_of (file_ops::dir_sep_chars ()); - - if (pos != std::string::npos) - { - std::string dirname = file.substr (pos_c, pos+1); - - file_stat fs (dirname); - - if (! (fs && fs.is_dir ())) - { - error ("drawnow: nonexistent directory '%s'", - dirname.c_str ()); - - gh_manager::unlock (); - - return retval; - } - } - } - - mono = (args.length () >= 3 ? args(2).bool_value () : false); - - if (! error_state) - { - debug_file = (args.length () > 3 ? args(3).string_value () - : ""); - - if (! error_state) - { - graphics_handle h = gcf (); - - if (h.ok ()) - { - graphics_object go = gh_manager::get_object (h); - - gh_manager::unlock (); - - go.get_toolkit ().print_figure (go, term, file, - mono, debug_file); - - gh_manager::lock (); - } - else - error ("drawnow: nothing to draw"); - } - else - error ("drawnow: invalid DEBUG_FILE, expected a string value"); - } - else - error ("drawnow: invalid colormode MONO, expected a boolean value"); + error ("drawnow: nothing to draw"); } else - error ("drawnow: invalid FILE, expected a string value"); + error ("drawnow: invalid DEBUG_FILE, expected a string value"); } else - error ("drawnow: invalid terminal TERM, expected a string value"); + error ("drawnow: invalid colormode MONO, expected a boolean value"); } else print_usage (); @@ -11137,31 +11112,25 @@ if (! error_state) { - std::string pname = args(1).string_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) + std::string pname = args(1).string_value ("addlistener: invalid property name, expected a string value"); + + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + go.add_property_listener (pname, args(2), POSTSET); + + if (args.length () == 4) { - graphics_object go = gh_manager::get_object (gh); - - go.add_property_listener (pname, args(2), POSTSET); - - if (args.length () == 4) - { - caseless_str persistent = args(3).string_value (); - if (persistent.compare ("persistent")) - go.add_property_listener (pname, args(2), PERSISTENT); - } + caseless_str persistent = args(3).string_value (); + if (persistent.compare ("persistent")) + go.add_property_listener (pname, args(2), PERSISTENT); } - else - error ("addlistener: invalid graphics object (= %g)", - h); } else - error ("addlistener: invalid property name, expected a string value"); + error ("addlistener: invalid graphics object (= %g)", h); } else error ("addlistener: invalid handle"); @@ -11210,39 +11179,32 @@ if (! error_state) { - std::string pname = args(1).string_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) + std::string pname = args(1).string_value ("dellistener: invalid property name, expected a string value"); + + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + if (args.length () == 2) + go.delete_property_listener (pname, octave_value (), POSTSET); + else { - graphics_object go = gh_manager::get_object (gh); - - if (args.length () == 2) - go.delete_property_listener (pname, octave_value (), - POSTSET); - else + if (args(2).is_string () + && args(2).string_value () == "persistent") { - if (args(2).is_string () - && args(2).string_value () == "persistent") - { - go.delete_property_listener (pname, octave_value (), - PERSISTENT); - go.delete_property_listener (pname, octave_value (), - POSTSET); - } - else - go.delete_property_listener (pname, args(2), POSTSET); + go.delete_property_listener (pname, octave_value (), + PERSISTENT); + go.delete_property_listener (pname, octave_value (), + POSTSET); } + else + go.delete_property_listener (pname, args(2), POSTSET); } - else - error ("dellistener: invalid graphics object (= %g)", - h); } else - error ("dellistener: invalid property name, expected a string value"); + error ("dellistener: invalid graphics object (= %g)", h); } else error ("dellistener: invalid handle"); @@ -11331,46 +11293,36 @@ if (args.length () >= 3) { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("addproperty: invalid property NAME, expected a string value"); + + double h = args(1).double_value (); if (! error_state) { - double h = args(1).double_value (); - - if (! error_state) - { - graphics_handle gh = gh_manager::lookup (h); - - if (gh.ok ()) + graphics_handle gh = gh_manager::lookup (h); + + if (gh.ok ()) + { + graphics_object go = gh_manager::get_object (gh); + + std::string type = args(2).string_value ("addproperty: invalid property TYPE, expected a string value"); + + if (! go.get_properties ().has_property (name)) { - graphics_object go = gh_manager::get_object (gh); - - std::string type = args(2).string_value (); - - if (! error_state) - { - if (! go.get_properties ().has_property (name)) - { - property p = property::create (name, gh, type, - args.splice (0, 3)); - - go.get_properties ().insert_property (name, p); - } - else - error ("addproperty: a '%s' property already exists in the graphics object", - name.c_str ()); - } - else - error ("addproperty: invalid property TYPE, expected a string value"); + property p = property::create (name, gh, type, + args.splice (0, 3)); + + go.get_properties ().insert_property (name, p); } else - error ("addproperty: invalid graphics object (= %g)", h); + error ("addproperty: a '%s' property already exists in the graphics object", + name.c_str ()); } else - error ("addproperty: invalid handle value"); + error ("addproperty: invalid graphics object (= %g)", h); } else - error ("addproperty: invalid property NAME, expected a string value"); + error ("addproperty: invalid handle value"); } else print_usage (); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/input.cc --- a/libinterp/corefcn/input.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/input.cc Fri Oct 09 10:06:39 2015 -0400 @@ -688,13 +688,7 @@ if (nargin == 2) read_as_string++; - std::string prompt = args(0).string_value (); - - if (error_state) - { - error ("input: unrecognized argument"); - return retval; - } + std::string prompt = args(0).string_value ("input: unrecognized argument"); flush_octave_stdout (); @@ -837,15 +831,7 @@ std::string prompt; if (nargin == 1) - { - if (args(0).is_string ()) - prompt = args(0).string_value (); - else - { - error ("yes_or_no: PROMPT must be a string"); - return retval; - } - } + prompt = args(0).string_value ("yes_or_no: PROMPT must be a string"); retval = octave_yes_or_no (prompt); } diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/matrix_type.cc --- a/libinterp/corefcn/matrix_type.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/matrix_type.cc Fri Oct 09 10:06:39 2015 -0400 @@ -214,109 +214,103 @@ else { // Ok, we're changing the matrix type - if (! args(1).is_string ()) - error ("matrix_type: TYPE must be a string"); - else - { - std::string str_typ = args(1).string_value (); + + std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); + + // FIXME: why do I have to explicitly call the constructor? + MatrixType mattyp = MatrixType (); - // FIXME: why do I have to explicitly call the constructor? - MatrixType mattyp = MatrixType (); + octave_idx_type nl = 0; + octave_idx_type nu = 0; - octave_idx_type nl = 0; - octave_idx_type nu = 0; + // Use STL function to convert to lower case + std::transform (str_typ.begin (), str_typ.end (), + str_typ.begin (), tolower); - // Use STL function to convert to lower case - std::transform (str_typ.begin (), str_typ.end (), - str_typ.begin (), tolower); + if (str_typ == "diagonal") + mattyp.mark_as_diagonal (); + if (str_typ == "permuted diagonal") + mattyp.mark_as_permuted_diagonal (); + else if (str_typ == "upper") + mattyp.mark_as_upper_triangular (); + else if (str_typ == "lower") + mattyp.mark_as_lower_triangular (); + else if (str_typ == "banded" + || str_typ == "banded positive definite") + { + if (nargin != 4) + error ("matrix_type: banded matrix type requires 4 arguments"); + else + { + nl = args(2).nint_value (); + nu = args(3).nint_value (); - if (str_typ == "diagonal") - mattyp.mark_as_diagonal (); - if (str_typ == "permuted diagonal") - mattyp.mark_as_permuted_diagonal (); - else if (str_typ == "upper") - mattyp.mark_as_upper_triangular (); - else if (str_typ == "lower") - mattyp.mark_as_lower_triangular (); - else if (str_typ == "banded" - || str_typ == "banded positive definite") - { - if (nargin != 4) - error ("matrix_type: banded matrix type requires 4 arguments"); + if (error_state) + error ("matrix_type: band size NL, NU must be integers"); else { - nl = args(2).nint_value (); - nu = args(3).nint_value (); - - if (error_state) - error ("matrix_type: band size NL, NU must be integers"); + if (nl == 1 && nu == 1) + mattyp.mark_as_tridiagonal (); else - { - if (nl == 1 && nu == 1) - mattyp.mark_as_tridiagonal (); - else - mattyp.mark_as_banded (nu, nl); + mattyp.mark_as_banded (nu, nl); - if (str_typ == "banded positive definite") - mattyp.mark_as_symmetric (); - } + if (str_typ == "banded positive definite") + mattyp.mark_as_symmetric (); } } - else if (str_typ == "positive definite") + } + else if (str_typ == "positive definite") + { + mattyp.mark_as_full (); + mattyp.mark_as_symmetric (); + } + else if (str_typ == "singular") + mattyp.mark_as_rectangular (); + else if (str_typ == "full") + mattyp.mark_as_full (); + else if (str_typ == "unknown") + mattyp.invalidate_type (); + else + error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); + + if (nargin == 3 + && (str_typ == "upper" || str_typ == "lower")) + { + const ColumnVector perm = + ColumnVector (args(2).vector_value ()); + + if (error_state) + error ("matrix_type: Invalid permutation vector PERM"); + else { - mattyp.mark_as_full (); - mattyp.mark_as_symmetric (); - } - else if (str_typ == "singular") - mattyp.mark_as_rectangular (); - else if (str_typ == "full") - mattyp.mark_as_full (); - else if (str_typ == "unknown") - mattyp.invalidate_type (); - else - error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); + octave_idx_type len = perm.numel (); + dim_vector dv = args(0).dims (); - if (nargin == 3 - && (str_typ == "upper" || str_typ == "lower")) - { - const ColumnVector perm = - ColumnVector (args(2).vector_value ()); - - if (error_state) + if (len != dv(0)) error ("matrix_type: Invalid permutation vector PERM"); else { - octave_idx_type len = perm.numel (); - dim_vector dv = args(0).dims (); + OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); - if (len != dv(0)) - error ("matrix_type: Invalid permutation vector PERM"); - else - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); + for (octave_idx_type i = 0; i < len; i++) + p[i] = static_cast (perm (i)) - 1; - for (octave_idx_type i = 0; i < len; i++) - p[i] = static_cast - (perm (i)) - - 1; - - mattyp.mark_as_permuted (len, p); - } + mattyp.mark_as_permuted (len, p); } } - else if (nargin != 2 - && str_typ != "banded positive definite" - && str_typ != "banded") - error ("matrix_type: Invalid number of arguments"); + } + else if (nargin != 2 + && str_typ != "banded positive definite" + && str_typ != "banded") + error ("matrix_type: Invalid number of arguments"); - // Set the matrix type - if (args(0).is_complex_type ()) - retval = octave_value (args(0).sparse_complex_matrix_value (), - mattyp); - else - retval = octave_value (args(0).sparse_matrix_value (), - mattyp); - } + // Set the matrix type + if (args(0).is_complex_type ()) + retval = octave_value (args(0).sparse_complex_matrix_value (), + mattyp); + else + retval = octave_value (args(0).sparse_matrix_value (), + mattyp); } } else @@ -398,88 +392,79 @@ else { // Ok, we're changing the matrix type - if (! args(1).is_string ()) - error ("matrix_type: TYPE must be a string"); - else - { - std::string str_typ = args(1).string_value (); + + std::string str_typ = args(1).string_value ("matrix_type: TYPE must be a string"); - // FIXME: why do I have to explicitly call the constructor? - MatrixType mattyp = MatrixType (MatrixType::Unknown, true); + // FIXME: why do I have to explicitly call the constructor? + MatrixType mattyp = MatrixType (MatrixType::Unknown, true); + + // Use STL function to convert to lower case + std::transform (str_typ.begin (), str_typ.end (), + str_typ.begin (), tolower); - // Use STL function to convert to lower case - std::transform (str_typ.begin (), str_typ.end (), - str_typ.begin (), tolower); + if (str_typ == "upper") + mattyp.mark_as_upper_triangular (); + else if (str_typ == "lower") + mattyp.mark_as_lower_triangular (); + else if (str_typ == "positive definite") + { + mattyp.mark_as_full (); + mattyp.mark_as_symmetric (); + } + else if (str_typ == "singular") + mattyp.mark_as_rectangular (); + else if (str_typ == "full") + mattyp.mark_as_full (); + else if (str_typ == "unknown") + mattyp.invalidate_type (); + else + error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); - if (str_typ == "upper") - mattyp.mark_as_upper_triangular (); - else if (str_typ == "lower") - mattyp.mark_as_lower_triangular (); - else if (str_typ == "positive definite") + if (nargin == 3 && (str_typ == "upper" || str_typ == "lower")) + { + const ColumnVector perm = + ColumnVector (args(2).vector_value ()); + + if (error_state) + error ("matrix_type: Invalid permutation vector PERM"); + else { - mattyp.mark_as_full (); - mattyp.mark_as_symmetric (); - } - else if (str_typ == "singular") - mattyp.mark_as_rectangular (); - else if (str_typ == "full") - mattyp.mark_as_full (); - else if (str_typ == "unknown") - mattyp.invalidate_type (); - else - error ("matrix_type: Unknown matrix type %s", - str_typ.c_str ()); + octave_idx_type len = perm.numel (); + dim_vector dv = args(0).dims (); - if (nargin == 3 && (str_typ == "upper" - || str_typ == "lower")) - { - const ColumnVector perm = - ColumnVector (args(2).vector_value ()); - - if (error_state) + if (len != dv(0)) error ("matrix_type: Invalid permutation vector PERM"); else { - octave_idx_type len = perm.numel (); - dim_vector dv = args(0).dims (); + OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); - if (len != dv(0)) - error ("matrix_type: Invalid permutation vector PERM"); - else - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); + for (octave_idx_type i = 0; i < len; i++) + p[i] = static_cast (perm (i)) - 1; - for (octave_idx_type i = 0; i < len; i++) - p[i] = static_cast - (perm (i)) - - 1; - - mattyp.mark_as_permuted (len, p); - } + mattyp.mark_as_permuted (len, p); } } - else if (nargin != 2) - error ("matrix_type: Invalid number of arguments"); + } + else if (nargin != 2) + error ("matrix_type: Invalid number of arguments"); - // Set the matrix type - if (args(0).is_single_type ()) - { - if (args(0).is_complex_type ()) - retval = octave_value (args(0).float_complex_matrix_value (), - mattyp); - else - retval = octave_value (args(0).float_matrix_value (), - mattyp); - } + // Set the matrix type + if (args(0).is_single_type ()) + { + if (args(0).is_complex_type ()) + retval = octave_value (args(0).float_complex_matrix_value (), + mattyp); else - { - if (args(0).is_complex_type ()) - retval = octave_value (args(0).complex_matrix_value (), - mattyp); - else - retval = octave_value (args(0).matrix_value (), - mattyp); - } + retval = octave_value (args(0).float_matrix_value (), + mattyp); + } + else + { + if (args(0).is_complex_type ()) + retval = octave_value (args(0).complex_matrix_value (), + mattyp); + else + retval = octave_value (args(0).matrix_value (), mattyp); } } } diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/oct-hist.cc --- a/libinterp/corefcn/oct-hist.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/oct-hist.cc Fri Oct 09 10:06:39 2015 -0400 @@ -171,14 +171,11 @@ { if (i < nargin - 1) { - if (args(i+1).is_string ()) - command_history::set_file (args(++i).string_value ()); - else - { - error ("history: expecting file name for %s option", - option.c_str ()); - return hlist; - } + std::string fname + = args(++i).string_value ("history: expecting file name for %s option", + option.c_str ()); + + command_history::set_file (fname); } else command_history::set_file (default_history_file ()); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/schur.cc --- a/libinterp/corefcn/schur.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/schur.cc Fri Oct 09 10:06:39 2015 -0400 @@ -143,15 +143,7 @@ std::string ord; if (nargin == 2) - { - if (args(1).is_string ()) - ord = args(1).string_value (); - else - { - error ("schur: second argument must be a string"); - return retval; - } - } + ord = args(1).string_value ("schur: second argument must be a string"); bool force_complex = false; diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/spparms.cc --- a/libinterp/corefcn/spparms.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/spparms.cc Fri Oct 09 10:06:39 2015 -0400 @@ -167,21 +167,16 @@ } else if (nargin == 2) { - if (args(0).is_string ()) - { - std::string str = args(0).string_value (); + std::string str = args(0).string_value ("spparms: first argument must be a string"); - double val = args(1).double_value (); + double val = args(1).double_value (); - if (error_state) - error ("spparms: second argument must be a real scalar"); - else if (str == "umfpack") - warning ("spparms: request to disable umfpack solvers ignored"); - else if (!octave_sparse_params::set_key (str, val)) - error ("spparms: KEY not found"); - } - else - error ("spparms: first argument must be a string"); + if (error_state) + error ("spparms: second argument must be a real scalar"); + else if (str == "umfpack") + warning ("spparms: request to disable umfpack solvers ignored"); + else if (!octave_sparse_params::set_key (str, val)) + error ("spparms: KEY not found"); } else error ("spparms: too many input arguments"); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/symtab.cc --- a/libinterp/corefcn/symtab.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/symtab.cc Fri Oct 09 10:06:39 2015 -0400 @@ -1688,20 +1688,16 @@ if (nargin == 1) { - if (args(0).is_string ()) - { - std::string sval = args(0).string_value (); - if (sval == "all") - Vignore_function_time_stamp = 2; - else if (sval == "system") - Vignore_function_time_stamp = 1; - else if (sval == "none") - Vignore_function_time_stamp = 0; - else - error ("ignore_function_time_stamp: argument must be \"all\", \"system\", or \"none\""); - } + std::string sval = args(0).string_value ("ignore_function_time_stamp: expecting argument to be a string"); + + if (sval == "all") + Vignore_function_time_stamp = 2; + else if (sval == "system") + Vignore_function_time_stamp = 1; + else if (sval == "none") + Vignore_function_time_stamp = 0; else - error ("ignore_function_time_stamp: expecting argument to be character string"); + error ("ignore_function_time_stamp: argument must be \"all\", \"system\", or \"none\""); } else if (nargin > 1) print_usage (); @@ -1823,27 +1819,22 @@ if (args.length () == 1) { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("__get_cmd_line_function_text__: expecting function name"); - if (! error_state) - { - octave_value ov = symbol_table::find_cmdline_function (name); + octave_value ov = symbol_table::find_cmdline_function (name); - octave_user_function *f = ov.user_function_value (); + octave_user_function *f = ov.user_function_value (); - if (f) - { - std::ostringstream buf; - - tree_print_code tpc (buf); + if (f) + { + std::ostringstream buf; - f->accept (tpc); + tree_print_code tpc (buf); - retval = buf.str (); - } + f->accept (tpc); + + retval = buf.str (); } - else - error ("__get_cmd_line_function_text__: expecting function name"); } else print_usage (); @@ -1861,12 +1852,9 @@ if (args.length () == 2) { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("set_variable: expecting variable name as first argument"); - if (! error_state) - symbol_table::assign (name, args(1)); - else - error ("set_variable: expecting variable name as first argument"); + symbol_table::assign (name, args(1)); } else print_usage (); @@ -1880,18 +1868,13 @@ if (args.length () == 1) { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("variable_value: expecting variable name as first argument"); - if (! error_state) - { - retval = symbol_table::varval (name); + retval = symbol_table::varval (name); - if (retval.is_undefined ()) - error ("variable_value: '%s' is not a variable in the current scope", - name.c_str ()); - } - else - error ("variable_value: expecting variable name as first argument"); + if (retval.is_undefined ()) + error ("variable_value: '%s' is not a variable in the current scope", + name.c_str ()); } else print_usage (); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/sysdep.cc --- a/libinterp/corefcn/sysdep.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/sysdep.cc Fri Oct 09 10:06:39 2015 -0400 @@ -195,27 +195,22 @@ if (args.length () == 1) { - std::string file = args(0).string_value (); + std::string file = args(0).string_value ("__open_with_system_app__: argument must be a file name"); - if (! error_state) - { #if defined (__WIN32__) && ! defined (_POSIX_VERSION) - HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, - SW_SHOWNORMAL); + HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, + SW_SHOWNORMAL); - // ShellExecute returns a value greater than 32 if successful. - retval = (reinterpret_cast (status) > 32); + // ShellExecute returns a value greater than 32 if successful. + retval = (reinterpret_cast (status) > 32); #else - octave_value_list tmp - = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", - false, "async"), - 1); + octave_value_list tmp + = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", + false, "async"), + 1); - retval = (tmp(0).double_value () == 0); + retval = (tmp(0).double_value () == 0); #endif - } - else - error ("__open_with_system_app__: argument must be a file name"); } else print_usage (); @@ -650,20 +645,13 @@ if (nargin == 2 || nargin == 1) { - if (args(0).is_string ()) - { - std::string var = args(0).string_value (); - - std::string val = (nargin == 2 - ? args(1).string_value () : std::string ()); + std::string var = args(0).string_value ("setenv: VAR must be a string"); - if (! error_state) - octave_env::putenv (var, val); - else - error ("setenv: VALUE must be a string"); - } - else - error ("setenv: VAR must be a string"); + std::string val = (nargin == 2 + ? args(1).string_value ("setenv: VALUE must be a string") + : std::string ()); + + octave_env::putenv (var, val); } else print_usage (); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/toplev.cc --- a/libinterp/corefcn/toplev.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/toplev.cc Fri Oct 09 10:06:39 2015 -0400 @@ -1037,23 +1037,15 @@ if (nargin == 3) { - if (args(2).is_string ()) - { - std::string type_str = args(2).string_value (); + std::string type_str = args(2).string_value ("system: TYPE must be a string"); - if (type_str == "sync") - type = et_sync; - else if (type_str == "async") - type = et_async; - else - { - error ("system: TYPE must be \"sync\" or \"async\""); - return retval; - } - } + if (type_str == "sync") + type = et_sync; + else if (type_str == "async") + type = et_async; else { - error ("system: TYPE must be a string"); + error ("system: TYPE must be \"sync\" or \"async\""); return retval; } } @@ -1075,75 +1067,70 @@ return retval; } - std::string cmd_str = args(0).string_value (); + std::string cmd_str = args(0).string_value ("system: expecting string as first argument"); - if (! error_state) - { #if defined (__WIN32__) && ! defined (__CYGWIN__) - // Work around weird double-quote handling on Windows systems. - if (type == et_sync) - cmd_str = "\"" + cmd_str + "\""; + // Work around weird double-quote handling on Windows systems. + if (type == et_sync) + cmd_str = "\"" + cmd_str + "\""; #endif - if (type == et_async) - { - // FIXME: maybe this should go in sysdep.cc? + if (type == et_async) + { + // FIXME: maybe this should go in sysdep.cc? #ifdef HAVE_FORK - pid_t pid = fork (); + pid_t pid = fork (); - if (pid < 0) - error ("system: fork failed -- can't create child process"); - else if (pid == 0) - { - // FIXME: should probably replace this - // call with something portable. + if (pid < 0) + error ("system: fork failed -- can't create child process"); + else if (pid == 0) + { + // FIXME: should probably replace this + // call with something portable. - execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), - static_cast (0)); + execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), + static_cast (0)); - panic_impossible (); - } - else - retval(0) = pid; + panic_impossible (); + } + else + retval(0) = pid; #elif defined (__WIN32__) - STARTUPINFO si; - PROCESS_INFORMATION pi; - ZeroMemory (&si, sizeof (si)); - ZeroMemory (&pi, sizeof (pi)); - OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); - strcpy (xcmd_str, cmd_str.c_str ()); + STARTUPINFO si; + PROCESS_INFORMATION pi; + ZeroMemory (&si, sizeof (si)); + ZeroMemory (&pi, sizeof (pi)); + OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); + strcpy (xcmd_str, cmd_str.c_str ()); - if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) - error ("system: CreateProcess failed -- can't create child process"); - else - { - retval(0) = pi.dwProcessId; - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - } -#else - error ("asynchronous system calls are not supported"); -#endif - } - else if (return_output) - retval = run_command_and_return_output (cmd_str); + if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) + error ("system: CreateProcess failed -- can't create child process"); else { - int status = system (cmd_str.c_str ()); - - // The value in status is as returned by waitpid. If - // the process exited normally, extract the actual exit - // status of the command. Otherwise, return 127 as a - // failure code. + retval(0) = pi.dwProcessId; + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + } +#else + error ("asynchronous system calls are not supported"); +#endif + } + else if (return_output) + retval = run_command_and_return_output (cmd_str); + else + { + int status = system (cmd_str.c_str ()); - if (octave_wait::ifexited (status)) - status = octave_wait::exitstatus (status); + // The value in status is as returned by waitpid. If + // the process exited normally, extract the actual exit + // status of the command. Otherwise, return 127 as a + // failure code. - retval(0) = status; - } + if (octave_wait::ifexited (status)) + status = octave_wait::exitstatus (status); + + retval(0) = status; } - else - error ("system: expecting string as first argument"); } else print_usage (); @@ -1235,32 +1222,27 @@ if (nargin == 1 || nargin == 2) { - if (args(0).is_string ()) - { - std::string arg = args(0).string_value (); + std::string arg = args(0).string_value ("atexit: FCN argument must be a string"); + + bool add_mode = true; - bool add_mode = true; - - if (nargin == 2) - { - add_mode = args(1).bool_value (); + if (nargin == 2) + { + add_mode = args(1).bool_value (); - if (error_state) - error ("atexit: FLAG argument must be a logical value"); - } + if (error_state) + error ("atexit: FLAG argument must be a logical value"); + } - if (add_mode) - octave_add_atexit_function (arg); - else - { - bool found = octave_remove_atexit_function (arg); + if (add_mode) + octave_add_atexit_function (arg); + else + { + bool found = octave_remove_atexit_function (arg); - if (nargout > 0) - retval(0) = found; - } + if (nargout > 0) + retval(0) = found; } - else - error ("atexit: FCN argument must be a string"); } else print_usage (); diff -r fd0efcdb3718 -r ba2b07c13913 libinterp/corefcn/utils.cc --- a/libinterp/corefcn/utils.cc Thu Oct 08 19:00:51 2015 -0400 +++ b/libinterp/corefcn/utils.cc Fri Oct 09 10:06:39 2015 -0400 @@ -393,32 +393,27 @@ if (nargin == 2 || nargin == 3) { - if (args(0).is_string ()) - { - std::string path = args(0).string_value (); + std::string path = args(0).string_value ("file_in_path: PATH must be a string"); + + string_vector names = args(1).all_strings (); - string_vector names = args(1).all_strings (); - - if (! error_state && names.numel () > 0) + if (! error_state && names.numel () > 0) + { + if (nargin == 2) + retval = search_path_for_file (path, names); + else if (nargin == 3) { - if (nargin == 2) - retval = search_path_for_file (path, names); - else if (nargin == 3) - { - std::string opt = args(2).string_value (); + std::string opt = args(2).string_value (); - if (! error_state && opt == "all") - retval = Cell (make_absolute - (search_path_for_all_files (path, names))); - else - error ("file_in_path: invalid option"); - } + if (! error_state && opt == "all") + retval = Cell (make_absolute + (search_path_for_all_files (path, names))); + else + error ("file_in_path: invalid option"); } - else - error ("file_in_path: all arguments must be strings"); } else - error ("file_in_path: PATH must be a string"); + error ("file_in_path: all arguments must be strings"); } else print_usage (); @@ -761,10 +756,9 @@ if (nargin == 1) { - if (args(0).is_string ()) - retval = do_string_escapes (args(0).string_value ()); - else - error ("do_string_escapes: STRING argument must be of type string"); + std::string str = args(0).string_value ("do_string_escapes: STRING argument must be of type string"); + + retval = do_string_escapes (str); } else print_usage (); @@ -905,10 +899,9 @@ if (nargin == 1) { - if (args(0).is_string ()) - retval = undo_string_escapes (args(0).string_value ()); - else - error ("undo_string_escapes: S argument must be a string"); + std::string str = args(0).string_value ("undo_string_escapes: S argument must be a string"); + + retval = undo_string_escapes (str); } else print_usage (); @@ -1002,12 +995,9 @@ if (args.length () == 1) { - std::string nm = args(0).string_value (); + std::string nm = args(0).string_value ("make_absolute_filename: FILE argument must be a file name"); - if (! error_state) - retval = octave_env::make_absolute (nm); - else - error ("make_absolute_filename: FILE argument must be a file name"); + retval = octave_env::make_absolute (nm); } else print_usage (); @@ -1047,17 +1037,12 @@ if (nargin == 1 || nargin == 2) { - dir = args(0).string_value (); + dir = args(0).string_value ("dir_in_loadpath: DIR must be a directory name"); - if (! error_state) - { - if (nargin == 1) - retval = load_path::find_dir (dir); - else if (nargin == 2) - retval = Cell (load_path::find_matching_dirs (dir)); - } - else - error ("dir_in_loadpath: DIR must be a directory name"); + if (nargin == 1) + retval = load_path::find_dir (dir); + else if (nargin == 2) + retval = Cell (load_path::find_matching_dirs (dir)); } else print_usage ();