From a70460833e498620122bd60a1e6708d2a263626a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 17 Oct 2003 15:35:46 +0000 Subject: moved platform/language constants to common/util.* svn-id: r10862 --- common/util.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'common/util.cpp') diff --git a/common/util.cpp b/common/util.cpp index cdb9bf9c60..05deda925b 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -75,6 +75,9 @@ void hexdump(const byte * data, int len, int bytesPerLine) { printf("|\n"); } +#pragma mark - + + RandomSource::RandomSource() { // Use system time as RNG seed. Normally not a good idea, if you are using // a RNG for security purposes, but good enough for our purposes. @@ -96,6 +99,9 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) { return getRandomNumber(max - min) + min; } +#pragma mark - + + StackLock::StackLock(OSystem::MutexRef mutex, OSystem *syst) : _mutex(mutex), _syst(syst) { if (syst == 0) @@ -117,4 +123,67 @@ void StackLock::unlock() { _syst->unlock_mutex(_mutex); } + +#pragma mark - + + +struct LanguageDescription { + const char *name; + const char *description; + Common::Language id; +}; + +static const struct LanguageDescription languages[] = { + {"en", "English", EN_USA}, + {"de", "German", DE_DEU}, + {"fr", "French", FR_FRA}, + {"it", "Italian", IT_ITA}, + {"pt", "Portuguese", PT_BRA}, + {"es", "Spanish", ES_ESP}, + {"jp", "Japanese", JA_JPN}, + {"zh", "Chinese (Taiwan)", ZH_TWN}, + {"kr", "Korean", KO_KOR}, + {"gb", "English", EN_GRB}, + {"se", "Swedish", SE_SWE}, + {"hb", "Hebrew", HB_HEB}, + {0, 0, UNK_LANG} +}; + +Language parseLanguage(const String &str) { + if (str.isEmpty()) + return UNK_LANG; + + const char *s = str.c_str(); + const LanguageDescription *l = languages; + while (l->name) { + if (!scumm_stricmp(l->name, s)) + return l->id; + l++; + } + + return UNK_LANG; +} + + +#pragma mark - + + +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")) + return kPlatformAmiga; + else if (!scumm_stricmp(s, "atari-st") || !scumm_stricmp(s, "atari") || !scumm_stricmp(s, "2")) + return kPlatformAtariST; + else if (!scumm_stricmp(s, "macintosh") || !scumm_stricmp(s, "mac") || !scumm_stricmp(s, "3")) + return kPlatformMacintosh; + else + return kPlatformUnknown; +} + + } // End of namespace Common -- cgit v1.2.3