Mercurial > octave
changeset 30241:ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
* NEWS: Announce change.
* dirfns.cc (Frmdir): Update documentation. Change return status to true/false
rather than 1.0/0.0.
* copyfile.m: Update documentation. Change internal variable "sts" to logical
variable. Change any assignments to status to true/false.
* movefile.m: Update documentation. Change internal variable "sts" to logical
variable. Change any assignments to status to true/false.
* mkdir.m: Update documentation.
* mkdir.m (mkdir_recur): Change internal variable "status" to logical.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 13 Oct 2021 10:36:20 -0700 |
parents | a0bcfaf04cc1 |
children | 33d895260fa4 |
files | NEWS libinterp/corefcn/dirfns.cc scripts/miscellaneous/copyfile.m scripts/miscellaneous/mkdir.m scripts/miscellaneous/movefile.m |
diffstat | 5 files changed, 40 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Wed Oct 13 17:59:06 2021 +0200 +++ b/NEWS Wed Oct 13 10:36:20 2021 -0700 @@ -76,14 +76,14 @@ same number of digits for each value such as `[0x00_00_01; 0x00_01_00; 0x01_00_00]`. -- The `factor` function has been overhauled for speed. For large -composite numbers > 1e14, it can be up to 10,000 times faster. - - The `mldivide` function (i.e., the `\` operator) now uses an LU decomposition to solve nearly singular full square matrices. This is Matlab-compatible and yields results which more nearly minimize `norm (A*x - b)`. Previously, Octave computed a minimum-norm solution. +- The `factor` function has been overhauled for speed. For large +composite numbers > 1e14, it can be up to 10,000 times faster. + - The `betainc` function now calculates an exact output for the important special cases where a or b are 1. @@ -209,6 +209,9 @@ - The function `importdata` now produces more compatible results when the file contains a 2-D text matrix. +- The file functions `copyfile`, `mkdir`, `movefile`, `rmdir` now return +a logical value (true/false) rather than a numeric value (1/0). + - `uimenu` now accepts property `"Text"` which is identical to `"Label"`. Matlab recommends using `"Text"` in new code, although there is no announced date for deprecating `"Label"`.
--- a/libinterp/corefcn/dirfns.cc Wed Oct 13 17:59:06 2021 +0200 +++ b/libinterp/corefcn/dirfns.cc Wed Oct 13 10:36:20 2021 -0700 @@ -236,10 +236,10 @@ If the optional second parameter is supplied with value @qcode{"s"}, recursively remove all subdirectories as well. -If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty -character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a -system-dependent error message, and @var{msgid} contains a unique message -identifier. +If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are empty +character strings (""). Otherwise, @var{status} is logical 0, @var{msg} +contains a system-dependent error message, and @var{msgid} contains a unique +message identifier. @seealso{mkdir, confirm_recursive_rmdir, pwd} @end deftypefn */) @@ -298,9 +298,9 @@ else { if (status < 0) - retval = ovl (0.0, msg, "rmdir"); + retval = ovl (false, msg, "rmdir"); else - retval = ovl (1.0, "", ""); + retval = ovl (true, "", ""); } return retval;
--- a/scripts/miscellaneous/copyfile.m Wed Oct 13 17:59:06 2021 +0200 +++ b/scripts/miscellaneous/copyfile.m Wed Oct 13 10:36:20 2021 -0700 @@ -38,11 +38,11 @@ ## When the force flag @qcode{'f'} is given any existing files will be ## overwritten without prompting. ## -## If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty -## character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a -## system-dependent error message, and @var{msgid} contains a unique message -## identifier. Note that the status code is exactly opposite that of the -## @code{system} command. +## If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are +## empty character strings (""). Otherwise, @var{status} is logical 0, +## @var{msg} contains a system-dependent error message, and @var{msgid} +## contains a unique message identifier. Note that the status code is exactly +## opposite that of the @code{system} command. ## @seealso{movefile, rename, unlink, delete, glob} ## @end deftypefn @@ -53,7 +53,7 @@ endif max_cmd_line = 1024; - sts = 1; + sts = true; msg = ""; msgid = ""; @@ -90,7 +90,7 @@ if (nargout == 0) error ("copyfile: when copying multiple files, F2 must be a directory"); else - status = 0; + status = false; msg = "when copying multiple files, F2 must be a directory"; msgid = "copyfile"; return; @@ -107,7 +107,7 @@ if (nargout == 0) error ("copyfile: no files to move"); else - status = 0; + status = false; msg = "no files to move"; msgid = "copyfile"; return; @@ -136,7 +136,7 @@ ## Copy the files. [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); if (err != 0) - sts = 0; + sts = false; msgid = "copyfile"; break; endif @@ -151,13 +151,13 @@ ## Copy the files. [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); if (err != 0) - sts = 0; + sts = false; msgid = "copyfile"; endif endif if (nargout == 0) - if (sts == 0) + if (! sts) error ("copyfile: operation failed: %s", msg); endif else
--- a/scripts/miscellaneous/mkdir.m Wed Oct 13 17:59:06 2021 +0200 +++ b/scripts/miscellaneous/mkdir.m Wed Oct 13 10:36:20 2021 -0700 @@ -33,10 +33,11 @@ ## If @var{dirname} is a relative path, and no @var{parent} directory is ## specified, then the present working directory is used. ## -## If successful, @var{status} is 1, and @var{msg} and @var{msgid} are empty -## strings (""). Otherwise, @var{status} is 0, @var{msg} contains a -## system-dependent error message, and @var{msgid} contains a unique message -## identifier. +## If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are +## empty character strings (""). Otherwise, @var{status} is logical 0, +## @var{msg} contains a system-dependent error message, and @var{msgid} +## contains a unique message identifier. Note that the status code is exactly +## opposite that of the @code{system} command. ## ## When creating a directory permissions will be set to ## @w{@code{0777 - UMASK}}. @@ -84,7 +85,7 @@ ## Recursively make directories until parent/dirname can be created. function [status, msg, msgid] = mkdir_recur (parent, dirname) - status = 1; + status = true; if (isempty (parent)) error ("mkdir: invalid PARENT");
--- a/scripts/miscellaneous/movefile.m Wed Oct 13 17:59:06 2021 +0200 +++ b/scripts/miscellaneous/movefile.m Wed Oct 13 10:36:20 2021 -0700 @@ -44,11 +44,11 @@ ## When the force flag @qcode{'f'} is given any existing files will be ## overwritten without prompting. ## -## If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty -## character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a -## system-dependent error message, and @var{msgid} contains a unique message -## identifier. Note that the status code is exactly opposite that of the -## @code{system} command. +## If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are +## empty character strings (""). Otherwise, @var{status} is logical 0, +## @var{msg} contains a system-dependent error message, and @var{msgid} +## contains a unique message identifier. Note that the status code is exactly +## opposite that of the @code{system} command. ## @seealso{rename, copyfile, unlink, delete, glob} ## @end deftypefn @@ -59,7 +59,7 @@ endif max_cmd_line = 1024; - sts = 1; + sts = true; msg = ""; msgid = ""; @@ -99,7 +99,7 @@ if (nargout == 0) error ("movefile: when copying multiple files, F2 must be a directory"); else - status = 0; + status = false; msg = "when copying multiple files, F2 must be a directory"; msgid = "movefile"; return; @@ -116,7 +116,7 @@ if (nargout == 0) error ("movefile: no files to move"); else - status = 0; + status = false; msg = "no files to move"; msgid = "movefile"; return; @@ -147,7 +147,7 @@ ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) - sts = 0; + sts = false; msgid = "movefile"; endif ## Load new file(s) in editor @@ -165,7 +165,7 @@ ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) - sts = 0; + sts = false; msgid = "movefile"; endif ## Load new file(s) in editor @@ -173,7 +173,7 @@ endif if (nargout == 0) - if (sts == 0) + if (! sts) error ("movefile: operation failed: %s", msg); endif else