# HG changeset patch # User John W. Eaton # Date 1444345251 14400 # Node ID fd0efcdb37188ecf35870f4751129c334a926f10 # Parent 729a85dafba8455407734a2f5484557dbe27c5da use new string_value method to handle value extraction errors * dirfns.cc, file-io.cc, gammainc.cc, help.cc, load-path.cc, octave-link.cc, qz.cc, regexp.cc, strfns.cc, syscalls.cc, time.cc, variables.cc: Use new string_value method. diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/dirfns.cc --- a/libinterp/corefcn/dirfns.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/dirfns.cc Thu Oct 08 19:00:51 2015 -0400 @@ -184,24 +184,19 @@ if (args.length () == 1) { - std::string dirname = args(0).string_value (); + std::string dirname = args(0).string_value ("readdir: DIR must be a string"); + + dir_entry dir (dirname); - if (error_state) - gripe_wrong_type_arg ("readdir", args(0)); + if (dir) + { + string_vector dirlist = dir.read (); + retval(1) = 0.0; + retval(0) = Cell (dirlist.sort ()); + } else { - dir_entry dir (dirname); - - if (dir) - { - string_vector dirlist = dir.read (); - retval(1) = 0.0; - retval(0) = Cell (dirlist.sort ()); - } - else - { - retval(2) = dir.error (); - } + retval(2) = dir.error (); } } else @@ -245,27 +240,13 @@ if (nargin == 2) { - std::string parent = args(0).string_value (); - std::string dir = args(1).string_value (); + std::string parent = args(0).string_value ("mkdir: PARENT must be a string"); + std::string dir = args(1).string_value ("mkdir: DIR must be a string"); - if (error_state) - { - gripe_wrong_type_arg ("mkdir", args(0)); - return retval; - } - else - dirname = file_ops::concat (parent, dir); + dirname = file_ops::concat (parent, dir); } else if (nargin == 1) - { - dirname = args(0).string_value (); - - if (error_state) - { - gripe_wrong_type_arg ("mkdir", args(0)); - return retval; - } - } + dirname = args(0).string_value ("mkdir: DIR must be a string"); if (nargin == 1 || nargin == 2) { @@ -331,48 +312,43 @@ if (nargin == 1 || nargin == 2) { - std::string dirname = args(0).string_value (); + std::string dirname = args(0).string_value ("rmdir: DIR must be a string"); - if (error_state) - gripe_wrong_type_arg ("rmdir", args(0)); - else + std::string fulldir = file_ops::tilde_expand (dirname); + int status = -1; + std::string msg; + + if (nargin == 2) { - std::string fulldir = file_ops::tilde_expand (dirname); - int status = -1; - std::string msg; + if (args(1).string_value () == "s") + { + bool doit = true; - if (nargin == 2) - { - if (args(1).string_value () == "s") + if (interactive && ! forced_interactive + && Vconfirm_recursive_rmdir) { - bool doit = true; - - if (interactive && ! forced_interactive - && Vconfirm_recursive_rmdir) - { - std::string prompt - = "remove entire contents of " + fulldir + "? "; + std::string prompt + = "remove entire contents of " + fulldir + "? "; - doit = octave_yes_or_no (prompt); - } + doit = octave_yes_or_no (prompt); + } - if (doit) - status = octave_recursive_rmdir (fulldir, msg); - } - else - error ("rmdir: expecting second argument to be \"s\""); + if (doit) + status = octave_recursive_rmdir (fulldir, msg); } else - status = octave_rmdir (fulldir, msg); + error ("rmdir: expecting second argument to be \"s\""); + } + else + status = octave_rmdir (fulldir, msg); - if (status < 0) - { - retval(2) = "rmdir"; - retval(1) = msg; - } - else - retval(0) = true; + if (status < 0) + { + retval(2) = "rmdir"; + retval(1) = msg; } + else + retval(0) = true; } else print_usage (); @@ -399,27 +375,17 @@ if (args.length () == 2) { - std::string from = args(0).string_value (); + std::string from = args(0).string_value ("link: OLD must be a string"); + std::string to = args(1).string_value ("link: NEW must be a string"); - if (error_state) - gripe_wrong_type_arg ("link", args(0)); - else - { - std::string to = args(1).string_value (); + std::string msg; - if (error_state) - gripe_wrong_type_arg ("link", args(1)); - else - { - std::string msg; + int status = octave_link (from, to, msg); - int status = octave_link (from, to, msg); + if (status < 0) + retval(1) = msg; - if (status < 0) - retval(1) = msg; - retval(0) = status; - } - } + retval(0) = status; } else print_usage (); @@ -446,27 +412,17 @@ if (args.length () == 2) { - std::string from = args(0).string_value (); + std::string from = args(0).string_value ("symlink: OLD must be a string"); + std::string to = args(1).string_value ("symlink: NEW must be a string"); - if (error_state) - gripe_wrong_type_arg ("symlink", args(0)); - else - { - std::string to = args(1).string_value (); + std::string msg; - if (error_state) - gripe_wrong_type_arg ("symlink", args(1)); - else - { - std::string msg; + int status = octave_symlink (from, to, msg); - int status = octave_symlink (from, to, msg); + if (status < 0) + retval(1) = msg; - if (status < 0) - retval(1) = msg; - retval(0) = status; - } - } + retval(0) = status; } else print_usage (); @@ -495,22 +451,18 @@ if (args.length () == 1) { - std::string symlink = args(0).string_value (); + std::string symlink = args(0).string_value ("readlink: SYMLINK must be a string"); + + std::string result; + std::string msg; - if (error_state) - gripe_wrong_type_arg ("readlink", args(0)); - else - { - std::string result; - std::string msg; + int status = octave_readlink (symlink, result, msg); - int status = octave_readlink (symlink, result, msg); + if (status < 0) + retval(2) = msg; - if (status < 0) - retval(2) = msg; - retval(1) = status; - retval(0) = result; - } + retval(1) = status; + retval(0) = result; } else print_usage (); @@ -537,27 +489,17 @@ if (args.length () == 2) { - std::string from = args(0).string_value (); + std::string from = args(0).string_value ("rename: OLD must be a string"); + std::string to = args(1).string_value ("rename: NEW must be a string"); - if (error_state) - gripe_wrong_type_arg ("rename", args(0)); - else - { - std::string to = args(1).string_value (); + std::string msg; - if (error_state) - gripe_wrong_type_arg ("rename", args(1)); - else - { - std::string msg; + int status = octave_rename (from, to, msg); - int status = octave_rename (from, to, msg); + if (status < 0) + retval(1) = msg; - if (status < 0) - retval(1) = msg; - retval(0) = status; - } - } + retval(0) = status; } else print_usage (); @@ -620,16 +562,11 @@ if (args.length () == 1) { - string_vector pat = args(0).all_strings (); + string_vector pat = args(0).all_strings ("glob: PATTERN must be a string"); - if (error_state) - gripe_wrong_type_arg ("glob", args(0)); - else - { - glob_match pattern (file_ops::tilde_expand (pat)); + glob_match pattern (file_ops::tilde_expand (pat)); - retval = Cell (pattern.glob ()); - } + retval = Cell (pattern.glob ()); } else print_usage (); @@ -727,17 +664,11 @@ retval = file_ops::dir_sep_str (); else if (args.length () == 1) { - std::string s = args(0).string_value (); - - if (! error_state) - { - if (s == "all") - retval = file_ops::dir_sep_chars (); - else - gripe_wrong_type_arg ("filesep", args(0)); - } + std::string s = args(0).string_value ("filesep: argument must be a string"); + if (s == "all") + retval = file_ops::dir_sep_chars (); else - gripe_wrong_type_arg ("filesep", args(0)); + error ("filesep: argument must be \"all\""); } else print_usage (); @@ -762,27 +693,22 @@ if (nargin == 1) { - std::string sval = args(0).string_value (); + std::string sval = args(0).string_value ("pathsep: argument must be a single character"); - if (! error_state) + switch (sval.length ()) { - switch (sval.length ()) - { - case 1: - dir_path::path_sep_char (sval[0]); - break; + case 1: + dir_path::path_sep_char (sval[0]); + break; - case 0: - dir_path::path_sep_char ('\0'); - break; + case 0: + dir_path::path_sep_char ('\0'); + break; - default: - error ("pathsep: argument must be a single character"); - break; - } + default: + error ("pathsep: argument must be a single character"); + break; } - else - error ("pathsep: argument must be a single character"); } else if (nargin > 1) print_usage (); diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/file-io.cc Thu Oct 08 19:00:51 2015 -0400 @@ -538,28 +538,11 @@ fid = -1; - if (tc_name.is_string ()) - { - std::string name = tc_name.string_value (); - - if (tc_mode.is_string ()) - { - std::string mode = tc_mode.string_value (); + std::string name = tc_name.string_value ("%s: file name must be a string", fcn); + std::string mode = tc_mode.string_value ("%s: file mode must be a string", fcn); + std::string arch = tc_arch.string_value ("%s: architecture type must be a string", fcn); - if (tc_arch.is_string ()) - { - std::string arch = tc_arch.string_value (); - - retval = do_stream_open (name, mode, arch, fid); - } - else - error ("%s: architecture type must be a string", fcn); - } - else - error ("%s: file mode must be a string", fcn); - } - else - error ("%s: file name must be a string", fcn); + retval = do_stream_open (name, mode, arch, fid); return retval; } @@ -1347,44 +1330,34 @@ if (! error_state) { - if (prec_arg.is_string ()) - { - std::string prec = prec_arg.string_value (); + std::string prec = prec_arg.string_value ("fread: PRECISION must be a string"); + + int block_size = 1; + oct_data_conv::data_type input_type; + oct_data_conv::data_type output_type; - int block_size = 1; - oct_data_conv::data_type input_type; - oct_data_conv::data_type output_type; + oct_data_conv::string_to_data_type (prec, block_size, + input_type, output_type); - oct_data_conv::string_to_data_type (prec, block_size, - input_type, output_type); + if (! error_state) + { + int skip = skip_arg.int_value (true); if (! error_state) { - int skip = skip_arg.int_value (true); - - if (! error_state) - { - if (arch_arg.is_string ()) - { - std::string arch = arch_arg.string_value (); + std::string arch = arch_arg.string_value ("fread: ARCH architecture type must be a string"); - oct_mach_info::float_format flt_fmt - = oct_mach_info::string_to_float_format (arch); + oct_mach_info::float_format flt_fmt + = oct_mach_info::string_to_float_format (arch); - retval = os.read (size, block_size, input_type, - output_type, skip, flt_fmt, count); - } - else - error ("fread: ARCH architecture type must be a string"); - } - else - error ("fread: SKIP must be an integer"); + retval = os.read (size, block_size, input_type, + output_type, skip, flt_fmt, count); } else - error ("fread: invalid PRECISION specified"); + error ("fread: SKIP must be an integer"); } else - error ("fread: PRECISION must be a string"); + error ("fread: invalid PRECISION specified"); } else error ("fread: invalid SIZE specified"); @@ -1618,42 +1591,32 @@ { int retval = -1; - if (prec_arg.is_string ()) - { - std::string prec = prec_arg.string_value (); + std::string prec = prec_arg.string_value ("fwrite: PRECISION must be a string"); + + int block_size = 1; + oct_data_conv::data_type output_type; - int block_size = 1; - oct_data_conv::data_type output_type; + oct_data_conv::string_to_data_type (prec, block_size, output_type); - oct_data_conv::string_to_data_type (prec, block_size, output_type); + if (! error_state) + { + int skip = skip_arg.int_value (true); if (! error_state) { - int skip = skip_arg.int_value (true); - - if (! error_state) - { - if (arch_arg.is_string ()) - { - std::string arch = arch_arg.string_value (); + std::string arch = arch_arg.string_value ("fwrite: ARCH architecture type must be a string"); - oct_mach_info::float_format flt_fmt - = oct_mach_info::string_to_float_format (arch); + oct_mach_info::float_format flt_fmt + = oct_mach_info::string_to_float_format (arch); - retval = os.write (data, block_size, output_type, - skip, flt_fmt); - } - else - error ("fwrite: ARCH architecture type must be a string"); - } - else - error ("fwrite: SKIP must be an integer"); + retval = os.write (data, block_size, output_type, + skip, flt_fmt); } else - error ("fwrite: invalid PRECISION specified"); + error ("fwrite: SKIP must be an integer"); } else - error ("fwrite: PRECISION must be a string"); + error ("fwrite: invalid PRECISION specified"); return retval; } @@ -1843,34 +1806,23 @@ if (nargin == 2) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("popen: COMMAND must be a string"); + std::string mode = args(1).string_value ("popen: MODE must be a string"); - if (args(1).is_string ()) - { - std::string mode = args(1).string_value (); - - if (mode == "r") - { - octave_stream ips = octave_iprocstream::create (name); + if (mode == "r") + { + octave_stream ips = octave_iprocstream::create (name); - retval = octave_stream_list::insert (ips); - } - else if (mode == "w") - { - octave_stream ops = octave_oprocstream::create (name); + retval = octave_stream_list::insert (ips); + } + else if (mode == "w") + { + octave_stream ops = octave_oprocstream::create (name); - retval = octave_stream_list::insert (ops); - } - else - error ("popen: invalid MODE specified"); - } - else - error ("popen: MODE must be a string"); + retval = octave_stream_list::insert (ops); } else - error ("popen: COMMAND must be a string"); + error ("popen: invalid MODE specified"); } else print_usage (); @@ -1926,22 +1878,14 @@ if (len < 3) { std::string dir; + if (len > 0) - { - if (args(0).is_string ()) - dir = args(0).string_value (); - else - error ("DIR must be a string"); - } + dir = args(0).string_value ("tempname: DIR must be a string"); std::string pfx ("oct-"); + if (len > 1) - { - if (args(1).is_string ()) - pfx = args(1).string_value (); - else - error ("PREFIX must be a string"); - } + pfx = args(1).string_value ("tempname: PREFIX must be a string"); retval = octave_tempnam (dir, pfx); } @@ -2084,54 +2028,49 @@ if (nargin == 1 || nargin == 2) { - if (args(0).is_string ()) + std::string tmpl8 = args(0).string_value ("mkstemp: TEMPLATE argument must be a string"); + + OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); + strcpy (tmp, tmpl8.c_str ()); + + int fd = gnulib::mkostemp (tmp, O_BINARY); + + if (fd < 0) { - std::string tmpl8 = args(0).string_value (); + retval(2) = gnulib::strerror (errno); + retval(0) = fd; + } + else + { + const char *fopen_mode = "w+b"; - OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); - strcpy (tmp, tmpl8.c_str ()); + FILE *fid = fdopen (fd, fopen_mode); - int fd = gnulib::mkostemp (tmp, O_BINARY); + if (fid) + { + std::string nm = tmp; + + std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); + + octave_stream s = octave_stdiostream::create (nm, fid, md); - if (fd < 0) - { - retval(2) = gnulib::strerror (errno); - retval(0) = fd; + if (s) + { + retval(1) = nm; + retval(0) = octave_stream_list::insert (s); + + if (nargin == 2 && args(1).is_true ()) + mark_for_deletion (nm); + } + else + error ("mkstemp: failed to create octave_stdiostream object"); } else { - const char *fopen_mode = "w+b"; - - FILE *fid = fdopen (fd, fopen_mode); - - if (fid) - { - std::string nm = tmp; - - std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); - - octave_stream s = octave_stdiostream::create (nm, fid, md); - - if (s) - { - retval(1) = nm; - retval(0) = octave_stream_list::insert (s); - - if (nargin == 2 && args(1).is_true ()) - mark_for_deletion (nm); - } - else - error ("mkstemp: failed to create octave_stdiostream object"); - } - else - { - retval(2) = gnulib::strerror (errno); - retval(0) = -1; - } + retval(2) = gnulib::strerror (errno); + retval(0) = -1; } } - else - error ("mkstemp: TEMPLATE argument must be a string"); } else print_usage (); diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/gammainc.cc --- a/libinterp/corefcn/gammainc.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/gammainc.cc Thu Oct 08 19:00:51 2015 -0400 @@ -85,18 +85,14 @@ if (nargin == 3) { - if (args(2).is_string ()) - { - std::string s = args(2).string_value (); - std::transform (s.begin (), s.end (), s.begin (), tolower); - if (s == "upper") - lower = false; - else if (s != "lower") - error ("gammainc: third argument must be \"lower\" or \"upper\""); - } - else + std::string s = args(2).string_value ("gammainc: third argument must be \"lower\" or \"upper\""); + + std::transform (s.begin (), s.end (), s.begin (), tolower); + + if (s == "upper") + lower = false; + else if (s != "lower") error ("gammainc: third argument must be \"lower\" or \"upper\""); - } if (nargin < 2 || nargin > 3) diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/help.cc --- a/libinterp/corefcn/help.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/help.cc Thu Oct 08 19:00:51 2015 -0400 @@ -1092,20 +1092,15 @@ if (args.length () == 1) { - const std::string name = args(0).string_value (); + const std::string name = args(0).string_value ("get_help_text: NAME must be a string"); - if (! error_state) - { - std::string text; - std::string format; + std::string text; + std::string format; - do_get_help_text (name, text, format); + do_get_help_text (name, text, format); - retval(1) = format; - retval(0) = text; - } - else - error ("get_help_text: invalid input"); + retval(1) = format; + retval(0) = text; } else print_usage (); @@ -1162,20 +1157,15 @@ if (args.length () == 1) { - const std::string fname = args(0).string_value (); + const std::string fname = args(0).string_value ("get_help_text_from_file: NAME must be a string"); - if (! error_state) - { - std::string text; - std::string format; + std::string text; + std::string format; - do_get_help_text_from_file (fname, text, format); + do_get_help_text_from_file (fname, text, format); - retval(1) = format; - retval(0) = text; - } - else - error ("get_help_text_from_file: invalid input"); + retval(1) = format; + retval(0) = text; } else print_usage (); @@ -1380,24 +1370,19 @@ if (args.length () == 0) retval = Cell (ffl.append (afl)); - else if (args(0).is_string ()) + else { - std::string dir = args(0).string_value (); + std::string dir = args(0).string_value ("__list_functions__: DIRECTORY argument must be a string"); string_vector fl = load_path::files (dir, true); - if (! error_state) - { - // Return a sorted list with unique entries (in case of - // .m and .oct versions of the same function in a given - // directory, for example). - fl.sort (true); + // Return a sorted list with unique entries (in case of + // .m and .oct versions of the same function in a given + // directory, for example). + fl.sort (true); - retval = Cell (fl); - } + retval = Cell (fl); } - else - error ("__list_functions__: DIRECTORY argument must be a string"); return retval; } diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/load-path.cc Thu Oct 08 19:00:51 2015 -0400 @@ -2239,26 +2239,20 @@ if (nargin == 1) { - std::string dirname = args(0).string_value (); - - if (! error_state) - retval = genpath (dirname); - else - error ("genpath: DIR must be a string"); + std::string dirname = args(0).string_value ("genpath: DIR must be a string"); + + retval = genpath (dirname); } else if (nargin > 1) { - std::string dirname = args(0).string_value (); + std::string dirname = args(0).string_value ("genpath: all arguments must be strings"); string_vector skip (nargin - 1); for (octave_idx_type i = 1; i < nargin; i++) - skip[i-1] = args(i).string_value (); - - if (! error_state) - retval = genpath (dirname, skip); - else - error ("genpath: all arguments must be strings"); + skip[i-1] = args(i).string_value ("genpath: all arguments must be strings"); + + retval = genpath (dirname, skip); } else print_usage (); @@ -2461,34 +2455,29 @@ for (int i = 0; i < nargin; i++) { - if (args(i).is_string ()) + std::string arg = args(i).string_value ("addpath: all arguments must be strings"); + + std::list dir_elts = split_path (arg); + + if (! append) + std::reverse (dir_elts.begin (), dir_elts.end ()); + + for (std::list::const_iterator p = dir_elts.begin (); + p != dir_elts.end (); + p++) { - std::string arg = args(i).string_value (); - - std::list dir_elts = split_path (arg); - - if (! append) - std::reverse (dir_elts.begin (), dir_elts.end ()); - - for (std::list::const_iterator p = dir_elts.begin (); - p != dir_elts.end (); - p++) - { - std::string dir = *p; - - //dir = regexprep (dir_elts{j}, '//+', "/"); - //dir = regexprep (dir, '/$', ""); - - if (append) - load_path::append (dir, true); - else - load_path::prepend (dir, true); - - need_to_update = true; - } + std::string dir = *p; + + //dir = regexprep (dir_elts{j}, '//+', "/"); + //dir = regexprep (dir, '/$', ""); + + if (append) + load_path::append (dir, true); + else + load_path::prepend (dir, true); + + need_to_update = true; } - else - error ("addpath: all arguments must be strings"); } if (need_to_update) @@ -2530,28 +2519,23 @@ for (int i = 0; i < nargin; i++) { - if (args(i).is_string ()) + std::string arg = args(i).string_value ("rmpath: all arguments must be strings"); + std::list dir_elts = split_path (arg); + + for (std::list::const_iterator p = dir_elts.begin (); + p != dir_elts.end (); + p++) { - std::string arg = args(i).string_value (); - std::list dir_elts = split_path (arg); - - for (std::list::const_iterator p = dir_elts.begin (); - p != dir_elts.end (); - p++) - { - std::string dir = *p; - - //dir = regexprep (dir_elts{j}, '//+', "/"); - //dir = regexprep (dir, '/$', ""); - - if (! load_path::remove (dir)) - warning ("rmpath: %s: not found", dir.c_str ()); - else - need_to_update = true; - } + std::string dir = *p; + + //dir = regexprep (dir_elts{j}, '//+', "/"); + //dir = regexprep (dir, '/$', ""); + + if (! load_path::remove (dir)) + warning ("rmpath: %s: not found", dir.c_str ()); + else + need_to_update = true; } - else - error ("addpath: all arguments must be strings"); } if (need_to_update) diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/octave-link.cc --- a/libinterp/corefcn/octave-link.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/octave-link.cc Thu Oct 08 19:00:51 2015 -0400 @@ -122,29 +122,19 @@ if (args.length () == 1) { - std::string file = args(0).string_value (); + std::string file = args(0).string_value ("expecting file name as argument"); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - retval = octave_link::edit_file (file); - } - else - error ("expecting file name as argument"); + retval = octave_link::edit_file (file); } else if (args.length () == 2) { - std::string file = args(0).string_value (); + std::string file = args(0).string_value ("expecting file name as first argument"); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - retval = octave_link::prompt_new_edit_file (file); - } - else - error ("expecting file name as first argument"); + retval = octave_link::prompt_new_edit_file (file); } return retval; @@ -160,18 +150,13 @@ if (args.length () == 3) { - std::string dlg = args(0).string_value (); - std::string msg = args(1).string_value (); - std::string title = args(2).string_value (); + std::string dlg = args(0).string_value ("invalid arguments"); + std::string msg = args(1).string_value ("invalid arguments"); + std::string title = args(2).string_value ("invalid arguments"); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - retval = octave_link::message_dialog (dlg, msg, title); - } - else - error ("invalid arguments"); + retval = octave_link::message_dialog (dlg, msg, title); } return retval; @@ -187,22 +172,17 @@ if (args.length () == 6) { - std::string msg = args(0).string_value (); - std::string title = args(1).string_value (); - std::string btn1 = args(2).string_value (); - std::string btn2 = args(3).string_value (); - std::string btn3 = args(4).string_value (); - std::string btndef = args(5).string_value (); + std::string msg = args(0).string_value ("invalid arguments"); + std::string title = args(1).string_value ("invalid arguments"); + std::string btn1 = args(2).string_value ("invalid arguments"); + std::string btn2 = args(3).string_value ("invalid arguments"); + std::string btn3 = args(4).string_value ("invalid arguments"); + std::string btndef = args(5).string_value ("invalid arguments"); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - retval = octave_link::question_dialog (msg, title, btn1, btn2, btn3, - btndef); - } - else - error ("invalid arguments"); + retval = octave_link::question_dialog (msg, title, btn1, btn2, btn3, + btndef); } return retval; @@ -327,30 +307,25 @@ std::string ok_string = args(6).string_value (); std::string cancel_string = args(7).string_value (); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - std::pair, int> result - = octave_link::list_dialog (list_lst, mode, width, height, - initial_lst, name, prompt_lst, - ok_string, cancel_string); + std::pair, int> result + = octave_link::list_dialog (list_lst, mode, width, height, + initial_lst, name, prompt_lst, + ok_string, cancel_string); - std::list items_lst = result.first; - nel = items_lst.size (); - Matrix items (dim_vector (1, nel)); - octave_idx_type i = 0; - for (std::list::iterator it = items_lst.begin (); - it != items_lst.end (); it++) - { - items.xelem(i++) = *it; - } + std::list items_lst = result.first; + nel = items_lst.size (); + Matrix items (dim_vector (1, nel)); + octave_idx_type i = 0; + for (std::list::iterator it = items_lst.begin (); + it != items_lst.end (); it++) + { + items.xelem(i++) = *it; + } - retval(1) = result.second; - retval(0) = items; - } - else - error ("invalid arguments"); + retval(1) = result.second; + retval(0) = items; } return retval; @@ -392,27 +367,22 @@ for (octave_idx_type i = 0; i < nel; i++) defaults_lst.push_back (tmp(i)); - if (! error_state) - { - flush_octave_stdout (); + flush_octave_stdout (); - std::list items_lst - = octave_link::input_dialog (prompt_lst, title, nr, nc, - defaults_lst); + std::list items_lst + = octave_link::input_dialog (prompt_lst, title, nr, nc, + defaults_lst); - nel = items_lst.size (); - Cell items (dim_vector (nel, 1)); - octave_idx_type i = 0; - for (std::list::iterator it = items_lst.begin (); - it != items_lst.end (); it++) - { - items.xelem(i++) = *it; - } + nel = items_lst.size (); + Cell items (dim_vector (nel, 1)); + octave_idx_type i = 0; + for (std::list::iterator it = items_lst.begin (); + it != items_lst.end (); it++) + { + items.xelem(i++) = *it; + } - retval = items; - } - else - error ("invalid arguments"); + retval = items; } return retval; diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/qz.cc --- a/libinterp/corefcn/qz.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/qz.cc Thu Oct 08 19:00:51 2015 -0400 @@ -403,14 +403,9 @@ if (nargin == 2) ord_job = 'N'; - else if (! args(2).is_string ()) - { - error ("qz: OPT must be a string"); - return retval; - } else { - std::string tmp = args(2).string_value (); + std::string tmp = args(2).string_value ("qz: OPT must be a string"); if (! tmp.empty ()) ord_job = tmp[0]; diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/regexp.cc --- a/libinterp/corefcn/regexp.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/regexp.cc Thu Oct 08 19:00:51 2015 -0400 @@ -288,13 +288,7 @@ { std::string str; - if (args(i).is_string ()) - str = args(i).string_value (); - else - { - error ("%s: optional arguments must be strings", who.c_str ()); - break; - } + str = args(i).string_value ("%s: optional arguments must be strings", who.c_str ()); std::transform (str.begin (), str.end (), str.begin (), tolower); diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/strfns.cc --- a/libinterp/corefcn/strfns.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/strfns.cc Thu Oct 08 19:00:51 2015 -0400 @@ -923,15 +923,7 @@ std::string prefix; if (nargin > 2) - { - if (args(2).is_string ()) - prefix = args(2).string_value (); - else - { - error ("list_in_columns: PREFIX must be a string"); - return retval; - } - } + prefix = args(2).string_value ("list_in_columns: PREFIX must be a string"); std::ostringstream buf; diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/syscalls.cc --- a/libinterp/corefcn/syscalls.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/syscalls.cc Thu Oct 08 19:00:51 2015 -0400 @@ -189,51 +189,46 @@ if (nargin == 1 || nargin == 2) { - if (args(0).is_string ()) - { - std::string exec_file = args(0).string_value (); + std::string exec_file = args(0).string_value ("exec: FILE must be a string"); + + string_vector exec_args; - string_vector exec_args; - - if (nargin == 2) - { - string_vector tmp = args(1).all_strings (); + if (nargin == 2) + { + string_vector tmp = args(1).all_strings (); - if (! error_state) - { - int len = tmp.numel (); - - exec_args.resize (len + 1); + if (! error_state) + { + int len = tmp.numel (); - exec_args[0] = exec_file; + exec_args.resize (len + 1); - for (int i = 0; i < len; i++) - exec_args[i+1] = tmp[i]; - } - else - error ("exec: all arguments must be strings"); + exec_args[0] = exec_file; + + for (int i = 0; i < len; i++) + exec_args[i+1] = tmp[i]; } else - { - exec_args.resize (1); - - exec_args[0] = exec_file; - } - - octave_history_write_timestamp (); - - if (! command_history::ignoring_entries ()) - command_history::clean_up_and_save (); - - std::string msg; - - int status = octave_syscalls::execvp (exec_file, exec_args, msg); - - retval(1) = msg; - retval(0) = status; + error ("exec: all arguments must be strings"); } else - error ("exec: FILE must be a string"); + { + exec_args.resize (1); + + exec_args[0] = exec_file; + } + + octave_history_write_timestamp (); + + if (! command_history::ignoring_entries ()) + command_history::clean_up_and_save (); + + std::string msg; + + int status = octave_syscalls::execvp (exec_file, exec_args, msg); + + retval(1) = msg; + retval(0) = status; } else print_usage (); @@ -298,74 +293,69 @@ if (nargin >= 1 && nargin <= 3) { - if (args(0).is_string ()) - { - std::string exec_file = args(0).string_value (); - - string_vector arg_list; + std::string exec_file = args(0).string_value ("popen2: COMMAND argument must be a string"); - if (nargin >= 2) - { - string_vector tmp = args(1).all_strings (); - - if (! error_state) - { - int len = tmp.numel (); + string_vector arg_list; - arg_list.resize (len + 1); - - arg_list[0] = exec_file; - - for (int i = 0; i < len; i++) - arg_list[i+1] = tmp[i]; - } - else - error ("popen2: all arguments must be strings"); - } - else - { - arg_list.resize (1); - - arg_list[0] = exec_file; - } + if (nargin >= 2) + { + string_vector tmp = args(1).all_strings (); if (! error_state) { - bool sync_mode = (nargin == 3 ? args(2).bool_value () : false); - - int fildes[2]; - std::string msg; - pid_t pid; + int len = tmp.numel (); - pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, - fildes, msg, interactive); - if (pid >= 0) - { - FILE *ifile = fdopen (fildes[1], "r"); - FILE *ofile = fdopen (fildes[0], "w"); - - std::string nm; + arg_list.resize (len + 1); - octave_stream is = octave_stdiostream::create (nm, ifile, - std::ios::in); - - octave_stream os = octave_stdiostream::create (nm, ofile, - std::ios::out); + arg_list[0] = exec_file; - Cell file_ids (1, 2); - - retval(2) = pid; - retval(1) = octave_stream_list::insert (is); - retval(0) = octave_stream_list::insert (os); - } - else - error (msg.c_str ()); + for (int i = 0; i < len; i++) + arg_list[i+1] = tmp[i]; } else error ("popen2: all arguments must be strings"); } else - error ("popen2: COMMAND argument must be a string"); + { + arg_list.resize (1); + + arg_list[0] = exec_file; + } + + if (! error_state) + { + bool sync_mode = (nargin == 3 ? args(2).bool_value () : false); + + int fildes[2]; + std::string msg; + pid_t pid; + + pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, + fildes, msg, interactive); + if (pid >= 0) + { + FILE *ifile = fdopen (fildes[1], "r"); + FILE *ofile = fdopen (fildes[0], "w"); + + std::string nm; + + octave_stream is = octave_stdiostream::create (nm, ifile, + std::ios::in); + + octave_stream os = octave_stdiostream::create (nm, ofile, + std::ios::out); + + Cell file_ids (1, 2); + + retval(2) = pid; + retval(1) = octave_stream_list::insert (is); + retval(0) = octave_stream_list::insert (os); + } + else + error (msg.c_str ()); + } + else + error ("popen2: all arguments must be strings"); } else print_usage (); @@ -786,7 +776,7 @@ if (args.length () == 1) { - std::string fname = args(0).string_value (); + std::string fname = args(0).string_value ("lstat: NAME must be a string"); file_stat fs (fname, false); @@ -853,35 +843,30 @@ if (nargin == 2) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("mkfifo: FILE must be a string"); + + int octal_mode = args(1).int_value (); - int octal_mode = args(1).int_value (); - - if (! error_state) + if (! error_state) + { + if (octal_mode < 0) + error ("mkfifo: MODE must be a positive integer value"); + else { - if (octal_mode < 0) - error ("mkfifo: MODE must be a positive integer value"); - else - { - int mode = convert (octal_mode, 8, 10); + int mode = convert (octal_mode, 8, 10); - std::string msg; + std::string msg; + + int status = octave_mkfifo (name, mode, msg); - int status = octave_mkfifo (name, mode, msg); - - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } + if (status < 0) + retval(1) = msg; } - else - error ("mkfifo: MODE must be an integer"); } else - error ("mkfifo: FILE must be a string"); + error ("mkfifo: MODE must be an integer"); } else print_usage (); @@ -1067,7 +1052,7 @@ } else { - std::string fname = args(0).string_value (); + std::string fname = args(0).string_value ("stat: NAME must be a string"); file_stat fs (fname); @@ -1347,19 +1332,14 @@ if (nargin == 1) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); + std::string name = args(0).string_value ("unlink: FILE must be a string"); - std::string msg; + std::string msg; - int status = octave_unlink (name, msg); + int status = octave_unlink (name, msg); - retval(1) = msg; - retval(0) = status; - } - else - error ("unlink: FILE must be a string"); + retval(1) = msg; + retval(0) = status; } else print_usage (); @@ -1668,19 +1648,14 @@ if (args.length () == 1) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); - std::string msg; - - std::string result = octave_canonicalize_file_name (name, msg); + std::string name = args(0).string_value ("canonicalize_file_name: NAME must be a string"); + std::string msg; - retval(2) = msg; - retval(1) = msg.empty () ? 0 : -1; - retval(0) = result; - } - else - error ("canonicalize_file_name: NAME must be a string"); + std::string result = octave_canonicalize_file_name (name, msg); + + retval(2) = msg; + retval(1) = msg.empty () ? 0 : -1; + retval(0) = result; } else print_usage (); diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/time.cc --- a/libinterp/corefcn/time.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/time.cc Thu Oct 08 19:00:51 2015 -0400 @@ -473,26 +473,21 @@ if (args.length () == 2) { - if (args(0).is_string ()) + std::string fmt = args(0).string_value ("strftime: FMT must be a string"); + + octave_scalar_map map = args(1).scalar_map_value (); + + if (! error_state) { - std::string fmt = args(0).string_value (); - - octave_scalar_map map = args(1).scalar_map_value (); + octave_base_tm tm = extract_tm (map); if (! error_state) - { - octave_base_tm tm = extract_tm (map); - - if (! error_state) - retval = tm.strftime (fmt); - else - error ("strftime: invalid TM_STRUCT argument"); - } + retval = tm.strftime (fmt); else - error ("strftime: TM_STRUCT must be a structure"); + error ("strftime: invalid TM_STRUCT argument"); } else - error ("strftime: FMT must be a string"); + error ("strftime: TM_STRUCT must be a structure"); } else print_usage (); @@ -529,24 +524,14 @@ if (args.length () == 2) { - if (args(0).is_string ()) - { - std::string str = args(0).string_value (); + std::string str = args(0).string_value ("strptime: argument STR must be a string"); - if (args(1).is_string ()) - { - std::string fmt = args(1).string_value (); + std::string fmt = args(1).string_value ("strptime: FMT must be a string"); - octave_strptime t (str, fmt); + octave_strptime t (str, fmt); - retval(1) = t.characters_converted (); - retval(0) = octave_value (mk_tm_map (t)); - } - else - error ("strptime: FMT must be a string"); - } - else - error ("strptime: argument STR must be a string"); + retval(1) = t.characters_converted (); + retval(0) = octave_value (mk_tm_map (t)); } else print_usage (); diff -r 729a85dafba8 -r fd0efcdb3718 libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Thu Oct 08 17:55:57 2015 -0400 +++ b/libinterp/corefcn/variables.cc Thu Oct 08 19:00:51 2015 -0400 @@ -147,39 +147,34 @@ if (! retval) { - if (arg.is_string ()) + std::string s = arg.string_value ("%s: expecting first argument to be a string", + warn_for.c_str ()); + + std::string cmd = header; + cmd.append (s); + cmd.append (trailer); + + int parse_status; + + eval_string (cmd, true, parse_status, 0); + + if (parse_status == 0) { - std::string s = arg.string_value (); - - std::string cmd = header; - cmd.append (s); - cmd.append (trailer); - - int parse_status; - - eval_string (cmd, true, parse_status, 0); - - if (parse_status == 0) + retval = is_valid_function (fname, warn_for, 0); + + if (! retval) { - 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 ()); - return retval; - } - - warning ("%s: passing function body as a string is obsolete; please use anonymous functions", - warn_for.c_str ()); + error ("%s: '%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); + return retval; } - else - 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 - error ("%s: expecting first argument to be a string", - warn_for.c_str ()); + error ("%s: '%s' is not valid as a function", + warn_for.c_str (), fname.c_str ()); } return retval; @@ -595,29 +590,19 @@ if (nargin == 1 || nargin == 2) { - if (args(0).is_string ()) + std::string name = args(0).string_value ("exist: NAME must be a string"); + + if (nargin == 2) { - std::string name = args(0).string_value (); - - if (nargin == 2) - { - if (args(1).is_string ()) - { - std::string type = args(1).string_value (); - - if (type == "class") - warning ("exist: \"class\" type argument is not implemented"); - - retval = symbol_exist (name, type); - } - else - error ("exist: TYPE must be a string"); - } - else - retval = symbol_exist (name); + std::string type = args(1).string_value ("exist: TYPE must be a string"); + + if (type == "class") + warning ("exist: \"class\" type argument is not implemented"); + + retval = symbol_exist (name, type); } else - error ("exist: NAME must be a string"); + retval = symbol_exist (name); } else print_usage (); @@ -826,27 +811,22 @@ if (nargin == 1) { - std::string sval = args(0).string_value (); - - if (! error_state) + std::string sval = args(0).string_value ("%s: argument must be a single character", nm); + + switch (sval.length ()) { - switch (sval.length ()) - { - case 1: - var = sval[0]; - break; - - case 0: - var = '\0'; - break; - - default: - error ("%s: argument must be a single character", nm); - break; - } + case 1: + var = sval[0]; + break; + + case 0: + var = '\0'; + break; + + default: + error ("%s: argument must be a single character", nm); + break; } - else - error ("%s: argument must be a single character", nm); } else if (nargin > 1) print_usage (); @@ -954,17 +934,12 @@ if (nargin == 1) { - if (args(0).is_string ()) - { - std::string sval = args(0).string_value (); - - if (empty_ok || ! sval.empty ()) - var = sval; - else - error ("%s: value must not be empty", nm); - } + std::string sval = args(0).string_value ("%s: first argument must be a string", nm); + + if (empty_ok || ! sval.empty ()) + var = sval; else - error ("%s: first argument must be a string", nm); + error ("%s: value must not be empty", nm); } else if (nargin > 1) print_usage (); @@ -995,24 +970,19 @@ if (nargin == 1) { - if (args(0).is_string ()) + std::string sval = args(0).string_value ("%s: first argument must be a string", nm); + + int i = 0; + for (; i < nchoices; i++) { - std::string sval = args(0).string_value (); - - int i = 0; - for (; i < nchoices; i++) + if (sval == choices[i]) { - if (sval == choices[i]) - { - var = i; - break; - } + var = i; + break; } - if (i == nchoices) - error ("%s: value not allowed (\"%s\")", nm, sval.c_str ()); } - else - error ("%s: first argument must be a string", nm); + if (i == nchoices) + error ("%s: value not allowed (\"%s\")", nm, sval.c_str ()); } else if (nargin > 1) print_usage (); @@ -2093,13 +2063,9 @@ if (args.length () == 1) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); - munlock (name); - } - else - error ("munlock: FCN must be a string"); + std::string name = args(0).string_value ("munlock: FCN must be a string"); + + munlock (name); } else if (args.length () == 0) { @@ -2131,13 +2097,9 @@ if (args.length () == 1) { - if (args(0).is_string ()) - { - std::string name = args(0).string_value (); - retval = mislocked (name); - } - else - error ("mislocked: FCN must be a string"); + std::string name = args(0).string_value ("mislocked: FCN must be a string"); + + retval = mislocked (name); } else if (args.length () == 0) { @@ -2712,12 +2674,9 @@ if (args.length () == 1) { - std::string name = args(0).string_value (); - - if (! error_state) - retval = symbol_table::varval (args(0).string_value ()); - else - error ("__varval__: expecting argument to be variable name"); + std::string name = args(0).string_value ("__varval__: expecting argument to be variable name"); + + retval = symbol_table::varval (args(0).string_value ()); } else print_usage ();