summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2024-05-23 21:36:54 -0400
committerSolomon Peachy <pizza@shaftnet.org>2024-05-24 21:37:54 -0400
commit8b8c0c7c2ac40cd729a9eeb39189c184978b6d57 (patch)
tree09ab71d2b8f13ae47960d5508a5afd3ac135e588
parentac20f8a73c9898ab66e176ab66f3ef89bb76692d (diff)
downloadrockbox-8b8c0c7c2ac40cd729a9eeb39189c184978b6d57.tar.gz
rockbox-8b8c0c7c2ac40cd729a9eeb39189c184978b6d57.zip
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
-rw-r--r--apps/gui/skin_engine/skin_parser.c35
-rw-r--r--apps/gui/skin_engine/wps_internals.h3
-rw-r--r--apps/lang/english.lang4
-rw-r--r--firmware/export/button.h2
-rw-r--r--firmware/export/config.h2
-rw-r--r--tools/checkwps/SOURCES1
-rw-r--r--tools/checkwps/checkwps.c9
-rw-r--r--tools/checkwps/checkwps.make39
-rwxr-xr-xtools/configure1
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 @@
44#else 44#else
45#include "action.h" 45#include "action.h"
46#include "checkwps.h" 46#include "checkwps.h"
47#include "language.h"
48#include "lang_enum.h"
47#include "audio.h" 49#include "audio.h"
48#define lang_is_rtl() (false) 50#define lang_is_rtl() (false)
49#define DEBUGF printf 51#define DEBUGF printf
@@ -804,22 +806,29 @@ static int parse_setting_and_lang(struct skin_element *element,
804 struct wps_token *token, 806 struct wps_token *token,
805 struct wps_data *wps_data) 807 struct wps_data *wps_data)
806{ 808{
807 /* NOTE: both the string validations that happen in here will
808 * automatically PASS on checkwps because its too hard to get
809 * settings_list.c and english.lang built for it.
810 * If that ever changes remove the #ifndef __PCTOOL__'s here
811 */
812 (void)wps_data; 809 (void)wps_data;
813 char *temp = get_param_text(element, 0); 810 char *temp = get_param_text(element, 0);
814 811
815 if (token->type == SKIN_TOKEN_TRANSLATEDSTRING) 812 if (token->type == SKIN_TOKEN_TRANSLATEDSTRING)
816 { 813 {
817#ifndef __PCTOOL__
818 int i = lang_english_to_id(temp); 814 int i = lang_english_to_id(temp);
819 if (i < 0) 815 if (i < 0) {
816 DEBUGF("Translated String [%s] NOT FOUND\n", temp);
817 /* Due to conditionals in a theme, a missing string
818 might never be hit. So currently we have to just treat
819 this as an advisory */
820#if 1
820 i = LANG_LAST_INDEX_IN_ARRAY; 821 i = LANG_LAST_INDEX_IN_ARRAY;
821 token->value.i = i; 822#else
823 return WPS_ERROR_INVALID_PARAM;
824#endif
825 }
826#ifdef DEBUG_SKIN_ENGINE
827 else if (debug_wps) {
828 DEBUGF("Translated String [%s] = %d\n", temp, i);
829 }
822#endif 830#endif
831 token->value.i = i;
823 } 832 }
824 else if (element->params_count > 1) 833 else if (element->params_count > 1)
825 { 834 {
@@ -830,11 +839,17 @@ static int parse_setting_and_lang(struct skin_element *element,
830 } 839 }
831 else 840 else
832 { 841 {
842 /* NOTE: The string validations that happen here will
843 * automatically PASS on checkwps because its too hard to get
844 * settings_list.c built for a specific target.
845 * If that ever changes remove the #ifndef __PCTOOL__ here
846 */
833#ifndef __PCTOOL__ 847#ifndef __PCTOOL__
834 const struct settings_list *setting = find_setting_by_cfgname(temp); 848 const struct settings_list *setting = find_setting_by_cfgname(temp);
835 if (!setting) 849 if (!setting) {
850 DEBUGF("Invalid setting [%s]\n", temp);
836 return WPS_ERROR_INVALID_PARAM; 851 return WPS_ERROR_INVALID_PARAM;
837 852 }
838 token->value.xdata = (void *)setting; 853 token->value.xdata = (void *)setting;
839#endif 854#endif
840 } 855 }
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 {
442}; 442};
443void *skin_find_item(const char *label, enum skin_find_what what, 443void *skin_find_item(const char *label, enum skin_find_what what,
444 struct wps_data *data); 444 struct wps_data *data);
445#ifdef SIMULATOR 445
446#if defined(SIMULATOR) || defined(CHECKWPS)
446#define DEBUG_SKIN_ENGINE 447#define DEBUG_SKIN_ENGINE
447extern bool debug_wps; 448extern bool debug_wps;
448#endif 449#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 @@
753</phrase> 753</phrase>
754<phrase> 754<phrase>
755 id: LANG_CHANNEL_STEREO 755 id: LANG_CHANNEL_STEREO
756 desc: in sound_settings 756 desc: in sound_settings and radio screen
757 user: core 757 user: core
758 <source> 758 <source>
759 *: "Stereo" 759 *: "Stereo"
@@ -767,7 +767,7 @@
767</phrase> 767</phrase>
768<phrase> 768<phrase>
769 id: LANG_CHANNEL_MONO 769 id: LANG_CHANNEL_MONO
770 desc: in sound_settings 770 desc: in sound_settings and radio screen
771 user: core 771 user: core
772 <source> 772 <source>
773 *: "Mono" 773 *: "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 @@
24#include <stdbool.h> 24#include <stdbool.h>
25#include <inttypes.h> 25#include <inttypes.h>
26#include "config.h" 26#include "config.h"
27#ifndef __PCTOOL__ 27#if defined(CHECKWPS) || !defined(__PCTOOL__)
28#include "button-target.h" 28#include "button-target.h"
29#endif 29#endif
30 30
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 */
915 915
916/* Enable the directory cache and tagcache in RAM if we have 916/* Enable the directory cache and tagcache in RAM if we have
917 * plenty of RAM. Both features can be enabled independently. */ 917 * plenty of RAM. Both features can be enabled independently. */
918#if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && !defined(__PCTOOL__) \ 918#if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && (defined(CHECKWPS) || !defined(__PCTOOL__)) \
919 && !defined(APPLICATION) 919 && !defined(APPLICATION)
920#ifndef SIMULATOR 920#ifndef SIMULATOR
921#define HAVE_DIRCACHE 921#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 @@
2../../apps/gui/skin_engine/skin_parser.c 2../../apps/gui/skin_engine/skin_parser.c
3../../apps/gui/skin_engine/skin_backdrops.c 3../../apps/gui/skin_engine/skin_backdrops.c
4../../apps/gui/viewport.c 4../../apps/gui/viewport.c
5../../apps/language.c
5../../apps/misc.c 6../../apps/misc.c
6../../firmware/common/strmemccpy.c 7../../firmware/common/strmemccpy.c
7../../firmware/common/strlcpy.c 8../../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 @@
35#include "file.h" 35#include "file.h"
36#include "font.h" 36#include "font.h"
37 37
38bool debug_wps = true; 38bool debug_wps = false;
39int wps_verbose_level = 0; 39int wps_verbose_level = 0;
40char *skin_buffer; 40char *skin_buffer;
41 41
@@ -167,9 +167,9 @@ int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
167int remote_getheight(void) { return LCD_REMOTE_HEIGHT; } 167int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
168#endif 168#endif
169 169
170static inline bool backdrop_load(const char *filename, char* backdrop_buffer) 170static inline bool backdrop_load(const char *filename, char* backdrop_buffer)
171{ 171{
172 (void)filename; (void)backdrop_buffer; return true; 172 (void)filename; (void)backdrop_buffer; return true;
173} 173}
174 174
175struct screen screens[NB_SCREENS] = 175struct screen screens[NB_SCREENS] =
@@ -282,6 +282,7 @@ int main(int argc, char **argv)
282 while (argv[1][i] && argv[1][i] == 'v') { 282 while (argv[1][i] && argv[1][i] == 'v') {
283 i++; 283 i++;
284 wps_verbose_level++; 284 wps_verbose_level++;
285 debug_wps = true;
285 } 286 }
286 } 287 }
287 skin_buffer = malloc(SKIN_BUFFER_SIZE); 288 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 @@
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/ 6# \/ \/ \/ \/ \/
7# $Id$ 7
8# 8ENGLISH := english
9 9
10# Use global GCCOPTS 10# Use global GCCOPTS
11GCCOPTS += -D__PCTOOL__ -DCHECKWPS 11GCCOPTS += -D__PCTOOL__ -DCHECKWPS
12 12
13CHECKWPS_SRC = $(call preprocess, $(TOOLSDIR)/checkwps/SOURCES) 13CHECKWPS_SRC = $(call preprocess, $(TOOLSDIR)/checkwps/SOURCES)
14CHECKWPS_OBJ = $(call c2obj,$(CHECKWPS_SRC)) 14CHECKWPS_OBJ = $(call c2obj,$(CHECKWPS_SRC)) $(BUILDDIR)/lang/lang_core.o
15 15
16OTHER_SRC += $(CHECKWPS_SRC) 16OTHER_SRC += $(CHECKWPS_SRC)
17 17
@@ -29,7 +29,9 @@ INCLUDES = -I$(ROOTDIR)/apps/gui \
29 -I$(ROOTDIR)/lib/rbcodec/metadata \ 29 -I$(ROOTDIR)/lib/rbcodec/metadata \
30 -I$(ROOTDIR)/lib/rbcodec/dsp \ 30 -I$(ROOTDIR)/lib/rbcodec/dsp \
31 -I$(APPSDIR) \ 31 -I$(APPSDIR) \
32 -I$(BUILDDIR) 32 -I$(BUILDDIR) \
33 -I$(BUILDDIR)/lang \
34 $(TARGET_INC)
33 35
34.SECONDEXPANSION: # $$(OBJ) is not populated until after this 36.SECONDEXPANSION: # $$(OBJ) is not populated until after this
35 37
@@ -37,3 +39,32 @@ $(BUILDDIR)/$(BINARY): $$(CHECKWPS_OBJ) $$(CORE_LIBS)
37 @echo LD $(BINARY) 39 @echo LD $(BINARY)
38 $(SILENT)$(HOSTCC) -o $@ $+ $(INCLUDE) $(GCCOPTS) \ 40 $(SILENT)$(HOSTCC) -o $@ $+ $(INCLUDE) $(GCCOPTS) \
39 -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) 41 -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS))
42
43#### Everything below is hacked in from apps.make and lang.make
44
45$(BUILDDIR)/apps/features: $(ROOTDIR)/apps/features.txt
46 $(SILENT)mkdir -p $(BUILDDIR)/apps
47 $(SILENT)mkdir -p $(BUILDDIR)/lang
48 $(call PRINTS,PP $(<F))
49 $(SILENT)$(CC) $(PPCFLAGS) \
50 -E -P -imacros "config.h" -imacros "button.h" -x c $< | \
51 grep -v "^#" | grep -v "^ *$$" > $(BUILDDIR)/apps/features; \
52
53$(BUILDDIR)/apps/genlang-features: $(BUILDDIR)/apps/features
54 $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@))tr \\n : < $< > $@
55
56$(BUILDDIR)/lang_enum.h: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang
57
58$(BUILDDIR)/lang/lang.h: $(ROOTDIR)/apps/lang/$(ENGLISH).lang $(BUILDDIR)/apps/features $(TOOLSDIR)/genlang
59 $(call PRINTS,GEN lang.h)
60 $(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done; \
61 perl -s $(TOOLSDIR)/genlang -p=$(BUILDDIR)/lang -t=$(MODELNAME)$$feat $<
62
63$(BUILDDIR)/lang/lang_core.c: $(BUILDDIR)/lang/lang.h $(TOOLSDIR)/genlang
64
65$(BUILDDIR)/lang/lang_core.o: $(BUILDDIR)/lang/lang.h $(BUILDDIR)/lang/lang_core.c
66 $(call PRINTS,CC lang_core.c)$(CC) $(CFLAGS) -c $(BUILDDIR)/lang/lang_core.c -o $@
67
68$(BUILDDIR)/lang/max_language_size.h: $(BUILDDIR)/lang/lang.h
69 $(call PRINTS,GEN $(subst $(BUILDDIR)/,,$@))
70 $(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
4307 uname=`uname` 4307 uname=`uname`
4308 simcc "checkwps" 4308 simcc "checkwps"
4309 toolset=''; 4309 toolset='';
4310 t_cpu='';
4311 GCCOPTS=''; 4310 GCCOPTS='';
4312 rbdir='.' 4311 rbdir='.'
4313 extradefines="$extradefines -DDEBUG" 4312 extradefines="$extradefines -DDEBUG"