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

dreammaster paulfgilbert at gmail.com
Sat Dec 29 05:47:07 CET 2018


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

Summary:
f218400d3b GLK: Simplify arrays of valid extensions in detection code


Commit: f218400d3b75ee1cf537e2ca9db23bc417475c10
    https://github.com/scummvm/scummvm/commit/f218400d3b75ee1cf537e2ca9db23bc417475c10
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2018-12-28T20:45:45-08:00

Commit Message:
GLK: Simplify arrays of valid extensions in detection code

Suggested by Sev as a way to avoid having both arrays and array sizes

Changed paths:
    engines/glk/alan2/detection.cpp
    engines/glk/frotz/detection.cpp
    engines/glk/glulxe/detection.cpp
    engines/glk/magnetic/detection.cpp
    engines/glk/scott/detection.cpp


diff --git a/engines/glk/alan2/detection.cpp b/engines/glk/alan2/detection.cpp
index d51a109..175c3d6 100644
--- a/engines/glk/alan2/detection.cpp
+++ b/engines/glk/alan2/detection.cpp
@@ -46,7 +46,7 @@ Alan2Descriptor Alan2MetaEngine::findGame(const char *gameId) {
 }
 
 bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
-	const char *const EXTENSIONS[2] = { ".acd", ".dat" };
+	const char *const EXTENSIONS[] = { ".acd", ".dat", nullptr };
 
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -55,8 +55,8 @@ bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
 			continue;
 		Common::String filename = file->getName();
 		bool hasExt = false;
-		for (int idx = 0; idx < 2 && !hasExt; ++idx)
-			hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]);
+		for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
+			hasExt = filename.hasSuffixIgnoreCase(*ext);
 		if (!hasExt)
 			continue;
 
diff --git a/engines/glk/frotz/detection.cpp b/engines/glk/frotz/detection.cpp
index 2ec48f9..fbe7126 100644
--- a/engines/glk/frotz/detection.cpp
+++ b/engines/glk/frotz/detection.cpp
@@ -47,7 +47,8 @@ PlainGameDescriptor FrotzMetaEngine::findGame(const char *gameId) {
 }
 
 bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
-	const char *const EXTENSIONS[11] = { ".z1", ".z2", ".z3", ".z4", ".z5", ".z6", ".z7", ".z8", ".zblorb", ".dat", ".zip" };
+	const char *const EXTENSIONS[] = { ".z1", ".z2", ".z3", ".z4", ".z5", ".z6", ".z7", ".z8",
+		".zblorb", ".dat", ".zip", nullptr };
 
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -56,8 +57,8 @@ bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
 			continue;
 		Common::String filename = file->getName();
 		bool hasExt = false;
-		for (int idx = 0; idx < 11 && !hasExt; ++idx)
-			hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]);
+		for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
+			hasExt = filename.hasSuffixIgnoreCase(*ext);
 		if (!hasExt)
 			continue;
 
diff --git a/engines/glk/glulxe/detection.cpp b/engines/glk/glulxe/detection.cpp
index fb70113..09b6e97 100644
--- a/engines/glk/glulxe/detection.cpp
+++ b/engines/glk/glulxe/detection.cpp
@@ -46,7 +46,7 @@ GlulxeDescriptor GlulxeMetaEngine::findGame(const char *gameId) {
 }
 
 bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
-	const char *const EXTENSIONS[3] = { ".ulx", ".blb", ".gblorb" };
+	const char *const EXTENSIONS[] = { ".ulx", ".blb", ".gblorb", nullptr };
 
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -55,8 +55,8 @@ bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
 			continue;
 		Common::String filename = file->getName();
 		bool hasExt = false;
-		for (int idx = 0; idx < 3 && !hasExt; ++idx)
-			hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]);
+		for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
+			hasExt = filename.hasSuffixIgnoreCase(*ext);
 		if (!hasExt)
 			continue;
 
diff --git a/engines/glk/magnetic/detection.cpp b/engines/glk/magnetic/detection.cpp
index 91d63cc..f702106 100644
--- a/engines/glk/magnetic/detection.cpp
+++ b/engines/glk/magnetic/detection.cpp
@@ -46,7 +46,7 @@ MagneticDescriptor MagneticMetaEngine::findGame(const char *gameId) {
 }
 
 bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
-	const char *const EXTENSIONS[1] = { ".magnetic" };
+	const char *const EXTENSIONS[] = { ".magnetic", nullptr };
 
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -55,8 +55,8 @@ bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames
 			continue;
 		Common::String filename = file->getName();
 		bool hasExt = false;
-		for (int idx = 0; idx < 1 && !hasExt; ++idx)
-			hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]);
+		for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
+			hasExt = filename.hasSuffixIgnoreCase(*ext);
 		if (!hasExt)
 			continue;
 
diff --git a/engines/glk/scott/detection.cpp b/engines/glk/scott/detection.cpp
index 30feb59..c418251 100644
--- a/engines/glk/scott/detection.cpp
+++ b/engines/glk/scott/detection.cpp
@@ -44,14 +44,21 @@ PlainGameDescriptor ScottMetaEngine::findGame(const char *gameId) {
 }
 
 bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
+	const char *const EXTENSIONS[] = { ".saga", ".dat", ".blb", ".blorb", nullptr };
 	Common::File gameFile;
 	Common::String md5;
 
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
 		Common::String name = file->getName();
-		if (file->isDirectory() || !(name.hasSuffixIgnoreCase(".saga")
-				|| name.hasSuffixIgnoreCase(".dat") || name.hasSuffixIgnoreCase(".blb")))
+		if (file->isDirectory())
+			continue;
+
+		Common::String filename = file->getName();
+		bool hasExt = false;
+		for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
+			hasExt = filename.hasSuffixIgnoreCase(*ext);
+		if (!hasExt)
 			continue;
 
 		if (gameFile.open(*file)) {





More information about the Scummvm-git-logs mailing list