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