[Scummvm-cvs-logs] CVS: scummvm/common util.cpp,1.26,1.27 util.h,1.31,1.32

Max Horn fingolfin at users.sourceforge.net
Tue Dec 30 11:08:04 CET 2003


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv32346/common

Modified Files:
	util.cpp util.h 
Log Message:
cleanup for language/platform functions

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- util.cpp	13 Dec 2003 17:33:21 -0000	1.26
+++ util.cpp	30 Dec 2003 19:07:55 -0000	1.27
@@ -151,20 +151,28 @@
 
 	const char *s = str.c_str();
 	const LanguageDescription *l = g_languages;
-	for (; l->name; ++l) {
-		if (!scumm_stricmp(l->name, s))
+	for (; l->code; ++l) {
+		if (!scumm_stricmp(l->code, s))
 			return l->id;
 	}
 
 	return UNK_LANG;
 }
 
+const char *getLanguageCode(Language id) {
+	const LanguageDescription *l = g_languages;
+	for (; l->code; ++l) {
+		if (l->id == id)
+			return l->code;
+	}
+	return 0;
+}
 
-const char *getLanguageString(Language id) {
+const char *getLanguageDescription(Language id) {
 	const LanguageDescription *l = g_languages;
-	for (; l->name; ++l) {
+	for (; l->code; ++l) {
 		if (l->id == id)
-			return l->name;
+			return l->description;
 	}
 	return 0;
 }
@@ -173,33 +181,63 @@
 #pragma mark -
 
 
+struct PlatformDescription {
+	const char *code;
+	const char *description;
+	Common::Platform id;
+};
+
+static const PlatformDescription g_platforms[] = {
+	{"pc", "PC", kPlatformPC},
+	{"amiga", "Amiga", kPlatformAmiga},
+	{"atari", "Atari ST", kPlatformAtariST},
+	{"macintosh", "Macintosh", kPlatformMacintosh},
+	{0, 0, kPlatformUnknown}
+};
+
 Platform parsePlatform(const String &str) {
 	if (str.isEmpty())
 		return kPlatformUnknown;
 
 	const char *s = str.c_str();
-	if (!scumm_stricmp(s, "pc"))
-		return kPlatformPC;
-	else if (!scumm_stricmp(s, "amiga") || !scumm_stricmp(s, "1"))
+	
+	// Handle some special case separately, for compatibility with old config
+	// files.
+	if (!scumm_stricmp(s, "amiga") || !scumm_stricmp(s, "1"))
 		return kPlatformAmiga;
-	else if (!scumm_stricmp(s, "atari-st") || !scumm_stricmp(s, "atari") || !scumm_stricmp(s, "2"))
+	else if (!scumm_stricmp(s, "atari-st") || !scumm_stricmp(s, "2"))
 		return kPlatformAtariST;
-	else if (!scumm_stricmp(s, "macintosh") || !scumm_stricmp(s, "mac") || !scumm_stricmp(s, "3"))
+	else if (!scumm_stricmp(s, "mac") || !scumm_stricmp(s, "3"))
 		return kPlatformMacintosh;
-	else
-		return kPlatformUnknown;
+
+	const PlatformDescription *l = g_platforms;
+	for (; l->code; ++l) {
+		if (!scumm_stricmp(l->code, s))
+			return l->id;
+	}
+
+	return kPlatformUnknown;
 }
 
 
-const char *getPlatformString(Platform id) {
-	switch (id) {
-	case Common::kPlatformPC:			return "pc";
-	case Common::kPlatformAmiga:		return "amiga";
-	case Common::kPlatformAtariST:		return "atari";
-	case Common::kPlatformMacintosh:	return "macintosh";
-	default:							return 0;
+const char *getPlatformCode(Platform id) {
+	const PlatformDescription *l = g_platforms;
+	for (; l->code; ++l) {
+		if (l->id == id)
+			return l->code;
 	}
+	return 0;
 }
+
+const char *getPlatformDescription(Platform id) {
+	const PlatformDescription *l = g_platforms;
+	for (; l->code; ++l) {
+		if (l->id == id)
+			return l->description;
+	}
+	return 0;
+}
+
 
 
 }	// End of namespace Common

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- util.h	8 Nov 2003 22:43:46 -0000	1.31
+++ util.h	30 Dec 2003 19:07:55 -0000	1.32
@@ -112,7 +112,7 @@
 };
 
 struct LanguageDescription {
-	const char *name;
+	const char *code;
 	const char *description;
 	Common::Language id;
 };
@@ -122,7 +122,8 @@
 
 /** Convert a string containing a language name into a Language enum value. */
 extern Language parseLanguage(const String &str);
-extern const char *getLanguageString(Language id);
+extern const char *getLanguageCode(Language id);
+extern const char *getLanguageDescription(Language id);
 
 /**
  * List of game platforms. Specifying a platform for a target can be used to
@@ -146,7 +147,8 @@
 
 /** Convert a string containing a platform name into a Platform enum value. */
 extern Platform parsePlatform(const String &str);
-extern const char *getPlatformString(Platform id);
+extern const char *getPlatformCode(Platform id);
+extern const char *getPlatformDescription(Platform id);
 
 }	// End of namespace Common
 





More information about the Scummvm-git-logs mailing list