[Scummvm-git-logs] scummvm master -> dbdb3dcbd4a6d726ab5ce865b1c9e06e335cb07c

djsrv dservilla at gmail.com
Mon Aug 9 21:53:53 UTC 2021


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
2aa7e3e558 COMMON: Replace matchString pathMode with general wildcard exclusions
ba28d7fde6 ALL: Change listMatchingMembers pattern to a Path
dbdb3dcbd4 AGS: Fix String -> Path conversion


Commit: 2aa7e3e558d872f0e80d594b07bb7bfc6f4e7759
    https://github.com/scummvm/scummvm/commit/2aa7e3e558d872f0e80d594b07bb7bfc6f4e7759
Author: djsrv (dservilla at gmail.com)
Date: 2021-08-09T17:43:12-04:00

Commit Message:
COMMON: Replace matchString pathMode with general wildcard exclusions

Different characters may need to be excluded for different path styles.

Changed paths:
    backends/platform/n64/framfs_save_manager.cpp
    backends/platform/n64/pakfs_save_manager.cpp
    common/archive.cpp
    common/fs.cpp
    common/str.cpp
    common/str.h
    engines/sci/engine/kfile.cpp
    engines/scumm/scumm.cpp


diff --git a/backends/platform/n64/framfs_save_manager.cpp b/backends/platform/n64/framfs_save_manager.cpp
index 7c56601398..55117ae564 100644
--- a/backends/platform/n64/framfs_save_manager.cpp
+++ b/backends/platform/n64/framfs_save_manager.cpp
@@ -58,7 +58,7 @@ Common::StringArray FRAMSaveManager::listSavefiles(const Common::String &pattern
 
 	while ((dp = framfs_readdir(dirp)) != NULL) {
 		fname = new Common::String(dp->entryname);
-		if (fname->matchString(pattern, false, false))
+		if (fname->matchString(pattern, false, NULL))
 			list.push_back(dp->entryname);
 
 		delete fname;
diff --git a/backends/platform/n64/pakfs_save_manager.cpp b/backends/platform/n64/pakfs_save_manager.cpp
index 3674bf56f0..9c6edcef81 100644
--- a/backends/platform/n64/pakfs_save_manager.cpp
+++ b/backends/platform/n64/pakfs_save_manager.cpp
@@ -59,7 +59,7 @@ Common::StringArray PAKSaveManager::listSavefiles(const Common::String &pattern)
 
 	while ((dp = pakfs_readdir(dirp)) != NULL) {
 		fname = new Common::String(dp->entryname);
-		if (fname->matchString(pattern, false, false))
+		if (fname->matchString(pattern, false, NULL))
 			list.push_back(dp->entryname);
 
 		delete fname;
diff --git a/common/archive.cpp b/common/archive.cpp
index 558b46b314..4fbf950fbf 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -51,7 +51,7 @@ int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern)
 	for (; it != allNames.end(); ++it) {
 		// TODO: We match case-insenstivie for now, our API does not define whether that's ok or not though...
 		// For our use case case-insensitive is probably what we want to have though.
-		if ((*it)->getName().matchString(pattern, true, true)) {
+		if ((*it)->getName().matchString(pattern, true, "/")) {
 			list.push_back(*it);
 			matches++;
 		}
diff --git a/common/fs.cpp b/common/fs.cpp
index 247ee59c38..e75b29819e 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -346,16 +346,19 @@ int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &patt
 	String lowercasePattern(pattern);
 	lowercasePattern.toLowercase();
 
+	// Prevent wildcards from matching the directory separator.
+	const char wildcardExclusions[] = { DIR_SEPARATOR, '\0' };
+
 	int matches = 0;
 	for (NodeCache::const_iterator it = _fileCache.begin(); it != _fileCache.end(); ++it) {
-		if (it->_key.matchString(lowercasePattern, false, true)) {
+		if (it->_key.matchString(lowercasePattern, false, wildcardExclusions)) {
 			list.push_back(ArchiveMemberPtr(new FSNode(it->_value)));
 			matches++;
 		}
 	}
 	if (_includeDirectories) {
 		for (NodeCache::const_iterator it = _subDirCache.begin(); it != _subDirCache.end(); ++it) {
-			if (it->_key.matchString(lowercasePattern, false, true)) {
+			if (it->_key.matchString(lowercasePattern, false, wildcardExclusions)) {
 				list.push_back(ArchiveMemberPtr(new FSNode(it->_value)));
 				matches++;
 			}
diff --git a/common/str.cpp b/common/str.cpp
index 06876598de..b861426adf 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -180,12 +180,12 @@ bool String::contains(char32_t x) const {
 
 #ifndef SCUMMVM_UTIL
 
-bool String::matchString(const char *pat, bool ignoreCase, bool pathMode) const {
-	return Common::matchString(c_str(), pat, ignoreCase, pathMode);
+bool String::matchString(const char *pat, bool ignoreCase, const char *wildcardExclusions) const {
+	return Common::matchString(c_str(), pat, ignoreCase, wildcardExclusions);
 }
 
-bool String::matchString(const String &pat, bool ignoreCase, bool pathMode) const {
-	return Common::matchString(c_str(), pat.c_str(), ignoreCase, pathMode);
+bool String::matchString(const String &pat, bool ignoreCase, const char *wildcardExclusions) const {
+	return Common::matchString(c_str(), pat.c_str(), ignoreCase, wildcardExclusions);
 }
 
 #endif
@@ -600,7 +600,7 @@ String normalizePath(const String &path, const char sep) {
 
 #ifndef SCUMMVM_UTIL
 
-bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMode) {
+bool matchString(const char *str, const char *pat, bool ignoreCase, const char *wildcardExclusions) {
 	assert(str);
 	assert(pat);
 
@@ -609,7 +609,7 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
 	bool escaped = false;
 
 	for (;;) {
-		if (pathMode && *str == '/') {
+		if (wildcardExclusions && strchr(wildcardExclusions, *str)) {
 			p = nullptr;
 			q = nullptr;
 			if (*pat == '?')
diff --git a/common/str.h b/common/str.h
index 1ceef848e9..70d7f982f2 100644
--- a/common/str.h
+++ b/common/str.h
@@ -141,12 +141,12 @@ public:
 	 *
 	 * @param pat Glob pattern.
 	 * @param ignoreCase Whether to ignore the case when doing pattern match
-	 * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+	 * @param wildcardExclusions Characters which are excluded from wildcards and must be matched explicitly.
 	 *
 	 * @return true if str matches the pattern, false otherwise.
 	 */
-	bool matchString(const char *pat, bool ignoreCase = false, bool pathMode = false) const;
-	bool matchString(const String &pat, bool ignoreCase = false, bool pathMode = false) const;
+	bool matchString(const char *pat, bool ignoreCase = false, const char *wildcardExclusions = NULL) const;
+	bool matchString(const String &pat, bool ignoreCase = false, const char *wildcardExclusions = NULL) const;
 
 	/**@{
 	 * Functions to replace some amount of chars with chars from some other string.
@@ -329,11 +329,11 @@ String normalizePath(const String &path, const char sep);
  * @param str Text to be matched against the given pattern.
  * @param pat Glob pattern.
  * @param ignoreCase Whether to ignore the case when doing pattern match
- * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+ * @param wildcardExclusions Characters which are excluded from wildcards and must be matched explicitly.
  *
  * @return true if str matches the pattern, false otherwise.
  */
-bool matchString(const char *str, const char *pat, bool ignoreCase = false, bool pathMode = false);
+bool matchString(const char *str, const char *pat, bool ignoreCase = false, const char *wildcardExclusions = NULL);
 
 /**
  * Function which replaces substring with the other. It happens in place.
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 37fbd8d369..a214b16ff9 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -103,7 +103,7 @@ reg_t kDeviceInfo(EngineState *s, int argc, reg_t *argv) {
 		Common::String path2_s = s->_segMan->getString(argv[2]);
 		debug(3, "K_DEVICE_INFO_PATHS_EQUAL(%s,%s)", path1_s.c_str(), path2_s.c_str());
 
-		return make_reg(0, Common::matchString(path2_s.c_str(), path1_s.c_str(), false, true));
+		return make_reg(0, Common::matchString(path2_s.c_str(), path1_s.c_str(), false, "/"));
 		}
 		break;
 
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 46d1f3e00c..71c773870c 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -2988,7 +2988,7 @@ bool ScummEngine::startManiac() {
 				// While strictly speaking it's too broad, this matchString
 				// ignores the presence or absence of trailing path separators
 				// in either currentPath or path.
-				if (path.matchString("*maniac*", true, false)) {
+				if (path.matchString("*maniac*", true, NULL)) {
 					maniacTarget = iter->_key;
 					break;
 				}


Commit: ba28d7fde6f02ee90f3ce60f7b70c423ca839234
    https://github.com/scummvm/scummvm/commit/ba28d7fde6f02ee90f3ce60f7b70c423ca839234
Author: djsrv (dservilla at gmail.com)
Date: 2021-08-09T17:47:30-04:00

Commit Message:
ALL: Change listMatchingMembers pattern to a Path

This handles any potential differences in directory separators passed to
the function, as with the other Archive functions.

Changed paths:
    common/archive.cpp
    common/archive.h
    common/fs.cpp
    common/fs.h
    common/macresman.cpp
    engines/stark/formats/xarc.cpp
    engines/stark/formats/xarc.h
    engines/ultima/shared/engine/data_archive.cpp
    engines/ultima/shared/engine/data_archive.h


diff --git a/common/archive.cpp b/common/archive.cpp
index 4fbf950fbf..d2be5d096b 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -40,18 +40,19 @@ SeekableReadStream *GenericArchiveMember::createReadStream() const {
 }
 
 
-int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern) const {
+int Archive::listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const {
 	// Get all "names" (TODO: "files" ?)
 	ArchiveMemberList allNames;
 	listMembers(allNames);
 
+	String patternString = pattern.toString();
 	int matches = 0;
 
 	ArchiveMemberList::const_iterator it = allNames.begin();
 	for (; it != allNames.end(); ++it) {
 		// TODO: We match case-insenstivie for now, our API does not define whether that's ok or not though...
 		// For our use case case-insensitive is probably what we want to have though.
-		if ((*it)->getName().matchString(pattern, true, "/")) {
+		if ((*it)->getName().matchString(patternString, true, "/")) {
 			list.push_back(*it);
 			matches++;
 		}
@@ -218,7 +219,7 @@ bool SearchSet::hasFile(const Path &path) const {
 	return false;
 }
 
-int SearchSet::listMatchingMembers(ArchiveMemberList &list, const String &pattern) const {
+int SearchSet::listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const {
 	int matches = 0;
 
 	ArchiveNodeList::const_iterator it = _list.begin();
diff --git a/common/archive.h b/common/archive.h
index ae39651cc3..303f3c656e 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -116,7 +116,7 @@ public:
 	 *
 	 * @return The number of members added to list.
 	 */
-	virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
+	virtual int listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const;
 
 	/**
 	 * Add all members of the Archive to the list.
@@ -253,7 +253,7 @@ public:
 	void setPriority(const String& name, int priority);
 
 	virtual bool hasFile(const Path &path) const;
-	virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
+	virtual int listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const;
 	virtual int listMembers(ArchiveMemberList &list) const;
 
 	virtual const ArchiveMemberPtr getMember(const Path &path) const;
diff --git a/common/fs.cpp b/common/fs.cpp
index e75b29819e..678eb32494 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -334,7 +334,7 @@ void FSDirectory::ensureCached() const  {
 	_cached = true;
 }
 
-int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) const {
+int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const {
 	if (!_node.isDirectory())
 		return 0;
 
@@ -343,7 +343,7 @@ int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &patt
 
 	// need to match lowercase key, since all entries in our file cache are
 	// stored as lowercase.
-	String lowercasePattern(pattern);
+	String lowercasePattern(pattern.rawString());
 	lowercasePattern.toLowercase();
 
 	// Prevent wildcards from matching the directory separator.
diff --git a/common/fs.h b/common/fs.h
index 2ed0515f9a..3eb67bbb5a 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -375,7 +375,7 @@ public:
 	/**
 	 * Return a list of matching file names. Pattern can use GLOB wildcards.
 	 */
-	virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern) const;
+	virtual int listMatchingMembers(ArchiveMemberList &list, const Path &pattern) const;
 
 	/**
 	 * Return a list of all the files in the cache.
diff --git a/common/macresman.cpp b/common/macresman.cpp
index 8262636d5a..4f75f1ab8c 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -216,7 +216,7 @@ void MacResManager::listFiles(StringArray &files, const String &pattern) {
 	SearchMan.listMatchingMembers(memberList, pattern);
 	SearchMan.listMatchingMembers(memberList, pattern + ".rsrc");
 	SearchMan.listMatchingMembers(memberList, pattern + ".bin");
-	SearchMan.listMatchingMembers(memberList, constructAppleDoubleName(pattern).toString());
+	SearchMan.listMatchingMembers(memberList, constructAppleDoubleName(pattern));
 
 	for (ArchiveMemberList::const_iterator i = memberList.begin(), end = memberList.end(); i != end; ++i) {
 		String filename = (*i)->getName();
diff --git a/engines/stark/formats/xarc.cpp b/engines/stark/formats/xarc.cpp
index 7bb6e9a54e..969e05fd40 100644
--- a/engines/stark/formats/xarc.cpp
+++ b/engines/stark/formats/xarc.cpp
@@ -147,10 +147,11 @@ bool XARCArchive::hasFile(const Common::Path &path) const {
 	return false;
 }
 
-int XARCArchive::listMatchingMembers(Common::ArchiveMemberList &list, const Common::String &pattern) const {
+int XARCArchive::listMatchingMembers(Common::ArchiveMemberList &list, const Common::Path &pattern) const {
+	Common::String patternString = pattern.toString();
 	int matches = 0;
 	for (Common::ArchiveMemberList::const_iterator it = _members.begin(); it != _members.end(); ++it) {
-		if ((*it)->getName().matchString(pattern)) {
+		if ((*it)->getName().matchString(patternString)) {
 			// This file matches, add it
 			list.push_back(*it);
 			matches++;
diff --git a/engines/stark/formats/xarc.h b/engines/stark/formats/xarc.h
index 24b52ffeba..8e33aa5731 100644
--- a/engines/stark/formats/xarc.h
+++ b/engines/stark/formats/xarc.h
@@ -38,7 +38,7 @@ public:
 
 	// Archive API
 	bool hasFile(const Common::Path &path) const;
-	int listMatchingMembers(Common::ArchiveMemberList &list, const Common::String &pattern) const;
+	int listMatchingMembers(Common::ArchiveMemberList &list, const Common::Path &pattern) const;
 	int listMembers(Common::ArchiveMemberList &list) const;
 	const Common::ArchiveMemberPtr getMember(const Common::Path &path) const;
 	Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const;
diff --git a/engines/ultima/shared/engine/data_archive.cpp b/engines/ultima/shared/engine/data_archive.cpp
index e88b8d1358..e692c0c3c8 100644
--- a/engines/ultima/shared/engine/data_archive.cpp
+++ b/engines/ultima/shared/engine/data_archive.cpp
@@ -125,10 +125,10 @@ bool UltimaDataArchive::hasFile(const Common::Path &path) const {
 	return _zip->hasFile(realFilename);
 }
 
-int UltimaDataArchive::listMatchingMembers(Common::ArchiveMemberList &list, const Common::String &pattern) const {
-	Common::String patt = pattern;
-	if (pattern.hasPrefixIgnoreCase(_publicFolder))
-		patt = innerToPublic(pattern);
+int UltimaDataArchive::listMatchingMembers(Common::ArchiveMemberList &list, const Common::Path &pattern) const {
+	Common::String patt = pattern.toString();
+	if (patt.hasPrefixIgnoreCase(_publicFolder))
+		patt = innerToPublic(patt);
 
 	// Get any matching files
 	Common::ArchiveMemberList innerList;
diff --git a/engines/ultima/shared/engine/data_archive.h b/engines/ultima/shared/engine/data_archive.h
index 5b807b28b5..7e8ba67eda 100644
--- a/engines/ultima/shared/engine/data_archive.h
+++ b/engines/ultima/shared/engine/data_archive.h
@@ -81,7 +81,7 @@ public:
 	 * @return the number of members added to list
 	 */
 	int listMatchingMembers(Common::ArchiveMemberList &list,
-		const Common::String &pattern) const override;
+		const Common::Path &pattern) const override;
 
 	/**
 	 * Add all members of the Archive to list.
@@ -148,7 +148,7 @@ public:
 	 * @return the number of members added to list
 	 */
 	int listMatchingMembers(Common::ArchiveMemberList &list,
-			const Common::String &pattern) const override {
+			const Common::Path &pattern) const override {
 		return 0;
 	}
 


Commit: dbdb3dcbd4a6d726ab5ce865b1c9e06e335cb07c
    https://github.com/scummvm/scummvm/commit/dbdb3dcbd4a6d726ab5ce865b1c9e06e335cb07c
Author: djsrv (dservilla at gmail.com)
Date: 2021-08-09T17:47:33-04:00

Commit Message:
AGS: Fix String -> Path conversion

Changed paths:
    engines/ags/engine/ac/listbox.cpp


diff --git a/engines/ags/engine/ac/listbox.cpp b/engines/ags/engine/ac/listbox.cpp
index e8604c0144..97c9550e59 100644
--- a/engines/ags/engine/ac/listbox.cpp
+++ b/engines/ags/engine/ac/listbox.cpp
@@ -84,7 +84,7 @@ void FillDirList(std::set<String> &files, const String &path) {
 
 	Common::FSDirectory dir(dirName.GetCStr());
 	Common::ArchiveMemberList fileList;
-	dir.listMatchingMembers(fileList, filePattern);
+	dir.listMatchingMembers(fileList, filePattern.GetCStr());
 	for (Common::ArchiveMemberList::iterator iter = fileList.begin(); iter != fileList.end(); ++iter) {
 		files.insert((*iter)->getName());
 	}




More information about the Scummvm-git-logs mailing list