Ejemplo n.º 1
0
std::vector<std::string> folder_wildcard (const std::string& directory, const std::string& wild, bool subdirs, bool files)
{
  std::string dir = directory.empty() ? std::string(".") : directory;
  std::vector<std::string> results;
#ifdef _WIN32
  std::string wildcard = create_filespec(dir, wild);
  long handle = -1;
  _finddata_t fileinfo;
  for (bool OK = (handle = _findfirst((char*)wildcard.c_str(), &fileinfo)) != -1; OK; OK = (_findnext(handle, &fileinfo)==0))
  {
    std::string strentry = fileinfo.name;
    if (strentry.compare(".")!=0 && strentry.compare("..")!=0)
      if ((subdirs && (fileinfo.attrib & _A_SUBDIR)) || (files && !(fileinfo.attrib & _A_SUBDIR)))
        results.push_back(strentry);
  }
  _findclose(handle);
#else
  DIR* d = opendir(dir.c_str());
  if (d)
  {
    for (dirent* entry = readdir(d); entry; entry = readdir(d))
    {
      std::string strentry = entry->d_name;
      if (strentry.compare(".")!=0 && strentry.compare("..")!=0)
      {
        std::string subpath = create_filespec(dir, strentry);
        if (((subdirs && is_folder(subpath)) || (files && is_file(subpath))) && (match_wildcard(wild, strentry)))
          results.push_back(strentry);
      }
    }
    closedir(d);
  }
#endif
  return results;
}
Ejemplo n.º 2
0
void INI::delete_pattern(const chowstring & group, const chowstring & item,
                         const chowstring & value)
{
    SectionMap::iterator it1;
    OptionMap::iterator it2;
    for (it1 = data->begin(); it1 != data->end(); ++it1) {
        if (!match_wildcard(group, (*it1).first))
            continue;
        OptionMap & option_map = (*it1).second;
        it2 = option_map.begin();
        while (it2 != option_map.end()) {
            if (!match_wildcard(item, (*it2).first) ||
                !match_wildcard(value, (*it2).second)) {
                ++it2;
                continue;
            }
            option_map.erase(it2++);
        }
    }
    save_auto();
}
Ejemplo n.º 3
0
void INI::search(const chowstring & group, const chowstring & item,
                 const chowstring & value)
{
    search_results.clear();
    search_time = frame->loop_count;
    SectionMap::const_iterator it1;
    OptionMap::const_iterator it2;
    for (it1 = data->begin(); it1 != data->end(); ++it1) {
        if (!match_wildcard(group, (*it1).first))
            continue;
        for (it2 = (*it1).second.begin(); it2 != (*it1).second.end();
             ++it2) {
            if (!match_wildcard(item, (*it2).first))
                continue;
            if (!match_wildcard(value, (*it2).second))
                continue;
            search_results.push_back(
                std::pair<chowstring, chowstring>(
                    (*it1).first,
                    (*it2).first
                ));
        }
    }
}
Ejemplo n.º 4
0
Status GetPathnames(const PIVFS& fs, const VfsPath& path, const wchar_t* filter, VfsPaths& pathnames)
{
	std::vector<CFileInfo> files;
	RETURN_STATUS_IF_ERR(fs->GetDirectoryEntries(path, &files, 0));

	pathnames.clear();
	pathnames.reserve(files.size());

	for(size_t i = 0; i < files.size(); i++)
	{
		if(match_wildcard(files[i].Name().string().c_str(), filter))
			pathnames.push_back(path / files[i].Name());
	}

	return INFO::OK;
}
Ejemplo n.º 5
0
int					glob__match(char *local, char *s, char *format, t_list **results)
{
	#ifdef DEBUG
//		printf("local = %s, s = %s, format = %s\n", local, s, format);
	#endif	

	if (!*s && !*format)
		return (1);
	else if (*format == '/')
		glob__open_directory(local, format + 1, 2, results);
	else if (*s == *format)
		return (glob__match(local, s + 1, format + 1, results));
	else if (*format == '*')
		return (match_wildcard(local, s, format, results));
	else if (*format == '?')
		return (glob__match(local, s + 1, format + 1, results));
	else if (*format == '[')
		return (match_bracket(local, s, format, results));
	return (0);
}
Ejemplo n.º 6
0
	/*
	** Determines whether the directory entry's name matches the glob
	** pattern.
	*/
	bool operator()(const directory_entry& ent)
	const noexcept
	{
		#ifndef NDEBUG
			assert(m_pat.length() > 0);
		#endif

		// Offset into pattern that we are matching.
		auto i = 0u;
		// Offset into the file name.
		auto j = 0u;
		auto s = ent.name();

		do switch(m_pat[i]) {
		default:   if (m_pat[i++] != s[j++])         return false; continue;
		case '*':  ++i; return match_wildcard(s, i, j);
		case '?':  ++i; ++j;                                       continue;
		case '[':  ++i; if (!match_group(s, i, j))   return false; continue;
		case '\\': ++i; if (m_pat[i++] != s[j++])    return false; continue;
		} while (i != m_pat.length() && j != s.length());
		return (i == m_pat.length() || m_pat[i] == '*') && j == s.length();
	}
Ejemplo n.º 7
0
Status ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const wchar_t* pattern, size_t flags)
{
	// (declare here to avoid reallocations)
	CFileInfos files;
	DirectoryNames subdirectoryNames;

	// (a FIFO queue is more efficient than recursion because it uses less
	// stack space and avoids seeks due to breadth-first traversal.)
	std::queue<VfsPath> pendingDirectories;
	pendingDirectories.push(startPath/"");
	while(!pendingDirectories.empty())
	{
		const VfsPath& path = pendingDirectories.front();

		RETURN_STATUS_IF_ERR(fs->GetDirectoryEntries(path, &files, &subdirectoryNames));

		for(size_t i = 0; i < files.size(); i++)
		{
			const CFileInfo fileInfo = files[i];
			if(!match_wildcard(fileInfo.Name().string().c_str(), pattern))
				continue;

			const VfsPath pathname(path / fileInfo.Name());	// (CFileInfo only stores the name)
			RETURN_STATUS_IF_ERR(cb(pathname, fileInfo, cbData));
		}

		if(!(flags & DIR_RECURSIVE))
			break;

		for(size_t i = 0; i < subdirectoryNames.size(); i++)
			pendingDirectories.push(path / subdirectoryNames[i]/"");
		pendingDirectories.pop();
	}

	return INFO::OK;
}
Ejemplo n.º 8
0
	FOR_EACH_CONST(i, items) {
		if (i.second && match_wildcard(i.first, name)) return i.second;
	}
Ejemplo n.º 9
0
url
complete (url base, url u, string filter, bool flag) {
  // cout << "complete " << base << " |||| " << u << LF;
  if (!is_rooted(u)) {
     if (is_none (base)) return base;
     if (is_none (u)) return u;
     if ((!is_root (base)) && (!is_rooted_name (base))) {
        failed_error << "base= " << base << LF;
        FAILED ("invalid base url");
     }
  }
  if (is_name (u) || (is_concat (u) && is_root (u[1]) && is_name (u[2]))) {
    url comp= base * u;
    if (is_rooted (comp, "default") || is_rooted (comp, "file")) {
      if (is_of_type (comp, filter)) return reroot (u, "default");
      return url_none ();
    }
    if (is_rooted_web (comp) || is_rooted_tmfs (comp) || is_ramdisc (comp)) {
      if (is_of_type (comp, filter)) return u;
      return url_none ();
    }
    failed_error << "base= " << base << LF;
    failed_error << "u= " << u << LF;
    ASSERT (is_rooted (comp), "unrooted url");
    FAILED ("bad protocol in url");
  }
  if (is_root (u)) {
    // FIXME: test filter flags here
    return u;
  }
  if (is_concat (u) && is_wildcard (u[1], 0) && is_wildcard (u[2], 1)) {
    // FIXME: ret= ret | ... is unefficient (quadratic) in main loop
    if (!(is_rooted (base, "default") || is_rooted (base, "file"))) {
      failed_error << "base= " << base << LF;
      FAILED ("wildcards only implemented for files");
    }
    url ret= url_none ();
    bool error_flag;
    array<string> dir= read_directory (base, error_flag);
    int i, n= N(dir);
    for (i=0; i<n; i++) {
      if ((!is_none (ret)) && flag) return ret;
      if ((dir[i] == ".") || (dir[i] == "..")) continue;
      if (starts (dir[i], "http://") || starts (dir[i], "ftp://"))
        if (is_directory (base * dir[i])) continue;
      ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag));
      if (match_wildcard (dir[i], u[2][1]->t->label))
	ret= ret | complete (base, dir[i], filter, flag);
    }
    return ret;
  }
  if (is_concat (u)) {
    url sub= complete (base, u[1], "", false);
    // "" should often be faster than the more correct "d" here
    return complete (base, sub, u[2], filter, flag);
  }
  if (is_or (u)) {
    url res1= complete (base, u[1], filter, flag);
    if ((!is_none (res1)) && flag) return res1;
    return res1 | complete (base, u[2], filter, flag);
  }
  if (is_wildcard (u)) {
    // FIXME: ret= ret | ... is unefficient (quadratic) in main loop
    if (!(is_rooted (base, "default") || is_rooted (base, "file"))) {
      failed_error << "base= " << base << LF;
      FAILED ("wildcards only implemented for files");
    }
    url ret= url_none ();
    if (is_wildcard (u, 0) && is_of_type (base, filter)) ret= url_here ();
    bool error_flag;
    array<string> dir= read_directory (base, error_flag);
    int i, n= N(dir);
    for (i=0; i<n; i++) {
      if ((!is_none (ret)) && flag) return ret;
      if ((dir[i] == ".") || (dir[i] == "..")) continue;
      if (starts (dir[i], "http://") || starts (dir[i], "ftp://"))
        if (is_directory (base * dir[i])) continue;
      if (is_wildcard (u, 0))
	ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag));
      else if (match_wildcard (dir[i], u[1]->t->label))
	ret= ret | complete (base, dir[i], filter, flag);
    }
    return ret;
  }
  failed_error << "url= " << u << LF;
  FAILED ("bad url");
  return u;
}