From 5840f459fa9ae5ce8f2cb4102af3a338886fe848 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 16 Aug 2022 09:21:32 +0200 Subject: [PATCH] Renamed UIStrings.h/.c to ui_strings.h/.c and refactored their content --- meson.build | 2 +- openrtx/include/core/voicePromptUtils.h | 2 +- openrtx/include/ui/EnglishStrings.h | 12 ++++---- .../include/ui/{UIStrings.h => ui_strings.h} | 30 ++++++++++++------- openrtx/src/core/voicePrompts.c | 2 +- openrtx/src/ui/ui_main.c | 2 +- openrtx/src/ui/ui_menu.c | 2 +- openrtx/src/ui/{UIStrings.c => ui_strings.c} | 24 ++++----------- 8 files changed, 38 insertions(+), 38 deletions(-) rename openrtx/include/ui/{UIStrings.h => ui_strings.h} (85%) rename openrtx/src/ui/{UIStrings.c => ui_strings.c} (74%) diff --git a/meson.build b/meson.build index c862a33d..d957f07a 100644 --- a/meson.build +++ b/meson.build @@ -54,7 +54,7 @@ openrtx_src = ['openrtx/src/core/state.c', 'openrtx/src/core/voicePrompts.c', 'openrtx/src/core/voicePromptUtils.c', 'openrtx/src/ui/ui.c', - 'openrtx/src/ui/UIStrings.c', + 'openrtx/src/ui/ui_strings.c', 'openrtx/src/ui/ui_main.c', 'openrtx/src/ui/ui_menu.c', 'openrtx/src/rtx/rtx.cpp', diff --git a/openrtx/include/core/voicePromptUtils.h b/openrtx/include/core/voicePromptUtils.h index 60369424..a72776e2 100644 --- a/openrtx/include/core/voicePromptUtils.h +++ b/openrtx/include/core/voicePromptUtils.h @@ -22,7 +22,7 @@ #define VOICE_PROMPT_UTILS_H_INCLUDED #include "cps.h" -#include "ui/UIStrings.h" +#include "ui/ui_strings.h" #include "voicePrompts.h" /* diff --git a/openrtx/include/ui/EnglishStrings.h b/openrtx/include/ui/EnglishStrings.h index 2436c110..79bf97a3 100644 --- a/openrtx/include/ui/EnglishStrings.h +++ b/openrtx/include/ui/EnglishStrings.h @@ -17,11 +17,13 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ -#ifndef EnglishStrings_h_included -#define EnglishStrings_h_included -#include "ui/UIStrings.h" +#ifndef ENGLISHSTRINGS_H +#define ENGLISHSTRINGS_H -const stringsTable_t englishStrings = { +#include "ui/ui_strings.h" + +const stringsTable_t englishStrings = +{ .languageName = "English", .off = "OFF", .on = "ON", @@ -87,4 +89,4 @@ const stringsTable_t englishStrings = { .forEmergencyUse = "For emergency use", .pressAnyButton = "press any button.", }; -#endif // EnglishStrings_h_included +#endif // ENGLISHSTRINGS_H diff --git a/openrtx/include/ui/UIStrings.h b/openrtx/include/ui/ui_strings.h similarity index 85% rename from openrtx/include/ui/UIStrings.h rename to openrtx/include/ui/ui_strings.h index bd04b8ec..78edcd6e 100644 --- a/openrtx/include/ui/UIStrings.h +++ b/openrtx/include/ui/ui_strings.h @@ -17,15 +17,16 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ -/* -This string table's order must not be altered as voice prompts will be indexed -in the same order as these strings. Also, menus may be printed using string -table offsets. -*/ -#ifndef UIStrings_h_included -#define UIStrings_h_included +#ifndef UI_STRINGS_H +#define UI_STRINGS_H + #define NUM_LANGUAGES 1 +/* + * NOTE: This string table's order must not be altered as voice prompts will be + * indexed in the same order as these strings. + * Also, menus may be printed using string table offsets. + */ typedef struct { const char* languageName; @@ -92,11 +93,20 @@ typedef struct const char* macroMenu; const char* forEmergencyUse; const char* pressAnyButton; -} stringsTable_t; +} +stringsTable_t; extern const stringsTable_t languages[]; extern const stringsTable_t* currentLanguage; -int GetEnglishStringTableOffset(char* text); +/** + * Search for a given string into the string table and, if found, return its + * offset with respect to the beginning. + * + * @param text: string to be searched. + * @return text position inside the string table or -1 if the string is not + * present. + */ +int GetEnglishStringTableOffset(const char* text); -#endif \ No newline at end of file +#endif diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 213ac4df..fb4d6e50 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -29,7 +29,7 @@ #include "interfaces/keyboard.h" -#include "ui/UIStrings.h" +#include "ui/ui_strings.h" const uint32_t VOICE_PROMPTS_DATA_MAGIC = 0x5056; //'VP' const uint32_t VOICE_PROMPTS_DATA_VERSION = 0x1000; // v1000 OpenRTX diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index ac628616..f281e42f 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -24,7 +24,7 @@ #include #include #include -#include "ui/UIStrings.h" +#include "ui/ui_strings.h" void _ui_drawMainBackground() { diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 10f91fd9..9ac90f16 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include /* UI main screen helper functions, their implementation is in "ui_main.c" */ diff --git a/openrtx/src/ui/UIStrings.c b/openrtx/src/ui/ui_strings.c similarity index 74% rename from openrtx/src/ui/UIStrings.c rename to openrtx/src/ui/ui_strings.c index 919afe17..60dedd2c 100644 --- a/openrtx/src/ui/UIStrings.c +++ b/openrtx/src/ui/ui_strings.c @@ -17,33 +17,21 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, see * ***************************************************************************/ -/* -This string table's order must not be altered as voice prompts will be indexed -in the same order as these strings. -*/ -#include "ui/UIStrings.h" #include #include +#include +#include -#include "ui/EnglishStrings.h" - -// add more languages here. const stringsTable_t languages[NUM_LANGUAGES] = {englishStrings}; -// default to English. const stringsTable_t* currentLanguage = &languages[0]; -/* -Given an english string such as a menu item or value, -search the english string table and return the offset if found. -This can then be used to look up the localized string in the currentLanguages -struct, or to announce an indexed voice prompt. -*/ -int GetEnglishStringTableOffset(char* text) +int GetEnglishStringTableOffset(const char* text) { - if (!text || !*text) return -1; // error. + if ((text == NULL) || (*text == '\0')) + return -1; - uint8_t stringCount = sizeof(stringsTable_t) / sizeof(char*); + uint8_t stringCount = sizeof(stringsTable_t) / sizeof(char *); for (uint8_t i = 0; i < stringCount; ++i) {