Mercurial > octave
diff src/dirfns.cc @ 2496:9823f8bfd1a5
[project @ 1996-11-11 03:17:10 by jwe]
author | jwe |
---|---|
date | Mon, 11 Nov 1996 03:17:12 +0000 |
parents | 29cd3862a9dc |
children | fda09c1e787e |
line wrap: on
line diff
--- a/src/dirfns.cc Mon Nov 11 02:42:44 1996 +0000 +++ b/src/dirfns.cc Mon Nov 11 03:17:12 1996 +0000 @@ -588,9 +588,9 @@ DEFUN (glob, args, , "glob (PATTERN)\n\ \n\ -Given an array of strings in PATTERN, return the list of file names -that any of them, or an empty string if no patterns match. Tilde -expansion is performed on each of the patterns before looking for +Given an array of strings in PATTERN, return the list of file names\n\ +that any of them, or an empty string if no patterns match. Tilde\n\ +expansion is performed on each of the patterns before looking for\n\ matching file names.") { octave_value retval; @@ -619,6 +619,44 @@ return retval; } +DEFUN (fnmatch, args, , + "fnmatch (PATTERN, STRING)\n\ +\n\ +Return 1 or zero for each element of STRING that matches any of the\n\ +elements of the string array PATTERN, using the rules of filename\n\ +pattern matching.") +{ + octave_value retval; + + if (args.length () == 2) + { + string_vector pat = args(0).all_strings (); + string_vector str = args(1).all_strings (); + + if (error_state) + gripe_wrong_type_arg ("fnmatch", args(0)); + else + { + glob_match pattern (oct_tilde_expand (pat)); + + Array<bool> tmp = pattern.match (str); + + int n = tmp.length (); + + ColumnVector result (n); + + for (int i = 0; i < n; i++) + result(i) = tmp(i); + + retval = octave_value (result, true); + } + } + else + print_usage ("fnmatch"); + + return retval; +} + static int pwd (void) {