Mercurial > octave
diff libinterp/corefcn/dirfns.cc @ 20581:fd0efcdb3718
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 19:00:51 -0400 |
parents | 1a0a433c8263 |
children | 8742e0b1cc49 |
line wrap: on
line diff
--- 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 ();