changeset 10345:33b012d39dce

Convert between back and forward slashes before and after calling glob.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 21 Feb 2010 17:46:30 +0000
parents 65974373505a
children 65d5776379c3
files liboctave/ChangeLog liboctave/oct-glob.cc
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Sun Feb 21 17:40:13 2010 +0000
+++ b/liboctave/ChangeLog	Sun Feb 21 17:46:30 2010 +0000
@@ -1,5 +1,9 @@
 2010-02-21  Michael Goffioul  <michael.goffioul@gmail.com>
 
+	* oct-glob.cc (octave_glob): Convert backslashes to forward slashes
+	automatically before calling glob, and convert back after the call
+	(implementation from jwe).
+
 	* Makefile.am: Add -bindir flag to liboctave_la_LDFLAGS.
 
 2010-02-19  Jaroslav Hajek  <highegg@gmail.com>
--- a/liboctave/oct-glob.cc	Sun Feb 21 17:40:13 2010 +0000
+++ b/liboctave/oct-glob.cc	Sun Feb 21 17:46:30 2010 +0000
@@ -24,6 +24,7 @@
 #include <config.h>
 #endif
 
+#include <algorithm>
 #include <string>
 
 #include <fnmatch.h>
@@ -78,6 +79,13 @@
         {
           glob_t glob_info;
 
+#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
+          && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) 
+              std::replace_if (xpat.begin (), xpat.end (), 
+                               std::bind2nd (std::equal_to<char> (), '\\'), 
+                               '/'); 
+#endif 
+
           int err = ::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info);
 
           if (! err)
@@ -98,7 +106,19 @@
                   retval.resize (k+n);
 
                   for (int j = 0; j < n; j++)
-                    retval[k++] = matches[j];
+                    { 
+                      std::string tmp = matches[j]; 
+
+#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
+                      && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) 
+                          std::replace_if (tmp.begin (), tmp.end (), 
+                                           std::bind2nd (std::equal_to<char> (), 
+                                                         '/'), 
+                                           '\\'); 
+#endif 
+
+                      retval[k++] = tmp; 
+                    } 
                 }
 
               globfree (&glob_info);