Mercurial > hg > octave-lyh
annotate src/dirfns.cc @ 13951:79aa00a94e9e
doc: Document "local" option for configuration variables.
* svd.cc, defaults.cc, dirfns.cc, error.cc, help.cc, input.cc, load-save.cc,
ls-oct-ascii.cc, oct-hist.cc, ov-base.cc, ov-range.cc, ov-struct.cc,
ov-usr-fcn.cc, pager.cc, pr-output.cc, pt-binop.cc, pt-eval.cc, pt-mat.cc,
sighandlers.cc, variables.cc: Document "local" option for configuration
variables.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 27 Nov 2011 16:07:13 -0800 |
parents | 8d19194c4b1f |
children | de90542b7afc |
rev | line source |
---|---|
523 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1994-2011 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" |
1750 | 54 #include "oct-obj.h" |
1355 | 55 #include "pager.h" |
56 #include "procstream.h" | |
57 #include "sysdep.h" | |
1750 | 58 #include "toplev.h" |
1449 | 59 #include "unwind-prot.h" |
523 | 60 #include "utils.h" |
1742 | 61 #include "variables.h" |
523 | 62 |
5640 | 63 // TRUE means we ask for confirmation before recursively removing a |
64 // directory tree. | |
65 static bool Vconfirm_recursive_rmdir = true; | |
66 | |
6323 | 67 // The time we last time we changed directories. |
68 octave_time Vlast_chdir_time = 0.0; | |
69 | |
1328 | 70 static int |
3523 | 71 octave_change_to_directory (const std::string& newdir) |
1328 | 72 { |
5979 | 73 int cd_ok = octave_env::chdir (file_ops::tilde_expand (newdir)); |
1328 | 74 |
75 if (cd_ok) | |
5832 | 76 { |
6323 | 77 Vlast_chdir_time.stamp (); |
78 | |
5832 | 79 // FIXME -- should this be handled as a list of functions |
80 // to call so users can add their own chdir handlers? | |
81 | |
82 load_path::update (); | |
83 } | |
1328 | 84 else |
10411 | 85 error ("%s: %s", newdir.c_str (), gnulib::strerror (errno)); |
1328 | 86 |
87 return cd_ok; | |
88 } | |
89 | |
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
|
90 DEFUN (cd, args, nargout, |
3301 | 91 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
92 @deftypefn {Command} {} cd dir\n\ |
11547 | 93 @deftypefnx {Command} {} chdir dir\n\ |
3301 | 94 Change the current working directory to @var{dir}. If @var{dir} is\n\ |
7001 | 95 omitted, the current directory is changed to the user's home\n\ |
3301 | 96 directory. For example,\n\ |
523 | 97 \n\ |
3301 | 98 @example\n\ |
99 cd ~/octave\n\ | |
100 @end example\n\ | |
101 \n\ | |
102 @noindent\n\ | |
10840 | 103 changes the current working directory to @file{~/octave}. If the\n\ |
3301 | 104 directory does not exist, an error message is printed and the working\n\ |
105 directory is not changed.\n\ | |
5597 | 106 @seealso{mkdir, rmdir, dir}\n\ |
11547 | 107 @end deftypefn") |
523 | 108 { |
2086 | 109 octave_value_list retval; |
523 | 110 |
1755 | 111 int argc = args.length () + 1; |
112 | |
1965 | 113 string_vector argv = args.make_argv ("cd"); |
1755 | 114 |
115 if (error_state) | |
116 return retval; | |
523 | 117 |
118 if (argc > 1) | |
119 { | |
5872 | 120 std::string dirname = argv[1]; |
523 | 121 |
1750 | 122 if (dirname.length () > 0 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
123 && ! octave_change_to_directory (dirname)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
124 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
125 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
126 } |
523 | 127 } |
128 else | |
129 { | |
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
|
130 // Behave like Unixy shells for "cd" by itself, but be Matlab |
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
|
131 // compatible if doing "current_dir = cd". |
2926 | 132 |
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
|
133 if (nargout == 0) |
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
|
134 { |
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
|
135 std::string home_dir = octave_env::get_home_directory (); |
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
|
136 |
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
|
137 if (home_dir.empty () || ! octave_change_to_directory (home_dir)) |
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
|
138 return retval; |
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
|
139 } |
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
|
140 else |
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
|
141 retval = octave_value (octave_env::get_current_directory ()); |
523 | 142 } |
143 | |
144 return retval; | |
145 } | |
146 | |
611 | 147 DEFALIAS (chdir, cd); |
148 | |
6482 | 149 DEFUN (pwd, , , |
3301 | 150 "-*- texinfo -*-\n\ |
151 @deftypefn {Built-in Function} {} pwd ()\n\ | |
152 Return the current working directory.\n\ | |
5597 | 153 @seealso{dir, ls}\n\ |
3301 | 154 @end deftypefn") |
523 | 155 { |
10250 | 156 return octave_value (octave_env::get_current_directory ()); |
523 | 157 } |
158 | |
1957 | 159 DEFUN (readdir, args, , |
3301 | 160 "-*- texinfo -*-\n\ |
161 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ | |
4691 | 162 Return names of the files in the directory @var{dir} as a cell array of\n\ |
163 strings. If an error occurs, return an empty cell array in @var{files}.\n\ | |
1389 | 164 \n\ |
3301 | 165 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
166 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
167 system-dependent error message.\n\ | |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
168 @seealso{ls, dir, glob}\n\ |
3301 | 169 @end deftypefn") |
1389 | 170 { |
2086 | 171 octave_value_list retval; |
1389 | 172 |
3523 | 173 retval(2) = std::string (); |
2669 | 174 retval(1) = -1.0; |
4691 | 175 retval(0) = Cell (); |
2669 | 176 |
1401 | 177 if (args.length () == 1) |
1389 | 178 { |
3523 | 179 std::string dirname = args(0).string_value (); |
1389 | 180 |
1401 | 181 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
182 gripe_wrong_type_arg ("readdir", args(0)); |
1401 | 183 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
184 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
185 dir_entry dir (dirname); |
1389 | 186 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
187 if (dir) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
188 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
189 string_vector dirlist = dir.read (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
190 retval(0) = Cell (dirlist.sort ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
191 retval(1) = 0.0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
192 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
193 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
194 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
195 retval(2) = dir.error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
196 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
197 } |
1389 | 198 } |
199 else | |
5823 | 200 print_usage (); |
1389 | 201 |
1401 | 202 return retval; |
203 } | |
204 | |
5775 | 205 // FIXME -- should maybe also allow second arg to specify |
5476 | 206 // mode? 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, , |
3301 | 209 "-*- texinfo -*-\n\ |
10840 | 210 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{dir})\n\ |
6192 | 211 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{parent}, @var{dir})\n\ |
8109 | 212 Create a directory named @var{dir} in the directory @var{parent}.\n\ |
1401 | 213 \n\ |
5476 | 214 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
215 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ | |
216 system-dependent error message, and @var{msgid} contains a unique\n\ | |
217 message identifier.\n\ | |
5597 | 218 @seealso{rmdir}\n\ |
3301 | 219 @end deftypefn") |
1401 | 220 { |
2086 | 221 octave_value_list retval; |
1401 | 222 |
5476 | 223 retval(2) = std::string (); |
3523 | 224 retval(1) = std::string (); |
5476 | 225 retval(0) = false; |
1401 | 226 |
6187 | 227 int nargin = args.length (); |
228 | |
229 std::string dirname; | |
230 | |
231 if (nargin == 2) | |
1401 | 232 { |
6187 | 233 std::string parent = args(0).string_value (); |
234 std::string dir = args(1).string_value (); | |
1401 | 235 |
236 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
238 gripe_wrong_type_arg ("mkdir", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
239 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
240 } |
6187 | 241 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 dirname = file_ops::concat (parent, dir); |
6187 | 243 } |
6200 | 244 else if (nargin == 1) |
6187 | 245 { |
246 dirname = args(0).string_value (); | |
2669 | 247 |
6187 | 248 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
249 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
250 gripe_wrong_type_arg ("mkdir", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
251 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
252 } |
6187 | 253 } |
254 | |
255 if (nargin == 1 || nargin == 2) | |
256 { | |
257 std::string msg; | |
258 | |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
259 dirname = file_ops::tilde_expand (dirname); |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
260 |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
261 file_stat fs (dirname); |
1489 | 262 |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
263 if (fs && fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
264 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
265 // For compatibility with Matlab, we return true when the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
266 // directory already exists. |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
267 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
268 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
269 retval(1) = "directory exists"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
270 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
271 } |
6187 | 272 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
273 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
274 int status = octave_mkdir (dirname, 0777, msg); |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
275 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
276 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
277 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
278 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
279 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
280 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
281 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
282 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
283 } |
1401 | 284 } |
285 else | |
5823 | 286 print_usage (); |
1401 | 287 |
288 return retval; | |
289 } | |
290 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
291 DEFUNX ("rmdir", Frmdir, args, , |
3301 | 292 "-*- texinfo -*-\n\ |
10840 | 293 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir})\n\ |
12681
c09ed93d1a8b
doc: Don't use @code{} within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
12668
diff
changeset
|
294 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir}, \"s\")\n\ |
3301 | 295 Remove the directory named @var{dir}.\n\ |
1401 | 296 \n\ |
5476 | 297 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
298 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ | |
299 system-dependent error message, and @var{msgid} contains a unique\n\ | |
300 message identifier.\n\ | |
301 \n\ | |
7007 | 302 If the optional second parameter is supplied with value @code{\"s\"},\n\ |
6134 | 303 recursively remove all subdirectories as well.\n\ |
5640 | 304 @seealso{mkdir, confirm_recursive_rmdir}\n\ |
3301 | 305 @end deftypefn") |
1401 | 306 { |
2086 | 307 octave_value_list retval; |
1401 | 308 |
5476 | 309 retval(2) = std::string (); |
3523 | 310 retval(1) = std::string (); |
5476 | 311 retval(0) = false; |
1401 | 312 |
5476 | 313 int nargin = args.length (); |
314 | |
315 if (nargin == 1 || nargin == 2) | |
1401 | 316 { |
3523 | 317 std::string dirname = args(0).string_value (); |
1401 | 318 |
319 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
320 gripe_wrong_type_arg ("rmdir", args(0)); |
1489 | 321 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
322 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
323 std::string fulldir = file_ops::tilde_expand (dirname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
324 int status = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
325 std::string msg; |
2669 | 326 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
327 if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
328 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
329 if (args(1).string_value () == "s") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
330 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
331 bool doit = true; |
5640 | 332 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
333 if (interactive && Vconfirm_recursive_rmdir) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
334 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
335 std::string prompt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
336 = "remove entire contents of " + fulldir + "? "; |
5640 | 337 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
338 doit = octave_yes_or_no (prompt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
339 } |
5640 | 340 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
341 if (doit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
342 status = octave_recursive_rmdir (fulldir, msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
343 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
344 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
345 error ("rmdir: expecting second argument to be \"s\""); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
346 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
347 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
348 status = octave_rmdir (fulldir, msg); |
2669 | 349 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
350 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
351 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
352 retval(2) = "rmdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
353 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
354 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
355 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
356 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
357 } |
1401 | 358 } |
1389 | 359 else |
5823 | 360 print_usage (); |
1401 | 361 |
362 return retval; | |
363 } | |
364 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
365 DEFUNX ("link", Flink, args, , |
3710 | 366 "-*- texinfo -*-\n\ |
367 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ | |
368 Create a new link (also known as a hard link) to an existing file.\n\ | |
369 \n\ | |
370 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
371 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
372 system-dependent error message.\n\ | |
5597 | 373 @seealso{symlink}\n\ |
3710 | 374 @end deftypefn") |
375 { | |
376 octave_value_list retval; | |
377 | |
378 retval(1) = std::string (); | |
379 retval(0) = -1.0; | |
380 | |
381 if (args.length () == 2) | |
382 { | |
383 std::string from = args(0).string_value (); | |
384 | |
385 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
386 gripe_wrong_type_arg ("link", args(0)); |
3710 | 387 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
388 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
389 std::string to = args(1).string_value (); |
3710 | 390 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
391 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
392 gripe_wrong_type_arg ("link", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
393 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
394 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
395 std::string msg; |
3710 | 396 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
397 int status = octave_link (from, to, msg); |
3710 | 398 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
399 retval(0) = status; |
3710 | 400 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
401 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
402 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
404 } |
3710 | 405 } |
406 else | |
5823 | 407 print_usage (); |
3710 | 408 |
409 return retval; | |
410 } | |
411 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
412 DEFUNX ("symlink", Fsymlink, args, , |
3710 | 413 "-*- texinfo -*-\n\ |
414 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ | |
415 Create a symbolic link @var{new} which contains the string @var{old}.\n\ | |
416 \n\ | |
417 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
418 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
419 system-dependent error message.\n\ | |
5597 | 420 @seealso{link, readlink}\n\ |
3710 | 421 @end deftypefn") |
422 { | |
423 octave_value_list retval; | |
424 | |
425 retval(1) = std::string (); | |
426 retval(0) = -1.0; | |
427 | |
428 if (args.length () == 2) | |
429 { | |
430 std::string from = args(0).string_value (); | |
431 | |
432 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
433 gripe_wrong_type_arg ("symlink", args(0)); |
3710 | 434 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
435 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
436 std::string to = args(1).string_value (); |
3710 | 437 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
438 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
439 gripe_wrong_type_arg ("symlink", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
440 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
442 std::string msg; |
3710 | 443 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
444 int status = octave_symlink (from, to, msg); |
3710 | 445 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
446 retval(0) = status; |
3710 | 447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
448 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
449 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
450 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
451 } |
3710 | 452 } |
453 else | |
5823 | 454 print_usage (); |
3710 | 455 |
456 return retval; | |
457 } | |
458 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
459 DEFUNX ("readlink", Freadlink, args, , |
3710 | 460 "-*- texinfo -*-\n\ |
4169 | 461 @deftypefn {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\ |
3710 | 462 Read the value of the symbolic link @var{symlink}.\n\ |
463 \n\ | |
464 If successful, @var{result} contains the contents of the symbolic link\n\ | |
465 @var{symlink}, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
466 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
467 system-dependent error message.\n\ | |
5597 | 468 @seealso{link, symlink}\n\ |
3710 | 469 @end deftypefn") |
470 { | |
471 octave_value_list retval; | |
472 | |
473 retval(2) = std::string (); | |
474 retval(1) = -1.0; | |
475 retval(0) = std::string (); | |
476 | |
477 if (args.length () == 1) | |
478 { | |
479 std::string symlink = args(0).string_value (); | |
480 | |
481 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
482 gripe_wrong_type_arg ("readlink", args(0)); |
3710 | 483 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
484 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
485 std::string result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
486 std::string msg; |
3710 | 487 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
488 int status = octave_readlink (symlink, result, msg); |
3710 | 489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
490 retval(0) = result; |
3710 | 491 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
492 retval(1) = status; |
3710 | 493 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
494 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
495 retval(2) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
496 } |
3710 | 497 } |
498 else | |
5823 | 499 print_usage (); |
3710 | 500 |
501 return retval; | |
502 } | |
503 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
504 DEFUNX ("rename", Frename, args, , |
3301 | 505 "-*- texinfo -*-\n\ |
506 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\ | |
507 Change the name of file @var{old} to @var{new}.\n\ | |
1401 | 508 \n\ |
3301 | 509 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
510 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
511 system-dependent error message.\n\ | |
5597 | 512 @seealso{ls, dir}\n\ |
3301 | 513 @end deftypefn") |
1401 | 514 { |
2086 | 515 octave_value_list retval; |
1401 | 516 |
3523 | 517 retval(1) = std::string (); |
2669 | 518 retval(0) = -1.0; |
1401 | 519 |
520 if (args.length () == 2) | |
521 { | |
3523 | 522 std::string from = args(0).string_value (); |
1728 | 523 |
1401 | 524 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
525 gripe_wrong_type_arg ("rename", args(0)); |
1402 | 526 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
527 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
528 std::string to = args(1).string_value (); |
1728 | 529 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
530 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
531 gripe_wrong_type_arg ("rename", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
532 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
533 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
534 std::string msg; |
2669 | 535 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
536 int status = octave_rename (from, to, msg); |
2669 | 537 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
538 retval(0) = status; |
2669 | 539 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
540 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
541 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
542 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
543 } |
1401 | 544 } |
545 else | |
5823 | 546 print_usage (); |
1401 | 547 |
1389 | 548 return retval; |
549 } | |
550 | |
2495 | 551 DEFUN (glob, args, , |
3301 | 552 "-*- texinfo -*-\n\ |
553 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
554 Given an array of pattern strings (as a char array or a cell array) in\n\ |
5444 | 555 @var{pattern}, return a cell array of file names that match any of\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12211
diff
changeset
|
556 them, or an empty cell array if no patterns match. The pattern strings are\n\ |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
557 interpreted as filename globbing patterns (as they are used by Unix shells).\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
558 Within a pattern\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
559 @table @code\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
560 @itemx *\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
561 matches any string, including the null string,\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
562 @itemx ?\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
563 matches any single character, and\n\ |
10840 | 564 \n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10411
diff
changeset
|
565 @item [@dots{}]\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
566 matches any of the enclosed characters.\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
567 @end table\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
568 \n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
569 Tilde expansion\n\ |
5444 | 570 is performed on each of the patterns before looking for matching file\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
571 names. For example:\n\ |
2495 | 572 \n\ |
3301 | 573 @example\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
574 ls\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
575 @result{}\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12211
diff
changeset
|
576 file1 file2 file3 myfile1 myfile1b\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
577 glob (\"*file1\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
578 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
579 @{\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
580 [1,1] = file1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
581 [2,1] = myfile1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
582 @}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
583 glob (\"myfile?\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
584 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
585 @{\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
586 [1,1] = myfile1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
587 @}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
588 glob (\"file[12]\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
589 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
590 @{\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
591 [1,1] = file1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
592 [2,1] = file2\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
593 @}\n\ |
3301 | 594 @end example\n\ |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
595 @seealso{ls, dir, readdir}\n\ |
5597 | 596 @end deftypefn") |
2495 | 597 { |
598 octave_value retval; | |
599 | |
600 if (args.length () == 1) | |
601 { | |
602 string_vector pat = args(0).all_strings (); | |
603 | |
604 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
605 gripe_wrong_type_arg ("glob", args(0)); |
2495 | 606 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
607 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
608 glob_match pattern (file_ops::tilde_expand (pat)); |
2495 | 609 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
610 retval = Cell (pattern.glob ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
611 } |
2495 | 612 } |
613 else | |
5823 | 614 print_usage (); |
2495 | 615 |
616 return retval; | |
617 } | |
618 | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
619 /* |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
620 %!test |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
621 %! tmpdir = tmpnam; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
622 %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
623 %! if (mkdir (tmpdir)) |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
624 %! cwd = pwd; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
625 %! cd (tmpdir); |
10348
df1df5f0c236
Make test of glob function more robust.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
10335
diff
changeset
|
626 %! if strcmp (canonicalize_file_name (pwd), ... |
df1df5f0c236
Make test of glob function more robust.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
10335
diff
changeset
|
627 %! canonicalize_file_name (tmpdir)) |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
628 %! a = 0; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
629 %! for n = 1:5 |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
630 %! save (filename{n}, "a"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
631 %! endfor |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
632 %! else |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
633 %! rmdir (tmpdir); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
634 %! error ("Couldn't change to temporary dir"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
635 %! endif |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
636 %! else |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
637 %! error ("Couldn't create temporary directory"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
638 %! endif |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
639 %! result1 = glob ("*file1"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
640 %! result2 = glob ("myfile?"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
641 %! result3 = glob ("file[12]"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
642 %! for n = 1:5 |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
643 %! delete (filename{n}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
644 %! endfor |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
645 %! cd (cwd); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
646 %! rmdir (tmpdir); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
647 %! assert (result1, {"file1"; "myfile1"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
648 %! assert (result2, {"myfile1"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
649 %! assert (result3, {"file1"; "file2"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
650 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
651 |
11531
f976dd63129c
fnmatch: use DEFUNX until gnulib's fnmatch is C++ friendly
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
652 DEFUNX ("fnmatch", Ffnmatch, args, , |
3301 | 653 "-*- texinfo -*-\n\ |
654 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\ | |
655 Return 1 or zero for each element of @var{string} that matches any of\n\ | |
656 the elements of the string array @var{pattern}, using the rules of\n\ | |
10840 | 657 filename pattern matching. For example:\n\ |
2496 | 658 \n\ |
3301 | 659 @example\n\ |
660 @group\n\ | |
6233 | 661 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\ |
3301 | 662 @result{} [ 1; 1; 0 ]\n\ |
663 @end group\n\ | |
664 @end example\n\ | |
665 @end deftypefn") | |
2496 | 666 { |
667 octave_value retval; | |
668 | |
669 if (args.length () == 2) | |
670 { | |
671 string_vector pat = args(0).all_strings (); | |
672 string_vector str = args(1).all_strings (); | |
673 | |
674 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
675 gripe_wrong_type_arg ("fnmatch", args(0)); |
2496 | 676 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
677 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
678 glob_match pattern (file_ops::tilde_expand (pat)); |
2496 | 679 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
680 retval = pattern.match (str); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
681 } |
2496 | 682 } |
683 else | |
5823 | 684 print_usage (); |
2496 | 685 |
686 return retval; | |
687 } | |
688 | |
5777 | 689 DEFUN (filesep, args, , |
5832 | 690 "-*- texinfo -*-\n\ |
10840 | 691 @deftypefn {Built-in Function} {} filesep ()\n\ |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
692 @deftypefnx {Built-in Function} {} filesep ('all')\n\ |
5777 | 693 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
|
694 \n\ |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
695 If 'all' is given, the function returns all valid file separators in\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
696 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
|
697 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
|
698 @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
|
699 @seealso{pathsep}\n\ |
5777 | 700 @end deftypefn") |
701 { | |
702 octave_value retval; | |
703 | |
704 if (args.length () == 0) | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7970
diff
changeset
|
705 retval = file_ops::dir_sep_str (); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
706 else if (args.length () == 1) |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
707 { |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
708 std::string s = args(0).string_value (); |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
709 |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
710 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
711 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
712 if (s == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
713 retval = file_ops::dir_sep_chars (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
714 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
715 gripe_wrong_type_arg ("filesep", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
716 } |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
717 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
718 gripe_wrong_type_arg ("filesep", args(0)); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
719 } |
5777 | 720 else |
5823 | 721 print_usage (); |
5777 | 722 |
723 return retval; | |
724 } | |
725 | |
9266 | 726 DEFUN (pathsep, args, nargout, |
5777 | 727 "-*- texinfo -*-\n\ |
10840 | 728 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\ |
9270
f9ac007bb926
fix typo in 9266:1d3b91166b9c
Jaroslav Hajek <highegg@gmail.com>
parents:
9266
diff
changeset
|
729 @deftypefnx {Built-in Function} {@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
|
730 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
|
731 @seealso{filesep}\n\ |
5777 | 732 @end deftypefn") |
733 { | |
734 octave_value retval; | |
735 | |
9266 | 736 int nargin = args.length (); |
737 | |
738 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
|
739 retval = dir_path::path_sep_str (); |
9266 | 740 |
741 if (nargin == 1) | |
742 { | |
743 std::string sval = args(0).string_value (); | |
744 | |
745 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
746 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
747 switch (sval.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
749 case 1: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 dir_path::path_sep_char (sval[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
751 break; |
9266 | 752 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 case 0: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 dir_path::path_sep_char ('\0'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 break; |
9266 | 756 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
757 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
758 error ("pathsep: argument must be a single character"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
759 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
761 } |
9266 | 762 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
763 error ("pathsep: argument must be a single character"); |
9266 | 764 } |
765 else if (nargin > 1) | |
5823 | 766 print_usage (); |
5777 | 767 |
768 return retval; | |
769 } | |
770 | |
5794 | 771 DEFUN (confirm_recursive_rmdir, args, nargout, |
772 "-*- texinfo -*-\n\ | |
10840 | 773 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\ |
5794 | 774 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13912
diff
changeset
|
775 @deftypefnx {Built-in Function} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\ |
5794 | 776 Query or set the internal variable that controls whether Octave\n\ |
777 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
|
778 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13912
diff
changeset
|
779 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13912
diff
changeset
|
780 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13912
diff
changeset
|
781 variable value is restored when exiting the function.\n\ |
5794 | 782 @end deftypefn") |
5640 | 783 { |
5794 | 784 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); |
4264 | 785 } |