Mercurial > octave-nkf
annotate libinterp/corefcn/dirfns.cc @ 20654:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | fd0efcdb3718 |
children |
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 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
187 std::string dirname = args(0).string_value ("readdir: DIR must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
188 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
189 dir_entry dir (dirname); |
1389 | 190 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
191 if (dir) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
192 { |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
193 string_vector dirlist = dir.read (); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
194 retval(1) = 0.0; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
195 retval(0) = Cell (dirlist.sort ()); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
196 } |
1401 | 197 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
198 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
199 retval(2) = dir.error (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
200 } |
1389 | 201 } |
202 else | |
5823 | 203 print_usage (); |
1389 | 204 |
1401 | 205 return retval; |
206 } | |
207 | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
208 // 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
|
209 // OTOH, that might cause trouble with compatibility later... |
1401 | 210 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
211 DEFUNX ("mkdir", Fmkdir, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
212 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
213 @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
|
214 @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
|
215 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@dots{})\n\ |
8109 | 216 Create a directory named @var{dir} in the directory @var{parent}.\n\ |
1401 | 217 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
218 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
|
219 used.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
220 \n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 identifier.\n\ |
20233
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20213
diff
changeset
|
225 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20213
diff
changeset
|
226 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
|
227 @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
|
228 @seealso{rmdir, pwd, cd, umask}\n\ |
3301 | 229 @end deftypefn") |
1401 | 230 { |
2086 | 231 octave_value_list retval; |
1401 | 232 |
5476 | 233 retval(2) = std::string (); |
3523 | 234 retval(1) = std::string (); |
5476 | 235 retval(0) = false; |
1401 | 236 |
6187 | 237 int nargin = args.length (); |
238 | |
239 std::string dirname; | |
240 | |
241 if (nargin == 2) | |
1401 | 242 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
243 std::string parent = args(0).string_value ("mkdir: PARENT must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
244 std::string dir = args(1).string_value ("mkdir: DIR must be a string"); |
1401 | 245 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
246 dirname = file_ops::concat (parent, dir); |
6187 | 247 } |
6200 | 248 else if (nargin == 1) |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
249 dirname = args(0).string_value ("mkdir: DIR must be a string"); |
6187 | 250 |
251 if (nargin == 1 || nargin == 2) | |
252 { | |
253 std::string msg; | |
254 | |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
255 dirname = file_ops::tilde_expand (dirname); |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
256 |
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
257 file_stat fs (dirname); |
1489 | 258 |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
259 if (fs && fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
260 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
261 // 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
|
262 // directory already exists. |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
263 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
264 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
265 retval(1) = "directory exists"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
266 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
267 } |
6187 | 268 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
269 { |
14741
0ab3dd0fad18
Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents:
14679
diff
changeset
|
270 int status = octave_mkdir (dirname, 0777, msg); |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
271 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
272 if (status < 0) |
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 retval(2) = "mkdir"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
275 retval(1) = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
276 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
277 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
278 retval(0) = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
279 } |
1401 | 280 } |
281 else | |
5823 | 282 print_usage (); |
1401 | 283 |
284 return retval; | |
285 } | |
286 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
287 DEFUNX ("rmdir", Frmdir, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
288 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
289 @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
|
290 @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
|
291 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{})\n\ |
3301 | 292 Remove the directory named @var{dir}.\n\ |
1401 | 293 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19895
diff
changeset
|
294 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
|
295 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
|
296 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 identifier.\n\ |
5476 | 301 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
302 @seealso{mkdir, confirm_recursive_rmdir, pwd}\n\ |
3301 | 303 @end deftypefn") |
1401 | 304 { |
2086 | 305 octave_value_list retval; |
1401 | 306 |
5476 | 307 retval(2) = std::string (); |
3523 | 308 retval(1) = std::string (); |
5476 | 309 retval(0) = false; |
1401 | 310 |
5476 | 311 int nargin = args.length (); |
312 | |
313 if (nargin == 1 || nargin == 2) | |
1401 | 314 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
315 std::string dirname = args(0).string_value ("rmdir: DIR must be a string"); |
1401 | 316 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
317 std::string fulldir = file_ops::tilde_expand (dirname); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
318 int status = -1; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
319 std::string msg; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
320 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
321 if (nargin == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
322 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
323 if (args(1).string_value () == "s") |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
324 { |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
325 bool doit = true; |
2669 | 326 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
327 if (interactive && ! forced_interactive |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
328 && Vconfirm_recursive_rmdir) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
329 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
330 std::string prompt |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
331 = "remove entire contents of " + fulldir + "? "; |
5640 | 332 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
333 doit = octave_yes_or_no (prompt); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
334 } |
5640 | 335 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
336 if (doit) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
337 status = octave_recursive_rmdir (fulldir, msg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
338 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
339 else |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
340 error ("rmdir: expecting second argument to be \"s\""); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
341 } |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
342 else |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
343 status = octave_rmdir (fulldir, msg); |
2669 | 344 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
345 if (status < 0) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
346 { |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
347 retval(2) = "rmdir"; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
348 retval(1) = msg; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
349 } |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
350 else |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
351 retval(0) = true; |
1401 | 352 } |
1389 | 353 else |
5823 | 354 print_usage (); |
1401 | 355 |
356 return retval; | |
357 } | |
358 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
359 DEFUNX ("link", Flink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
360 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
361 @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
|
362 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ |
3710 | 363 Create a new link (also known as a hard link) to an existing file.\n\ |
364 \n\ | |
365 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
|
366 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
|
367 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
368 @seealso{symlink, unlink, readlink, lstat}\n\ |
3710 | 369 @end deftypefn") |
370 { | |
371 octave_value_list retval; | |
372 | |
373 retval(1) = std::string (); | |
374 retval(0) = -1.0; | |
375 | |
376 if (args.length () == 2) | |
377 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
378 std::string from = args(0).string_value ("link: OLD must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
379 std::string to = args(1).string_value ("link: NEW must be a string"); |
3710 | 380 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
381 std::string msg; |
3710 | 382 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
383 int status = octave_link (from, to, msg); |
3710 | 384 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
385 if (status < 0) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
386 retval(1) = msg; |
3710 | 387 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
388 retval(0) = status; |
3710 | 389 } |
390 else | |
5823 | 391 print_usage (); |
3710 | 392 |
393 return retval; | |
394 } | |
395 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
396 DEFUNX ("symlink", Fsymlink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
397 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
398 @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
|
399 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ |
3710 | 400 Create a symbolic link @var{new} which contains the string @var{old}.\n\ |
401 \n\ | |
402 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
|
403 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
|
404 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
405 @seealso{link, unlink, readlink, lstat}\n\ |
3710 | 406 @end deftypefn") |
407 { | |
408 octave_value_list retval; | |
409 | |
410 retval(1) = std::string (); | |
411 retval(0) = -1.0; | |
412 | |
413 if (args.length () == 2) | |
414 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
415 std::string from = args(0).string_value ("symlink: OLD must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
416 std::string to = args(1).string_value ("symlink: NEW must be a string"); |
3710 | 417 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
418 std::string msg; |
3710 | 419 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
420 int status = octave_symlink (from, to, msg); |
3710 | 421 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
422 if (status < 0) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
423 retval(1) = msg; |
3710 | 424 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
425 retval(0) = status; |
3710 | 426 } |
427 else | |
5823 | 428 print_usage (); |
3710 | 429 |
430 return retval; | |
431 } | |
432 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
433 DEFUNX ("readlink", Freadlink, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
434 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
435 @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
|
436 @deftypefnx {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\ |
3710 | 437 Read the value of the symbolic link @var{symlink}.\n\ |
438 \n\ | |
439 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
|
440 @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
|
441 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
|
442 error message.\n\ |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
443 @seealso{lstat, symlink, link, unlink, delete}\n\ |
3710 | 444 @end deftypefn") |
445 { | |
446 octave_value_list retval; | |
447 | |
448 retval(2) = std::string (); | |
449 retval(1) = -1.0; | |
450 retval(0) = std::string (); | |
451 | |
452 if (args.length () == 1) | |
453 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
454 std::string symlink = args(0).string_value ("readlink: SYMLINK must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
455 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
456 std::string result; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
457 std::string msg; |
3710 | 458 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
459 int status = octave_readlink (symlink, result, msg); |
3710 | 460 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
461 if (status < 0) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
462 retval(2) = msg; |
3710 | 463 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
464 retval(1) = status; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
465 retval(0) = result; |
3710 | 466 } |
467 else | |
5823 | 468 print_usage (); |
3710 | 469 |
470 return retval; | |
471 } | |
472 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
473 DEFUNX ("rename", Frename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
474 "-*- texinfo -*-\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
475 @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
|
476 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\ |
3301 | 477 Change the name of file @var{old} to @var{new}.\n\ |
1401 | 478 \n\ |
3301 | 479 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
|
480 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
|
481 error message.\n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
482 @seealso{movefile, copyfile, ls, dir}\n\ |
3301 | 483 @end deftypefn") |
1401 | 484 { |
2086 | 485 octave_value_list retval; |
1401 | 486 |
3523 | 487 retval(1) = std::string (); |
2669 | 488 retval(0) = -1.0; |
1401 | 489 |
490 if (args.length () == 2) | |
491 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
492 std::string from = args(0).string_value ("rename: OLD must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
493 std::string to = args(1).string_value ("rename: NEW must be a string"); |
1728 | 494 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
495 std::string msg; |
1728 | 496 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
497 int status = octave_rename (from, to, msg); |
2669 | 498 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
499 if (status < 0) |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
500 retval(1) = msg; |
2669 | 501 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
502 retval(0) = status; |
1401 | 503 } |
504 else | |
5823 | 505 print_usage (); |
1401 | 506 |
1389 | 507 return retval; |
508 } | |
509 | |
2495 | 510 DEFUN (glob, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
511 "-*- texinfo -*-\n\ |
3301 | 512 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
513 Given an array of pattern strings (as a char array or a cell array) in\n\ |
5444 | 514 @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
|
515 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
|
516 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19895
diff
changeset
|
517 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
|
518 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
|
519 \n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
520 Within a pattern\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
521 \n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
522 @table @code\n\ |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
523 @item *\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
524 matches any string, including the null string,\n\ |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16526
diff
changeset
|
525 \n\ |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
526 @item ?\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
527 matches any single character, and\n\ |
10840 | 528 \n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10411
diff
changeset
|
529 @item [@dots{}]\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
530 matches any of the enclosed characters.\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
531 @end table\n\ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
532 \n\ |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
533 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
|
534 matching file names. For example:\n\ |
2495 | 535 \n\ |
3301 | 536 @example\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
537 ls\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
538 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
539 file1 file2 file3 myfile1 myfile1b\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
540 glob (\"*file1\")\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
541 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
542 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
543 [1,1] = file1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
544 [2,1] = myfile1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
545 @}\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
546 glob (\"myfile?\")\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
547 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
548 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
549 [1,1] = myfile1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
550 @}\n\ |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
551 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
|
552 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
553 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
554 [1,1] = file1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
555 [2,1] = file2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
556 @}\n\ |
3301 | 557 @end example\n\ |
19153 | 558 @seealso{ls, dir, readdir, what}\n\ |
5597 | 559 @end deftypefn") |
2495 | 560 { |
561 octave_value retval; | |
562 | |
563 if (args.length () == 1) | |
564 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
565 string_vector pat = args(0).all_strings ("glob: PATTERN must be a string"); |
2495 | 566 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
567 glob_match pattern (file_ops::tilde_expand (pat)); |
2495 | 568 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
569 retval = Cell (pattern.glob ()); |
2495 | 570 } |
571 else | |
5823 | 572 print_usage (); |
2495 | 573 |
574 return retval; | |
575 } | |
576 | |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
577 /* |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
578 %!test |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19153
diff
changeset
|
579 %! tmpdir = tempname; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
580 %! 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
|
581 %! if (mkdir (tmpdir)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
582 %! cwd = pwd; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
583 %! cd (tmpdir); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
584 %! 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
|
585 %! a = 0; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
586 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
587 %! save (filename{n}, "a"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
588 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
589 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
590 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
591 %! 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
|
592 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
593 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
594 %! 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
|
595 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
596 %! result1 = glob ("*file1"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
597 %! result2 = glob ("myfile?"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
598 %! result3 = glob ("file[12]"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
599 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
600 %! delete (filename{n}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
601 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
602 %! cd (cwd); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
603 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
604 %! assert (result1, {"file1"; "myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
605 %! assert (result2, {"myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
606 %! assert (result3, {"file1"; "file2"}); |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
607 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
608 |
19153 | 609 DEFUN (__fnmatch__, args, , |
19895
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19883
diff
changeset
|
610 "-*- texinfo -*-\n\ |
3301 | 611 @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
|
612 Return true or false for each element of @var{string} that matches any of\n\ |
3301 | 613 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
|
614 \n\ |
10840 | 615 filename pattern matching. For example:\n\ |
2496 | 616 \n\ |
3301 | 617 @example\n\ |
618 @group\n\ | |
6233 | 619 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\ |
3301 | 620 @result{} [ 1; 1; 0 ]\n\ |
621 @end group\n\ | |
622 @end example\n\ | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
623 @seealso{glob, regexp}\n\ |
3301 | 624 @end deftypefn") |
2496 | 625 { |
626 octave_value retval; | |
627 | |
628 if (args.length () == 2) | |
629 { | |
630 string_vector pat = args(0).all_strings (); | |
631 string_vector str = args(1).all_strings (); | |
632 | |
633 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
634 gripe_wrong_type_arg ("fnmatch", args(0)); |
2496 | 635 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
637 glob_match pattern (file_ops::tilde_expand (pat)); |
2496 | 638 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
639 retval = pattern.match (str); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
640 } |
2496 | 641 } |
642 else | |
5823 | 643 print_usage (); |
2496 | 644 |
645 return retval; | |
646 } | |
647 | |
5777 | 648 DEFUN (filesep, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
649 "-*- texinfo -*-\n\ |
10840 | 650 @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
|
651 @deftypefnx {Built-in Function} {} filesep (\"all\")\n\ |
5777 | 652 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
|
653 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 @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
|
658 @seealso{pathsep}\n\ |
5777 | 659 @end deftypefn") |
660 { | |
661 octave_value retval; | |
662 | |
663 if (args.length () == 0) | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7970
diff
changeset
|
664 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
|
665 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
|
666 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
667 std::string s = args(0).string_value ("filesep: argument must be a string"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
668 if (s == "all") |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
669 retval = file_ops::dir_sep_chars (); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
670 else |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
671 error ("filesep: argument must be \"all\""); |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
672 } |
5777 | 673 else |
5823 | 674 print_usage (); |
5777 | 675 |
676 return retval; | |
677 } | |
678 | |
9266 | 679 DEFUN (pathsep, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
680 "-*- texinfo -*-\n\ |
10840 | 681 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\ |
9270
f9ac007bb926
fix typo in 9266:1d3b91166b9c
Jaroslav Hajek <highegg@gmail.com>
parents:
9266
diff
changeset
|
682 @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
|
683 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
|
684 @seealso{filesep}\n\ |
5777 | 685 @end deftypefn") |
686 { | |
687 octave_value retval; | |
688 | |
9266 | 689 int nargin = args.length (); |
690 | |
691 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
|
692 retval = dir_path::path_sep_str (); |
9266 | 693 |
694 if (nargin == 1) | |
695 { | |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
696 std::string sval = args(0).string_value ("pathsep: argument must be a single character"); |
9266 | 697 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
698 switch (sval.length ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
699 { |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
700 case 1: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
701 dir_path::path_sep_char (sval[0]); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
702 break; |
9266 | 703 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
704 case 0: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
705 dir_path::path_sep_char ('\0'); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
706 break; |
9266 | 707 |
20616
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
708 default: |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
709 error ("pathsep: argument must be a single character"); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20590
diff
changeset
|
710 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
711 } |
9266 | 712 } |
713 else if (nargin > 1) | |
5823 | 714 print_usage (); |
5777 | 715 |
716 return retval; | |
717 } | |
718 | |
5794 | 719 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
|
720 "-*- texinfo -*-\n\ |
10840 | 721 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\ |
5794 | 722 @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
|
723 @deftypefnx {Built-in Function} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\ |
5794 | 724 Query or set the internal variable that controls whether Octave\n\ |
725 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
|
726 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
727 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
|
728 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
|
729 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
|
730 @seealso{rmdir}\n\ |
5794 | 731 @end deftypefn") |
5640 | 732 { |
5794 | 733 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); |
4264 | 734 } |