Mercurial > octave
annotate libinterp/corefcn/dirfns.cc @ 20853:1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 12 Dec 2015 07:40:03 -0800 |
parents | 3d551b2ae928 |
children | f1b2a2dbc0e1 |
rev | line source |
---|---|
523 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19278
diff
changeset
|
3 Copyright (C) 1994-2015 John W. Eaton |
523 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
523 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
523 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
1192 | 24 #include <config.h> |
523 | 25 #endif |
26 | |
1341 | 27 #include <cerrno> |
28 #include <cstdio> | |
29 #include <cstddef> | |
30 #include <cstdlib> | |
31 #include <cstring> | |
32 | |
5765 | 33 #include <sstream> |
1728 | 34 #include <string> |
35 | |
1832 | 36 #include <sys/types.h> |
37 #include <unistd.h> | |
38 | |
2926 | 39 #include "file-ops.h" |
40 #include "file-stat.h" | |
41 #include "glob-match.h" | |
42 #include "oct-env.h" | |
5777 | 43 #include "pathsearch.h" |
1755 | 44 #include "str-vec.h" |
45 | |
5102 | 46 #include "Cell.h" |
1355 | 47 #include "defun.h" |
1781 | 48 #include "dir-ops.h" |
1355 | 49 #include "dirfns.h" |
50 #include "error.h" | |
1402 | 51 #include "gripes.h" |
5640 | 52 #include "input.h" |
5832 | 53 #include "load-path.h" |
16437
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
54 #include "octave-link.h" |
1750 | 55 #include "oct-obj.h" |
1355 | 56 #include "pager.h" |
57 #include "procstream.h" | |
58 #include "sysdep.h" | |
1750 | 59 #include "toplev.h" |
1449 | 60 #include "unwind-prot.h" |
523 | 61 #include "utils.h" |
1742 | 62 #include "variables.h" |
523 | 63 |
5640 | 64 // TRUE means we ask for confirmation before recursively removing a |
65 // directory tree. | |
66 static bool Vconfirm_recursive_rmdir = true; | |
67 | |
6323 | 68 // The time we last time we changed directories. |
69 octave_time Vlast_chdir_time = 0.0; | |
70 | |
1328 | 71 static int |
3523 | 72 octave_change_to_directory (const std::string& newdir) |
1328 | 73 { |
16437
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
74 std::string xdir = file_ops::tilde_expand (newdir); |
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
75 |
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
76 int cd_ok = octave_env::chdir (xdir); |
1328 | 77 |
78 if (cd_ok) | |
5832 | 79 { |
6323 | 80 Vlast_chdir_time.stamp (); |
81 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 // FIXME: should these actions be handled as a list of functions |
5832 | 83 // to call so users can add their own chdir handlers? |
84 | |
85 load_path::update (); | |
16437
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
86 |
16526
01541f7321f7
correctly track directory for cd ..
John W. Eaton <jwe@octave.org>
parents:
16437
diff
changeset
|
87 octave_link::change_directory (octave_env::get_current_directory ()); |
5832 | 88 } |
1328 | 89 else |
10411 | 90 error ("%s: %s", newdir.c_str (), gnulib::strerror (errno)); |
1328 | 91 |
92 return cd_ok; | |
93 } | |
94 | |
13912
8d19194c4b1f
cd: behave like unixy shells for "cd" alone, but be Matlab compatible if doing "current_dir = cd"
John W. Eaton <jwe@octave.org>
parents:
12681
diff
changeset
|
95 DEFUN (cd, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
97 @deftypefn {} {} cd @var{dir}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
98 @deftypefnx {} {} cd\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
99 @deftypefnx {} {@var{old_dir} =} cd (@var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
100 @deftypefnx {} {} chdir @dots{}\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
101 Change the current working directory to @var{dir}.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
102 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
103 If @var{dir} is omitted, the current directory is changed to the user's home\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
104 directory (@qcode{\"~\"}).\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
105 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
106 For example,\n\ |
523 | 107 \n\ |
3301 | 108 @example\n\ |
109 cd ~/octave\n\ | |
110 @end example\n\ | |
111 \n\ | |
112 @noindent\n\ | |
10840 | 113 changes the current working directory to @file{~/octave}. If the\n\ |
3301 | 114 directory does not exist, an error message is printed and the working\n\ |
115 directory is not changed.\n\ | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
116 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
117 @code{chdir} is an alias for @code{cd} and can be used in all of the same\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
118 calling formats.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
119 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
120 Compatibility Note: When called with no arguments, @sc{matlab} prints the\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
121 present working directory rather than changing to the user's home directory.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
122 @seealso{pwd, mkdir, rmdir, dir, ls}\n\ |
11547 | 123 @end deftypefn") |
523 | 124 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
125 int nargin = args.length (); |
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
126 |
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
127 if (nargin > 1) |
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
128 print_usage (); |
523 | 129 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
130 octave_value_list retval; |
1755 | 131 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
132 if (nargout > 0) |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
133 retval = octave_value (octave_env::get_current_directory ()); |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
134 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
135 if (nargin == 1) |
523 | 136 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
137 std::string dirname = args(0).xstring_value ("cd: DIR must be a string"); |
523 | 138 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
139 if (! dirname.empty ()) |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
140 octave_change_to_directory (dirname); |
523 | 141 } |
142 else | |
143 { | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
144 std::string home_dir = octave_env::get_home_directory (); |
2926 | 145 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
146 if (! home_dir.empty ()) |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
147 octave_change_to_directory (home_dir); |
523 | 148 } |
149 | |
150 return retval; | |
151 } | |
152 | |
611 | 153 DEFALIAS (chdir, cd); |
154 | |
6482 | 155 DEFUN (pwd, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
157 @deftypefn {} {} pwd ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
158 @deftypefnx {} {@var{dir} =} pwd ()\n\ |
3301 | 159 Return the current working directory.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
160 @seealso{cd, dir, ls, mkdir, rmdir}\n\ |
3301 | 161 @end deftypefn") |
523 | 162 { |
10250 | 163 return octave_value (octave_env::get_current_directory ()); |
523 | 164 } |
165 | |
1957 | 166 DEFUN (readdir, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
167 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
168 @deftypefn {} {@var{files} =} readdir (@var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
169 @deftypefnx {} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
170 Return the names of files in the directory @var{dir} as a cell array of\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
171 strings.\n\ |
1389 | 172 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
173 If an error occurs, return an empty cell array in @var{files}.\n\ |
3301 | 174 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
175 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
176 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
177 @seealso{ls, dir, glob, what}\n\ |
3301 | 178 @end deftypefn") |
1389 | 179 { |
2086 | 180 octave_value_list retval; |
1389 | 181 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
182 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
183 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
184 |
3523 | 185 retval(2) = std::string (); |
2669 | 186 retval(1) = -1.0; |
4691 | 187 retval(0) = Cell (); |
2669 | 188 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
189 std::string dirname = args(0).xstring_value ("readdir: DIR 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
|
190 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
191 dir_entry dir (dirname); |
1389 | 192 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
193 if (dir) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
194 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
195 string_vector dirlist = dir.read (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
196 retval(1) = 0.0; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
197 retval(0) = Cell (dirlist.sort ()); |
1389 | 198 } |
199 else | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
200 retval(2) = dir.error (); |
1389 | 201 |
1401 | 202 return retval; |
203 } | |
204 | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
205 // 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
|
206 // OTOH, that might cause trouble with compatibility later... |
1401 | 207 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
208 DEFUNX ("mkdir", Fmkdir, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
209 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
210 @deftypefn {} {} mkdir @var{dir}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
211 @deftypefnx {} {} mkdir (@var{parent}, @var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
212 @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@dots{})\n\ |
8109 | 213 Create a directory named @var{dir} in the directory @var{parent}.\n\ |
1401 | 214 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
215 If no @var{parent} directory is specified the present working directory is\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
216 used.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
217 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
218 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
219 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
220 system-dependent error message, and @var{msgid} contains a unique message\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
221 identifier.\n\ |
20198
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20178
diff
changeset
|
222 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20178
diff
changeset
|
223 When creating a directory permissions will be set to\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20178
diff
changeset
|
224 @code{0777 - @var{umask}}.\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20178
diff
changeset
|
225 @seealso{rmdir, pwd, cd, umask}\n\ |
3301 | 226 @end deftypefn") |
1401 | 227 { |
2086 | 228 octave_value_list retval; |
1401 | 229 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
230 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
231 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
232 if (nargin < 1 || nargin > 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
233 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
234 |
5476 | 235 retval(2) = std::string (); |
3523 | 236 retval(1) = std::string (); |
5476 | 237 retval(0) = false; |
1401 | 238 |
6187 | 239 std::string dirname; |
240 | |
241 if (nargin == 2) | |
1401 | 242 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
243 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
|
244 std::string dir = args(1).xstring_value ("mkdir: DIR must be a string"); |
1401 | 245 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
246 dirname = file_ops::concat (parent, dir); |
6187 | 247 } |
6200 | 248 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
|
249 dirname = args(0).xstring_value ("mkdir: DIR must be a string"); |
6187 | 250 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
251 std::string msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
252 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
253 dirname = file_ops::tilde_expand (dirname); |
6187 | 254 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
255 file_stat fs (dirname); |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
256 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
257 if (fs && fs.is_dir ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
258 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
259 // For compatibility with Matlab, we return true when the |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
260 // directory already exists. |
1489 | 261 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
262 retval(2) = "mkdir"; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
263 retval(1) = "directory exists"; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
264 retval(0) = true; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
265 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
266 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
267 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
268 int status = octave_mkdir (dirname, 0777, msg); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
269 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
270 if (status < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
271 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
272 retval(2) = "mkdir"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
273 retval(1) = msg; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
274 } |
6187 | 275 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
276 retval(0) = true; |
1401 | 277 } |
278 | |
279 return retval; | |
280 } | |
281 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
282 DEFUNX ("rmdir", Frmdir, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
283 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
284 @deftypefn {} {} rmdir @var{dir}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
285 @deftypefnx {} {} rmdir (@var{dir}, \"s\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
286 @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{})\n\ |
3301 | 287 Remove the directory named @var{dir}.\n\ |
1401 | 288 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
289 If the optional second parameter is supplied with value @qcode{\"s\"},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
290 recursively remove all subdirectories as well.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
291 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
292 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
293 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
294 system-dependent error message, and @var{msgid} contains a unique message\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
295 identifier.\n\ |
5476 | 296 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
297 @seealso{mkdir, confirm_recursive_rmdir, pwd}\n\ |
3301 | 298 @end deftypefn") |
1401 | 299 { |
2086 | 300 octave_value_list retval; |
1401 | 301 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
302 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
303 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
304 if (nargin < 1 || nargin > 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
305 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
306 |
5476 | 307 retval(2) = std::string (); |
3523 | 308 retval(1) = std::string (); |
5476 | 309 retval(0) = false; |
1401 | 310 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
311 std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); |
5476 | 312 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
313 std::string fulldir = file_ops::tilde_expand (dirname); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
314 int status = -1; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
315 std::string msg; |
1401 | 316 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
317 if (nargin == 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
318 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
319 if (args(1).string_value () == "s") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
320 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
321 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
|
322 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
323 if (interactive && ! forced_interactive |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
324 && Vconfirm_recursive_rmdir) |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
325 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
326 std::string prompt |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
327 = "remove entire contents of " + fulldir + "? "; |
5640 | 328 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
329 doit = octave_yes_or_no (prompt); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
330 } |
5640 | 331 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
332 if (doit) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
333 status = octave_recursive_rmdir (fulldir, msg); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
334 } |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
335 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
336 error ("rmdir: second argument must be \"s\" for recursive removal"); |
1401 | 337 } |
1389 | 338 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
339 status = octave_rmdir (fulldir, msg); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
340 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
341 if (status < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
342 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
343 retval(2) = "rmdir"; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
344 retval(1) = msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
345 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
346 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
347 retval(0) = true; |
1401 | 348 |
349 return retval; | |
350 } | |
351 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
352 DEFUNX ("link", Flink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
353 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
354 @deftypefn {} {} link @var{old} @var{new}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
355 @deftypefnx {} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ |
3710 | 356 Create a new link (also known as a hard link) to an existing file.\n\ |
357 \n\ | |
358 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
359 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
360 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
361 @seealso{symlink, unlink, readlink, lstat}\n\ |
3710 | 362 @end deftypefn") |
363 { | |
364 octave_value_list retval; | |
365 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
366 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
367 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
368 |
3710 | 369 retval(1) = std::string (); |
370 retval(0) = -1.0; | |
371 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
372 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
|
373 std::string to = args(1).xstring_value ("link: NEW must be a string"); |
3710 | 374 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
375 std::string msg; |
3710 | 376 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
377 int status = octave_link (from, to, msg); |
3710 | 378 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
379 if (status < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
380 retval(1) = msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
381 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
382 retval(0) = status; |
3710 | 383 |
384 return retval; | |
385 } | |
386 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
387 DEFUNX ("symlink", Fsymlink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
388 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
389 @deftypefn {} {} symlink @var{old} @var{new}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
390 @deftypefnx {} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ |
3710 | 391 Create a symbolic link @var{new} which contains the string @var{old}.\n\ |
392 \n\ | |
393 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
394 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
395 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
396 @seealso{link, unlink, readlink, lstat}\n\ |
3710 | 397 @end deftypefn") |
398 { | |
399 octave_value_list retval; | |
400 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
401 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
402 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
403 |
3710 | 404 retval(1) = std::string (); |
405 retval(0) = -1.0; | |
406 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
407 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
|
408 std::string to = args(1).xstring_value ("symlink: NEW must be a string"); |
3710 | 409 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
410 std::string msg; |
3710 | 411 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
412 int status = octave_symlink (from, to, msg); |
3710 | 413 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
414 if (status < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
415 retval(1) = msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
416 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
417 retval(0) = status; |
3710 | 418 |
419 return retval; | |
420 } | |
421 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
422 DEFUNX ("readlink", Freadlink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
423 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
424 @deftypefn {} {} readlink @var{symlink}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
425 @deftypefnx {} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\ |
3710 | 426 Read the value of the symbolic link @var{symlink}.\n\ |
427 \n\ | |
428 If successful, @var{result} contains the contents of the symbolic link\n\ | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
429 @var{symlink}, @var{err} is 0, and @var{msg} is an empty string.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
430 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
431 error message.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
432 @seealso{lstat, symlink, link, unlink, delete}\n\ |
3710 | 433 @end deftypefn") |
434 { | |
435 octave_value_list retval; | |
436 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
437 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
438 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
439 |
3710 | 440 retval(2) = std::string (); |
441 retval(1) = -1.0; | |
442 retval(0) = std::string (); | |
443 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
444 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
|
445 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
446 std::string result; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
447 std::string msg; |
3710 | 448 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
449 int status = octave_readlink (symlink, result, msg); |
3710 | 450 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
451 if (status < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
452 retval(2) = msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
453 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
454 retval(1) = status; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
455 retval(0) = result; |
3710 | 456 |
457 return retval; | |
458 } | |
459 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
460 DEFUNX ("rename", Frename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
462 @deftypefn {} {} rename @var{old} @var{new}\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
463 @deftypefnx {} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\ |
3301 | 464 Change the name of file @var{old} to @var{new}.\n\ |
1401 | 465 \n\ |
3301 | 466 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
467 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
468 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
469 @seealso{movefile, copyfile, ls, dir}\n\ |
3301 | 470 @end deftypefn") |
1401 | 471 { |
2086 | 472 octave_value_list retval; |
1401 | 473 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
474 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
475 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
476 |
3523 | 477 retval(1) = std::string (); |
2669 | 478 retval(0) = -1.0; |
1401 | 479 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
480 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
|
481 std::string to = args(1).xstring_value ("rename: NEW must be a string"); |
1728 | 482 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
483 std::string msg; |
1728 | 484 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
485 int status = octave_rename (from, to, msg); |
2669 | 486 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
487 if (status < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
488 retval(1) = msg; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
489 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
490 retval(0) = status; |
1401 | 491 |
1389 | 492 return retval; |
493 } | |
494 | |
2495 | 495 DEFUN (glob, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
496 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
497 @deftypefn {} {} glob (@var{pattern})\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
498 Given an array of pattern strings (as a char array or a cell array) in\n\ |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
499 @var{pattern}, return a cell array of filenames that match any of\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
500 them, or an empty cell array if no patterns match.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
501 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
502 The pattern strings are interpreted as filename globbing patterns (as they\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
503 are used by Unix shells).\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
504 \n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
505 Within a pattern\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
506 \n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
507 @table @code\n\ |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
508 @item *\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
509 matches any string, including the null string,\n\ |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16526
diff
changeset
|
510 \n\ |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
511 @item ?\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
512 matches any single character, and\n\ |
10840 | 513 \n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10411
diff
changeset
|
514 @item [@dots{}]\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
515 matches any of the enclosed characters.\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
516 @end table\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
517 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
518 Tilde expansion is performed on each of the patterns before looking for\n\ |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
519 matching filenames. For example:\n\ |
2495 | 520 \n\ |
3301 | 521 @example\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
522 ls\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
523 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
524 file1 file2 file3 myfile1 myfile1b\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
525 glob (\"*file1\")\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
526 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
527 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
528 [1,1] = file1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
529 [2,1] = myfile1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
530 @}\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
531 glob (\"myfile?\")\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
532 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
533 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
534 [1,1] = myfile1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
535 @}\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
536 glob (\"file[12]\")\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
537 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
538 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
539 [1,1] = file1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
540 [2,1] = file2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
541 @}\n\ |
3301 | 542 @end example\n\ |
19119 | 543 @seealso{ls, dir, readdir, what}\n\ |
5597 | 544 @end deftypefn") |
2495 | 545 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
546 if (args.length () != 1) |
5823 | 547 print_usage (); |
2495 | 548 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
549 string_vector pat = args(0).xall_strings ("glob: PATTERN must be a string"); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
550 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
551 glob_match pattern (file_ops::tilde_expand (pat)); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
552 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
553 return octave_value (Cell (pattern.glob ())); |
2495 | 554 } |
555 | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
556 /* |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
557 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19119
diff
changeset
|
558 %! tmpdir = tempname; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
559 %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
560 %! if (mkdir (tmpdir)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
561 %! cwd = pwd; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
562 %! cd (tmpdir); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
563 %! if (strcmp (canonicalize_file_name (pwd), canonicalize_file_name (tmpdir))) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
564 %! a = 0; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
565 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
566 %! save (filename{n}, "a"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
567 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
568 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
569 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
570 %! error ("Couldn't change to temporary dir"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
571 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
572 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
573 %! error ("Couldn't create temporary directory"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
574 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
575 %! result1 = glob ("*file1"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
576 %! result2 = glob ("myfile?"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
577 %! result3 = glob ("file[12]"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
578 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
579 %! delete (filename{n}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
580 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
581 %! cd (cwd); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
582 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
583 %! assert (result1, {"file1"; "myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
584 %! assert (result2, {"myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
585 %! assert (result3, {"file1"; "file2"}); |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
586 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
587 |
19119 | 588 DEFUN (__fnmatch__, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19849
diff
changeset
|
589 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
590 @deftypefn {} {} fnmatch (@var{pattern}, @var{string})\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
591 Return true or false for each element of @var{string} that matches any of\n\ |
3301 | 592 the elements of the string array @var{pattern}, using the rules of\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
593 \n\ |
10840 | 594 filename pattern matching. For example:\n\ |
2496 | 595 \n\ |
3301 | 596 @example\n\ |
597 @group\n\ | |
6233 | 598 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\ |
3301 | 599 @result{} [ 1; 1; 0 ]\n\ |
600 @end group\n\ | |
601 @end example\n\ | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
602 @seealso{glob, regexp}\n\ |
3301 | 603 @end deftypefn") |
2496 | 604 { |
605 octave_value retval; | |
606 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
607 if (args.length () != 2) |
5823 | 608 print_usage (); |
2496 | 609 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
610 string_vector pat = args(0).all_strings (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
611 string_vector str = args(1).all_strings (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
612 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
613 glob_match pattern (file_ops::tilde_expand (pat)); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
614 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
615 return octave_value (pattern.match (str)); |
2496 | 616 } |
617 | |
5777 | 618 DEFUN (filesep, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
619 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
620 @deftypefn {} {} filesep ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
621 @deftypefnx {} {} filesep (\"all\")\n\ |
5777 | 622 Return the system-dependent character used to separate directory names.\n\ |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
623 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
624 If @qcode{\"all\"} is given, the function returns all valid file separators\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
625 in the form of a string. The list of file separators is system-dependent.\n\ |
12668
e3dc23f7dd54
doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
626 It is @samp{/} (forward slash) under UNIX or @w{Mac OS X}, @samp{/} and\n\ |
e3dc23f7dd54
doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
627 @samp{\\} (forward and backward slashes) under Windows.\n\ |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
628 @seealso{pathsep}\n\ |
5777 | 629 @end deftypefn") |
630 { | |
631 octave_value retval; | |
632 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
633 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
634 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
635 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
636 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
637 if (nargin == 0) |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7970
diff
changeset
|
638 retval = 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
|
639 else |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
640 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
641 std::string s = args(0).xstring_value ("filesep: argument 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
|
642 if (s == "all") |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
643 retval = 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
|
644 else |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
645 error ("filesep: argument must be \"all\""); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
646 } |
5777 | 647 |
648 return retval; | |
649 } | |
650 | |
9266 | 651 DEFUN (pathsep, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
653 @deftypefn {} {@var{val} =} pathsep ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
654 @deftypefnx {} {@var{old_val} =} pathsep (@var{new_val})\n\ |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
655 Query or set the character used to separate directories in a path.\n\ |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
656 @seealso{filesep}\n\ |
5777 | 657 @end deftypefn") |
658 { | |
659 octave_value retval; | |
660 | |
9266 | 661 int nargin = args.length (); |
662 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
663 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
664 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
665 |
9266 | 666 if (nargout > 0 || nargin == 0) |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
667 retval = dir_path::path_sep_str (); |
9266 | 668 |
669 if (nargin == 1) | |
670 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
671 std::string sval = args(0).xstring_value ("pathsep: argument must be a single character"); |
9266 | 672 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
673 switch (sval.length ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
674 { |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
675 case 1: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
676 dir_path::path_sep_char (sval[0]); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
677 break; |
9266 | 678 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
679 case 0: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
680 dir_path::path_sep_char ('\0'); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
681 break; |
9266 | 682 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
683 default: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
684 error ("pathsep: argument must be a single character"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
685 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
686 } |
9266 | 687 } |
5777 | 688 |
689 return retval; | |
690 } | |
691 | |
5794 | 692 DEFUN (confirm_recursive_rmdir, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
693 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
694 @deftypefn {} {@var{val} =} confirm_recursive_rmdir ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
695 @deftypefnx {} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20817
diff
changeset
|
696 @deftypefnx {} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\ |
5794 | 697 Query or set the internal variable that controls whether Octave\n\ |
698 will ask for confirmation before recursively removing a directory tree.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13912
diff
changeset
|
699 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
700 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
701 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
702 The original variable value is restored when exiting the function.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
703 @seealso{rmdir}\n\ |
5794 | 704 @end deftypefn") |
5640 | 705 { |
5794 | 706 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); |
4264 | 707 } |