From 8b8c0c7c2ac40cd729a9eeb39189c184978b6d57 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 23 May 2024 21:36:54 -0400 Subject: checkwps: Validate translated strings (%Sx) In verbose mode it will log valid the strings found, otherwise it will only complain when we encounter a missing string. Unfortunately a missing string is not inherently a problem, due to conditional expressions. So all we can do is complain in checkwps or if wps debugging is turned on. Meanwhile, this is the first step in actually enumerating the translated strings used by themes. Change-Id: Ia93b333085e825d5b085c4d372ad8e13aa3e3ba1 --- apps/gui/skin_engine/skin_parser.c | 35 +++++++++++++++++++++++++---------- apps/gui/skin_engine/wps_internals.h | 3 ++- 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'apps/gui/skin_engine') diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index be25bd0125..867f2b6a18 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -44,6 +44,8 @@ #else #include "action.h" #include "checkwps.h" +#include "language.h" +#include "lang_enum.h" #include "audio.h" #define lang_is_rtl() (false) #define DEBUGF printf @@ -804,22 +806,29 @@ static int parse_setting_and_lang(struct skin_element *element, struct wps_token *token, struct wps_data *wps_data) { - /* NOTE: both the string validations that happen in here will - * automatically PASS on checkwps because its too hard to get - * settings_list.c and english.lang built for it. - * If that ever changes remove the #ifndef __PCTOOL__'s here - */ (void)wps_data; char *temp = get_param_text(element, 0); if (token->type == SKIN_TOKEN_TRANSLATEDSTRING) { -#ifndef __PCTOOL__ int i = lang_english_to_id(temp); - if (i < 0) + if (i < 0) { + DEBUGF("Translated String [%s] NOT FOUND\n", temp); + /* Due to conditionals in a theme, a missing string + might never be hit. So currently we have to just treat + this as an advisory */ +#if 1 i = LANG_LAST_INDEX_IN_ARRAY; - token->value.i = i; +#else + return WPS_ERROR_INVALID_PARAM; +#endif + } +#ifdef DEBUG_SKIN_ENGINE + else if (debug_wps) { + DEBUGF("Translated String [%s] = %d\n", temp, i); + } #endif + token->value.i = i; } else if (element->params_count > 1) { @@ -830,11 +839,17 @@ static int parse_setting_and_lang(struct skin_element *element, } else { + /* NOTE: The string validations that happen here will + * automatically PASS on checkwps because its too hard to get + * settings_list.c built for a specific target. + * If that ever changes remove the #ifndef __PCTOOL__ here + */ #ifndef __PCTOOL__ const struct settings_list *setting = find_setting_by_cfgname(temp); - if (!setting) + if (!setting) { + DEBUGF("Invalid setting [%s]\n", temp); return WPS_ERROR_INVALID_PARAM; - + } token->value.xdata = (void *)setting; #endif } diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index 6e20ed8da9..c4e319fca5 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -442,7 +442,8 @@ enum skin_find_what { }; void *skin_find_item(const char *label, enum skin_find_what what, struct wps_data *data); -#ifdef SIMULATOR + +#if defined(SIMULATOR) || defined(CHECKWPS) #define DEBUG_SKIN_ENGINE extern bool debug_wps; #endif -- cgit v1.2.3