Mercurial > octave
annotate libinterp/corefcn/dirfns.cc @ 33617:ec2635a02328 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 21 May 2024 18:29:03 +0200 |
parents | 2e484f9f1f18 |
children |
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 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32080
diff
changeset
|
3 // Copyright (C) 1994-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
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/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
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 //////////////////////////////////////////////////////////////////////// |
523 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21696
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
523 | 28 #endif |
29 | |
1341 | 30 #include <cerrno> |
31 #include <cstdio> | |
32 #include <cstddef> | |
33 #include <cstdlib> | |
34 #include <cstring> | |
35 | |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
2926 | 39 #include "file-ops.h" |
40 #include "file-stat.h" | |
41 #include "glob-match.h" | |
32080
e9fdfebc6db0
Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31706
diff
changeset
|
42 #include "lo-sysdep.h" |
2926 | 43 #include "oct-env.h" |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
44 #include "oct-glob.h" |
5777 | 45 #include "pathsearch.h" |
1755 | 46 #include "str-vec.h" |
47 | |
5102 | 48 #include "Cell.h" |
1355 | 49 #include "defun.h" |
1781 | 50 #include "dir-ops.h" |
1355 | 51 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
52 #include "errwarn.h" |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
53 #include "event-manager.h" |
5640 | 54 #include "input.h" |
5832 | 55 #include "load-path.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
56 #include "octave.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
57 #include "ovl.h" |
1355 | 58 #include "pager.h" |
59 #include "procstream.h" | |
60 #include "sysdep.h" | |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22089
diff
changeset
|
61 #include "interpreter.h" |
1449 | 62 #include "unwind-prot.h" |
523 | 63 #include "utils.h" |
1742 | 64 #include "variables.h" |
523 | 65 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31028
diff
changeset
|
66 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
67 |
5640 | 68 // TRUE means we ask for confirmation before recursively removing a |
69 // directory tree. | |
70 static bool Vconfirm_recursive_rmdir = true; | |
71 | |
27408
9b19eec60931
move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents:
27395
diff
changeset
|
72 DEFMETHOD (cd, interp, args, nargout, |
9b19eec60931
move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents:
27395
diff
changeset
|
73 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
74 @deftypefn {} {} cd @var{dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
75 @deftypefnx {} {} cd |
27190
8ebe70b98e97
cd: only change to home directory if nargin and nargout are zero (bug #41275)
Michael C. Grant <mcg@cvxr.com>
parents:
26376
diff
changeset
|
76 @deftypefnx {} {@var{old_dir} =} cd |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
77 @deftypefnx {} {@var{old_dir} =} cd (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
78 @deftypefnx {} {} chdir @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
79 Change the current working directory to @var{dir}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
80 |
27190
8ebe70b98e97
cd: only change to home directory if nargin and nargout are zero (bug #41275)
Michael C. Grant <mcg@cvxr.com>
parents:
26376
diff
changeset
|
81 If called with no input or output arguments, the current directory is |
8ebe70b98e97
cd: only change to home directory if nargin and nargout are zero (bug #41275)
Michael C. Grant <mcg@cvxr.com>
parents:
26376
diff
changeset
|
82 changed to the user's home directory (@qcode{"~"}). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
83 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
84 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
85 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
86 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
87 cd ~/octave |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
88 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
89 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
90 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
91 changes the current working directory to @file{~/octave}. If the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
92 directory does not exist, an error message is printed and the working |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
93 directory is not changed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
94 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
95 Programming Note: @code{chdir} is an alias for @code{cd} and can be used with |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
96 all of the same calling formats. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
97 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
98 Compatibility Note: When called with no arguments, @sc{matlab} prints the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
99 present working directory rather than changing to the user's home directory. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
100 @seealso{pwd, mkdir, rmdir, dir, ls} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
101 @end deftypefn */) |
523 | 102 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
103 int nargin = args.length (); |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
104 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
105 if (nargin > 1) |
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
106 print_usage (); |
523 | 107 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
108 octave_value_list retval; |
1755 | 109 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
110 if (nargout > 0) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
111 retval = octave_value (sys::env::get_current_directory ()); |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
112 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
113 if (nargin == 1) |
523 | 114 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
115 std::string dirname = args(0).xstring_value ("cd: DIR must be a string"); |
523 | 116 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
117 if (! dirname.empty ()) |
27408
9b19eec60931
move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents:
27395
diff
changeset
|
118 interp.chdir (dirname); |
523 | 119 } |
27190
8ebe70b98e97
cd: only change to home directory if nargin and nargout are zero (bug #41275)
Michael C. Grant <mcg@cvxr.com>
parents:
26376
diff
changeset
|
120 else if (nargout == 0) |
523 | 121 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
122 std::string home_dir = sys::env::get_home_directory (); |
2926 | 123 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
124 if (! home_dir.empty ()) |
27408
9b19eec60931
move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents:
27395
diff
changeset
|
125 interp.chdir (home_dir); |
523 | 126 } |
127 | |
128 return retval; | |
129 } | |
130 | |
611 | 131 DEFALIAS (chdir, cd); |
132 | |
6482 | 133 DEFUN (pwd, , , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
134 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
135 @deftypefn {} {@var{dir} =} pwd () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
136 Return the current working directory. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
137 @seealso{cd, dir, ls, mkdir, rmdir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
138 @end deftypefn */) |
523 | 139 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
140 return ovl (sys::env::get_current_directory ()); |
523 | 141 } |
142 | |
1957 | 143 DEFUN (readdir, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
144 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
145 @deftypefn {} {@var{files} =} readdir (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
146 @deftypefnx {} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
147 Return the names of files in the directory @var{dir} as a cell array of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
148 strings. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
149 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
150 If an error occurs, return an empty cell array in @var{files}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
151 If successful, @var{err} is 0 and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
152 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
153 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
154 @seealso{ls, dir, glob, what} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
155 @end deftypefn */) |
1389 | 156 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
157 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
158 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
159 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
160 std::string dirname = args(0).xstring_value ("readdir: DIR must be a string"); |
2669 | 161 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
162 octave_value_list retval = ovl (Cell (), -1.0, ""); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
163 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
164 dirname = sys::file_ops::tilde_expand (dirname); |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
165 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25407
diff
changeset
|
166 string_vector dirlist; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25407
diff
changeset
|
167 std::string msg; |
1389 | 168 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
169 if (sys::get_dirlist (dirname, dirlist, msg)) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
170 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
171 retval(0) = Cell (dirlist.sort ()); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
172 retval(1) = 0.0; |
1389 | 173 } |
174 else | |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25407
diff
changeset
|
175 retval(2) = msg; |
1389 | 176 |
1401 | 177 return retval; |
178 } | |
179 | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
180 // FIXME: should maybe also allow second arg to specify mode? |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
181 // OTOH, that might cause trouble with compatibility later... |
1401 | 182 |
21696
b8c05cc524ef
mkdir.m: new script to implement recursive mkdir (bug #30650).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
183 DEFUN (__mkdir__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
184 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
185 @deftypefn {} {} __mkdir__ (@var{dir}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
186 @deftypefnx {} {} __mkdir__ (@var{parent}, @var{dir}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
187 @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} __mkdir__ (@dots{}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
188 Internal function called by mkdir.m. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
189 @seealso{mkdir, rmdir, pwd, cd, umask} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
190 @end deftypefn */) |
1401 | 191 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
192 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
193 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
194 if (nargin < 1 || nargin > 2) |
21696
b8c05cc524ef
mkdir.m: new script to implement recursive mkdir (bug #30650).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
195 print_usage ("mkdir"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
196 |
6187 | 197 std::string dirname; |
198 | |
199 if (nargin == 2) | |
1401 | 200 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
201 std::string parent = args(0).xstring_value ("mkdir: PARENT must be a string"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
202 std::string dir = args(1).xstring_value ("mkdir: DIR must be a string"); |
1401 | 203 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
204 dirname = sys::file_ops::concat (parent, dir); |
6187 | 205 } |
6200 | 206 else if (nargin == 1) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
207 dirname = args(0).xstring_value ("mkdir: DIR must be a string"); |
6187 | 208 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
209 dirname = sys::file_ops::tilde_expand (dirname); |
6187 | 210 |
32080
e9fdfebc6db0
Avoid using file_stat in libinterp/corefcn (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31706
diff
changeset
|
211 if (sys::dir_exists (dirname)) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
212 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
213 // For Matlab compatibility, return true when directory already exists. |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
214 return ovl (true, "directory exists", "mkdir"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
215 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
216 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
217 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
218 std::string msg; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
219 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
220 int status = sys::mkdir (dirname, 0777, msg); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
221 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
222 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
223 return ovl (false, msg, "mkdir"); |
6187 | 224 else |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
225 return ovl (true, "", ""); |
1401 | 226 } |
227 } | |
228 | |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
229 DEFMETHODX ("rmdir", Frmdir, interp, args, nargout, |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
230 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
231 @deftypefn {} {} rmdir @var{dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
232 @deftypefnx {} {} rmdir (@var{dir}, "s") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
233 @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
234 Remove the directory named @var{dir}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
235 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
236 If the optional second parameter is supplied with value @qcode{"s"}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
237 recursively remove all subdirectories as well. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
238 |
30241
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
239 If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are empty |
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
240 character strings (""). Otherwise, @var{status} is logical 0, @var{msg} |
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
241 contains a system-dependent error message, and @var{msgid} contains a unique |
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
242 message identifier. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
243 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
244 @seealso{mkdir, confirm_recursive_rmdir, pwd} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
245 @end deftypefn */) |
1401 | 246 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
247 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
248 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
249 if (nargin < 1 || nargin > 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
250 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
251 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
252 std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); |
5476 | 253 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
254 std::string fulldir = sys::file_ops::tilde_expand (dirname); |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
255 octave_value_list retval; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
256 int status = -1; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
257 std::string msg; |
1401 | 258 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
259 event_manager& evmgr = interp.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27190
diff
changeset
|
260 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
261 if (nargin == 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
262 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
263 if (args(1).string_value () != "s") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23743
diff
changeset
|
264 error (R"(rmdir: second argument must be "s" for recursive removal)"); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
265 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
266 bool doit = true; |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
267 |
27301
a2b1ba6c92d5
eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents:
27263
diff
changeset
|
268 if (interp.interactive () |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
269 && ! application::forced_interactive () |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
270 && Vconfirm_recursive_rmdir) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
271 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
272 input_system& input_sys = interp.get_input_system (); |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
273 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
274 std::string prompt = "remove entire contents of " + fulldir + "? "; |
5640 | 275 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
276 doit = input_sys.yes_or_no (prompt); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
277 } |
5640 | 278 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
279 if (doit) |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
280 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
281 evmgr.file_remove (fulldir, ""); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
282 status = sys::recursive_rmdir (fulldir, msg); |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
283 } |
1401 | 284 } |
1389 | 285 else |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
286 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
287 evmgr.file_remove (fulldir, ""); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
288 status = sys::rmdir (fulldir, msg); |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
289 } |
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
290 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
291 evmgr.file_renamed (status >= 0); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
292 |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
293 if (nargout == 0) |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
294 { |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
295 if (status < 0) |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
296 error ("rmdir: operation failed: %s", msg.c_str ()); |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
297 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
298 else |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
299 { |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
300 if (status < 0) |
30241
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
301 retval = ovl (false, msg, "rmdir"); |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
302 else |
30241
ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
Rik <rik@octave.org>
parents:
30001
diff
changeset
|
303 retval = ovl (true, "", ""); |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
304 } |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
305 |
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
306 return retval; |
1401 | 307 } |
308 | |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
309 DEFUNX ("link", Flink, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
310 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
311 @deftypefn {} {} link @var{old} @var{new} |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
312 @deftypefnx {} {[@var{status}, @var{msg}] =} link (@var{old}, @var{new}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
313 Create a new link (also known as a hard link) to an existing file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
314 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
315 If successful, @var{status} is 0 and @var{msg} is an empty string. |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
316 Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
317 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
318 @seealso{symlink, unlink, readlink, lstat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
319 @end deftypefn */) |
3710 | 320 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
321 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
322 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
323 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
324 std::string from = args(0).xstring_value ("link: OLD must be a string"); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
325 std::string to = args(1).xstring_value ("link: NEW must be a string"); |
3710 | 326 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
327 from = sys::file_ops::tilde_expand (from); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
328 to = sys::file_ops::tilde_expand (to); |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
329 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
330 octave_value_list retval; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
331 std::string msg; |
3710 | 332 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
333 int status = sys::link (from, to, msg); |
3710 | 334 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
335 if (nargout == 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
336 { |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
337 if (status < 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
338 error ("link: operation failed: %s", msg.c_str ()); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
339 } |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
340 else |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
341 { |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
342 if (status < 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
343 retval = ovl (-1.0, msg); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
344 else |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
345 retval = ovl (0.0, ""); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
346 } |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
347 |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
348 return retval; |
3710 | 349 } |
350 | |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
351 DEFUNX ("symlink", Fsymlink, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
352 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
353 @deftypefn {} {} symlink @var{old} @var{new} |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
354 @deftypefnx {} {[@var{status}, @var{msg}] =} symlink (@var{old}, @var{new}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
355 Create a symbolic link @var{new} which contains the string @var{old}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
356 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
357 If successful, @var{status} is 0 and @var{msg} is an empty string. |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
358 Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
359 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
360 @seealso{link, unlink, readlink, lstat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
361 @end deftypefn */) |
3710 | 362 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
363 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
364 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
365 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
366 std::string from = args(0).xstring_value ("symlink: OLD must be a string"); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
367 std::string to = args(1).xstring_value ("symlink: NEW must be a string"); |
3710 | 368 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
369 from = sys::file_ops::tilde_expand (from); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
370 to = sys::file_ops::tilde_expand (to); |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
371 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
372 octave_value_list retval; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
373 std::string msg; |
3710 | 374 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
375 int status = sys::symlink (from, to, msg); |
3710 | 376 |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
377 if (nargout == 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
378 { |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
379 if (status < 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
380 error ("symlink: operation failed: %s", msg.c_str ()); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
381 } |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
382 else |
28096
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
383 { |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
384 if (status < 0) |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
385 retval = ovl (-1.0, msg); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
386 else |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
387 retval = ovl (0.0, ""); |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
388 } |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
389 |
e8246b4a5459
link, symlink: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
390 return retval; |
3710 | 391 } |
392 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
393 DEFUNX ("readlink", Freadlink, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
394 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
395 @deftypefn {} {@var{result} =} readlink @var{symlink} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
396 @deftypefnx {} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
397 Read the value of the symbolic link @var{symlink}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
398 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
399 If successful, @var{result} contains the contents of the symbolic link |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
400 @var{symlink}, @var{err} is 0, and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
401 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
402 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
403 @seealso{lstat, symlink, link, unlink, delete} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
404 @end deftypefn */) |
3710 | 405 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
406 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
407 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
408 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
409 std::string symlink = args(0).xstring_value ("readlink: SYMLINK must be a string"); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
410 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
411 symlink = sys::file_ops::tilde_expand (symlink); |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
412 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
413 std::string result, msg; |
3710 | 414 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
415 int status = sys::readlink (symlink, result, msg); |
3710 | 416 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
417 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
418 return ovl ("", -1.0, msg); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
419 else |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
420 return ovl (result, status, ""); |
3710 | 421 } |
422 | |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
423 DEFMETHODX ("rename", Frename, interp, args, nargout, |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27190
diff
changeset
|
424 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
425 @deftypefn {} {} rename @var{old} @var{new} |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
426 @deftypefnx {} {[@var{status}, @var{msg}] =} rename (@var{old}, @var{new}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
427 Change the name of file @var{old} to @var{new}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
428 |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
429 If successful, @var{status} is 0 and @var{msg} is an empty string. |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
430 Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
431 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
432 @seealso{movefile, copyfile, ls, dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
433 @end deftypefn */) |
1401 | 434 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
435 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
436 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
437 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
438 std::string from = args(0).xstring_value ("rename: OLD must be a string"); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
439 std::string to = args(1).xstring_value ("rename: NEW must be a string"); |
1728 | 440 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
441 from = sys::file_ops::tilde_expand (from); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
442 to = sys::file_ops::tilde_expand (to); |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
443 |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
444 octave_value_list retval; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
445 std::string msg; |
1728 | 446 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
447 event_manager& evmgr = interp.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27190
diff
changeset
|
448 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
449 evmgr.file_remove (from, to); |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
450 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
451 int status = sys::rename (from, to, msg); |
2669 | 452 |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
453 evmgr.file_renamed (status >= 0); |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
454 |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
455 if (nargout == 0) |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
456 { |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
457 if (status < 0) |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
458 error ("rename: operation failed: %s", msg.c_str ()); |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
459 } |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
460 else |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
461 { |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
462 if (status < 0) |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
463 retval = ovl (-1.0, msg); |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
464 else |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
465 retval = ovl (0.0, ""); |
25742
d3c6de326bae
close/reload editor tab when file is (re)moved in gui terminal (bug #43922)
Torsten <mttl@mailbox.org>
parents:
25516
diff
changeset
|
466 } |
28099
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
467 |
ce660f584f00
rename: throw error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28097
diff
changeset
|
468 return retval; |
1389 | 469 } |
470 | |
2495 | 471 DEFUN (glob, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
472 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
473 @deftypefn {} {@var{cstr} =} glob (@var{pattern}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
474 Given an array of pattern strings (as a char array or a cell array) in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
475 @var{pattern}, return a cell array of filenames that match any of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
476 them, or an empty cell array if no patterns match. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
477 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
478 The pattern strings are interpreted as filename globbing patterns (as they |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
479 are used by Unix shells). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
480 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
481 Within a pattern |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
482 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
483 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
484 @item * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
485 matches any string, including the null string, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
486 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
487 @item ? |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
488 matches any single character, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
489 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
490 @item [@dots{}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
491 matches any of the enclosed characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
492 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
493 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
494 Tilde expansion is performed on each of the patterns before looking for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
495 matching filenames. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
496 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
497 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
498 ls |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
499 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
500 file1 file2 file3 myfile1 myfile1b |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
501 glob ("*file1") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
502 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
503 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
504 [1,1] = file1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
505 [2,1] = myfile1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
506 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
507 glob ("myfile?") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
508 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
509 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
510 [1,1] = myfile1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
511 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
512 glob ("file[12]") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
513 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
514 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
515 [1,1] = file1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
516 [2,1] = file2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
517 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
518 @end example |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
519 |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
520 Note: On Windows, patterns that contain non-ASCII characters are not |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
521 supported. |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
522 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
523 @seealso{ls, dir, readdir, what} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
524 @end deftypefn */) |
2495 | 525 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
526 if (args.length () != 1) |
5823 | 527 print_usage (); |
2495 | 528 |
28869
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
529 string_vector pat |
4e64416772f1
Use Windows wide character API for __wglob__ (bug #59231).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28099
diff
changeset
|
530 = args(0).xstring_vector_value ("glob: PATTERN must be a string"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
531 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
532 glob_match pattern (sys::file_ops::tilde_expand (pat)); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
533 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
534 return ovl (Cell (pattern.glob ())); |
2495 | 535 } |
536 | |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
537 /* |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
538 %!test |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
539 %! tmpdir = tempname (); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
540 %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
541 %! if (mkdir (tmpdir)) |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
542 %! cwd = pwd (); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
543 %! cd (tmpdir); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
544 %! if (strcmp (canonicalize_file_name (pwd), canonicalize_file_name (tmpdir))) |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
545 %! a = 0; |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
546 %! for n = 1:5 |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
547 %! save (filename{n}, "a"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
548 %! endfor |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
549 %! else |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
550 %! sts = rmdir (tmpdir); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
551 %! error ("Couldn't change to temporary directory"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
552 %! endif |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
553 %! else |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
554 %! error ("Couldn't create temporary directory"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
555 %! endif |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
556 %! result1 = glob ("*file1"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
557 %! result2 = glob ("myfile?"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
558 %! result3 = glob ("file[12]"); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
559 %! for n = 1:5 |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
560 %! delete (filename{n}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
561 %! endfor |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
562 %! cd (cwd); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
563 %! sts = rmdir (tmpdir); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
564 %! assert (result1, {"file1"; "myfile1"}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
565 %! assert (result2, {"myfile1"}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
566 %! assert (result3, {"file1"; "file2"}); |
31027
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
567 |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
568 ## Check backslash handling on Windows |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
569 %!testif ; ispc () |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
570 %! win_dir = getenv ("WINDIR"); |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
571 %! assert (glob (win_dir), {win_dir}); |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
572 %! assert (glob ([win_dir, filesep]), {[win_dir, filesep]}); |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
573 %! win_dir2 = strrep(win_dir, filesep, '/'); |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
574 %! assert (glob (win_dir2), {win_dir}); |
72786e150001
oct-glob.cc: Fix yet another typo in 8475b51b990c.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31018
diff
changeset
|
575 %! assert (glob ([win_dir2, '/']), {[win_dir, filesep]}); |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
576 */ |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
577 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
578 DEFUN (__wglob__, args, , |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
579 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
580 @deftypefn {} {@var{cstr} =} __wglob__ (@var{pattern}) |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
581 Windows-like glob for dir. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
582 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
583 Given an array of pattern strings (as a char array or a cell array) in |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
584 @var{pattern}, return a cell array of filenames that match any of |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
585 them, or an empty cell array if no patterns match. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
586 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
587 The pattern strings are interpreted as filename globbing patterns |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
588 (roughly as they are used by Windows dir). |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
589 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
590 Within a pattern |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
591 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
592 @table @code |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
593 @item * |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
594 matches any string, including the null string, |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
595 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
596 @item ? |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
597 matches any single character, and |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
598 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
599 @item *.* |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
600 matches any string, even if no . is present. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
601 @end table |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
602 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
603 Tilde expansion is performed on each of the patterns before looking for |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
604 matching filenames. For example: |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
605 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
606 @example |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
607 ls |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
608 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
609 file1 file2 file3 myfile1 myfile1b |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
610 glob ("*file1") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
611 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
612 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
613 [1,1] = file1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
614 [2,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
615 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
616 glob ("myfile?") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
617 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
618 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
619 [1,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
620 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
621 glob ("*.*") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
622 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
623 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
624 [1,1] = file1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
625 [2,1] = file2 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
626 [3,1] = file3 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
627 [4,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
628 [5,1] = myfile1b |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
629 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
630 @end example |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
631 @seealso{glob, dir} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
632 @end deftypefn */) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
633 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
634 if (args.length () == 0) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
635 return ovl (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
636 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
637 string_vector pat = args(0).string_vector_value (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
638 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
639 string_vector pattern (sys::file_ops::tilde_expand (pat)); |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
640 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
641 return ovl (Cell (sys::windows_glob (pattern))); |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
642 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
643 |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
644 /* |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
645 %!test <*62414> |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
646 %! ## get name of current directory and one file in it |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
647 %! [~, curr_dir, ext] = fileparts (pwd ()); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
648 %! curr_dir = [curr_dir, ext]; |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
649 %! files = dir (); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
650 %! if (numel (files) < 3) |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
651 %! return; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
652 %! endif |
30979
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
653 %! ## check some patterns including "." and ".." |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
654 %! file_in_pwd = files(3).name; |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
655 %! assert (__wglob__ (file_in_pwd), {file_in_pwd}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
656 %! glob_pattern = fullfile (".", file_in_pwd); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
657 %! assert (__wglob__ (glob_pattern), {glob_pattern}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
658 %! glob_pattern = fullfile ("..", curr_dir, file_in_pwd); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
659 %! assert (__wglob__ (glob_pattern), {glob_pattern}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
660 %! glob_pattern = fullfile ("..", curr_dir, "..", ".", curr_dir, ".", file_in_pwd); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
661 %! assert (__wglob__ (glob_pattern), {glob_pattern}); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
662 |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
663 %!test <*62414> |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
664 %! old_dir = cd (fileparts (which ("plot.m"))); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
665 %! unwind_protect |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
666 %! assert (__wglob__ (fullfile (".", "*.m")), ... |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
667 %! fullfile (".", __wglob__ ("*.m"))); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
668 %! unwind_protect_cleanup |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
669 %! cd (old_dir); |
302faf5bc425
__wglob__: Correctly handle "." and ".." in patterns on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
670 %! end_unwind_protect |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
671 |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
672 ## retain trailing file separator |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
673 %!test <*62414> |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
674 %! old_dir = cd (fileparts (which ("plot.m"))); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
675 %! unwind_protect |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
676 %! assert (__wglob__ ("private"), {"private"}); |
31018
4f2f81989d50
dirfns.cc: Fix typos in BIST.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31016
diff
changeset
|
677 %! assert (__wglob__ ("private/"), {["private", filesep()]}); |
4f2f81989d50
dirfns.cc: Fix typos in BIST.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31016
diff
changeset
|
678 %! assert (__wglob__ ("private///"), {["private", filesep()]}); |
31016
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
679 %! assert (__wglob__ ("./private"), {fullfile(".", "private")}); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
680 %! assert (__wglob__ ("./private/"), ... |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
681 %! {[fullfile(".", "private"), filesep()]}); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
682 %! assert (__wglob__ ("./private///"), ... |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
683 %! {[fullfile(".", "private"), filesep()]}); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
684 %! assert (__wglob__ (["./p*","/"]), ... |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
685 %! {[fullfile(".", "private"), filesep()]}); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
686 %! unwind_protect_cleanup |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
687 %! cd (old_dir); |
8475b51b990c
__wglob__: Retain trailing file separator on Windows (bug #62414).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30979
diff
changeset
|
688 %! end_unwind_protect |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
689 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
690 |
19119 | 691 DEFUN (__fnmatch__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
692 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
693 @deftypefn {} {@var{TF} =} fnmatch (@var{pattern}, @var{string}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
694 Return true or false for each element of @var{string} that matches any of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
695 the elements of the string array @var{pattern}, using the rules of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
696 filename pattern matching. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
697 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
698 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
699 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
700 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
701 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
702 fnmatch ("a*b", @{"ab"; "axyzb"; "xyzab"@}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
703 @result{} [ 1; 1; 0 ] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
704 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
705 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
706 @seealso{glob, regexp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
707 @end deftypefn */) |
2496 | 708 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
709 if (args.length () != 2) |
5823 | 710 print_usage (); |
2496 | 711 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
712 string_vector pat = args(0).string_vector_value (); |
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
713 string_vector str = args(1).string_vector_value (); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
714 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
715 glob_match pattern (sys::file_ops::tilde_expand (pat)); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
716 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
717 return ovl (pattern.match (str)); |
2496 | 718 } |
719 | |
5777 | 720 DEFUN (filesep, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
721 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30588
diff
changeset
|
722 @deftypefn {} {@var{sep} =} filesep () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
723 @deftypefnx {} {} filesep ("all") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
724 Return the system-dependent character used to separate directory names. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
725 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
726 If @qcode{"all"} is given, the function returns all valid file separators |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
727 in the form of a string. The list of file separators is system-dependent. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
728 It is @samp{/} (forward slash) under UNIX or @w{Mac OS X}, @samp{/} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
729 @samp{\} (forward and backward slashes) under Windows. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
730 @seealso{pathsep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
731 @end deftypefn */) |
5777 | 732 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
733 int nargin = args.length (); |
5777 | 734 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
735 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
736 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
737 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
738 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
739 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
740 if (nargin == 0) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
741 retval = sys::file_ops::dir_sep_str (); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
742 else |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
743 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
744 std::string s = args(0).xstring_value ("filesep: argument must be a string"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
745 if (s != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23743
diff
changeset
|
746 error (R"(filesep: argument must be "all")"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
747 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
748 retval = sys::file_ops::dir_sep_chars (); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
749 } |
5777 | 750 |
751 return retval; | |
752 } | |
753 | |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
754 DEFUN (pathsep, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
755 doc: /* -*- texinfo -*- |
24986
0b9e7fcaab91
doc: grammarcheck docstrings in C++ files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
756 @deftypefn {} {@var{val} =} pathsep () |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
757 Query the character used to separate directories in a path. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
758 @seealso{filesep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
759 @end deftypefn */) |
5777 | 760 { |
28946
ef2b0a00daef
maint: Don't declare nargin in C++ files if it is used only once.
Rik <rik@octave.org>
parents:
28894
diff
changeset
|
761 if (args.length () > 0) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
762 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
763 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
764 return ovl (directory_path::path_sep_str ()); |
5777 | 765 } |
766 | |
5794 | 767 DEFUN (confirm_recursive_rmdir, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
768 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
769 @deftypefn {} {@var{val} =} confirm_recursive_rmdir () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
770 @deftypefnx {} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val}) |
30588
ed17822e7662
doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
771 @deftypefnx {} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val}, "local") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
772 Query or set the internal variable that controls whether Octave |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
773 will ask for confirmation before recursively removing a directory tree. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
774 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
775 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
776 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
777 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
778 @seealso{rmdir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
779 @end deftypefn */) |
5640 | 780 { |
30001
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
781 return set_internal_variable (Vconfirm_recursive_rmdir, args, nargout, |
428cccc75cc9
move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
782 "confirm_recursive_rmdir"); |
4264 | 783 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
784 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31028
diff
changeset
|
785 OCTAVE_END_NAMESPACE(octave) |