523
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
523
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
523
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
523
|
26 #endif |
|
27 |
1341
|
28 #include <cerrno> |
|
29 #include <cstdio> |
|
30 #include <cstddef> |
|
31 #include <cstdlib> |
|
32 #include <cstring> |
|
33 |
1728
|
34 #include <string> |
|
35 |
1832
|
36 #ifdef HAVE_UNISTD_H |
2442
|
37 #ifdef HAVE_SYS_TYPES_H |
1832
|
38 #include <sys/types.h> |
2442
|
39 #endif |
1832
|
40 #include <unistd.h> |
|
41 #endif |
|
42 |
2926
|
43 #include "file-ops.h" |
|
44 #include "file-stat.h" |
|
45 #include "glob-match.h" |
4051
|
46 #include "lo-sstream.h" |
2926
|
47 #include "oct-env.h" |
1755
|
48 #include "str-vec.h" |
|
49 |
5102
|
50 #include "Cell.h" |
1355
|
51 #include "defun.h" |
1781
|
52 #include "dir-ops.h" |
1355
|
53 #include "dirfns.h" |
|
54 #include "error.h" |
1402
|
55 #include "gripes.h" |
1750
|
56 #include "oct-obj.h" |
1355
|
57 #include "pager.h" |
|
58 #include "procstream.h" |
|
59 #include "sysdep.h" |
1750
|
60 #include "toplev.h" |
1449
|
61 #include "unwind-prot.h" |
523
|
62 #include "utils.h" |
1742
|
63 #include "variables.h" |
523
|
64 |
2926
|
65 // XXX FIXME XXX -- changing the plotter directory should be handled |
|
66 // by registering a function for octave_env::chdir to call so that |
|
67 // this function can be eliminated. |
523
|
68 |
1328
|
69 static int |
3523
|
70 octave_change_to_directory (const std::string& newdir) |
1328
|
71 { |
2926
|
72 int cd_ok = octave_env::chdir (newdir); |
1328
|
73 |
|
74 if (cd_ok) |
5102
|
75 // XXX FIXME XXX -- this should be handled as a list of functions |
|
76 // to call so users can add their own chdir handlers. |
|
77 /* do_external_plotter_cd (newdir) */; |
1328
|
78 else |
3531
|
79 { |
|
80 using namespace std; |
|
81 |
|
82 error ("%s: %s", newdir.c_str (), strerror (errno)); |
|
83 } |
1328
|
84 |
|
85 return cd_ok; |
|
86 } |
|
87 |
4208
|
88 DEFCMD (cd, args, , |
3301
|
89 "-*- texinfo -*-\n\ |
|
90 @deffn {Command} cd dir\n\ |
|
91 @deffnx {Command} chdir dir\n\ |
|
92 Change the current working directory to @var{dir}. If @var{dir} is\n\ |
|
93 omitted, the current directory is changed to the users home\n\ |
|
94 directory. For example,\n\ |
523
|
95 \n\ |
3301
|
96 @example\n\ |
|
97 cd ~/octave\n\ |
|
98 @end example\n\ |
|
99 \n\ |
|
100 @noindent\n\ |
|
101 Changes the current working directory to @file{~/octave}. If the\n\ |
|
102 directory does not exist, an error message is printed and the working\n\ |
|
103 directory is not changed.\n\ |
|
104 @end deffn") |
523
|
105 { |
2086
|
106 octave_value_list retval; |
523
|
107 |
1755
|
108 int argc = args.length () + 1; |
|
109 |
1965
|
110 string_vector argv = args.make_argv ("cd"); |
1755
|
111 |
|
112 if (error_state) |
|
113 return retval; |
523
|
114 |
|
115 if (argc > 1) |
|
116 { |
3523
|
117 std::string dirname = file_ops::tilde_expand (argv[1]); |
523
|
118 |
1750
|
119 if (dirname.length () > 0 |
1755
|
120 && ! octave_change_to_directory (dirname)) |
523
|
121 { |
|
122 return retval; |
|
123 } |
|
124 } |
|
125 else |
|
126 { |
3523
|
127 std::string home_dir = octave_env::get_home_directory (); |
2926
|
128 |
|
129 if (home_dir.empty () || ! octave_change_to_directory (home_dir)) |
|
130 return retval; |
523
|
131 } |
|
132 |
|
133 return retval; |
|
134 } |
|
135 |
611
|
136 DEFALIAS (chdir, cd); |
|
137 |
661
|
138 // Get a directory listing. |
|
139 |
1965
|
140 static void |
|
141 cleanup_iprocstream (void *p) |
|
142 { |
2800
|
143 delete static_cast <iprocstream *> (p); |
1965
|
144 } |
|
145 |
4691
|
146 DEFCMD (ls, args, nargout, |
3301
|
147 "-*- texinfo -*-\n\ |
|
148 @deffn {Command} ls options\n\ |
|
149 List directory contents. For example,\n\ |
523
|
150 \n\ |
3301
|
151 @example\n\ |
|
152 ls -l\n\ |
|
153 @print{} total 12\n\ |
|
154 @print{} -rw-r--r-- 1 jwe users 4488 Aug 19 04:02 foo.m\n\ |
|
155 @print{} -rw-r--r-- 1 jwe users 1315 Aug 17 23:14 bar.m\n\ |
|
156 @end example\n\ |
|
157 \n\ |
|
158 The @code{dir} and @code{ls} commands are implemented by calling your\n\ |
|
159 system's directory listing command, so the available options may vary\n\ |
|
160 from system to system.\n\ |
|
161 @end deffn") |
523
|
162 { |
4691
|
163 octave_value retval; |
523
|
164 |
1755
|
165 int argc = args.length () + 1; |
|
166 |
1965
|
167 string_vector argv = args.make_argv ("ls"); |
1755
|
168 |
|
169 if (error_state) |
|
170 return retval; |
523
|
171 |
4051
|
172 OSSTREAM ls_buf; |
523
|
173 |
|
174 ls_buf << "ls -C "; |
|
175 for (int i = 1; i < argc; i++) |
2926
|
176 ls_buf << file_ops::tilde_expand (argv[i]) << " "; |
523
|
177 |
4051
|
178 ls_buf << OSSTREAM_ENDS; |
523
|
179 |
4051
|
180 iprocstream *cmd = new iprocstream (OSSTREAM_STR (ls_buf)); |
523
|
181 |
4051
|
182 OSSTREAM_FREEZE (ls_buf); |
1469
|
183 |
2985
|
184 unwind_protect::add (cleanup_iprocstream, cmd); |
523
|
185 |
1449
|
186 if (cmd && *cmd) |
|
187 { |
3147
|
188 char ch; |
|
189 |
4691
|
190 OSSTREAM output_buf; |
|
191 |
4489
|
192 for (;;) |
|
193 { |
|
194 if (cmd->get (ch)) |
5145
|
195 output_buf << ch; |
4489
|
196 else |
5144
|
197 break; |
4489
|
198 } |
4691
|
199 |
|
200 output_buf << OSSTREAM_ENDS; |
|
201 |
5145
|
202 std::string output = OSSTREAM_STR (output_buf); |
|
203 |
4691
|
204 if (nargout > 0) |
5145
|
205 retval = output; |
|
206 else |
|
207 octave_stdout << output; |
4691
|
208 |
|
209 OSSTREAM_FREEZE (output_buf); |
1449
|
210 } |
|
211 else |
|
212 error ("couldn't start process for ls!"); |
523
|
213 |
2985
|
214 unwind_protect::run (); |
523
|
215 |
|
216 return retval; |
|
217 } |
|
218 |
1957
|
219 DEFUN (pwd, , nargout, |
3301
|
220 "-*- texinfo -*-\n\ |
|
221 @deftypefn {Built-in Function} {} pwd ()\n\ |
|
222 Return the current working directory.\n\ |
|
223 @end deftypefn") |
523
|
224 { |
4233
|
225 octave_value retval; |
523
|
226 |
3523
|
227 std::string directory = octave_env::getcwd (); |
523
|
228 |
2926
|
229 if (directory.empty ()) |
|
230 warning ("pwd: can't find working directory!"); |
523
|
231 else |
|
232 { |
1592
|
233 if (nargout == 0) |
2095
|
234 octave_stdout << directory << "\n"; |
1592
|
235 else |
|
236 retval = directory; |
523
|
237 } |
1592
|
238 |
523
|
239 return retval; |
|
240 } |
|
241 |
1957
|
242 DEFUN (readdir, args, , |
3301
|
243 "-*- texinfo -*-\n\ |
|
244 @deftypefn {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\ |
4691
|
245 Return names of the files in the directory @var{dir} as a cell array of\n\ |
|
246 strings. If an error occurs, return an empty cell array in @var{files}.\n\ |
1389
|
247 \n\ |
3301
|
248 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
249 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
250 system-dependent error message.\n\ |
|
251 @end deftypefn") |
1389
|
252 { |
2086
|
253 octave_value_list retval; |
1389
|
254 |
3523
|
255 retval(2) = std::string (); |
2669
|
256 retval(1) = -1.0; |
4691
|
257 retval(0) = Cell (); |
2669
|
258 |
1401
|
259 if (args.length () == 1) |
1389
|
260 { |
3523
|
261 std::string dirname = args(0).string_value (); |
1389
|
262 |
1401
|
263 if (error_state) |
1781
|
264 gripe_wrong_type_arg ("readdir", args(0)); |
1401
|
265 else |
|
266 { |
2926
|
267 dir_entry dir (file_ops::tilde_expand (dirname)); |
1389
|
268 |
1401
|
269 if (dir) |
1389
|
270 { |
1781
|
271 string_vector dirlist = dir.read (); |
4691
|
272 retval(0) = Cell (dirlist.qsort ()); |
2669
|
273 retval(1) = 0.0; |
1401
|
274 } |
|
275 else |
|
276 { |
2669
|
277 retval(2) = dir.error (); |
1401
|
278 } |
1389
|
279 } |
|
280 } |
|
281 else |
|
282 print_usage ("readdir"); |
|
283 |
1401
|
284 return retval; |
|
285 } |
|
286 |
5476
|
287 // XXX FIXME XXX -- should maybe also allow second arg to specify |
|
288 // mode? OTOH, that might cause trouble with compatibility later... |
1401
|
289 |
1957
|
290 DEFUN (mkdir, args, , |
3301
|
291 "-*- texinfo -*-\n\ |
5476
|
292 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@var{dir})\n\ |
3301
|
293 Create a directory named @var{dir}.\n\ |
1401
|
294 \n\ |
5476
|
295 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
|
296 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ |
|
297 system-dependent error message, and @var{msgid} contains a unique\n\ |
|
298 message identifier.\n\ |
3301
|
299 @end deftypefn") |
1401
|
300 { |
2086
|
301 octave_value_list retval; |
1401
|
302 |
5476
|
303 retval(2) = std::string (); |
3523
|
304 retval(1) = std::string (); |
5476
|
305 retval(0) = false; |
1401
|
306 |
|
307 if (args.length () == 1) |
|
308 { |
3523
|
309 std::string dirname = args(0).string_value (); |
1401
|
310 |
|
311 if (error_state) |
1402
|
312 gripe_wrong_type_arg ("mkdir", args(0)); |
1489
|
313 else |
1401
|
314 { |
3523
|
315 std::string msg; |
2669
|
316 |
2926
|
317 int status = file_ops::mkdir (file_ops::tilde_expand (dirname), |
|
318 0777, msg); |
1489
|
319 |
2669
|
320 if (status < 0) |
5476
|
321 { |
|
322 retval(2) = "mkdir"; |
|
323 retval(1) = msg; |
|
324 } |
|
325 else |
|
326 retval(0) = true; |
1401
|
327 } |
|
328 } |
|
329 else |
|
330 print_usage ("mkdir"); |
|
331 |
|
332 return retval; |
|
333 } |
|
334 |
1957
|
335 DEFUN (rmdir, args, , |
3301
|
336 "-*- texinfo -*-\n\ |
5476
|
337 @deftypefn {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir})\n\ |
|
338 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@var{dir}, @code{\"s\"})\n\ |
3301
|
339 Remove the directory named @var{dir}.\n\ |
1401
|
340 \n\ |
5476
|
341 If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
|
342 character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ |
|
343 system-dependent error message, and @var{msgid} contains a unique\n\ |
|
344 message identifier.\n\ |
|
345 \n\ |
|
346 If the optional second parameter is suplied, recursively remove all\n\ |
|
347 subdirectories as well.\n\ |
3301
|
348 @end deftypefn") |
1401
|
349 { |
2086
|
350 octave_value_list retval; |
1401
|
351 |
5476
|
352 retval(2) = std::string (); |
3523
|
353 retval(1) = std::string (); |
5476
|
354 retval(0) = false; |
1401
|
355 |
5476
|
356 int nargin = args.length (); |
|
357 |
|
358 if (nargin == 1 || nargin == 2) |
1401
|
359 { |
3523
|
360 std::string dirname = args(0).string_value (); |
1401
|
361 |
|
362 if (error_state) |
1402
|
363 gripe_wrong_type_arg ("rmdir", args(0)); |
1489
|
364 else |
1401
|
365 { |
3523
|
366 std::string msg; |
2669
|
367 |
5476
|
368 std::string fulldir = file_ops::tilde_expand (dirname); |
1489
|
369 |
5476
|
370 int status = (nargin == 1) |
|
371 ? file_ops::rmdir (fulldir, msg) |
|
372 : file_ops::recursive_rmdir (fulldir, msg); |
2669
|
373 |
|
374 if (status < 0) |
5476
|
375 { |
|
376 retval(2) = "rmdir"; |
|
377 retval(1) = msg; |
|
378 } |
|
379 else |
|
380 retval(0) = true; |
1401
|
381 } |
|
382 } |
1389
|
383 else |
1401
|
384 print_usage ("rmdir"); |
|
385 |
|
386 return retval; |
|
387 } |
|
388 |
3710
|
389 DEFUN (link, args, , |
|
390 "-*- texinfo -*-\n\ |
|
391 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ |
|
392 Create a new link (also known as a hard link) to an existing file.\n\ |
|
393 \n\ |
|
394 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
395 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
396 system-dependent error message.\n\ |
|
397 @end deftypefn") |
|
398 { |
|
399 octave_value_list retval; |
|
400 |
|
401 retval(1) = std::string (); |
|
402 retval(0) = -1.0; |
|
403 |
|
404 if (args.length () == 2) |
|
405 { |
|
406 std::string from = args(0).string_value (); |
|
407 |
|
408 if (error_state) |
|
409 gripe_wrong_type_arg ("link", args(0)); |
|
410 else |
|
411 { |
|
412 std::string to = args(1).string_value (); |
|
413 |
|
414 if (error_state) |
|
415 gripe_wrong_type_arg ("link", args(1)); |
|
416 else |
|
417 { |
|
418 std::string msg; |
|
419 |
|
420 int status = file_ops::link (from, to, msg); |
|
421 |
4233
|
422 retval(0) = status; |
3710
|
423 |
|
424 if (status < 0) |
|
425 retval(1) = msg; |
|
426 } |
|
427 } |
|
428 } |
|
429 else |
|
430 print_usage ("link"); |
|
431 |
|
432 return retval; |
|
433 } |
|
434 |
|
435 DEFUN (symlink, args, , |
|
436 "-*- texinfo -*-\n\ |
|
437 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ |
|
438 Create a symbolic link @var{new} which contains the string @var{old}.\n\ |
|
439 \n\ |
|
440 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
441 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
442 system-dependent error message.\n\ |
|
443 @end deftypefn") |
|
444 { |
|
445 octave_value_list retval; |
|
446 |
|
447 retval(1) = std::string (); |
|
448 retval(0) = -1.0; |
|
449 |
|
450 if (args.length () == 2) |
|
451 { |
|
452 std::string from = args(0).string_value (); |
|
453 |
|
454 if (error_state) |
|
455 gripe_wrong_type_arg ("symlink", args(0)); |
|
456 else |
|
457 { |
|
458 std::string to = args(1).string_value (); |
|
459 |
|
460 if (error_state) |
|
461 gripe_wrong_type_arg ("symlink", args(1)); |
|
462 else |
|
463 { |
|
464 std::string msg; |
|
465 |
|
466 int status = file_ops::symlink (from, to, msg); |
|
467 |
4233
|
468 retval(0) = status; |
3710
|
469 |
|
470 if (status < 0) |
|
471 retval(1) = msg; |
|
472 } |
|
473 } |
|
474 } |
|
475 else |
|
476 print_usage ("symlink"); |
|
477 |
|
478 return retval; |
|
479 } |
|
480 |
|
481 DEFUN (readlink, args, , |
|
482 "-*- texinfo -*-\n\ |
4169
|
483 @deftypefn {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\ |
3710
|
484 Read the value of the symbolic link @var{symlink}.\n\ |
|
485 \n\ |
|
486 If successful, @var{result} contains the contents of the symbolic link\n\ |
|
487 @var{symlink}, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
488 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
489 system-dependent error message.\n\ |
|
490 @end deftypefn") |
|
491 { |
|
492 octave_value_list retval; |
|
493 |
|
494 retval(2) = std::string (); |
|
495 retval(1) = -1.0; |
|
496 retval(0) = std::string (); |
|
497 |
|
498 if (args.length () == 1) |
|
499 { |
|
500 std::string symlink = args(0).string_value (); |
|
501 |
|
502 if (error_state) |
|
503 gripe_wrong_type_arg ("readlink", args(0)); |
|
504 else |
|
505 { |
|
506 std::string result; |
|
507 std::string msg; |
|
508 |
|
509 int status = file_ops::readlink (symlink, result, msg); |
|
510 |
|
511 retval(0) = result; |
|
512 |
4233
|
513 retval(1) = status; |
3710
|
514 |
|
515 if (status < 0) |
|
516 retval(2) = msg; |
|
517 } |
|
518 } |
|
519 else |
|
520 print_usage ("readlink"); |
|
521 |
|
522 return retval; |
|
523 } |
|
524 |
1957
|
525 DEFUN (rename, args, , |
3301
|
526 "-*- texinfo -*-\n\ |
|
527 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\ |
|
528 Change the name of file @var{old} to @var{new}.\n\ |
1401
|
529 \n\ |
3301
|
530 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ |
|
531 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ |
|
532 system-dependent error message.\n\ |
|
533 @end deftypefn") |
1401
|
534 { |
2086
|
535 octave_value_list retval; |
1401
|
536 |
3523
|
537 retval(1) = std::string (); |
2669
|
538 retval(0) = -1.0; |
1401
|
539 |
|
540 if (args.length () == 2) |
|
541 { |
3523
|
542 std::string from = args(0).string_value (); |
1728
|
543 |
1401
|
544 if (error_state) |
1402
|
545 gripe_wrong_type_arg ("rename", args(0)); |
|
546 else |
1401
|
547 { |
3523
|
548 std::string to = args(1).string_value (); |
1728
|
549 |
1402
|
550 if (error_state) |
|
551 gripe_wrong_type_arg ("rename", args(1)); |
2669
|
552 else |
1402
|
553 { |
3523
|
554 std::string msg; |
2669
|
555 |
2926
|
556 int status = file_ops::rename (from, to, msg); |
2669
|
557 |
4233
|
558 retval(0) = status; |
2669
|
559 |
|
560 if (status < 0) |
|
561 retval(1) = msg; |
1402
|
562 } |
1401
|
563 } |
|
564 } |
|
565 else |
|
566 print_usage ("rename"); |
|
567 |
1389
|
568 return retval; |
|
569 } |
|
570 |
2495
|
571 DEFUN (glob, args, , |
3301
|
572 "-*- texinfo -*-\n\ |
|
573 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\ |
5444
|
574 Given an array of strings (as a char array or a cell array) in\n\ |
|
575 @var{pattern}, return a cell array of file names that match any of\n\ |
|
576 them, or an empty cell array if no patterns match. Tilde expansion\n\ |
|
577 is performed on each of the patterns before looking for matching file\n\ |
|
578 names. For example,\n\ |
2495
|
579 \n\ |
3301
|
580 @example\n\ |
|
581 @group\n\ |
|
582 glob (\"/vm*\")\n\ |
|
583 @result{} \"/vmlinuz\"\n\ |
|
584 @end group\n\ |
|
585 @end example\n\ |
5444
|
586 @end deftypefn\n\ |
|
587 @seealso{ls,dir}") |
2495
|
588 { |
|
589 octave_value retval; |
|
590 |
|
591 if (args.length () == 1) |
|
592 { |
|
593 string_vector pat = args(0).all_strings (); |
|
594 |
|
595 if (error_state) |
|
596 gripe_wrong_type_arg ("glob", args(0)); |
|
597 else |
|
598 { |
2926
|
599 glob_match pattern (file_ops::tilde_expand (pat)); |
2495
|
600 |
4691
|
601 retval = Cell (pattern.glob ()); |
2495
|
602 } |
|
603 } |
|
604 else |
|
605 print_usage ("glob"); |
|
606 |
|
607 return retval; |
|
608 } |
|
609 |
2496
|
610 DEFUN (fnmatch, args, , |
3301
|
611 "-*- texinfo -*-\n\ |
|
612 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\ |
|
613 Return 1 or zero for each element of @var{string} that matches any of\n\ |
|
614 the elements of the string array @var{pattern}, using the rules of\n\ |
|
615 filename pattern matching. For example,\n\ |
2496
|
616 \n\ |
3301
|
617 @example\n\ |
|
618 @group\n\ |
|
619 fnmatch (\"a*b\", [\"ab\"; \"axyzb\"; \"xyzab\"])\n\ |
|
620 @result{} [ 1; 1; 0 ]\n\ |
|
621 @end group\n\ |
|
622 @end example\n\ |
|
623 @end deftypefn") |
2496
|
624 { |
|
625 octave_value retval; |
|
626 |
|
627 if (args.length () == 2) |
|
628 { |
|
629 string_vector pat = args(0).all_strings (); |
|
630 string_vector str = args(1).all_strings (); |
|
631 |
|
632 if (error_state) |
|
633 gripe_wrong_type_arg ("fnmatch", args(0)); |
|
634 else |
|
635 { |
2926
|
636 glob_match pattern (file_ops::tilde_expand (pat)); |
2496
|
637 |
|
638 Array<bool> tmp = pattern.match (str); |
|
639 |
5275
|
640 octave_idx_type n = tmp.length (); |
2496
|
641 |
|
642 ColumnVector result (n); |
|
643 |
5275
|
644 for (octave_idx_type i = 0; i < n; i++) |
2496
|
645 result(i) = tmp(i); |
|
646 |
3418
|
647 retval = result; |
2496
|
648 } |
|
649 } |
|
650 else |
|
651 print_usage ("fnmatch"); |
|
652 |
|
653 return retval; |
|
654 } |
|
655 |
4264
|
656 void |
|
657 symbols_of_dirfns (void) |
|
658 { |
|
659 DEFCONST (filesep, file_ops::dir_sep_str, |
|
660 "-*- texinfo -*-\n\ |
|
661 @defvr {Built-in Variable} filesep\n\ |
|
662 The character used to separate directory names. The value\n\ |
|
663 of this variable is system dependent.\n\ |
|
664 @end defvr"); |
|
665 |
|
666 } |
|
667 |
523
|
668 /* |
|
669 ;;; Local Variables: *** |
|
670 ;;; mode: C++ *** |
|
671 ;;; End: *** |
|
672 */ |