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 ++- apps/lang/english.lang | 4 ++-- firmware/export/button.h | 2 +- firmware/export/config.h | 2 +- tools/checkwps/SOURCES | 1 + tools/checkwps/checkwps.c | 9 +++++---- tools/checkwps/checkwps.make | 39 ++++++++++++++++++++++++++++++++---- tools/configure | 1 - 9 files changed, 72 insertions(+), 24 deletions(-) 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 diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 6c09aa3d40..fdedf01866 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -753,7 +753,7 @@ id: LANG_CHANNEL_STEREO - desc: in sound_settings + desc: in sound_settings and radio screen user: core *: "Stereo" @@ -767,7 +767,7 @@ id: LANG_CHANNEL_MONO - desc: in sound_settings + desc: in sound_settings and radio screen user: core *: "Mono" diff --git a/firmware/export/button.h b/firmware/export/button.h index 3abad2d4f0..75a72ab66e 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h @@ -24,7 +24,7 @@ #include #include #include "config.h" -#ifndef __PCTOOL__ +#if defined(CHECKWPS) || !defined(__PCTOOL__) #include "button-target.h" #endif diff --git a/firmware/export/config.h b/firmware/export/config.h index 9812db9161..5ea5c71c70 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -915,7 +915,7 @@ Lyre prototype 1 */ /* Enable the directory cache and tagcache in RAM if we have * plenty of RAM. Both features can be enabled independently. */ -#if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && !defined(__PCTOOL__) \ +#if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && (defined(CHECKWPS) || !defined(__PCTOOL__)) \ && !defined(APPLICATION) #ifndef SIMULATOR #define HAVE_DIRCACHE diff --git a/tools/checkwps/SOURCES b/tools/checkwps/SOURCES index c00268fa75..45d59a16a5 100644 --- a/tools/checkwps/SOURCES +++ b/tools/checkwps/SOURCES @@ -2,6 +2,7 @@ ../../apps/gui/skin_engine/skin_parser.c ../../apps/gui/skin_engine/skin_backdrops.c ../../apps/gui/viewport.c +../../apps/language.c ../../apps/misc.c ../../firmware/common/strmemccpy.c ../../firmware/common/strlcpy.c diff --git a/tools/checkwps/checkwps.c b/tools/checkwps/checkwps.c index 932dc3884c..dd2115d5ef 100644 --- a/tools/checkwps/checkwps.c +++ b/tools/checkwps/checkwps.c @@ -35,7 +35,7 @@ #include "file.h" #include "font.h" -bool debug_wps = true; +bool debug_wps = false; int wps_verbose_level = 0; char *skin_buffer; @@ -167,9 +167,9 @@ int remote_getwidth(void) { return LCD_REMOTE_WIDTH; } int remote_getheight(void) { return LCD_REMOTE_HEIGHT; } #endif -static inline bool backdrop_load(const char *filename, char* backdrop_buffer) -{ - (void)filename; (void)backdrop_buffer; return true; +static inline bool backdrop_load(const char *filename, char* backdrop_buffer) +{ + (void)filename; (void)backdrop_buffer; return true; } struct screen screens[NB_SCREENS] = @@ -282,6 +282,7 @@ int main(int argc, char **argv) while (argv[1][i] && argv[1][i] == 'v') { i++; wps_verbose_level++; + debug_wps = true; } } skin_buffer = malloc(SKIN_BUFFER_SIZE); diff --git a/tools/checkwps/checkwps.make b/tools/checkwps/checkwps.make index 3004bbc2ed..ce02ce3ffd 100644 --- a/tools/checkwps/checkwps.make +++ b/tools/checkwps/checkwps.make @@ -4,14 +4,14 @@ # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ # \/ \/ \/ \/ \/ -# $Id$ -# + +ENGLISH := english # Use global GCCOPTS GCCOPTS += -D__PCTOOL__ -DCHECKWPS CHECKWPS_SRC = $(call preprocess, $(TOOLSDIR)/checkwps/SOURCES) -CHECKWPS_OBJ = $(call c2obj,$(CHECKWPS_SRC)) +CHECKWPS_OBJ = $(call c2obj,$(CHECKWPS_SRC)) $(BUILDDIR)/lang/lang_core.o OTHER_SRC += $(CHECKWPS_SRC) @@ -29,7 +29,9 @@ INCLUDES = -I$(ROOTDIR)/apps/gui \ -I$(ROOTDIR)/lib/rbcodec/metadata \ -I$(ROOTDIR)/lib/rbcodec/dsp \ -I$(APPSDIR) \ - -I$(BUILDDIR) + -I$(BUILDDIR) \ + -I$(BUILDDIR)/lang \ + $(TARGET_INC) .SECONDEXPANSION: # $$(OBJ) is not populated until after this @@ -37,3 +39,32 @@ $(BUILDDIR)/$(BINARY): $$(CHECKWPS_OBJ) $$(CORE_LIBS) @echo LD $(BINARY) $(SILENT)$(HOSTCC) -o $@ $+ $(INCLUDE) $(GCCOPTS) \ -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) + +#### Everything below is hacked in from apps.make and lang.make + +$(BUILDDIR)/apps/features: $(ROOTDIR)/apps/features.txt + $(SILENT)mkdir -p $(BUILDDIR)/apps + $(SILENT)mkdir -p $(BUILDDIR)/lang + $(call PRINTS,PP $( $(BUILDDIR)/apps/features; \ + +$(BUILDDIR)/apps/genlang-features: $(BUILDDIR)/apps/features + $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@))tr \\n : < $< > $@ + +$(BUILDDIR)/lang_enum.h: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang + +$(BUILDDIR)/lang/lang.h: $(ROOTDIR)/apps/lang/$(ENGLISH).lang $(BUILDDIR)/apps/features $(TOOLSDIR)/genlang + $(call PRINTS,GEN lang.h) + $(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done; \ + perl -s $(TOOLSDIR)/genlang -p=$(BUILDDIR)/lang -t=$(MODELNAME)$$feat $< + +$(BUILDDIR)/lang/lang_core.c: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang + +$(BUILDDIR)/lang/lang_core.o: $(BUILDDIR)/lang/lang.h $(BUILDDIR)/lang/lang_core.c + $(call PRINTS,CC lang_core.c)$(CC) $(CFLAGS) -c $(BUILDDIR)/lang/lang_core.c -o $@ + +$(BUILDDIR)/lang/max_language_size.h: $(BUILDDIR)/lang/lang.h + $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@)) + $(SILENT)echo "#define MAX_LANGUAGE_SIZE 131072" > $@ diff --git a/tools/configure b/tools/configure index 1a03f3f010..0f617d7093 100755 --- a/tools/configure +++ b/tools/configure @@ -4307,7 +4307,6 @@ fi uname=`uname` simcc "checkwps" toolset=''; - t_cpu=''; GCCOPTS=''; rbdir='.' extradefines="$extradefines -DDEBUG" -- cgit v1.2.3