diff options
author | Max Horn | 2003-12-30 19:07:55 +0000 |
---|---|---|
committer | Max Horn | 2003-12-30 19:07:55 +0000 |
commit | 24fcd71e8474f05462a99704ff2f7c18e1ee73f2 (patch) | |
tree | dcf2b5e748bf2e76a22cdc95682b7e9ea09b94b9 | |
parent | 9cb5cc07ff917c2ad7fb6363aa4e7223baa37056 (diff) | |
download | scummvm-rg350-24fcd71e8474f05462a99704ff2f7c18e1ee73f2.tar.gz scummvm-rg350-24fcd71e8474f05462a99704ff2f7c18e1ee73f2.tar.bz2 scummvm-rg350-24fcd71e8474f05462a99704ff2f7c18e1ee73f2.zip |
cleanup for language/platform functions
svn-id: r12034
-rw-r--r-- | common/util.cpp | 76 | ||||
-rw-r--r-- | common/util.h | 8 | ||||
-rw-r--r-- | gui/launcher.cpp | 12 |
3 files changed, 68 insertions, 28 deletions
diff --git a/common/util.cpp b/common/util.cpp index f270025816..f53ba300d5 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -151,20 +151,28 @@ Language parseLanguage(const String &str) { 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 @@ const char *getLanguageString(Language id) { #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 diff --git a/common/util.h b/common/util.h index e3b0c97e2a..d1a15a3b5a 100644 --- a/common/util.h +++ b/common/util.h @@ -112,7 +112,7 @@ enum Language { }; struct LanguageDescription { - const char *name; + const char *code; const char *description; Common::Language id; }; @@ -122,7 +122,8 @@ extern const LanguageDescription g_languages[]; /** 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 @@ enum Platform { /** 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 diff --git a/gui/launcher.cpp b/gui/launcher.cpp index ad4feb27cb..d174767d15 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -149,7 +149,7 @@ EditGameDialog::EditGameDialog(const String &domain, GameSettings target) _langPopUp->appendEntry("<default>"); _langPopUp->appendEntry(""); const Common::LanguageDescription *l = Common::g_languages; - for (; l->name; ++l) { + for (; l->code; ++l) { _langPopUp->appendEntry(l->description, l->id); } @@ -231,7 +231,7 @@ void EditGameDialog::open() { const Common::LanguageDescription *l = Common::g_languages; int lang = Common::parseLanguage(ConfMan.get("language", _domain)); - for (int i = 0; l->name; ++l, ++i) { + for (int i = 0; l->code; ++l, ++i) { if (lang == l->id) sel = i + 2; } @@ -257,13 +257,13 @@ void EditGameDialog::close() { if (lang < 0) ConfMan.removeKey("language", _domain); else - ConfMan.set("language", Common::getLanguageString(lang), _domain); + ConfMan.set("language", Common::getLanguageCode(lang), _domain); Common::Platform platform = (Common::Platform)_platformPopUp->getSelectedTag(); if (platform < 0) ConfMan.removeKey("platform", _domain); else - ConfMan.set("platform", Common::getPlatformString(platform), _domain); + ConfMan.set("platform", Common::getPlatformCode(platform), _domain); } OptionsDialog::close(); } @@ -447,11 +447,11 @@ void LauncherDialog::addGame() { // Set language if specified if (result.language != Common::UNK_LANG) - ConfMan.set("language", Common::getLanguageString(result.language), domain); + ConfMan.set("language", Common::getLanguageCode(result.language), domain); // Set platform if specified if (result.platform != Common::kPlatformUnknown) - ConfMan.set("platform", Common::getPlatformString(result.platform), domain); + ConfMan.set("platform", Common::getPlatformCode(result.platform), domain); // Display edit dialog for the new entry EditGameDialog editDialog(domain, result); |