32 #ifndef _QORE_INTERN_GLOB_H
33 #define _QORE_INTERN_GLOB_H
40 #include "qore/intern/QoreRegex.h"
42 typedef int (*glob_error_t)(
const char *, int);
48 #define GLOB_NOSORT (1 << 0)
52 typedef std::vector<std::string> names_t;
57 const char** gl_pathv;
59 DLLLOCAL QoreGlobWin() : gl_pathc(0), gl_pathv(0) {
62 DLLLOCAL ~QoreGlobWin() {
66 DLLLOCAL
int set(
const char* pattern,
int flags, glob_error_t errfunc) {
80 orig_dir.concat(
'\\');
84 unsigned len = strlen(dirp);
90 HANDLE h = ::FindFirstFile(dir.getBuffer(), &pfd);
91 ON_BLOCK_EXIT(::FindClose, h);
95 dir.terminate(dir.size() - 3);
103 bool get_dot = (str[0] ==
'.');
106 str.replaceAll(
".",
"\\.");
107 str.replaceAll(
"?",
".");
108 str.replaceAll(
"*",
".*");
113 QoreRegex qrn(&str, PCRE_CASELESS, &xsink);
117 while (FindNextFile(h, &pfd)) {
118 if (pfd.cFileName[0] ==
'.' && !get_dot)
120 if (qrn.exec(pfd.cFileName, strlen(pfd.cFileName))) {
122 str.concat(pfd.cFileName);
123 names.push_back(str.c_str());
129 if (!(flags & GLOB_NOSORT))
130 std::sort(names.begin(), names.end());
132 gl_pathc = names.size();
134 gl_pathv = (
const char**)malloc(
sizeof(
char*) * names.size());
135 for (
unsigned i = 0; i < names.size(); ++i) {
136 gl_pathv[i] = names[i].c_str();
143 DLLLOCAL
int reset() {
154 typedef QoreGlobWin glob_t;
156 #error no glob implementation for this platform
160 DLLLOCAL
int glob(
const char *pattern,
int flags, glob_error_t errfunc, glob_t *buf);
161 DLLLOCAL
int globfree(glob_t *buf);