COMMON: Move Language and Platform functionality into separate files

This commit is contained in:
Max Horn 2012-02-22 21:03:17 +01:00
parent 215b41b244
commit 367131ef0e
20 changed files with 394 additions and 274 deletions

View file

@ -29,6 +29,8 @@
#include "backends/audiocd/default/default-audiocd.h"
#include "backends/fs/fs-factory.h"
#include "audio/mixer_intern.h"
#include "common/language.h"
#include "common/platform.h"
#ifdef DYNAMIC_MODULES
#include "backends/plugins/dynamic-plugin.h"
#endif

View file

@ -23,7 +23,7 @@
#ifndef COMMON_GUI_OPTIONS_H
#define COMMON_GUI_OPTIONS_H
#include "common/util.h" // for Common::Language
#include "common/language.h"
#define GUIO_NONE "\000"
#define GUIO_NOSUBTITLES "\001"

107
common/language.cpp Normal file
View file

@ -0,0 +1,107 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "common/language.h"
#include "common/str.h"
namespace Common {
const LanguageDescription g_languages[] = {
{ "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA },
{ "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN },
{ "cz", "cs_CZ", "Czech", CZ_CZE },
{ "nl", "nl_NL", "Dutch", NL_NLD },
{ "en", "en", "English", EN_ANY }, // Generic English (when only one game version exist)
{ "gb", "en_GB", "English (GB)", EN_GRB },
{ "us", "en_US", "English (US)", EN_USA },
{ "fr", "fr_FR", "French", FR_FRA },
{ "de", "de_DE", "German", DE_DEU },
{ "gr", "el_GR", "Greek", GR_GRE },
{ "he", "he_IL", "Hebrew", HE_ISR },
{ "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated
{ "hr", "hr_HR", "Croatian", HR_HRV },
{ "hu", "hu_HU", "Hungarian", HU_HUN },
{ "it", "it_IT", "Italian", IT_ITA },
{ "jp", "ja_JP", "Japanese", JA_JPN },
{ "kr", "ko_KR", "Korean", KO_KOR },
{ "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale
{ "pl", "pl_PL", "Polish", PL_POL },
{ "br", "pt_BR", "Portuguese", PT_BRA },
{ "ru", "ru_RU", "Russian", RU_RUS },
{ "es", "es_ES", "Spanish", ES_ESP },
{ "se", "sv_SE", "Swedish", SE_SWE },
{ 0, 0, 0, UNK_LANG }
};
Language parseLanguage(const String &str) {
if (str.empty())
return UNK_LANG;
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (str.equalsIgnoreCase(l->code))
return l->id;
}
return UNK_LANG;
}
Language parseLanguageFromLocale(const char *locale) {
if (!locale || !*locale)
return UNK_LANG;
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (!strcmp(l->unixLocale, locale))
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 *getLanguageLocale(Language id) {
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (l->id == id)
return l->unixLocale;
}
return 0;
}
const char *getLanguageDescription(Language id) {
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (l->id == id)
return l->description;
}
return 0;
}
} // End of namespace Common

80
common/language.h Normal file
View file

@ -0,0 +1,80 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef COMMON_LANGUAGE_H
#define COMMON_LANGUAGE_H
#include "common/scummsys.h"
namespace Common {
class String;
/**
* List of game language.
*/
enum Language {
ZH_CNA,
ZH_TWN,
CZ_CZE,
NL_NLD,
EN_ANY, // Generic English (when only one game version exist)
EN_GRB,
EN_USA,
FR_FRA,
DE_DEU,
GR_GRE,
HE_ISR,
HR_HRV,
HU_HUN,
IT_ITA,
JA_JPN,
KO_KOR,
NB_NOR,
PL_POL,
PT_BRA,
RU_RUS,
ES_ESP,
SE_SWE,
UNK_LANG = -1 // Use default language (i.e. none specified)
};
struct LanguageDescription {
const char *code;
const char *unixLocale;
const char *description;
Language id;
};
extern const LanguageDescription g_languages[];
/** Convert a string containing a language name into a Language enum value. */
extern Language parseLanguage(const String &str);
extern Language parseLanguageFromLocale(const char *locale);
extern const char *getLanguageCode(Language id);
extern const char *getLanguageLocale(Language id);
extern const char *getLanguageDescription(Language id);
} // End of namespace Common
#endif

View file

@ -22,7 +22,7 @@
#ifndef COMMON_LOCALIZATION_H
#define COMMON_LOCALIZATION_H
#include "common/util.h"
#include "common/language.h"
#include "common/keyboard.h"
namespace Common {

View file

@ -15,11 +15,13 @@ MODULE_OBJS := \
gui_options.o \
hashmap.o \
iff_container.o \
language.o \
localization.o \
macresman.o \
memorypool.o \
md5.o \
mutex.o \
platform.o \
quicktime.o \
random.o \
rational.o \

107
common/platform.cpp Normal file
View file

@ -0,0 +1,107 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "common/platform.h"
#include "common/str.h"
namespace Common {
const PlatformDescription g_platforms[] = {
{ "2gs", "2gs", "2gs", "Apple IIgs", kPlatformApple2GS },
{ "3do", "3do", "3do", "3DO", kPlatform3DO },
{ "acorn", "acorn", "acorn", "Acorn", kPlatformAcorn },
{ "amiga", "ami", "amiga", "Amiga", kPlatformAmiga },
{ "atari", "atari-st", "st", "Atari ST", kPlatformAtariST },
{ "c64", "c64", "c64", "Commodore 64", kPlatformC64 },
{ "pc", "dos", "ibm", "DOS", kPlatformPC },
{ "pc98", "pc98", "pc98", "PC-98", kPlatformPC98 },
{ "wii", "wii", "wii", "Nintendo Wii", kPlatformWii },
{ "coco3", "coco3", "coco3", "CoCo3", kPlatformCoCo3 },
// The 'official' spelling seems to be "FM-TOWNS" (e.g. in the Indy4 demo).
// However, on the net many variations can be seen, like "FMTOWNS",
// "FM TOWNS", "FmTowns", etc.
{ "fmtowns", "towns", "fm", "FM-TOWNS", kPlatformFMTowns },
{ "linux", "linux", "linux", "Linux", kPlatformLinux },
{ "macintosh", "mac", "mac", "Macintosh", kPlatformMacintosh },
{ "pce", "pce", "pce", "PC-Engine", kPlatformPCEngine },
{ "nes", "nes", "nes", "NES", kPlatformNES },
{ "segacd", "segacd", "sega", "SegaCD", kPlatformSegaCD },
{ "windows", "win", "win", "Windows", kPlatformWindows },
{ "playstation", "psx", "psx", "Sony PlayStation", kPlatformPSX },
{ "cdi", "cdi", "cdi", "Philips CD-i", kPlatformCDi },
{ "ios", "ios", "ios", "Apple iOS", kPlatformIOS },
{ 0, 0, 0, "Default", kPlatformUnknown }
};
Platform parsePlatform(const String &str) {
if (str.empty())
return kPlatformUnknown;
// Handle some special case separately, for compatibility with old config
// files.
if (str == "1")
return kPlatformAmiga;
else if (str == "2")
return kPlatformAtariST;
else if (str == "3")
return kPlatformMacintosh;
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (str.equalsIgnoreCase(l->code) || str.equalsIgnoreCase(l->code2) || str.equalsIgnoreCase(l->abbrev))
return l->id;
}
return kPlatformUnknown;
}
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 *getPlatformAbbrev(Platform id) {
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (l->id == id)
return l->abbrev;
}
return 0;
}
const char *getPlatformDescription(Platform id) {
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (l->id == id)
return l->description;
}
return l->description;
}
} // End of namespace Common

80
common/platform.h Normal file
View file

@ -0,0 +1,80 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef COMMON_PLATFORM_H
#define COMMON_PLATFORM_H
#include "common/scummsys.h"
namespace Common {
class String;
/**
* List of game platforms. Specifying a platform for a target can be used to
* give the game engines a hint for which platform the game data file are.
* This may be optional or required, depending on the game engine and the
* game in question.
*/
enum Platform {
kPlatformPC,
kPlatformAmiga,
kPlatformAtariST,
kPlatformMacintosh,
kPlatformFMTowns,
kPlatformWindows,
kPlatformNES,
kPlatformC64,
kPlatformCoCo3,
kPlatformLinux,
kPlatformAcorn,
kPlatformSegaCD,
kPlatform3DO,
kPlatformPCEngine,
kPlatformApple2GS,
kPlatformPC98,
kPlatformWii,
kPlatformPSX,
kPlatformCDi,
kPlatformIOS,
kPlatformUnknown = -1
};
struct PlatformDescription {
const char *code;
const char *code2;
const char *abbrev;
const char *description;
Platform id;
};
extern const PlatformDescription g_platforms[];
/** Convert a string containing a platform name into a Platform enum value. */
extern Platform parsePlatform(const String &str);
extern const char *getPlatformCode(Platform id);
extern const char *getPlatformAbbrev(Platform id);
extern const char *getPlatformDescription(Platform id);
} // End of namespace Common
#endif

View file

@ -110,174 +110,6 @@ bool parseBool(const String &val, bool &valAsBool) {
#pragma mark -
const LanguageDescription g_languages[] = {
{ "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA },
{ "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN },
{ "cz", "cs_CZ", "Czech", CZ_CZE },
{ "nl", "nl_NL", "Dutch", NL_NLD },
{ "en", "en", "English", EN_ANY }, // Generic English (when only one game version exist)
{ "gb", "en_GB", "English (GB)", EN_GRB },
{ "us", "en_US", "English (US)", EN_USA },
{ "fr", "fr_FR", "French", FR_FRA },
{ "de", "de_DE", "German", DE_DEU },
{ "gr", "el_GR", "Greek", GR_GRE },
{ "he", "he_IL", "Hebrew", HE_ISR },
{ "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated
{ "hr", "hr_HR", "Croatian", HR_HRV },
{ "hu", "hu_HU", "Hungarian", HU_HUN },
{ "it", "it_IT", "Italian", IT_ITA },
{ "jp", "ja_JP", "Japanese", JA_JPN },
{ "kr", "ko_KR", "Korean", KO_KOR },
{ "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale
{ "pl", "pl_PL", "Polish", PL_POL },
{ "br", "pt_BR", "Portuguese", PT_BRA },
{ "ru", "ru_RU", "Russian", RU_RUS },
{ "es", "es_ES", "Spanish", ES_ESP },
{ "se", "sv_SE", "Swedish", SE_SWE },
{ 0, 0, 0, UNK_LANG }
};
Language parseLanguage(const String &str) {
if (str.empty())
return UNK_LANG;
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (str.equalsIgnoreCase(l->code))
return l->id;
}
return UNK_LANG;
}
Language parseLanguageFromLocale(const char *locale) {
if (!locale || !*locale)
return UNK_LANG;
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (!strcmp(l->unixLocale, locale))
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 *getLanguageLocale(Language id) {
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (l->id == id)
return l->unixLocale;
}
return 0;
}
const char *getLanguageDescription(Language id) {
const LanguageDescription *l = g_languages;
for (; l->code; ++l) {
if (l->id == id)
return l->description;
}
return 0;
}
#pragma mark -
const PlatformDescription g_platforms[] = {
{ "2gs", "2gs", "2gs", "Apple IIgs", kPlatformApple2GS },
{ "3do", "3do", "3do", "3DO", kPlatform3DO },
{ "acorn", "acorn", "acorn", "Acorn", kPlatformAcorn },
{ "amiga", "ami", "amiga", "Amiga", kPlatformAmiga },
{ "atari", "atari-st", "st", "Atari ST", kPlatformAtariST },
{ "c64", "c64", "c64", "Commodore 64", kPlatformC64 },
{ "pc", "dos", "ibm", "DOS", kPlatformPC },
{ "pc98", "pc98", "pc98", "PC-98", kPlatformPC98 },
{ "wii", "wii", "wii", "Nintendo Wii", kPlatformWii },
{ "coco3", "coco3", "coco3", "CoCo3", kPlatformCoCo3 },
// The 'official' spelling seems to be "FM-TOWNS" (e.g. in the Indy4 demo).
// However, on the net many variations can be seen, like "FMTOWNS",
// "FM TOWNS", "FmTowns", etc.
{ "fmtowns", "towns", "fm", "FM-TOWNS", kPlatformFMTowns },
{ "linux", "linux", "linux", "Linux", kPlatformLinux },
{ "macintosh", "mac", "mac", "Macintosh", kPlatformMacintosh },
{ "pce", "pce", "pce", "PC-Engine", kPlatformPCEngine },
{ "nes", "nes", "nes", "NES", kPlatformNES },
{ "segacd", "segacd", "sega", "SegaCD", kPlatformSegaCD },
{ "windows", "win", "win", "Windows", kPlatformWindows },
{ "playstation", "psx", "psx", "Sony PlayStation", kPlatformPSX },
{ "cdi", "cdi", "cdi", "Philips CD-i", kPlatformCDi },
{ "ios", "ios", "ios", "Apple iOS", kPlatformIOS },
{ 0, 0, 0, "Default", kPlatformUnknown }
};
Platform parsePlatform(const String &str) {
if (str.empty())
return kPlatformUnknown;
// Handle some special case separately, for compatibility with old config
// files.
if (str == "1")
return kPlatformAmiga;
else if (str == "2")
return kPlatformAtariST;
else if (str == "3")
return kPlatformMacintosh;
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (str.equalsIgnoreCase(l->code) || str.equalsIgnoreCase(l->code2) || str.equalsIgnoreCase(l->abbrev))
return l->id;
}
return kPlatformUnknown;
}
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 *getPlatformAbbrev(Platform id) {
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (l->id == id)
return l->abbrev;
}
return 0;
}
const char *getPlatformDescription(Platform id) {
const PlatformDescription *l = g_platforms;
for (; l->code; ++l) {
if (l->id == id)
return l->description;
}
return l->description;
}
#pragma mark -
#define ENSURE_ASCII_CHAR(c) \
if (c < 0 || c > 127) \
return false

View file

@ -165,102 +165,6 @@ bool isSpace(int c);
*/
bool isUpper(int c);
/**
* List of game language.
*/
enum Language {
ZH_CNA,
ZH_TWN,
CZ_CZE,
NL_NLD,
EN_ANY, // Generic English (when only one game version exist)
EN_GRB,
EN_USA,
FR_FRA,
DE_DEU,
GR_GRE,
HE_ISR,
HR_HRV,
HU_HUN,
IT_ITA,
JA_JPN,
KO_KOR,
NB_NOR,
PL_POL,
PT_BRA,
RU_RUS,
ES_ESP,
SE_SWE,
UNK_LANG = -1 // Use default language (i.e. none specified)
};
struct LanguageDescription {
const char *code;
const char *unixLocale;
const char *description;
Language id;
};
extern const LanguageDescription g_languages[];
/** Convert a string containing a language name into a Language enum value. */
extern Language parseLanguage(const String &str);
extern Language parseLanguageFromLocale(const char *locale);
extern const char *getLanguageCode(Language id);
extern const char *getLanguageLocale(Language id);
extern const char *getLanguageDescription(Language id);
/**
* List of game platforms. Specifying a platform for a target can be used to
* give the game engines a hint for which platform the game data file are.
* This may be optional or required, depending on the game engine and the
* game in question.
*/
enum Platform {
kPlatformPC,
kPlatformAmiga,
kPlatformAtariST,
kPlatformMacintosh,
kPlatformFMTowns,
kPlatformWindows,
kPlatformNES,
kPlatformC64,
kPlatformCoCo3,
kPlatformLinux,
kPlatformAcorn,
kPlatformSegaCD,
kPlatform3DO,
kPlatformPCEngine,
kPlatformApple2GS,
kPlatformPC98,
kPlatformWii,
kPlatformPSX,
kPlatformCDi,
kPlatformIOS,
kPlatformUnknown = -1
};
struct PlatformDescription {
const char *code;
const char *code2;
const char *abbrev;
const char *description;
Platform id;
};
extern const PlatformDescription g_platforms[];
/** Convert a string containing a platform name into a Platform enum value. */
extern Platform parsePlatform(const String &str);
extern const char *getPlatformCode(Platform id);
extern const char *getPlatformAbbrev(Platform id);
extern const char *getPlatformDescription(Platform id);
} // End of namespace Common
#endif

View file

@ -24,6 +24,8 @@
#include "common/scummsys.h"
#include "common/str.h"
#include "common/language.h"
#include "common/platform.h"
class OSystem;

View file

@ -26,7 +26,8 @@
#include "common/array.h"
#include "common/hash-str.h"
#include "common/str.h"
#include "common/util.h"
#include "common/language.h"
#include "common/platform.h"
/**
* A simple structure used to map gameids (like "monkey", "sword1", ...) to

View file

@ -26,7 +26,7 @@
#include "common/str.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/util.h"
#include "common/language.h"
#include "gob/dbase.h"

View file

@ -23,7 +23,7 @@
#ifndef QUEEN_INPUT_H
#define QUEEN_INPUT_H
#include "common/util.h"
#include "common/language.h"
#include "common/rect.h"
#include "common/events.h"
#include "queen/defs.h"

View file

@ -25,7 +25,8 @@
#include "common/file.h"
#include "common/str-array.h"
#include "common/util.h"
#include "common/language.h"
#include "common/platform.h"
#include "queen/defs.h"
namespace Queen {

View file

@ -23,7 +23,8 @@
#ifndef SCUMM_DETECTION_H
#define SCUMM_DETECTION_H
#include "common/util.h"
#include "common/language.h"
#include "common/platform.h"
namespace Scumm {

View file

@ -24,6 +24,7 @@
#define SCUMM_HELP_H
#include "common/str.h"
#include "common/platform.h"
namespace Scumm {

View file

@ -22,7 +22,7 @@
#include "sword25/util/lua/scummvm_file.h"
#include "common/config-manager.h"
#include "common/util.h"
#include "common/language.h"
namespace Sword25 {

View file

@ -23,7 +23,7 @@
#ifndef TOUCHE_GRAPHICS_H
#define TOUCHE_GRAPHICS_H
#include "common/util.h"
#include "common/language.h"
namespace Touche {

View file

@ -43,7 +43,7 @@
#endif
#include "common/scummsys.h"
#include "common/util.h"
#include "common/platform.h"
namespace Graphics {