diff options
author | Johannes Schickel | 2008-12-20 15:04:17 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-12-20 15:04:17 +0000 |
commit | 1f0b94a9ca256a7eeddfb2e808818672e7642180 (patch) | |
tree | 62ef6d9d825b9fd8522c6f679bd253068dda7a4d | |
parent | 3c01f4f0e1b3134d5a0f0167ea4c0e8a3ac92672 (diff) | |
download | scummvm-rg350-1f0b94a9ca256a7eeddfb2e808818672e7642180.tar.gz scummvm-rg350-1f0b94a9ca256a7eeddfb2e808818672e7642180.tar.bz2 scummvm-rg350-1f0b94a9ca256a7eeddfb2e808818672e7642180.zip |
Committed slightly modified version of my patch at bug tracker item #2309974 "ALL: */? match path separator in FSDir::listMatchingMembers".
svn-id: r35450
-rw-r--r-- | common/archive.cpp | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/common/archive.cpp b/common/archive.cpp index f5c6a8372d..8a3e08bf78 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -234,6 +234,57 @@ void FSDirectory::ensureCached() { _cached = true; } +bool matchPath(const char *str, const char *pat) { + assert(str); + assert(pat); + + const char *p = 0; + const char *q = 0; + + for (;;) { + if (*str == '/') { + p = 0; + q = 0; + } + + switch (*pat) { + case '*': + // Record pattern / string possition for backtracking + p = ++pat; + q = str; + // If pattern ended with * -> match + if (!*pat) + return true; + break; + + default: + if (*pat != *str) { + if (p) { + // No match, oops -> try to backtrack + pat = p; + str = ++q; + if (!*str) + return !*pat; + break; + } + else + return false; + } + if (!*str) + return !*pat; + pat++; + str++; + break; + + case '?': + if (!*str || *str == '/') + return !*pat; + pat++; + str++; + } + } +} + int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { if (!_node.isDirectory()) return 0; @@ -247,7 +298,7 @@ int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &patt int matches = 0; NodeCache::iterator it = _fileCache.begin(); for ( ; it != _fileCache.end(); it++) { - if (it->_key.matchString(lowercasePattern)) { + if (matchPath(it->_key.c_str(), lowercasePattern.c_str())) { list.push_back(ArchiveMemberPtr(new FSDirectoryMember(it->_value))); matches++; } @@ -256,7 +307,19 @@ int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &patt } int FSDirectory::listMembers(ArchiveMemberList &list) { - return listMatchingMembers(list, "*"); + if (!_node.isDirectory()) + return 0; + + // Cache dir data + ensureCached(); + + int files = 0; + for (NodeCache::iterator it = _fileCache.begin(); it != _fileCache.end(); ++it) { + list.push_back(ArchiveMemberPtr(new FSDirectoryMember(it->_value))); + ++files; + } + + return files; } |