23#ifndef GEMMI_DIRWALK_HPP_
24#define GEMMI_DIRWALK_HPP_
29#if defined(_MSC_VER) && !defined(NOMINMAX)
32#include "third_party/tinydir.h"
37#if defined(_WIN32) && defined(_UNICODE)
44#if defined(_WIN32) && defined(_UNICODE)
52inline bool glob_match(
const std::string& pattern,
const std::string& str) {
65 }
else if (
str_pos < str.size() && (c ==
'?' || c == str[
str_pos])) {
83inline bool is_rxsf_ent_filename(
const std::string& filename) {
84 return filename[0] ==
'r' &&
giends_with(filename,
"sf.ent")
85 && filename.find(
'.') >= 4;
89 static bool check(
const std::string& filename) {
95 static bool check(
const std::string& filename) {
96 return giends_with(filename,
".cif") || is_rxsf_ent_filename(filename);
101 static bool check(
const std::string& filename) {
103 (
giends_with(filename,
".ent") && !is_rxsf_ent_filename(filename));
107struct IsCoordinateFile {
108 static bool check(
const std::string& filename) {
110 return IsPdbFile::check(filename) ||
111 (IsMmCifFile::check(filename) && !
giends_with(filename,
"-sf.cif"));
116 static bool check(
const std::string&) {
return true; }
119struct IsMatchingFile {
120 bool check(
const std::string& filename)
const {
126inline int utf8_tinydir_file_open(tinydir_file* file,
const char* path) {
127#if defined(_WIN32) && defined(_UNICODE)
130 return tinydir_file_open(file, path);
137template<
bool FileOnly=true,
typename Filter=impl::IsAnyFile>
141 if (impl::utf8_tinydir_file_open(&top_, path) != -1)
145 if (impl::utf8_tinydir_file_open(&top_,
epath.c_str()) != -1)
149 sys_fail(
"Cannot open " + std::string(path));
154 for (
auto&
d : dirs_)
158 dirs_.emplace_back();
165 size_t old_pos = dirs_.back().first;
178 if (
walk.dirs_.empty())
188 return name[0] ==
'.' && (name[1] ==
'\0' ||
189 (name[1] ==
'.' && name[2] ==
'\0'));
202 while (!
walk.dirs_.empty()) {
242 std::vector<std::pair<size_t, tinydir_dir>> dirs_;
void push_dir(size_t cur_pos, const _tinydir_char_t *path)
DirWalk(const char *path, char try_pdbid='\0')
DirWalk(const std::string &path, char try_pdbid='\0')
bool is_pdb_code(const std::string &str)
std::wstring UTF8_to_wchar(const char *in)
std::string expand_pdb_code_to_path(const std::string &code, char type, bool throw_if_unset=false)
Call it after checking the code with gemmi::is_pdb_code(code).
std::string wchar_to_UTF8(const wchar_t *in)
GEMMI_COLD void sys_fail(const std::string &msg)
bool glob_match(const std::string &pattern, const std::string &str)
bool giends_with(const std::string &str, const std::string &suffix)
std::string as_utf8(const _tinydir_char_t *path)
const tinydir_dir & get_dir() const
std::string operator*() const
bool operator==(const Iter &o) const
bool is_special(const _tinydir_char_t *name) const
const tinydir_file & get() const
bool operator!=(const Iter &o) const
GlobWalk(const std::string &path, const std::string &glob)