[PATCH 4/8] Add language + kbd layout command line options

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Which for now relies on earlier setting NVRAM functionality.
---
 src/includes/tos.h |  2 ++
 src/options.c      | 24 ++++++++++++++++++++++-
 src/tos.c          | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/src/includes/tos.h b/src/includes/tos.h
index fc9adc0d..0b8632dc 100644
--- a/src/includes/tos.h
+++ b/src/includes/tos.h
@@ -46,4 +46,6 @@ extern void TOS_MemorySnapShot_Capture(bool bSave);
 extern int TOS_InitImage(void);
 extern void TOS_SetTestPrgName(const char *testprg);
 
+extern int TOS_ParseCountryCode(const char *code, const char *info);
+
 #endif
diff --git a/src/options.c b/src/options.c
index a84a9943..0343ec44 100644
--- a/src/options.c
+++ b/src/options.c
@@ -65,6 +65,8 @@ enum {
 	OPT_CONFIRMQUIT,
 	OPT_CONFIGFILE,
 	OPT_KEYMAPFILE,
+	OPT_KBD_LAYOUT,
+	OPT_LANGUAGE,
 	OPT_FASTFORWARD,
 	OPT_AUTOSTART,
 
@@ -225,7 +227,11 @@ static const opt_t HatariOptions[] = {
 	{ OPT_CONFIGFILE, "-c", "--configfile",
 	  "<file>", "Read (additional) configuration values from <file>" },
 	{ OPT_KEYMAPFILE, "-k", "--keymap",
-	  "<file>", "Read (additional) keyboard mappings from <file>" },
+	  "<file>", "Read keyboard mappings from <file>" },
+	{ OPT_KBD_LAYOUT, NULL, "--layout",
+	  "<x>", "Set (TT/Falcon) NVRAM keyboard layout value" },
+	{ OPT_LANGUAGE, NULL, "--language",
+	  "<x>", "Set (TT/Falcon) NVRAM language value" },
 	{ OPT_FASTFORWARD, NULL, "--fast-forward",
 	  "<bool>", "Help skipping stuff on fast machine" },
 	{ OPT_AUTOSTART, NULL, "--auto",
@@ -2012,6 +2018,22 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			ok = Opt_Bool(argv[++i], OPT_MICROPHONE, &ConfigureParams.Sound.bEnableMicrophone);
 			break;
 
+		case OPT_LANGUAGE:
+			val = TOS_ParseCountryCode(argv[++i], "language");
+			if (val != TOS_LANG_UNKNOWN)
+				ConfigureParams.Keyboard.nLanguage = val;
+			else
+				ok = false;
+			break;
+
+		case OPT_KBD_LAYOUT:
+			val = TOS_ParseCountryCode(argv[++i], "keyboard layout");
+			if (val != TOS_LANG_UNKNOWN)
+				ConfigureParams.Keyboard.nKbdLayout = val;
+			else
+				ok = false;
+			break;
+
 		case OPT_KEYMAPFILE:
 			i += 1;
 			ok = Opt_StrCpy(OPT_KEYMAPFILE, true, ConfigureParams.Keyboard.szMappingFileName,
diff --git a/src/tos.c b/src/tos.c
index eccf76a1..c9120665 100644
--- a/src/tos.c
+++ b/src/tos.c
@@ -1221,3 +1221,52 @@ int TOS_InitImage(void)
 	bTosImageLoaded = true;
 	return 0;
 }
+
+static const struct {
+	uint8_t value;
+	const char *code;
+	const char *name;
+} countries[] = {
+	{ TOS_LANG_US,    "us",    "USA" },
+	{ TOS_LANG_DE,    "de",    "Germany" },
+	{ TOS_LANG_FR,    "fr",    "France" },
+	{ TOS_LANG_UK,    "uk",    "United Kingdom" },
+	{ TOS_LANG_ES,    "es",    "Spain" },
+	{ TOS_LANG_IT,    "it",    "Italy" },
+	{ TOS_LANG_SE,    "se",    "Sweden" },
+	{ TOS_LANG_CH_FR, "ch_fr", "Switzerland (French)" },
+	{ TOS_LANG_CH_DE, "ch_de", "Switzerland (German)" },
+	{ TOS_LANG_TR,    "tr",    "Turkey" },
+	{ TOS_LANG_FI,    "fi",    "Finland" },
+	{ TOS_LANG_NO,    "no",    "Norway" },
+	{ TOS_LANG_DK,    "dk",    "Denmark" },
+	{ TOS_LANG_SA,    "sa",    "Saudi Arabia" },
+	{ TOS_LANG_NL,    "nl",    "Holland" },
+	{ TOS_LANG_CS,    "cs",    "Czech Republic" },
+	{ TOS_LANG_HU,    "hu",    "Hungary" },
+	{ TOS_LANG_RU,    "ru",    "Russia" },
+	{ TOS_LANG_GR,    "gr",    "Greece" },
+	{ TOS_LANG_ALL,   "all",   "Multilanguage" }
+};
+
+/**
+ * TOS_ValidCountryCode: returns parsed country code if
+ * it's recognized, otherwise valid ones are shown and
+ * TOS_LANG_UNKNOWN is returned
+ */
+int TOS_ParseCountryCode(const char *code, const char *info)
+{
+	for (int i = 0; i < ARRAY_SIZE(countries); i++) {
+		if (strcmp(code, countries[i].code) == 0) {
+			return countries[i].value;
+		}
+	}
+	fprintf(stderr, "Invalid %s code '%s'!\n", info, code);
+
+	fprintf(stderr, "\nValid ones are:\n");
+	for (int i = 0; i < ARRAY_SIZE(countries); i++) {
+		fprintf(stderr, "- %s : %s\n",
+			countries[i].code, countries[i].name);
+	}
+	return TOS_LANG_UNKNOWN;
+}
-- 
2.30.2


--------------C9D85C665CB14AB33C38696A
Content-Type: text/x-patch; charset=UTF-8;
 name="0003-Set-NVRAM-language-layout-based-on-config-variables.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0003-Set-NVRAM-language-layout-based-on-config-variables.pat";
 filename*1="ch"



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/