annotate src/dirfns.cc @ 10182:0522a65bcd56

assume unistd.h and sys/types.h exist
author John W. Eaton <jwe@octave.org>
date Thu, 21 Jan 2010 15:41:19 -0500
parents cd96d29c5efa
children 4d433bd2d4dc
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
7
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
8 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
9 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
10 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
11 option) any later version.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
12
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
17
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
18 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
19 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
20 <http://www.gnu.org/licenses/>.
523
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
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1158
diff changeset
25 #include <config.h>
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
26 #endif
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
27
1341
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
28 #include <cerrno>
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
29 #include <cstdio>
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
30 #include <cstddef>
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
31 #include <cstdlib>
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
32 #include <cstring>
e4e4131b1648 [project @ 1995-09-04 00:13:33 by jwe]
jwe
parents: 1328
diff changeset
33
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5640
diff changeset
34 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1690
diff changeset
35 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1690
diff changeset
36
1832
0c0d14cc90cd [project @ 1996-02-03 05:03:40 by jwe]
jwe
parents: 1804
diff changeset
37 #include <sys/types.h>
0c0d14cc90cd [project @ 1996-02-03 05:03:40 by jwe]
jwe
parents: 1804
diff changeset
38 #include <unistd.h>
0c0d14cc90cd [project @ 1996-02-03 05:03:40 by jwe]
jwe
parents: 1804
diff changeset
39
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
40 #include "file-ops.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
41 #include "file-stat.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
42 #include "glob-match.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
43 #include "oct-env.h"
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
44 #include "pathsearch.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
45 #include "str-vec.h"
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
46
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 4928
diff changeset
47 #include "Cell.h"
1355
94697d007075 [project @ 1995-09-05 20:04:15 by jwe]
jwe
parents: 1341
diff changeset
48 #include "defun.h"
1781
e090f89bf2f5 [project @ 1996-01-24 08:04:14 by jwe]
jwe
parents: 1773
diff changeset
49 #include "dir-ops.h"
1355
94697d007075 [project @ 1995-09-05 20:04:15 by jwe]
jwe
parents: 1341
diff changeset
50 #include "dirfns.h"
94697d007075 [project @ 1995-09-05 20:04:15 by jwe]
jwe
parents: 1341
diff changeset
51 #include "error.h"
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
52 #include "gripes.h"
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
53 #include "input.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
54 #include "load-path.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
55 #include "oct-obj.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 {
5979
8c35d219139d [project @ 2006-09-01 18:00:01 by jwe]
jwe
parents: 5872
diff changeset
74 int cd_ok = octave_env::chdir (file_ops::tilde_expand (newdir));
1328
ec2ab864e8eb [project @ 1995-08-22 22:32:34 by jwe]
jwe
parents: 1315
diff changeset
75
ec2ab864e8eb [project @ 1995-08-22 22:32:34 by jwe]
jwe
parents: 1315
diff changeset
76 if (cd_ok)
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
77 {
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6233
diff changeset
78 Vlast_chdir_time.stamp ();
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6233
diff changeset
79
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
80 // FIXME -- should this be handled as a list of functions
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
81 // to call so users can add their own chdir handlers?
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
82
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
83 load_path::update ();
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
84 }
1328
ec2ab864e8eb [project @ 1995-08-22 22:32:34 by jwe]
jwe
parents: 1315
diff changeset
85 else
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
86 {
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
87 using namespace std;
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
88
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
89 error ("%s: %s", newdir.c_str (), strerror (errno));
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
90 }
1328
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 return cd_ok;
ec2ab864e8eb [project @ 1995-08-22 22:32:34 by jwe]
jwe
parents: 1315
diff changeset
93 }
ec2ab864e8eb [project @ 1995-08-22 22:32:34 by jwe]
jwe
parents: 1315
diff changeset
94
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8503
diff changeset
95 DEFUN (cd, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
96 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
97 @deffn {Command} cd dir\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
98 @deffnx {Command} chdir dir\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
99 Change the current working directory to @var{dir}. If @var{dir} is\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6482
diff changeset
100 omitted, the current directory is changed to the user's home\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
101 directory. For example,\n\
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
102 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
103 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
104 cd ~/octave\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
105 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
106 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
107 @noindent\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
108 Changes the current working directory to @file{~/octave}. If the\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
109 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
110 directory is not changed.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
111 @seealso{mkdir, rmdir, dir}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
112 @end deffn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
113 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
114 octave_value_list retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
115
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
116 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
117
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
118 string_vector argv = args.make_argv ("cd");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
119
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
120 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
121 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
122
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
123 if (argc > 1)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
124 {
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5832
diff changeset
125 std::string dirname = argv[1];
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
126
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
127 if (dirname.length () > 0
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
128 && ! octave_change_to_directory (dirname))
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
129 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
130 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
131 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
132 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
133 else
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
134 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
135 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
136
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
137 if (home_dir.empty () || ! octave_change_to_directory (home_dir))
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
138 return retval;
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
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
141 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
142 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
143
611
60f885cd0d87 [project @ 1994-08-14 20:53:44 by jwe]
jwe
parents: 549
diff changeset
144 DEFALIAS (chdir, cd);
60f885cd0d87 [project @ 1994-08-14 20:53:44 by jwe]
jwe
parents: 549
diff changeset
145
6482
7e958a1532c6 [project @ 2007-04-04 02:37:07 by jwe]
jwe
parents: 6323
diff changeset
146 DEFUN (pwd, , ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
147 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
148 @deftypefn {Built-in Function} {} pwd ()\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
149 Return the current working directory.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
150 @seealso{dir, ls}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
151 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
152 {
5979
8c35d219139d [project @ 2006-09-01 18:00:01 by jwe]
jwe
parents: 5872
diff changeset
153 return octave_value (octave_env::getcwd ());
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
154 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
155
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
156 DEFUN (readdir, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
157 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
158 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4494
diff changeset
159 Return names of the files in the directory @var{dir} as a cell array of\n\
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4494
diff changeset
160 strings. If an error occurs, return an empty cell array in @var{files}.\n\
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
161 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
162 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
163 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
164 system-dependent error message.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
165 @seealso{dir, glob}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
166 @end deftypefn")
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
167 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
168 octave_value_list retval;
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
169
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
170 retval(2) = std::string ();
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
171 retval(1) = -1.0;
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4494
diff changeset
172 retval(0) = Cell ();
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
173
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
174 if (args.length () == 1)
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
175 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
176 std::string dirname = args(0).string_value ();
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
177
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
178 if (error_state)
1781
e090f89bf2f5 [project @ 1996-01-24 08:04:14 by jwe]
jwe
parents: 1773
diff changeset
179 gripe_wrong_type_arg ("readdir", args(0));
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
180 else
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
181 {
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5832
diff changeset
182 dir_entry dir (dirname);
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
183
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
184 if (dir)
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
185 {
1781
e090f89bf2f5 [project @ 1996-01-24 08:04:14 by jwe]
jwe
parents: 1773
diff changeset
186 string_vector dirlist = dir.read ();
8503
8ba2ee57c594 remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents: 8317
diff changeset
187 retval(0) = Cell (dirlist.sort ());
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
188 retval(1) = 0.0;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
189 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
190 else
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
191 {
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
192 retval(2) = dir.error ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
193 }
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
194 }
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
195 }
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
196 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
197 print_usage ();
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
198
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
199 return retval;
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
200 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
201
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
202 // FIXME -- should maybe also allow second arg to specify
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
203 // mode? OTOH, that might cause trouble with compatibility later...
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
204
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8503
diff changeset
205 DEFUN (mkdir, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
206 "-*- texinfo -*-\n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
207 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{dir})\n\
6192
5a53bf0f15b0 [project @ 2006-11-30 18:52:46 by jwe]
jwe
parents: 6187
diff changeset
208 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{parent}, @var{dir})\n\
8109
f3be63199134 Document mkdir()'s parent argument
weber@atlan
parents: 8008
diff changeset
209 Create a directory named @var{dir} in the directory @var{parent}.\n\
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
210 \n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
211 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
212 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
213 system-dependent error message, and @var{msgid} contains a unique\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
214 message identifier.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
215 @seealso{rmdir}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
216 @end deftypefn")
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
217 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
218 octave_value_list retval;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
219
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
220 retval(2) = std::string ();
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
221 retval(1) = std::string ();
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
222 retval(0) = false;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
223
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
224 int nargin = args.length ();
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
225
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
226 std::string dirname;
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
227
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
228 if (nargin == 2)
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
229 {
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
230 std::string parent = args(0).string_value ();
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
231 std::string dir = args(1).string_value ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
232
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
233 if (error_state)
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
234 {
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
235 gripe_wrong_type_arg ("mkdir", args(0));
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
236 return retval;
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
237 }
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
238 else
7272
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
239 dirname = file_ops::concat (parent, dir);
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
240 }
6200
1ec9de3cd12c [project @ 2006-12-05 18:05:11 by jwe]
jwe
parents: 6192
diff changeset
241 else if (nargin == 1)
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
242 {
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
243 dirname = args(0).string_value ();
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
244
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
245 if (error_state)
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
246 {
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
247 gripe_wrong_type_arg ("mkdir", args(0));
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
248 return retval;
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
249 }
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
250 }
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
251
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
252 if (nargin == 1 || nargin == 2)
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
253 {
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
254 std::string msg;
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
255
7970
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
256 dirname = file_ops::tilde_expand (dirname);
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
257
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
258 file_stat fs (dirname);
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
259
7970
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
260 if (fs && fs.is_dir ())
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
261 {
7970
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
262 // For compatibility with Matlab, we return true when the
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
263 // directory already exists.
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
264
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
265 retval(2) = "mkdir";
7970
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
266 retval(1) = "directory exists";
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
267 retval(0) = true;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
268 }
6187
2a8922007c12 [project @ 2006-11-29 01:59:59 by jwe]
jwe
parents: 6134
diff changeset
269 else
7970
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
270 {
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
271 int status = file_ops::mkdir (dirname, 0777, msg);
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
272
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
273 if (status < 0)
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
274 {
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
275 retval(2) = "mkdir";
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
276 retval(1) = msg;
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
277 }
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
278 else
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
279 retval(0) = true;
b6d4c644b4b6 Fmkdir: improve compatibility
John W. Eaton <jwe@octave.org>
parents: 7272
diff changeset
280 }
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
281 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
282 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
283 print_usage ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
284
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
285 return retval;
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
286 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
287
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8503
diff changeset
288 DEFUN (rmdir, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
289 "-*- texinfo -*-\n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
290 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir})\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
291 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir}, @code{\"s\"})\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
292 Remove the directory named @var{dir}.\n\
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
293 \n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
294 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
295 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
296 system-dependent error message, and @var{msgid} contains a unique\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
297 message identifier.\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
298 \n\
7007
6304d9ea0a30 [project @ 2007-10-11 16:26:36 by jwe]
jwe
parents: 7001
diff changeset
299 If the optional second parameter is supplied with value @code{\"s\"},\n\
6134
3010a2ecde0b [project @ 2006-11-02 15:29:28 by jwe]
jwe
parents: 6116
diff changeset
300 recursively remove all subdirectories as well.\n\
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
301 @seealso{mkdir, confirm_recursive_rmdir}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
302 @end deftypefn")
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
303 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
304 octave_value_list retval;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
305
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
306 retval(2) = std::string ();
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
307 retval(1) = std::string ();
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
308 retval(0) = false;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
309
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
310 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
311
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
312 if (nargin == 1 || nargin == 2)
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
313 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
314 std::string dirname = args(0).string_value ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
315
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
316 if (error_state)
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
317 gripe_wrong_type_arg ("rmdir", args(0));
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1488
diff changeset
318 else
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
319 {
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
320 std::string fulldir = file_ops::tilde_expand (dirname);
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
321 int status = -1;
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
322 std::string msg;
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
323
5639
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
324 if (nargin == 2)
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
325 {
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
326 if (args(1).string_value () == "s")
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
327 {
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
328 bool doit = true;
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
329
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
330 if (interactive && Vconfirm_recursive_rmdir)
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
331 {
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
332 std::string prompt
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
333 = "remove entire contents of " + fulldir + "? ";
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
334
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
335 doit = octave_yes_or_no (prompt);
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
336 }
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
337
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
338 if (doit)
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
339 status = file_ops::recursive_rmdir (fulldir, msg);
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
340 }
5639
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
341 else
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
342 error ("rmdir: expecting second argument to be \"s\"");
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
343 }
acbcb9f164ca [project @ 2006-03-03 16:39:34 by jwe]
jwe
parents: 5637
diff changeset
344 else
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
345 status = file_ops::rmdir (fulldir, msg);
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
346
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
347 if (status < 0)
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
348 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
349 retval(2) = "rmdir";
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
350 retval(1) = msg;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
351 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
352 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5444
diff changeset
353 retval(0) = true;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
354 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
355 }
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
356 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
357 print_usage ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
358
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
359 return retval;
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
360 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
361
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
362 DEFUN (link, args, ,
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
363 "-*- texinfo -*-\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
364 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
365 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
366 \n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
367 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
368 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
369 system-dependent error message.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
370 @seealso{symlink}\n\
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
371 @end deftypefn")
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
372 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
373 octave_value_list retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
374
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
375 retval(1) = std::string ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
376 retval(0) = -1.0;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
377
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
378 if (args.length () == 2)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
379 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
380 std::string from = args(0).string_value ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
381
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
382 if (error_state)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
383 gripe_wrong_type_arg ("link", args(0));
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
384 else
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 std::string to = args(1).string_value ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
387
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
388 if (error_state)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
389 gripe_wrong_type_arg ("link", args(1));
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
390 else
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
391 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
392 std::string msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
393
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
394 int status = file_ops::link (from, to, msg);
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
395
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4208
diff changeset
396 retval(0) = status;
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
397
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
398 if (status < 0)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
399 retval(1) = msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
400 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
401 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
402 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
403 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
404 print_usage ();
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
405
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
406 return retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
407 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
408
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
409 DEFUN (symlink, args, ,
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
410 "-*- texinfo -*-\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
411 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
412 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
413 \n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
414 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
415 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
416 system-dependent error message.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
417 @seealso{link, readlink}\n\
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
418 @end deftypefn")
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
419 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
420 octave_value_list retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
421
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
422 retval(1) = std::string ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
423 retval(0) = -1.0;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
424
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
425 if (args.length () == 2)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
426 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
427 std::string from = args(0).string_value ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
428
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
429 if (error_state)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
430 gripe_wrong_type_arg ("symlink", args(0));
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
431 else
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
432 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
433 std::string to = args(1).string_value ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
434
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
435 if (error_state)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
436 gripe_wrong_type_arg ("symlink", args(1));
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
437 else
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
438 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
439 std::string msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
440
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
441 int status = file_ops::symlink (from, to, msg);
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
442
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4208
diff changeset
443 retval(0) = status;
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
444
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
445 if (status < 0)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
446 retval(1) = msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
447 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
448 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
449 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
450 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
451 print_usage ();
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
452
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
453 return retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
454 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
455
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
456 DEFUN (readlink, args, ,
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
457 "-*- texinfo -*-\n\
4169
d5667eaf8859 [project @ 2002-11-12 03:13:42 by jwe]
jwe
parents: 4051
diff changeset
458 @deftypefn {Built-in Function} {[@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
459 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
460 \n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
461 If successful, @var{result} contains the contents of the symbolic link\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
462 @var{symlink}, @var{err} is 0 and @var{msg} is an empty string.\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
463 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
464 system-dependent error message.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
465 @seealso{link, symlink}\n\
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
466 @end deftypefn")
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
467 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
468 octave_value_list retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
469
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
470 retval(2) = std::string ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
471 retval(1) = -1.0;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
472 retval(0) = std::string ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
473
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
474 if (args.length () == 1)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
475 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
476 std::string symlink = args(0).string_value ();
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
477
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
478 if (error_state)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
479 gripe_wrong_type_arg ("readlink", args(0));
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
480 else
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
481 {
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
482 std::string result;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
483 std::string msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
484
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
485 int status = file_ops::readlink (symlink, result, msg);
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
486
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
487 retval(0) = result;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
488
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4208
diff changeset
489 retval(1) = status;
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
490
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
491 if (status < 0)
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
492 retval(2) = msg;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
493 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
494 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
495 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
496 print_usage ();
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
497
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
498 return retval;
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
499 }
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3690
diff changeset
500
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
501 DEFUN (rename, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
502 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
503 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
504 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
505 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
506 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
507 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
508 system-dependent error message.\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
509 @seealso{ls, dir}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
510 @end deftypefn")
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
511 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
512 octave_value_list retval;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
513
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
514 retval(1) = std::string ();
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
515 retval(0) = -1.0;
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
516
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
517 if (args.length () == 2)
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
518 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
519 std::string from = args(0).string_value ();
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1690
diff changeset
520
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
521 if (error_state)
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
522 gripe_wrong_type_arg ("rename", args(0));
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
523 else
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
524 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
525 std::string to = args(1).string_value ();
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1690
diff changeset
526
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
527 if (error_state)
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
528 gripe_wrong_type_arg ("rename", args(1));
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
529 else
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
530 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
531 std::string msg;
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
532
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
533 int status = file_ops::rename (from, to, msg);
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
534
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4208
diff changeset
535 retval(0) = status;
2669
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
536
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
537 if (status < 0)
c821858188b6 [project @ 1997-02-13 18:25:39 by jwe]
jwe
parents: 2512
diff changeset
538 retval(1) = msg;
1402
6550c74777b9 [project @ 1995-09-15 04:27:57 by jwe]
jwe
parents: 1401
diff changeset
539 }
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
540 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
541 }
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
542 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
543 print_usage ();
1401
633199854158 [project @ 1995-09-15 04:15:27 by jwe]
jwe
parents: 1389
diff changeset
544
1389
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
545 return retval;
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
546 }
affbd42dd0c1 [project @ 1995-09-14 07:41:09 by jwe]
jwe
parents: 1380
diff changeset
547
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
548 DEFUN (glob, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
549 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
550 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\
5444
781c9e7dbb73 [project @ 2005-09-08 02:55:21 by jwe]
jwe
parents: 5307
diff changeset
551 Given an array of strings (as a char array or a cell array) in\n\
781c9e7dbb73 [project @ 2005-09-08 02:55:21 by jwe]
jwe
parents: 5307
diff changeset
552 @var{pattern}, return a cell array of file names that match any of\n\
781c9e7dbb73 [project @ 2005-09-08 02:55:21 by jwe]
jwe
parents: 5307
diff changeset
553 them, or an empty cell array if no patterns match. Tilde expansion\n\
781c9e7dbb73 [project @ 2005-09-08 02:55:21 by jwe]
jwe
parents: 5307
diff changeset
554 is performed on each of the patterns before looking for matching file\n\
781c9e7dbb73 [project @ 2005-09-08 02:55:21 by jwe]
jwe
parents: 5307
diff changeset
555 names. For example,\n\
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
556 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
557 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
558 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
559 glob (\"/vm*\")\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
560 @result{} \"/vmlinuz\"\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
561 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
562 @end example\n\
5597
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
563 @seealso{dir, ls, stat, readdir}\n\
e0e48ea2a93c [project @ 2006-01-13 21:17:37 by jwe]
jwe
parents: 5476
diff changeset
564 @end deftypefn")
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
565 {
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
566 octave_value retval;
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
567
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
568 if (args.length () == 1)
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
569 {
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
570 string_vector pat = args(0).all_strings ();
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
571
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
572 if (error_state)
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
573 gripe_wrong_type_arg ("glob", args(0));
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
574 else
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
575 {
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
576 glob_match pattern (file_ops::tilde_expand (pat));
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
577
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4494
diff changeset
578 retval = Cell (pattern.glob ());
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
579 }
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
580 }
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
581 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
582 print_usage ();
2495
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
583
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
584 return retval;
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
585 }
29cd3862a9dc [project @ 1996-11-11 02:39:49 by jwe]
jwe
parents: 2442
diff changeset
586
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
587 DEFUN (fnmatch, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
588 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
589 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
590 Return 1 or zero for each element of @var{string} that matches any of\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
591 the elements of the string array @var{pattern}, using the rules of\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
592 filename pattern matching. For example,\n\
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
593 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
594 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
595 @group\n\
6233
a299c8a6d96e [project @ 2007-01-09 04:31:18 by jwe]
jwe
parents: 6200
diff changeset
596 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
597 @result{} [ 1; 1; 0 ]\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
598 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
599 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3147
diff changeset
600 @end deftypefn")
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
601 {
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
602 octave_value retval;
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
603
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
604 if (args.length () == 2)
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
605 {
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
606 string_vector pat = args(0).all_strings ();
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
607 string_vector str = args(1).all_strings ();
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
608
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
609 if (error_state)
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
610 gripe_wrong_type_arg ("fnmatch", args(0));
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
611 else
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
612 {
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
613 glob_match pattern (file_ops::tilde_expand (pat));
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
614
9942
314d2234b660 return logical result from fnmatch
Jaroslav Hajek <highegg@gmail.com>
parents: 9270
diff changeset
615 retval = pattern.match (str);
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
616 }
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
617 }
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
618 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
619 print_usage ();
2496
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
620
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
621 return retval;
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
622 }
9823f8bfd1a5 [project @ 1996-11-11 03:17:10 by jwe]
jwe
parents: 2495
diff changeset
623
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
624 DEFUN (filesep, args, ,
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
625 "-*- texinfo -*-\n\
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
626 @deftypefn {Built-in Function} {} filesep ()\n\
8317
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
627 @deftypefnx {Built-in Function} {} filesep ('all')\n\
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
628 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
629 \n\
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
630 If 'all' is given, the function return all valid file separators in\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
631 the form of a string. The list of file separators is system-dependent.\n\
8317
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
632 It is / (forward slash) under UNIX or Mac OS X, / and \\ (forward and\n\
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
633 backward slashes) under Windows.\n\
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
634 @seealso{pathsep, dir, ls}\n\
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
635 @end deftypefn")
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
636 {
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
637 octave_value retval;
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
638
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
639 if (args.length () == 0)
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7970
diff changeset
640 retval = file_ops::dir_sep_str ();
8317
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
641 else if (args.length () == 1)
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
642 {
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
643 std::string s = args(0).string_value ();
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
644
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
645 if (! error_state)
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
646 {
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
647 if (s == "all")
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
648 retval = file_ops::dir_sep_chars ();
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
649 else
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
650 gripe_wrong_type_arg ("filesep", args(0));
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
651 }
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
652 else
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
653 gripe_wrong_type_arg ("filesep", args(0));
135c0e7d7802 Extend filesep functionality by allowing to return all valid file separators
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8109
diff changeset
654 }
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
655 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
656 print_usage ();
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
657
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
658 return retval;
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
659 }
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
660
9266
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
661 DEFUN (pathsep, args, nargout,
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
662 "-*- texinfo -*-\n\
9266
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
663 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\
9270
f9ac007bb926 fix typo in 9266:1d3b91166b9c
Jaroslav Hajek <highegg@gmail.com>
parents: 9266
diff changeset
664 @deftypefnx {Built-in Function} {@var{old_val} =} pathsep (@var{new_val})\n\
9266
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
665 Query or set the character used to separate directories in\n\
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
666 a path.\n\
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
667 @seealso{filesep, dir, ls}\n\
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
668 @end deftypefn")
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
669 {
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
670 octave_value retval;
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
671
9266
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
672 int nargin = args.length ();
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
673
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
674 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
675 retval = dir_path::path_sep_str ();
9266
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
676
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
677 if (nargin == 1)
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
678 {
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
679 std::string sval = args(0).string_value ();
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
680
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
681 if (! error_state)
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
682 {
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
683 switch (sval.length ())
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
684 {
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
685 case 1:
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
686 dir_path::path_sep_char (sval[0]);
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
687 break;
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
688
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
689 case 0:
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
690 dir_path::path_sep_char ('\0');
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
691 break;
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
692
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
693 default:
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
694 error ("pathsep: argument must be a single character");
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
695 break;
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
696 }
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
697 }
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
698 else
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
699 error ("pathsep: argument must be a single character");
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
700 }
1d3b91166b9c allow pathsep to be set
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
701 else if (nargin > 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
702 print_usage ();
5777
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
703
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
704 return retval;
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
705 }
246b1fc1e628 [project @ 2006-04-26 18:16:24 by jwe]
jwe
parents: 5775
diff changeset
706
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
707 DEFUN (confirm_recursive_rmdir, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
708 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
709 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
710 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
711 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
712 will ask for confirmation before recursively removing a directory tree.\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
713 @end deftypefn")
5640
426719471ac6 [project @ 2006-03-04 06:02:14 by jwe]
jwe
parents: 5639
diff changeset
714 {
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5777
diff changeset
715 return SET_INTERNAL_VARIABLE (confirm_recursive_rmdir);
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4233
diff changeset
716 }