[Scummvm-cvs-logs] SF.net SVN: scummvm:[35450] scummvm/trunk/common/archive.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Dec 20 16:04:17 CET 2008


Revision: 35450
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35450&view=rev
Author:   lordhoto
Date:     2008-12-20 15:04:17 +0000 (Sat, 20 Dec 2008)

Log Message:
-----------
Committed slightly modified version of my patch at bug tracker item #2309974 "ALL: */? match path separator in FSDir::listMatchingMembers".

Modified Paths:
--------------
    scummvm/trunk/common/archive.cpp

Modified: scummvm/trunk/common/archive.cpp
===================================================================
--- scummvm/trunk/common/archive.cpp	2008-12-20 12:05:35 UTC (rev 35449)
+++ scummvm/trunk/common/archive.cpp	2008-12-20 15:04:17 UTC (rev 35450)
@@ -234,6 +234,57 @@
 	_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 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::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;
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list