Mercurial > hg > octave-nkf
annotate src/dirfns.cc @ 10791:3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
interpreter/doccheck: New directory for spelling/grammar scripts.
interpreter/doccheck/README: Instructions for using scripts.
interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file.
interpreter/doccheck/aspell.conf: GNU Aspell configuration file for
Octave documentation.
interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary.
interpreter/doccheck/add_to_aspell_dict: Script to add new
Octave-specific words to
private Aspell dictionary.
interpreter/octave.texi: New @nospell macro which forces Aspell
to ignore the word marked by the macro.
interpreter/mk_doc_cache.m: Skip new @nospell macro when building
doc_cache.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 17 Jul 2010 19:53:01 -0700 |
parents | fbd7843974fa |
children | 89f4d7e294cc |
rev | line source |
---|---|
523 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, |
8920 | 4 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
523 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
523 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
523 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
1192 | 25 #include <config.h> |
523 | 26 #endif |
27 | |
1341 | 28 #include <cerrno> |
29 #include <cstdio> | |
30 #include <cstddef> | |
31 #include <cstdlib> | |
32 #include <cstring> | |
33 | |
5765 | 34 #include <sstream> |
1728 | 35 #include <string> |
36 | |
1832 | 37 #include <sys/types.h> |
38 #include <unistd.h> | |
39 | |
2926 | 40 #include "file-ops.h" |
41 #include "file-stat.h" | |
42 #include "glob-match.h" | |
43 #include "oct-env.h" | |
5777 | 44 #include "pathsearch.h" |
1755 | 45 #include "str-vec.h" |
46 | |
5102 | 47 #include "Cell.h" |
1355 | 48 #include "defun.h" |
1781 | 49 #include "dir-ops.h" |
1355 | 50 #include "dirfns.h" |
51 #include "error.h" | |
1402 | 52 #include "gripes.h" |
5640 | 53 #include "input.h" |
5832 | 54 #include "load-path.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 { |
5979 | 74 int cd_ok = octave_env::chdir (file_ops::tilde_expand (newdir)); |
1328 | 75 |
76 if (cd_ok) | |
5832 | 77 { |
6323 | 78 Vlast_chdir_time.stamp (); |
79 | |
5832 | 80 // FIXME -- should this be handled as a list of functions |
81 // to call so users can add their own chdir handlers? | |
82 | |
83 load_path::update (); | |
84 } | |
1328 | 85 else |
10411 | 86 error ("%s: %s", newdir.c_str (), gnulib::strerror (errno)); |
1328 | 87 |
88 return cd_ok; | |
89 } | |
90 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8503
diff
changeset
|
91 DEFUN (cd, args, , |
3301 | 92 "-*- texinfo -*-\n\ |
93 @deffn {Command} cd dir\n\ | |
94 @deffnx {Command} chdir dir\n\ | |
95 Change the current working directory to @var{dir}. If @var{dir} is\n\ | |
7001 | 96 omitted, the current directory is changed to the user's home\n\ |
3301 | 97 directory. For example,\n\ |
523 | 98 \n\ |
3301 | 99 @example\n\ |
100 cd ~/octave\n\ | |
101 @end example\n\ | |
102 \n\ | |
103 @noindent\n\ | |
104 Changes the current working directory to @file{~/octave}. If the\n\ | |
105 directory does not exist, an error message is printed and the working\n\ | |
106 directory is not changed.\n\ | |
5597 | 107 @seealso{mkdir, rmdir, dir}\n\ |
3301 | 108 @end deffn") |
523 | 109 { |
2086 | 110 octave_value_list retval; |
523 | 111 |
1755 | 112 int argc = args.length () + 1; |
113 | |
1965 | 114 string_vector argv = args.make_argv ("cd"); |
1755 | 115 |
116 if (error_state) | |
117 return retval; | |
523 | 118 |
119 if (argc > 1) | |
120 { | |
5872 | 121 std::string dirname = argv[1]; |
523 | 122 |
1750 | 123 if (dirname.length () > 0 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
124 && ! octave_change_to_directory (dirname)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
126 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
127 } |
523 | 128 } |
129 else | |
130 { | |
3523 | 131 std::string home_dir = octave_env::get_home_directory (); |
2926 | 132 |
133 if (home_dir.empty () || ! octave_change_to_directory (home_dir)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
134 return retval; |
523 | 135 } |
136 | |
137 return retval; | |
138 } | |
139 | |
611 | 140 DEFALIAS (chdir, cd); |
141 | |
6482 | 142 DEFUN (pwd, , , |
3301 | 143 "-*- texinfo -*-\n\ |
144 @deftypefn {Built-in Function} {} pwd ()\n\ | |
145 Return the current working directory.\n\ | |
5597 | 146 @seealso{dir, ls}\n\ |
3301 | 147 @end deftypefn") |
523 | 148 { |
10250 | 149 return octave_value (octave_env::get_current_directory ()); |
523 | 150 } |
151 | |
1957 | 152 DEFUN (readdir, args, , |
3301 | 153 "-*- texinfo -*-\n\ |
154 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ | |
4691 | 155 Return names of the files in the directory @var{dir} as a cell array of\n\ |
156 strings. If an error occurs, return an empty cell array in @var{files}.\n\ | |
1389 | 157 \n\ |
3301 | 158 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
159 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
160 system-dependent error message.\n\ | |
5597 | 161 @seealso{dir, glob}\n\ |
3301 | 162 @end deftypefn") |
1389 | 163 { |
2086 | 164 octave_value_list retval; |
1389 | 165 |
3523 | 166 retval(2) = std::string (); |
2669 | 167 retval(1) = -1.0; |
4691 | 168 retval(0) = Cell (); |
2669 | 169 |
1401 | 170 if (args.length () == 1) |
1389 | 171 { |
3523 | 172 std::string dirname = args(0).string_value (); |
1389 | 173 |
1401 | 174 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
175 gripe_wrong_type_arg ("readdir", args(0)); |
1401 | 176 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
177 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
178 dir_entry dir (dirname); |
1389 | 179 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
180 if (dir) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
182 string_vector dirlist = dir.read (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
183 retval(0) = Cell (dirlist.sort ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
184 retval(1) = 0.0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
185 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
186 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
187 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
188 retval(2) = dir.error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
189 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
190 } |
1389 | 191 } |
192 else | |
5823 | 193 print_usage (); |
1389 | 194 |
1401 | 195 return retval; |
196 } | |
197 | |
5775 | 198 // FIXME -- should maybe also allow second arg to specify |
5476 | 199 // mode? OTOH, that might cause trouble with compatibility later... |
1401 | 200 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
201 DEFUNX ("mkdir", Fmkdir, args, , |
3301 | 202 "-*- texinfo -*-\n\ |
5476 | 203 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{dir})\n\ |
6192 | 204 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{parent}, @var{dir})\n\ |
8109 | 205 Create a directory named @var{dir} in the directory @var{parent}.\n\ |
1401 | 206 \n\ |
5476 | 207 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
208 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ | |
209 system-dependent error message, and @var{msgid} contains a unique\n\ | |
210 message identifier.\n\ | |
5597 | 211 @seealso{rmdir}\n\ |
3301 | 212 @end deftypefn") |
1401 | 213 { |
2086 | 214 octave_value_list retval; |
1401 | 215 |
5476 | 216 retval(2) = std::string (); |
3523 | 217 retval(1) = std::string (); |
5476 | 218 retval(0) = false; |
1401 | 219 |
6187 | 220 int nargin = args.length (); |
221 | |
222 std::string dirname; | |
223 | |
224 if (nargin == 2) | |
1401 | 225 { |
6187 | 226 std::string parent = args(0).string_value (); |
227 std::string dir = args(1).string_value (); | |
1401 | 228 |
229 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
230 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
231 gripe_wrong_type_arg ("mkdir", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
232 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
233 } |
6187 | 234 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
235 dirname = file_ops::concat (parent, dir); |
6187 | 236 } |
6200 | 237 else if (nargin == 1) |
6187 | 238 { |
239 dirname = args(0).string_value (); | |
2669 | 240 |
6187 | 241 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
243 gripe_wrong_type_arg ("mkdir", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
244 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
245 } |
6187 | 246 } |
247 | |
248 if (nargin == 1 || nargin == 2) | |
249 { | |
250 std::string msg; | |
251 | |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
252 dirname = file_ops::tilde_expand (dirname); |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
253 |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
254 file_stat fs (dirname); |
1489 | 255 |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
256 if (fs && fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
257 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
258 // 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
|
259 // directory already exists. |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
260 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
261 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
262 retval(1) = "directory exists"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
263 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
264 } |
6187 | 265 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
266 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
267 int status = octave_mkdir (dirname, 0777, msg); |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
268 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
269 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
270 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
271 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
272 retval(1) = msg; |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
275 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
276 } |
1401 | 277 } |
278 else | |
5823 | 279 print_usage (); |
1401 | 280 |
281 return retval; | |
282 } | |
283 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
284 DEFUNX ("rmdir", Frmdir, args, , |
3301 | 285 "-*- texinfo -*-\n\ |
5476 | 286 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir})\n\ |
287 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir}, @code{\"s\"})\n\ | |
3301 | 288 Remove the directory named @var{dir}.\n\ |
1401 | 289 \n\ |
5476 | 290 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
291 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ | |
292 system-dependent error message, and @var{msgid} contains a unique\n\ | |
293 message identifier.\n\ | |
294 \n\ | |
7007 | 295 If the optional second parameter is supplied with value @code{\"s\"},\n\ |
6134 | 296 recursively remove all subdirectories as well.\n\ |
5640 | 297 @seealso{mkdir, confirm_recursive_rmdir}\n\ |
3301 | 298 @end deftypefn") |
1401 | 299 { |
2086 | 300 octave_value_list retval; |
1401 | 301 |
5476 | 302 retval(2) = std::string (); |
3523 | 303 retval(1) = std::string (); |
5476 | 304 retval(0) = false; |
1401 | 305 |
5476 | 306 int nargin = args.length (); |
307 | |
308 if (nargin == 1 || nargin == 2) | |
1401 | 309 { |
3523 | 310 std::string dirname = args(0).string_value (); |
1401 | 311 |
312 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
313 gripe_wrong_type_arg ("rmdir", args(0)); |
1489 | 314 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
316 std::string fulldir = file_ops::tilde_expand (dirname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
317 int status = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
318 std::string msg; |
2669 | 319 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
320 if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
322 if (args(1).string_value () == "s") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
323 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
324 bool doit = true; |
5640 | 325 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
326 if (interactive && Vconfirm_recursive_rmdir) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
328 std::string prompt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
329 = "remove entire contents of " + fulldir + "? "; |
5640 | 330 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
331 doit = octave_yes_or_no (prompt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
332 } |
5640 | 333 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
334 if (doit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
335 status = octave_recursive_rmdir (fulldir, msg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
336 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
337 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
338 error ("rmdir: expecting second argument to be \"s\""); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
339 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
340 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
341 status = octave_rmdir (fulldir, msg); |
2669 | 342 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
343 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
344 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
345 retval(2) = "rmdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
346 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
347 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
348 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
349 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
350 } |
1401 | 351 } |
1389 | 352 else |
5823 | 353 print_usage (); |
1401 | 354 |
355 return retval; | |
356 } | |
357 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
358 DEFUNX ("link", Flink, args, , |
3710 | 359 "-*- texinfo -*-\n\ |
360 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ | |
361 Create a new link (also known as a hard link) to an existing file.\n\ | |
362 \n\ | |
363 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
364 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
365 system-dependent error message.\n\ | |
5597 | 366 @seealso{symlink}\n\ |
3710 | 367 @end deftypefn") |
368 { | |
369 octave_value_list retval; | |
370 | |
371 retval(1) = std::string (); | |
372 retval(0) = -1.0; | |
373 | |
374 if (args.length () == 2) | |
375 { | |
376 std::string from = args(0).string_value (); | |
377 | |
378 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
379 gripe_wrong_type_arg ("link", args(0)); |
3710 | 380 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
381 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
382 std::string to = args(1).string_value (); |
3710 | 383 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
384 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
385 gripe_wrong_type_arg ("link", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
386 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
388 std::string msg; |
3710 | 389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
390 int status = octave_link (from, to, msg); |
3710 | 391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
392 retval(0) = status; |
3710 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
394 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
395 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
396 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
397 } |
3710 | 398 } |
399 else | |
5823 | 400 print_usage (); |
3710 | 401 |
402 return retval; | |
403 } | |
404 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
405 DEFUNX ("symlink", Fsymlink, args, , |
3710 | 406 "-*- texinfo -*-\n\ |
407 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ | |
408 Create a symbolic link @var{new} which contains the string @var{old}.\n\ | |
409 \n\ | |
410 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
411 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
412 system-dependent error message.\n\ | |
5597 | 413 @seealso{link, readlink}\n\ |
3710 | 414 @end deftypefn") |
415 { | |
416 octave_value_list retval; | |
417 | |
418 retval(1) = std::string (); | |
419 retval(0) = -1.0; | |
420 | |
421 if (args.length () == 2) | |
422 { | |
423 std::string from = args(0).string_value (); | |
424 | |
425 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
426 gripe_wrong_type_arg ("symlink", args(0)); |
3710 | 427 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
428 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
429 std::string to = args(1).string_value (); |
3710 | 430 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
431 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
432 gripe_wrong_type_arg ("symlink", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
433 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
434 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
435 std::string msg; |
3710 | 436 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
437 int status = octave_symlink (from, to, msg); |
3710 | 438 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
439 retval(0) = status; |
3710 | 440 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
441 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
442 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
443 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
444 } |
3710 | 445 } |
446 else | |
5823 | 447 print_usage (); |
3710 | 448 |
449 return retval; | |
450 } | |
451 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
452 DEFUNX ("readlink", Freadlink, args, , |
3710 | 453 "-*- texinfo -*-\n\ |
4169 | 454 @deftypefn {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\ |
3710 | 455 Read the value of the symbolic link @var{symlink}.\n\ |
456 \n\ | |
457 If successful, @var{result} contains the contents of the symbolic link\n\ | |
458 @var{symlink}, @var{err} is 0 and @var{msg} is an empty string.\n\ | |
459 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
460 system-dependent error message.\n\ | |
5597 | 461 @seealso{link, symlink}\n\ |
3710 | 462 @end deftypefn") |
463 { | |
464 octave_value_list retval; | |
465 | |
466 retval(2) = std::string (); | |
467 retval(1) = -1.0; | |
468 retval(0) = std::string (); | |
469 | |
470 if (args.length () == 1) | |
471 { | |
472 std::string symlink = args(0).string_value (); | |
473 | |
474 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
475 gripe_wrong_type_arg ("readlink", args(0)); |
3710 | 476 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
477 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
478 std::string result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
479 std::string msg; |
3710 | 480 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
481 int status = octave_readlink (symlink, result, msg); |
3710 | 482 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
483 retval(0) = result; |
3710 | 484 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
485 retval(1) = status; |
3710 | 486 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
487 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
488 retval(2) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
489 } |
3710 | 490 } |
491 else | |
5823 | 492 print_usage (); |
3710 | 493 |
494 return retval; | |
495 } | |
496 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
497 DEFUNX ("rename", Frename, args, , |
3301 | 498 "-*- texinfo -*-\n\ |
499 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\ | |
500 Change the name of file @var{old} to @var{new}.\n\ | |
1401 | 501 \n\ |
3301 | 502 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
503 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ | |
504 system-dependent error message.\n\ | |
5597 | 505 @seealso{ls, dir}\n\ |
3301 | 506 @end deftypefn") |
1401 | 507 { |
2086 | 508 octave_value_list retval; |
1401 | 509 |
3523 | 510 retval(1) = std::string (); |
2669 | 511 retval(0) = -1.0; |
1401 | 512 |
513 if (args.length () == 2) | |
514 { | |
3523 | 515 std::string from = args(0).string_value (); |
1728 | 516 |
1401 | 517 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
518 gripe_wrong_type_arg ("rename", args(0)); |
1402 | 519 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
520 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
521 std::string to = args(1).string_value (); |
1728 | 522 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
523 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
524 gripe_wrong_type_arg ("rename", args(1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
525 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
526 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
527 std::string msg; |
2669 | 528 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
529 int status = octave_rename (from, to, msg); |
2669 | 530 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
531 retval(0) = status; |
2669 | 532 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
533 if (status < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
534 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
535 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
536 } |
1401 | 537 } |
538 else | |
5823 | 539 print_usage (); |
1401 | 540 |
1389 | 541 return retval; |
542 } | |
543 | |
2495 | 544 DEFUN (glob, args, , |
3301 | 545 "-*- texinfo -*-\n\ |
546 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
547 Given an array of pattern strings (as a char array or a cell array) in\n\ |
5444 | 548 @var{pattern}, return a cell array of file names that match any of\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
549 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
|
550 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
|
551 Within a pattern\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
552 @table @code\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
553 @itemx *\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
554 matches any string, including the null string,\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
555 @itemx ?\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
556 matches any single character, and\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10411
diff
changeset
|
557 @item [@dots{}]\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
558 matches any of the enclosed characters.\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
559 @end table\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
560 \n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
561 Tilde expansion\n\ |
5444 | 562 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
|
563 names. For example:\n\ |
2495 | 564 \n\ |
3301 | 565 @example\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
566 ls\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
567 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
568 file1 file2 file3 myfile1 myfile1b \n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
569 glob (\"*file1\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
570 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
571 @{\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
572 [1,1] = file1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
573 [2,1] = myfile1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
574 @}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
575 glob (\"myfile?\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
576 @result{}\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
577 @{\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
578 [1,1] = myfile1\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 glob (\"file[12]\")\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
581 @result{}\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 [1,1] = file1\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
584 [2,1] = file2\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
585 @}\n\ |
3301 | 586 @end example\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
587 @seealso{dir, ls, stat, readdir, regexp}\n\ |
5597 | 588 @end deftypefn") |
2495 | 589 { |
590 octave_value retval; | |
591 | |
592 if (args.length () == 1) | |
593 { | |
594 string_vector pat = args(0).all_strings (); | |
595 | |
596 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
597 gripe_wrong_type_arg ("glob", args(0)); |
2495 | 598 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
599 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
600 glob_match pattern (file_ops::tilde_expand (pat)); |
2495 | 601 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
602 retval = Cell (pattern.glob ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
603 } |
2495 | 604 } |
605 else | |
5823 | 606 print_usage (); |
2495 | 607 |
608 return retval; | |
609 } | |
610 | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
611 /* |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
612 %!test |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
613 %! tmpdir = tmpnam; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
614 %! filename = {"file1", "file2", "file3", "myfile1", "myfile1b"}; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
615 %! if (mkdir (tmpdir)) |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
616 %! cwd = pwd; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
617 %! cd (tmpdir); |
10348
df1df5f0c236
Make test of glob function more robust.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
10335
diff
changeset
|
618 %! if strcmp (canonicalize_file_name (pwd), ... |
df1df5f0c236
Make test of glob function more robust.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
10335
diff
changeset
|
619 %! canonicalize_file_name (tmpdir)) |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
620 %! a = 0; |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
621 %! for n = 1:5 |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
622 %! save (filename{n}, "a"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
623 %! endfor |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
624 %! else |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
625 %! rmdir (tmpdir); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
626 %! error ("Couldn't change to temporary dir"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
627 %! endif |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
628 %! else |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
629 %! error ("Couldn't create temporary directory"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
630 %! endif |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
631 %! result1 = glob ("*file1"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
632 %! result2 = glob ("myfile?"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
633 %! result3 = glob ("file[12]"); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
634 %! for n = 1:5 |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
635 %! delete (filename{n}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
636 %! endfor |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
637 %! cd (cwd); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
638 %! rmdir (tmpdir); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
639 %! assert (result1, {"file1"; "myfile1"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
640 %! assert (result2, {"myfile1"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
641 %! assert (result3, {"file1"; "file2"}); |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
642 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
643 |
2496 | 644 DEFUN (fnmatch, args, , |
3301 | 645 "-*- texinfo -*-\n\ |
646 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\ | |
647 Return 1 or zero for each element of @var{string} that matches any of\n\ | |
648 the elements of the string array @var{pattern}, using the rules of\n\ | |
649 filename pattern matching. For example,\n\ | |
2496 | 650 \n\ |
3301 | 651 @example\n\ |
652 @group\n\ | |
6233 | 653 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\ |
3301 | 654 @result{} [ 1; 1; 0 ]\n\ |
655 @end group\n\ | |
656 @end example\n\ | |
657 @end deftypefn") | |
2496 | 658 { |
659 octave_value retval; | |
660 | |
661 if (args.length () == 2) | |
662 { | |
663 string_vector pat = args(0).all_strings (); | |
664 string_vector str = args(1).all_strings (); | |
665 | |
666 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
667 gripe_wrong_type_arg ("fnmatch", args(0)); |
2496 | 668 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
669 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
670 glob_match pattern (file_ops::tilde_expand (pat)); |
2496 | 671 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
672 retval = pattern.match (str); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
673 } |
2496 | 674 } |
675 else | |
5823 | 676 print_usage (); |
2496 | 677 |
678 return retval; | |
679 } | |
680 | |
5777 | 681 DEFUN (filesep, args, , |
5832 | 682 "-*- texinfo -*-\n\ |
683 @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
|
684 @deftypefnx {Built-in Function} {} filesep ('all')\n\ |
5777 | 685 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
|
686 \n\ |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
687 If 'all' is given, the function return all valid file separators in\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
688 the form of a string. The list of file separators is system-dependent.\n\ |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
689 It is / (forward slash) under UNIX or Mac OS X, / and \\ (forward and\n\ |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
690 backward slashes) under Windows.\n\ |
5777 | 691 @seealso{pathsep, dir, ls}\n\ |
692 @end deftypefn") | |
693 { | |
694 octave_value retval; | |
695 | |
696 if (args.length () == 0) | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7970
diff
changeset
|
697 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
|
698 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
|
699 { |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
700 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
|
701 |
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
702 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
704 if (s == "all") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
705 retval = file_ops::dir_sep_chars (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
706 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
707 gripe_wrong_type_arg ("filesep", args(0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
708 } |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
709 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
710 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
|
711 } |
5777 | 712 else |
5823 | 713 print_usage (); |
5777 | 714 |
715 return retval; | |
716 } | |
717 | |
9266 | 718 DEFUN (pathsep, args, nargout, |
5777 | 719 "-*- texinfo -*-\n\ |
9266 | 720 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\ |
9270
f9ac007bb926
fix typo in 9266:1d3b91166b9c
Jaroslav Hajek <highegg@gmail.com>
parents:
9266
diff
changeset
|
721 @deftypefnx {Built-in Function} {@var{old_val} =} pathsep (@var{new_val})\n\ |
9266 | 722 Query or set the character used to separate directories in\n\ |
5777 | 723 a path.\n\ |
724 @seealso{filesep, dir, ls}\n\ | |
725 @end deftypefn") | |
726 { | |
727 octave_value retval; | |
728 | |
9266 | 729 int nargin = args.length (); |
730 | |
731 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
|
732 retval = dir_path::path_sep_str (); |
9266 | 733 |
734 if (nargin == 1) | |
735 { | |
736 std::string sval = args(0).string_value (); | |
737 | |
738 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
739 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
740 switch (sval.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
741 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 case 1: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 dir_path::path_sep_char (sval[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
744 break; |
9266 | 745 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
746 case 0: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
747 dir_path::path_sep_char ('\0'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 break; |
9266 | 749 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
751 error ("pathsep: argument must be a single character"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
752 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 } |
9266 | 755 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
756 error ("pathsep: argument must be a single character"); |
9266 | 757 } |
758 else if (nargin > 1) | |
5823 | 759 print_usage (); |
5777 | 760 |
761 return retval; | |
762 } | |
763 | |
5794 | 764 DEFUN (confirm_recursive_rmdir, args, nargout, |
765 "-*- texinfo -*-\n\ | |
766 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\ | |
767 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\ | |
768 Query or set the internal variable that controls whether Octave\n\ | |
769 will ask for confirmation before recursively removing a directory tree.\n\ | |
770 @end deftypefn") | |
5640 | 771 { |
5794 | 772 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); |
4264 | 773 } |