26 #if defined (HAVE_CONFIG_H)
40 #if defined (OCTAVE_USE_WINDOWS_API)
59 sys::file_stat s (file);
69 int npat = pat.
numel ();
71 const char *cstr = str.c_str ();
73 for (
int i = 0; i < npat; i++)
86 int npat = pat.
numel ();
95 for (
int i = 0; i < npat; i++)
97 std::string xpat = pat(i);
101 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
102 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
103 std::replace (xpat.begin (), xpat.end (),
'\\',
'/');
114 const char *
const *matches
128 for (
int j = 0; j <
n; j++)
130 std::string tmp = matches[j];
132 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
133 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
134 std::replace (tmp.begin (), tmp.end (),
'/',
'\\');
146 return retval.
sort ();
149 #if defined (OCTAVE_USE_WINDOWS_API)
152 find_files (std::list<std::string>& dirlist,
const std::string& dir,
153 const std::string& pat, std::string& file)
156 bool is_file_empty = file.
empty ();
158 file = file.substr (1, std::string::npos);
160 bool is_trailing_file_sep = ! is_file_empty && file.empty ();
162 if (! pat.compare (
".") || ! pat.compare (
".."))
169 std::string pat_str = file.substr (0, sep_pos);
170 std::string file_str = (sep_pos != std::string::npos)
171 ? file.substr (sep_pos) :
"";
174 if (pat_str.empty ())
176 if (is_trailing_file_sep)
190 _WIN32_FIND_DATAW ffd;
191 HANDLE h_find = FindFirstFileW (wpat.c_str (), &ffd);
193 if (h_find == INVALID_HANDLE_VALUE)
202 if (! (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
203 && (! file.empty () || is_trailing_file_sep))
211 if (found_dir.compare (
".") && found_dir.compare (
".."))
213 if (is_trailing_file_sep)
223 std::string pat_str = file.substr (0, sep_pos);
224 std::string file_str = (sep_pos != std::string::npos)
225 ? file.substr (sep_pos) :
"";
232 while (FindNextFileW (h_find, &ffd) != 0);
244 int npat = pat.
numel ();
246 #if defined (OCTAVE_USE_WINDOWS_API)
248 std::list<std::string> dirlist;
250 for (
int i = 0; i < npat; i++)
252 std::string xpat = pat(i);
256 std::string dir =
"";
263 if (sep_pos == 0 && xpat.length () > 1
268 if (sep_pos != std::string::npos)
271 if (sep_pos != std::string::npos)
273 dir = xpat.substr(0, sep_pos);
274 xpat = xpat.substr (sep_pos+1);
279 std::string file = (sep_pos != std::string::npos)
280 ? xpat.substr (sep_pos) :
"";
281 xpat = xpat.substr (0, sep_pos);
283 if ((sep_pos == 2 || xpat.length () == 2) && xpat[1] ==
':')
289 file = file.substr (1, std::string::npos);
293 xpat = file.substr (0, sep_pos);
294 file = (sep_pos != std::string::npos)
295 ? file.substr (sep_pos) :
"";
300 if (PathFileExistsW (wpat.c_str ()))
303 dirlist.push_back (dir +
306 dirlist.push_back (dir);
312 find_files (dirlist, dir, xpat, file);
326 for (
int i = 0; i < npat; i++)
328 std::string xpat = pat(i);
333 escaped.reserve (xpat.length ());
335 for (std::size_t j = 0; j < xpat.length (); j++)
337 # if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
338 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
344 if (xpat[j] ==
']' || xpat[j] ==
'[')
352 int len = escaped.length ();
353 if (
len >= 3 && escaped.substr (
len - 3) ==
"*.*")
354 escaped = escaped.substr (0,
len - 2);
364 const char *
const *matches
378 for (
int j = 0; j <
n; j++)
380 std::string tmp = matches[j];
382 std::string unescaped;
383 unescaped.reserve (tmp.length ());
385 for (std::size_t
m = 0;
m < tmp.length ();
m++)
387 # if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
388 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
395 && ++
m == tmp.length ())
402 retval[k++] = unescaped;
412 return retval.
sort ();
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
string_vector & sort(bool make_uniq=false)
void resize(octave_idx_type n, const std::string &rfv="")
octave_idx_type numel(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
int octave_fnm_nomatch_wrapper(void)
int octave_glob_nosort_wrapper(void)
void octave_destroy_glob_info_struct(void *glob_info)
void octave_globfree_wrapper(void *glob_info)
void * octave_create_glob_info_struct(void)
int octave_glob_num_matches(void *glob_info)
int octave_glob_wrapper(const char *pattern, int flags, void *glob_info)
int octave_fnmatch_wrapper(const char *pattern, const char *name, int flags)
char ** octave_glob_match_list(void *glob_info)
std::string u8_from_wstring(const std::wstring &wchar_string)
std::wstring u8_to_wstring(const std::string &utf8_string)
string_vector windows_glob(const string_vector &pat)
bool fnmatch(const string_vector &pat, const std::string &str, int fnm_flags)
static bool single_match_exists(const std::string &file)
string_vector glob(const string_vector &pat)
static const char dir_sep_char
static bool is_dir_sep(char c)
static std::string dir_sep_chars