Mercurial > octave
annotate scripts/miscellaneous/movefile.m @ 28896:90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
* acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m,
asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m,
cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, cart2pol.m, cart2sph.m,
celldisp.m, common_size.m, deal.m, del2.m, fliplr.m, integral2.m, interp1.m,
isequal.m, isequaln.m, nextpow2.m, pol2cart.m, quad2d.m, quadl.m, quadv.m,
randi.m, rat.m, repelem.m, rescale.m, shiftdim.m, sortrows.m, sph2cart.m,
xor.m, convhull.m, delaunay.m, delaunayn.m, griddata.m, griddatan.m,
inpolygon.m, voronoi.m, voronoin.m, listdlg.m, msgbox.m, questdlg.m,
rmappdata.m, setappdata.m, __gripe_missing_component__.m,
get_first_help_sentence.m, type.m, which.m, cmpermute.m, cmunique.m,
gray2ind.m, imfinfo.m, imshow.m, imwrite.m, ind2rgb.m, movie.m, rgb2ind.m,
importdata.m, bandwidth.m, condeig.m, gls.m, housh.m, linsolve.m, logm.m,
lscov.m, normest.m, normest1.m, ols.m, ordeig.m, planerot.m, qzhess.m, rref.m,
copyfile.m, delete.m, dos.m, fileparts.m, getfield.m, menu.m, mkdir.m,
movefile.m, orderfields.m, publish.m, setfield.m, substruct.m, unix.m,
unpack.m, decic.m, ode23.m, ode23s.m, ode45.m, fminsearch.m, lsqnonneg.m,
pqpnonneg.m, sqp.m, annotation.m, lighting.m, shading.m, area.m, compass.m,
contourc.m, feather.m, fplot.m, hist.m, isocaps.m, isocolors.m, isonormals.m,
isosurface.m, ostreamtube.m, pie.m, pie3.m, reducepatch.m, reducevolume.m,
rose.m, smooth3.m, stairs.m, stem.m, stem3.m, stream2.m, stream3.m,
streamline.m, streamribbon.m, streamtube.m, surfnorm.m, trimesh.m, trisurf.m,
colstyle.m, hgload.m, linkprop.m, meshgrid.m, ndgrid.m, padecoef.m, polyfit.m,
polyval.m, unmkpp.m, profexport.m, ismember.m, unique.m, movfun.m, movslice.m,
periodogram.m, sinc.m, spdiags.m, sprandsym.m, betaincinv.m, ellipke.m,
factor.m, gammainc.m, gammaincinv.m, isprime.m, lcm.m, gallery.m, hadamard.m,
bounds.m, corrcoef.m, discrete_rnd.m, empirical_rnd.m, histc.m, mode.m,
movmad.m, movmax.m, movmean.m, movmedian.m, movmin.m, movprod.m, movstd.m,
movsum.m, movvar.m, ranks.m, runlength.m, zscore.m, str2num.m, strchr.m,
strsplit.m, strtok.m, untabify.m, assert.m, demo.m, example.m, speed.m, test.m,
datenum.m, datevec.m, webread.m, webwrite.m:
Add expected error message <Invalid call> to BIST tests for nargin.
Remove redundant tests for nargin greater than the number of declared inputs
which are now handled by interpreter.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 11 Oct 2020 21:59:35 -0700 |
parents | 3cac3ceb9629 |
children | 1c212b36a35e |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2005-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27263
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
6047 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6047 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
6047 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
6047 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
6047 | 25 |
26 ## -*- texinfo -*- | |
25040
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
27 ## @deftypefn {} {} movefile @var{f1} |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
28 ## @deftypefnx {} {} movefile @var{f1} @var{f2} |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
29 ## @deftypefnx {} {} movefile @var{f1} @var{f2} f |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
30 ## @deftypefnx {} {} movefile (@var{f1}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
31 ## @deftypefnx {} {} movefile (@var{f1}, @var{f2}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
32 ## @deftypefnx {} {} movefile (@var{f1}, @var{f2}, 'f') |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
33 ## @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} movefile (@dots{}) |
25040
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
34 ## Move the source file or directory @var{f1} to the destination @var{f2}. |
6047 | 35 ## |
25040
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
36 ## The name @var{f1} may contain globbing patterns, or may be a cell array of |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
37 ## strings. If @var{f1} expands to multiple filenames, @var{f2} must be a |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
38 ## directory. |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
39 ## |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
40 ## If no destination @var{f2} is specified then the destination is the present |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
41 ## working directory. If @var{f2} is a filename then @var{f1} is renamed to |
328518881291
Add command forms to documentation of copyfile, mkdir, movefile.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
42 ## @var{f2}. |
19261 | 43 ## |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
44 ## When the force flag @qcode{'f'} is given any existing files will be |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
45 ## overwritten without prompting. |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
46 ## |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
47 ## If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
48 ## character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
49 ## system-dependent error message, and @var{msgid} contains a unique message |
17514
5b916efea542
doc: spellcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
50 ## identifier. Note that the status code is exactly opposite that of the |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
51 ## @code{system} command. |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17394
diff
changeset
|
52 ## @seealso{rename, copyfile, unlink, delete, glob} |
6047 | 53 ## @end deftypefn |
54 | |
55 function [status, msg, msgid] = movefile (f1, f2, force) | |
56 | |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28104
diff
changeset
|
57 if (nargin < 1) |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
58 print_usage (); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
59 endif |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
60 |
6679 | 61 max_cmd_line = 1024; |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
62 sts = 1; |
6047 | 63 msg = ""; |
64 msgid = ""; | |
65 | |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
66 ## FIXME: maybe use the same method as in ls to allow users control |
19261 | 67 ## over the command that is executed. |
6210 | 68 |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
69 if (ispc () && ! isunix () |
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
70 && isempty (file_in_path (getenv ("PATH"), "mv.exe"))) |
6233 | 71 ## Windows. |
6210 | 72 cmd = "cmd /C move"; |
73 cmd_force_flag = "/Y"; | |
74 else | |
75 cmd = "mv"; | |
76 cmd_force_flag = "-f"; | |
77 endif | |
78 | |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
79 ## Input type check. |
19261 | 80 if (ischar (f1)) |
81 f1 = cellstr (f1); | |
82 elseif (! iscellstr (f1)) | |
83 error ("copyfile: F1 must be a string or a cell array of strings"); | |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
84 endif |
6233 | 85 |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
86 if (nargin == 1) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
87 f2 = pwd (); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
88 elseif (! ischar (f2)) |
19261 | 89 error ("movefile: F2 must be a string"); |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
90 endif |
6069 | 91 |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
92 if (nargin == 3 && strcmp (force, "f")) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
93 cmd = [cmd " " cmd_force_flag]; |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
94 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
96 ## If f1 has more than 1 element f2 must be a directory |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
97 isdir = isfolder (f2); |
19261 | 98 if (numel (f1) > 1 && ! isdir) |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
99 if (nargout == 0) |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
100 error ("movefile: when copying multiple files, F2 must be a directory"); |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
101 else |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
102 status = 0; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
103 msg = "when copying multiple files, F2 must be a directory"; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
104 msgid = "movefile"; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
105 return; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
106 endif |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
107 endif |
6069 | 108 |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
109 ## Protect the filename(s). |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
110 f1 = glob (f1); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
111 if (isempty (f1)) |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
112 if (nargout == 0) |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
113 error ("movefile: no files to move"); |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
114 else |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
115 status = 0; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
116 msg = "no files to move"; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
117 msgid = "movefile"; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
118 return; |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
119 endif |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
120 endif |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
121 p1 = sprintf ('"%s" ', f1{:}); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
122 p2 = tilde_expand (f2); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
123 |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
124 if (isdir && length (p1) > max_cmd_line) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
125 l2 = length (p2) + length (cmd) + 6; |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
126 while (! isempty (f1)) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
127 p1 = sprintf ('"%s" ', f1{1}); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
128 f1(1) = []; |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
129 while (! isempty (f1) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
130 && (length (p1) + length (f1{1}) + l2 < max_cmd_line)) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
131 p1 = sprintf ('%s"%s" ', p1, f1{1}); |
10549 | 132 f1(1) = []; |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
133 endwhile |
6679 | 134 |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
135 if (ispc () && ! isunix () |
12497
1536ed546219
Fix bug #32443 preventing 'pkg install' on Windows platforms.
Rik <octave@nomad.inbox5.com>
parents:
12211
diff
changeset
|
136 && ! isempty (file_in_path (getenv ("PATH"), "cp.exe"))) |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
137 p1 = strrep (p1, '\', '/'); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
138 p2 = strrep (p2, '\', '/'); |
6679 | 139 endif |
140 | |
25790
872111558bc0
reload editor files when their path changes by using movefile (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25781
diff
changeset
|
141 ## Close old file(s) in editor |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
142 __event_manager_file_remove__ (p1, p2); |
6679 | 143 ## Move the file(s). |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
144 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
145 if (err != 0) |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
146 sts = 0; |
10549 | 147 msgid = "movefile"; |
6679 | 148 endif |
25790
872111558bc0
reload editor files when their path changes by using movefile (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25781
diff
changeset
|
149 ## Load new file(s) in editor |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
150 __event_manager_file_renamed__ (sts); |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
151 endwhile |
6047 | 152 else |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
153 if (ispc () && ! isunix () |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
154 && ! isempty (file_in_path (getenv ("PATH"), "cp.exe"))) |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
155 p1 = strrep (p1, '\', '/'); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
156 p2 = strrep (p2, '\', '/'); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
157 endif |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
158 |
25790
872111558bc0
reload editor files when their path changes by using movefile (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25781
diff
changeset
|
159 ## Close old file(s) in editor |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
160 __event_manager_file_remove__ (p1, p2); |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
161 ## Move the file(s). |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
162 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
163 if (err != 0) |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
164 sts = 0; |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
165 msgid = "movefile"; |
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
166 endif |
25790
872111558bc0
reload editor files when their path changes by using movefile (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25781
diff
changeset
|
167 ## Load new file(s) in editor |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
168 __event_manager_file_renamed__ (sts); |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
169 endif |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
170 |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
171 if (nargout == 0) |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
172 if (sts == 0) |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
173 error ("movefile: operation failed: %s", msg); |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
174 endif |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
175 else |
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
176 status = sts; |
6047 | 177 endif |
17394
b6867a09d7cf
Return correct status code for copyfile, movefile.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
178 |
6047 | 179 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
180 |
19261 | 181 |
182 %!test | |
183 %! unwind_protect | |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
184 %! f1 = tempname (); |
19261 | 185 %! tmp_var = pi; |
186 %! save (f1, "tmp_var"); | |
187 %! fid = fopen (f1, "rb"); | |
188 %! assert (fid >= 0); | |
189 %! orig_data = fread (fid); | |
190 %! fclose (fid); | |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
191 %! f2 = tempname (); |
19261 | 192 %! assert (movefile (f1, f2)); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19261
diff
changeset
|
193 %! assert (! exist (f1, "file")); |
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19261
diff
changeset
|
194 %! assert (exist (f2, "file")); |
19261 | 195 %! fid = fopen (f2, "rb"); |
196 %! assert (fid >= 0); | |
197 %! new_data = fread (fid); | |
198 %! fclose (fid); | |
199 %! if (orig_data != new_data) | |
200 %! error ("moved file not equal to original file!"); | |
201 %! endif | |
202 %! unwind_protect_cleanup | |
203 %! delete (f2); | |
204 %! end_unwind_protect | |
205 | |
206 ## Test input validation | |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
207 %!error <Invalid call> movefile () |
19261 | 208 %!error <F1 must be a string> movefile (1, "foobar") |
209 %!error <F2 must be a string> movefile ("foobar", 1) | |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19261
diff
changeset
|
210 %!error <F2 must be a directory> movefile ({"a", "b"}, "%_NOT_A_DIR_%") |
28104
b2e0a2ddfd7d
movefile.m: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
211 %!error <no files to move> movefile ("%_NOT_A_FILENAME1_%", "%_NOT_A_FILENAME2_%") |