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