comparison liboctave/oct-glob.cc @ 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 07ebe522dac2
children 479cc8a0a846
comparison
equal deleted inserted replaced
10344:65974373505a 10345:33b012d39dce
22 22
23 #ifdef HAVE_CONFIG_H 23 #ifdef HAVE_CONFIG_H
24 #include <config.h> 24 #include <config.h>
25 #endif 25 #endif
26 26
27 #include <algorithm>
27 #include <string> 28 #include <string>
28 29
29 #include <fnmatch.h> 30 #include <fnmatch.h>
30 #include <glob.h> 31 #include <glob.h>
31 32
76 77
77 if (! xpat.empty ()) 78 if (! xpat.empty ())
78 { 79 {
79 glob_t glob_info; 80 glob_t glob_info;
80 81
82 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
83 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
84 std::replace_if (xpat.begin (), xpat.end (),
85 std::bind2nd (std::equal_to<char> (), '\\'),
86 '/');
87 #endif
88
81 int err = ::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info); 89 int err = ::glob (xpat.c_str (), GLOB_NOSORT, 0, &glob_info);
82 90
83 if (! err) 91 if (! err)
84 { 92 {
85 int n = glob_info.gl_pathc; 93 int n = glob_info.gl_pathc;
96 && single_match_exists (std::string (matches[0])))) 104 && single_match_exists (std::string (matches[0]))))
97 { 105 {
98 retval.resize (k+n); 106 retval.resize (k+n);
99 107
100 for (int j = 0; j < n; j++) 108 for (int j = 0; j < n; j++)
101 retval[k++] = matches[j]; 109 {
110 std::string tmp = matches[j];
111
112 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
113 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
114 std::replace_if (tmp.begin (), tmp.end (),
115 std::bind2nd (std::equal_to<char> (),
116 '/'),
117 '\\');
118 #endif
119
120 retval[k++] = tmp;
121 }
102 } 122 }
103 123
104 globfree (&glob_info); 124 globfree (&glob_info);
105 } 125 }
106 } 126 }