annotate libinterp/corefcn/dirfns.cc @ 21696:b8c05cc524ef

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