Mercurial > octave
annotate libinterp/corefcn/dirfns.cc @ 25407:ab10403a0b50
new input_system class to manage user input for the interpreter
Encapsulate many command-line input functions and data within a new
class that is a member of the interpreter object.
* input.h, input.cc (input_system): New class. Include data members
for former static variables VPS1, VPS2, Vcompletion_append_char,
last_debugging_command, Vgud_mode, input_event_hook_functions, and
Vmfile_encoding. Change all uses.
(is_variable, generate_struct_completions, looks_like_struct):
Move here from variables.cc and make static.
(set_default_prompts, octave_yes_or_no, do_keyboard,
remove_input_event_hook_functions, get_input_from_stdin): Deprecate.
(Fadd_input_event_hook, Fremove_input_event_hook, FPS1, FPS2,
Fcompletion_append_char, F__request_drawnow__, F__gud_mode__,
F__mfile_encoding__, Finput, Fyes_or_no): Define with DEFMETHOD.
Change all uses.
(input_system::have_input_event_hooks,
input_system::add_input_event_hook,
input_system::remove_input_event_hook,
input_system::clear_input_event_hooks,
input_system::run_input_event_hooks):
New functions to manage input event hooks.
(input_system::yes_or_no, input_system::interactive_input,
input_system::get_user_input, input_system::keyboard,
input_system::gnu_readline, input_system::get_debug_input):
New functions adapted from former file-scope static and global
functions.
* interpreter.h, interpreter.cc (interpreter::m_input_system):
New data member.
(interpreter::get_input_system): New function.
(interpreter::intepreter): Don't call set_default_prompts. Call
input_system::initialize.
(interpreter::maximum_braindamage): Call input_system::PS1 and
input_system::PS2 directly here.
* variables.h, variables.cc (get_struct_elts): Deprecate.
* main-window.cc (octave_interpreter::m_app_context): Now pointer to
gui_application, not application.
(octave_interpreter::octave_interpreter): Arg is now
gui_application, not application. Set default prompt strings directly
here.
* qt-link.h, qt-link.cc (octave_qt_link::do_set_default_prompts):
Delete.
* octave-link.h, octave-link.cc (octave_link::set_default_prompts,
octave_link::do_set_default_prompts): Delete.
* hook-fcn.h, hook-fcn.cc (named_hook_function::eval,
fcn_handle_hook_function::eval): Move code from .h to .cc file.
Make id and is_valid methods const.
* interpreter-private.h, interpreter-private.cc
(__get_input_system__): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 May 2018 17:12:57 -0400 |
parents | 078b795c5219 |
children | 8945a6a6c0eb |
rev | line source |
---|---|
523 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24986
diff
changeset
|
3 Copyright (C) 1994-2018 John W. Eaton |
523 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24082
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24082
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
523 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
523 | 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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24082
diff
changeset
|
19 <https://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" | |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
40 #include "oct-glob.h" |
5777 | 41 #include "pathsearch.h" |
1755 | 42 #include "str-vec.h" |
43 | |
5102 | 44 #include "Cell.h" |
1355 | 45 #include "defun.h" |
1781 | 46 #include "dir-ops.h" |
1355 | 47 #include "dirfns.h" |
48 #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
|
49 #include "errwarn.h" |
5640 | 50 #include "input.h" |
5832 | 51 #include "load-path.h" |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
52 #include "octave.h" |
16437
919796a440c6
use signal for changing directory
John W. Eaton <jwe@octave.org>
parents:
16094
diff
changeset
|
53 #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
|
54 #include "ovl.h" |
1355 | 55 #include "pager.h" |
56 #include "procstream.h" | |
57 #include "sysdep.h" | |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
58 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22089
diff
changeset
|
59 #include "interpreter.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. |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
69 octave::sys::time Vlast_chdir_time = 0.0; |
6323 | 70 |
1328 | 71 static int |
3523 | 72 octave_change_to_directory (const std::string& newdir) |
1328 | 73 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
74 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
|
75 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
76 int cd_ok = octave::sys::env::chdir (xdir); |
1328 | 77 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
78 if (! cd_ok) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21897
diff
changeset
|
79 error ("%s: %s", newdir.c_str (), std::strerror (errno)); |
6323 | 80 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
81 Vlast_chdir_time.stamp (); |
5832 | 82 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
83 // 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
|
84 // 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
|
85 |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
86 octave::load_path& lp = |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
87 octave::__get_load_path__ ("octave_change_to_directory"); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
88 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
89 lp.update (); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
90 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
91 octave_link::change_directory (octave::sys::env::get_current_directory ()); |
1328 | 92 |
93 return cd_ok; | |
94 } | |
95 | |
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
|
96 DEFUN (cd, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
97 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
98 @deftypefn {} {} cd @var{dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
99 @deftypefnx {} {} cd |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
100 @deftypefnx {} {@var{old_dir} =} cd (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
101 @deftypefnx {} {} chdir @dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
102 Change the current working directory to @var{dir}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
103 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
104 If @var{dir} is omitted, the current directory is changed to the user's home |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
105 directory (@qcode{"~"}). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
106 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
107 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
108 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
109 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
110 cd ~/octave |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
111 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
112 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
113 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
114 changes the current working directory to @file{~/octave}. If the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
115 directory does not exist, an error message is printed and the working |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
116 directory is not changed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
117 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
118 @code{chdir} is an alias for @code{cd} and can be used in all of the same |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
119 calling formats. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
120 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
121 Compatibility Note: When called with no arguments, @sc{matlab} prints the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
122 present working directory rather than changing to the user's home directory. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
123 @seealso{pwd, mkdir, rmdir, dir, ls} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
124 @end deftypefn */) |
523 | 125 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
126 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
|
127 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
128 if (nargin > 1) |
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
129 print_usage (); |
523 | 130 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
131 octave_value_list retval; |
1755 | 132 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
133 if (nargout > 0) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
134 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
|
135 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
136 if (nargin == 1) |
523 | 137 { |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
138 std::string dirname = args(0).xstring_value ("cd: DIR must be a string"); |
523 | 139 |
20817
3d551b2ae928
Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
140 if (! dirname.empty ()) |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
141 octave_change_to_directory (dirname); |
523 | 142 } |
143 else | |
144 { | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
145 std::string home_dir = octave::sys::env::get_home_directory (); |
2926 | 146 |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
147 if (! home_dir.empty ()) |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
148 octave_change_to_directory (home_dir); |
523 | 149 } |
150 | |
151 return retval; | |
152 } | |
153 | |
611 | 154 DEFALIAS (chdir, cd); |
155 | |
6482 | 156 DEFUN (pwd, , , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
157 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
158 @deftypefn {} {} pwd () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
159 @deftypefnx {} {@var{dir} =} pwd () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
160 Return the current working directory. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
161 @seealso{cd, dir, ls, mkdir, rmdir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
162 @end deftypefn */) |
523 | 163 { |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
164 return ovl (octave::sys::env::get_current_directory ()); |
523 | 165 } |
166 | |
1957 | 167 DEFUN (readdir, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
168 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
169 @deftypefn {} {@var{files} =} readdir (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
170 @deftypefnx {} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
171 Return the names of files in the directory @var{dir} as a cell array of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
172 strings. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
173 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
174 If an error occurs, return an empty cell array in @var{files}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
175 If successful, @var{err} is 0 and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
176 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
177 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
178 @seealso{ls, dir, glob, what} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
179 @end deftypefn */) |
1389 | 180 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
181 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
182 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
183 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
184 std::string dirname = args(0).xstring_value ("readdir: DIR must be a string"); |
2669 | 185 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
186 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
|
187 |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
188 dirname = octave::sys::file_ops::tilde_expand (dirname); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
189 |
21735
60212efcd9cb
use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
190 octave::sys::dir_entry dir (dirname); |
1389 | 191 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
192 if (dir) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
193 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
194 string_vector dirlist = dir.read (); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
195 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
|
196 retval(1) = 0.0; |
1389 | 197 } |
198 else | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
199 retval(2) = dir.error (); |
1389 | 200 |
1401 | 201 return retval; |
202 } | |
203 | |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
204 // 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
|
205 // OTOH, that might cause trouble with compatibility later... |
1401 | 206 |
21696
b8c05cc524ef
mkdir.m: new script to implement recursive mkdir (bug #30650).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
207 DEFUN (__mkdir__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
208 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
209 @deftypefn {} {} __mkdir__ (@var{parent}, @var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
210 Internal function called by mkdir.m. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
211 @seealso{mkdir, rmdir, pwd, cd, umask} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
212 @end deftypefn */) |
1401 | 213 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
214 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
215 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
216 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
|
217 print_usage ("mkdir"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
218 |
6187 | 219 std::string dirname; |
220 | |
221 if (nargin == 2) | |
1401 | 222 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
223 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
|
224 std::string dir = args(1).xstring_value ("mkdir: DIR must be a string"); |
1401 | 225 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
226 dirname = octave::sys::file_ops::concat (parent, dir); |
6187 | 227 } |
6200 | 228 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
|
229 dirname = args(0).xstring_value ("mkdir: DIR must be a string"); |
6187 | 230 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
231 dirname = octave::sys::file_ops::tilde_expand (dirname); |
6187 | 232 |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21735
diff
changeset
|
233 octave::sys::file_stat fs (dirname); |
7970
b6d4c644b4b6
Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents:
7272
diff
changeset
|
234 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
235 if (fs && fs.is_dir ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
236 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
237 // 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
|
238 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
|
239 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
240 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
241 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
242 std::string msg; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
243 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
244 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
|
245 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
246 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
247 return ovl (false, msg, "mkdir"); |
6187 | 248 else |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
249 return ovl (true, "", ""); |
1401 | 250 } |
251 } | |
252 | |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
253 DEFMETHODX ("rmdir", Frmdir, interp, args, , |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
254 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
255 @deftypefn {} {} rmdir @var{dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
256 @deftypefnx {} {} rmdir (@var{dir}, "s") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
257 @deftypefnx {} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
258 Remove the directory named @var{dir}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
259 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
260 If the optional second parameter is supplied with value @qcode{"s"}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
261 recursively remove all subdirectories as well. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
262 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
263 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
264 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
265 system-dependent error message, and @var{msgid} contains a unique message |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
266 identifier. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
267 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
268 @seealso{mkdir, confirm_recursive_rmdir, pwd} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
269 @end deftypefn */) |
1401 | 270 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
271 int nargin = args.length (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
272 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
273 if (nargin < 1 || nargin > 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
274 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
275 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
276 std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); |
5476 | 277 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
278 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
|
279 int status = -1; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
280 std::string msg; |
1401 | 281 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
282 if (nargin == 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
283 { |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
284 if (args(1).string_value () != "s") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23743
diff
changeset
|
285 error (R"(rmdir: second argument must be "s" for recursive removal)"); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
286 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
287 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
|
288 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
289 if (octave::application::interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
290 && ! octave::application::forced_interactive () |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
291 && Vconfirm_recursive_rmdir) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
292 { |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
293 octave::input_system& input_sys = interp.get_input_system (); |
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
294 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
295 std::string prompt = "remove entire contents of " + fulldir + "? "; |
5640 | 296 |
25407
ab10403a0b50
new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
297 doit = input_sys.yes_or_no (prompt); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
298 } |
5640 | 299 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
300 if (doit) |
24082
0052d47ddc3e
Backed out changeset ba164db1c4a4
Torsten <mttl@mailbox.org>
parents:
24048
diff
changeset
|
301 status = octave::sys::recursive_rmdir (fulldir, msg); |
1401 | 302 } |
1389 | 303 else |
24082
0052d47ddc3e
Backed out changeset ba164db1c4a4
Torsten <mttl@mailbox.org>
parents:
24048
diff
changeset
|
304 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
|
305 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
306 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
307 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
|
308 else |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
309 return ovl (true, "", ""); |
1401 | 310 } |
311 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
312 DEFUNX ("link", Flink, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
313 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
314 @deftypefn {} {} link @var{old} @var{new} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
315 @deftypefnx {} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
316 Create a new link (also known as a hard link) to an existing file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
317 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
318 If successful, @var{err} is 0 and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
319 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
320 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
321 @seealso{symlink, unlink, readlink, lstat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
322 @end deftypefn */) |
3710 | 323 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
324 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
325 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
326 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
327 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
|
328 std::string to = args(1).xstring_value ("link: NEW must be a string"); |
3710 | 329 |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
330 from = octave::sys::file_ops::tilde_expand (from); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
331 to = octave::sys::file_ops::tilde_expand (to); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
332 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
333 std::string msg; |
3710 | 334 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
335 int status = octave::sys::link (from, to, msg); |
3710 | 336 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
337 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
338 return ovl (-1.0, msg); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
339 else |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
340 return ovl (status, ""); |
3710 | 341 } |
342 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
343 DEFUNX ("symlink", Fsymlink, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
344 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
345 @deftypefn {} {} symlink @var{old} @var{new} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
346 @deftypefnx {} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
347 Create a symbolic link @var{new} which contains the string @var{old}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
348 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
349 If successful, @var{err} is 0 and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
350 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
351 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
352 @seealso{link, unlink, readlink, lstat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
353 @end deftypefn */) |
3710 | 354 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
355 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
356 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
357 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
358 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
|
359 std::string to = args(1).xstring_value ("symlink: NEW must be a string"); |
3710 | 360 |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
361 from = octave::sys::file_ops::tilde_expand (from); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
362 to = octave::sys::file_ops::tilde_expand (to); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
363 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
364 std::string msg; |
3710 | 365 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
366 int status = octave::sys::symlink (from, to, msg); |
3710 | 367 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
368 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
369 return ovl (-1.0, msg); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
370 else |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
371 return ovl (status, ""); |
3710 | 372 } |
373 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
374 DEFUNX ("readlink", Freadlink, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
375 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
376 @deftypefn {} {} readlink @var{symlink} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
377 @deftypefnx {} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
378 Read the value of the symbolic link @var{symlink}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
379 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
380 If successful, @var{result} contains the contents of the symbolic link |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
381 @var{symlink}, @var{err} is 0, and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
382 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
383 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
384 @seealso{lstat, symlink, link, unlink, delete} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
385 @end deftypefn */) |
3710 | 386 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
387 if (args.length () != 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
388 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
389 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
390 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
|
391 |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
392 symlink = octave::sys::file_ops::tilde_expand (symlink); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
393 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
394 std::string result, msg; |
3710 | 395 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
396 int status = octave::sys::readlink (symlink, result, msg); |
3710 | 397 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
398 if (status < 0) |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
399 return ovl ("", -1.0, msg); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
400 else |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
401 return ovl (result, status, ""); |
3710 | 402 } |
403 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
404 DEFUNX ("rename", Frename, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
405 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
406 @deftypefn {} {} rename @var{old} @var{new} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
407 @deftypefnx {} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
408 Change the name of file @var{old} to @var{new}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
409 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
410 If successful, @var{err} is 0 and @var{msg} is an empty string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
411 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
412 error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
413 @seealso{movefile, copyfile, ls, dir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
414 @end deftypefn */) |
1401 | 415 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
416 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
417 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
418 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
419 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
|
420 std::string to = args(1).xstring_value ("rename: NEW must be a string"); |
1728 | 421 |
21897
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
422 from = octave::sys::file_ops::tilde_expand (from); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
423 to = octave::sys::file_ops::tilde_expand (to); |
39afd54c2981
perform tilde expansion for more file and directory functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
424 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
425 std::string msg; |
1728 | 426 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
427 int status = octave::sys::rename (from, to, msg); |
2669 | 428 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
429 if (status < 0) |
24082
0052d47ddc3e
Backed out changeset ba164db1c4a4
Torsten <mttl@mailbox.org>
parents:
24048
diff
changeset
|
430 return ovl (-1.0, msg); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
431 else |
24082
0052d47ddc3e
Backed out changeset ba164db1c4a4
Torsten <mttl@mailbox.org>
parents:
24048
diff
changeset
|
432 return ovl (status, ""); |
1389 | 433 } |
434 | |
2495 | 435 DEFUN (glob, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
436 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
437 @deftypefn {} {} glob (@var{pattern}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
438 Given an array of pattern strings (as a char array or a cell array) in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
439 @var{pattern}, return a cell array of filenames that match any of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
440 them, or an empty cell array if no patterns match. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
441 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
442 The pattern strings are interpreted as filename globbing patterns (as they |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
443 are used by Unix shells). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
444 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
445 Within a pattern |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
446 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
447 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
448 @item * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
449 matches any string, including the null string, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
450 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
451 @item ? |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
452 matches any single character, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
453 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
454 @item [@dots{}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
455 matches any of the enclosed characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
456 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
457 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
458 Tilde expansion is performed on each of the patterns before looking for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
459 matching filenames. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
460 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
461 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
462 ls |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
463 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
464 file1 file2 file3 myfile1 myfile1b |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
465 glob ("*file1") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
466 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
467 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
468 [1,1] = file1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
469 [2,1] = myfile1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
470 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
471 glob ("myfile?") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
472 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
473 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
474 [1,1] = myfile1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
475 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
476 glob ("file[12]") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
477 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
478 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
479 [1,1] = file1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
480 [2,1] = file2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
481 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
482 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
483 @seealso{ls, dir, readdir, what} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
484 @end deftypefn */) |
2495 | 485 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
486 if (args.length () != 1) |
5823 | 487 print_usage (); |
2495 | 488 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
489 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
|
490 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
491 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
|
492 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
493 return ovl (Cell (pattern.glob ())); |
2495 | 494 } |
495 | |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
496 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
497 DEFUN (__wglob__, args, , |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
498 doc: /* -*- texinfo -*- |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
499 @deftypefn {} {} __wglob__ (@var{pattern}) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
500 Windows-like glob for dir. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
501 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
502 Given an array of pattern strings (as a char array or a cell array) in |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
503 @var{pattern}, return a cell array of filenames that match any of |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
504 them, or an empty cell array if no patterns match. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
505 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
506 The pattern strings are interpreted as filename globbing patterns |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
507 (roughly as they are used by Windows dir). |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
508 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
509 Within a pattern |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
510 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
511 @table @code |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
512 @item * |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
513 matches any string, including the null string, |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
514 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
515 @item ? |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
516 matches any single character, and |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
517 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
518 @item *.* |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
519 matches any string, even if no . is present. |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
520 @end table |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
521 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
522 Tilde expansion is performed on each of the patterns before looking for |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
523 matching filenames. For example: |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
524 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
525 @example |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
526 ls |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
527 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
528 file1 file2 file3 myfile1 myfile1b |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
529 glob ("*file1") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
530 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
531 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
532 [1,1] = file1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
533 [2,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
534 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
535 glob ("myfile?") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
536 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
537 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
538 [1,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
539 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
540 glob ("*.*") |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
541 @result{} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
542 @{ |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
543 [1,1] = file1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
544 [2,1] = file2 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
545 [3,1] = file3 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
546 [4,1] = myfile1 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
547 [5,1] = myfile1b |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
548 @} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
549 @end example |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
550 @seealso{glob, dir} |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
551 @end deftypefn */) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
552 { |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
553 if (args.length () == 0) |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
554 return ovl (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
555 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
556 string_vector pat = args(0).string_vector_value (); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
557 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
558 string_vector pattern (octave::sys::file_ops::tilde_expand (pat)); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
559 |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
560 return ovl (Cell (octave::sys::windows_glob (pattern))); |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
561 } |
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
22094
diff
changeset
|
562 |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
563 /* |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
564 %!test |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19119
diff
changeset
|
565 %! tmpdir = tempname; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
566 %! 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
|
567 %! if (mkdir (tmpdir)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
568 %! cwd = pwd; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
569 %! cd (tmpdir); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
570 %! 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
|
571 %! a = 0; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
572 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
573 %! save (filename{n}, "a"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
574 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
575 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
576 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
577 %! 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
|
578 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
579 %! else |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
580 %! 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
|
581 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
582 %! result1 = glob ("*file1"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
583 %! result2 = glob ("myfile?"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
584 %! result3 = glob ("file[12]"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
585 %! for n = 1:5 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
586 %! delete (filename{n}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
587 %! endfor |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
588 %! cd (cwd); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
589 %! rmdir (tmpdir); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
590 %! assert (result1, {"file1"; "myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
591 %! assert (result2, {"myfile1"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
592 %! assert (result3, {"file1"; "file2"}); |
10335
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
593 */ |
9dd04a06410e
document glob patterns
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10315
diff
changeset
|
594 |
19119 | 595 DEFUN (__fnmatch__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
596 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
597 @deftypefn {} {} fnmatch (@var{pattern}, @var{string}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
598 Return true or false for each element of @var{string} that matches any of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
599 the elements of the string array @var{pattern}, using the rules of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
600 filename pattern matching. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
601 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
602 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
603 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
604 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
605 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
606 fnmatch ("a*b", @{"ab"; "axyzb"; "xyzab"@}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
607 @result{} [ 1; 1; 0 ] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
608 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
609 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
610 @seealso{glob, regexp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
611 @end deftypefn */) |
2496 | 612 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
613 if (args.length () != 2) |
5823 | 614 print_usage (); |
2496 | 615 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
616 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
|
617 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
|
618 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
619 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
|
620 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
621 return ovl (pattern.match (str)); |
2496 | 622 } |
623 | |
5777 | 624 DEFUN (filesep, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
625 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
626 @deftypefn {} {} filesep () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
627 @deftypefnx {} {} filesep ("all") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
628 Return the system-dependent character used to separate directory names. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
629 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
630 If @qcode{"all"} is given, the function returns all valid file separators |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
631 in the form of a string. The list of file separators is system-dependent. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
632 It is @samp{/} (forward slash) under UNIX or @w{Mac OS X}, @samp{/} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
633 @samp{\} (forward and backward slashes) under Windows. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
634 @seealso{pathsep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
635 @end deftypefn */) |
5777 | 636 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
637 int nargin = args.length (); |
5777 | 638 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
639 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
640 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
641 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
642 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
643 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
644 if (nargin == 0) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
645 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
|
646 else |
8317
135c0e7d7802
Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8109
diff
changeset
|
647 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20667
diff
changeset
|
648 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
|
649 if (s != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23743
diff
changeset
|
650 error (R"(filesep: argument must be "all")"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
651 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
652 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
|
653 } |
5777 | 654 |
655 return retval; | |
656 } | |
657 | |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
658 DEFUN (pathsep, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
659 doc: /* -*- texinfo -*- |
24986
0b9e7fcaab91
doc: grammarcheck docstrings in C++ files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
660 @deftypefn {} {@var{val} =} pathsep () |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
661 Query the character used to separate directories in a path. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
662 @seealso{filesep} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
663 @end deftypefn */) |
5777 | 664 { |
9266 | 665 int nargin = args.length (); |
666 | |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
667 if (nargin > 0) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
668 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20752
diff
changeset
|
669 |
23743
e919cc8d9d92
don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents:
23445
diff
changeset
|
670 return ovl (octave::directory_path::path_sep_str ()); |
5777 | 671 } |
672 | |
5794 | 673 DEFUN (confirm_recursive_rmdir, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
674 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
675 @deftypefn {} {@var{val} =} confirm_recursive_rmdir () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
676 @deftypefnx {} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
677 @deftypefnx {} {} confirm_recursive_rmdir (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
678 Query or set the internal variable that controls whether Octave |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
679 will ask for confirmation before recursively removing a directory tree. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
680 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
681 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
682 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
683 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
684 @seealso{rmdir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
685 @end deftypefn */) |
5640 | 686 { |
5794 | 687 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir); |
4264 | 688 } |