diff src/dirfns.cc @ 2495:29cd3862a9dc

[project @ 1996-11-11 02:39:49 by jwe]
author jwe
date Mon, 11 Nov 1996 02:42:44 +0000
parents f667d7ec08b9
children 9823f8bfd1a5
line wrap: on
line diff
--- a/src/dirfns.cc
+++ b/src/dirfns.cc
@@ -54,6 +54,7 @@
 #include <unistd.h>
 #endif
 
+#include "oct-glob.h"
 #include "str-vec.h"
 
 #include "defun.h"
@@ -584,6 +585,40 @@
   return retval;
 }
 
+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
+matching file names.")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      string_vector pat = args(0).all_strings ();
+
+      if (error_state)
+	gripe_wrong_type_arg ("glob", args(0));
+      else
+	{
+	  glob_match pattern (oct_tilde_expand (pat));
+
+	  string_vector list = pattern.glob ();
+
+	  if (list.empty ())
+	    retval = "";
+	  else
+	    retval = list;
+	}
+    }
+  else
+    print_usage ("glob");
+
+  return retval;
+}
+
 static int
 pwd (void)
 {