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 /common | |
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
Diffstat (limited to 'common')
-rw-r--r-- | common/util.cpp | 76 | ||||
-rw-r--r-- | common/util.h | 8 |
2 files changed, 62 insertions, 22 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 |