26#if defined (HAVE_CONFIG_H)
41#if defined (OCTAVE_USE_WINDOWS_API)
60 int npat = pat.
numel ();
62 const char *cstr = str.c_str ();
64 for (
int i = 0; i < npat; i++)
77 int npat = pat.
numel ();
86 for (
int i = 0; i < npat; i++)
88 std::string xpat = pat(i);
92#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
93 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
94 std::replace (xpat.begin (), xpat.end (),
'\\',
'/');
105 const char *
const *matches
115 && sys::file_exists (std::string (matches[0]))))
119 for (
int j = 0; j < n; j++)
121 std::string tmp = matches[j];
123#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
124 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
125 std::replace (tmp.begin (), tmp.end (),
'/',
'\\');
137 return retval.
sort ();
140#if defined (OCTAVE_USE_WINDOWS_API)
143find_files (std::list<std::string>& dirlist,
const std::string& dir,
144 const std::string& pat, std::string& file)
147 bool is_file_empty = file.
empty ();
148 while (! file.empty () && sys::file_ops::is_dir_sep (file[0]))
149 file = file.substr (1, std::string::npos);
151 bool is_trailing_file_sep = ! is_file_empty && file.empty ();
153 if (! pat.compare (
".") || ! pat.compare (
".."))
159 = file.find_first_of (sys::file_ops::dir_sep_chars ());
160 std::string pat_str = file.substr (0, sep_pos);
161 std::string file_str = (sep_pos != std::string::npos)
162 ? file.substr (sep_pos) :
"";
165 if (pat_str.empty ())
167 if (is_trailing_file_sep)
168 pat_str = sys::file_ops::dir_sep_char ();
169 dirlist.push_back (sys::file_ops::concat (dir, pat) + pat_str);
174 find_files (dirlist, sys::file_ops::concat (dir, pat),
180 std::wstring wpat =
u8_to_wstring (sys::file_ops::concat (dir, pat));
181 _WIN32_FIND_DATAW ffd;
182 HANDLE h_find = FindFirstFileW (wpat.c_str (), &ffd);
184 if (h_find == INVALID_HANDLE_VALUE)
187 unwind_action close_h_find ([h_find] () { FindClose (h_find); });
193 if (! (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
194 && (! file.empty () || is_trailing_file_sep))
202 if (found_dir.compare (
".") && found_dir.compare (
".."))
204 if (is_trailing_file_sep)
205 found_dir += sys::file_ops::dir_sep_char ();
206 dirlist.push_back (sys::file_ops::concat (dir, found_dir));
213 = file.find_first_of (sys::file_ops::dir_sep_chars ());
214 std::string pat_str = file.substr (0, sep_pos);
215 std::string file_str = (sep_pos != std::string::npos)
216 ? file.substr (sep_pos) :
"";
219 find_files (dirlist, sys::file_ops::concat (dir, found_dir),
223 while (FindNextFileW (h_find, &ffd) != 0);
235 int npat = pat.
numel ();
237#if defined (OCTAVE_USE_WINDOWS_API)
239 std::list<std::string> dirlist;
241 for (
int i = 0; i < npat; i++)
243 std::string xpat = pat(i);
247 std::string dir =
"";
251 = xpat.find_first_of (sys::file_ops::dir_sep_chars ());
254 if (sep_pos == 0 && xpat.length () > 1
255 && sys::file_ops::is_dir_sep (xpat[1]))
258 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (), 2);
259 if (sep_pos != std::string::npos)
260 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars (),
262 if (sep_pos != std::string::npos)
264 dir = xpat.substr(0, sep_pos);
265 xpat = xpat.substr (sep_pos+1);
266 sep_pos = xpat.find_first_of (sys::file_ops::dir_sep_chars ());
270 std::string file = (sep_pos != std::string::npos)
271 ? xpat.substr (sep_pos) :
"";
272 xpat = xpat.substr (0, sep_pos);
274 if ((sep_pos == 2 || xpat.length () == 2) && xpat[1] ==
':')
279 while (file.length () > 1 && sys::file_ops::is_dir_sep (file[0]))
280 file = file.substr (1, std::string::npos);
282 sep_pos = file.find_first_of (sys::file_ops::dir_sep_chars ());
284 xpat = file.substr (0, sep_pos);
285 file = (sep_pos != std::string::npos)
286 ? file.substr (sep_pos) :
"";
291 if (PathFileExistsW (wpat.c_str ()))
293 if (sys::file_ops::is_dir_sep (pat(i).back ()))
294 dirlist.push_back (dir +
295 sys::file_ops::dir_sep_char ());
297 dirlist.push_back (dir);
303 find_files (dirlist, dir, xpat, file);
316 for (
int i = 0; i < npat; i++)
318 std::string xpat = pat(i);
323 escaped.reserve (xpat.length ());
325 for (std::size_t j = 0; j < xpat.length (); j++)
327# if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
328 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
334 if (xpat[j] ==
']' || xpat[j] ==
'[')
342 int len = escaped.length ();
343 if (
len >= 3 && escaped.substr (
len - 3) ==
"*.*")
344 escaped = escaped.substr (0,
len - 2);
354 const char *
const *matches
364 && sys::file_exists (std::string (matches[0]))))
368 for (
int j = 0; j < n; j++)
370 std::string tmp = matches[j];
372 std::string unescaped;
373 unescaped.reserve (tmp.length ());
375 for (std::size_t m = 0; m < tmp.length (); m++)
377# if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
378 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
385 && ++m == tmp.length ())
392 retval[k++] = unescaped;
402 return retval.
sort ();
405OCTAVE_END_NAMESPACE(sys)
406OCTAVE_END_NAMESPACE(octave)
string_vector & sort(bool make_uniq=false)
void resize(octave_idx_type n, const std::string &rfv="")
octave_idx_type numel() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void * octave_create_glob_info_struct(void)
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)
char ** octave_glob_match_list(void *glob_info)
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)
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)
string_vector glob(const string_vector &pat)