On Thu, Sep 24, 2009 at 07:21:21PM -0700, Jonathan Gordon wrote:
> I need a Makefile guru to fix checkwps because it now relies on
> english.lang being parsed and the 4 autogenerated lang files being
> available.

I've had a quick look at it, and with the attached patch (your changes
plus mine) checkwps gets a bit further. There's a cost however, normal
builds don't work anymore. You'll have to work out for yourself if
that's serious enough to wait with commiting.

Frank

-- 
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
Index: tools/checkwps/checkwps.make
===================================================================
--- tools/checkwps/checkwps.make	(revision 22826)
+++ tools/checkwps/checkwps.make	(working copy)
@@ -7,6 +7,9 @@
 # $Id$
 #
 
+include $(ROOTDIR)/apps/lang/lang.make
+include $(ROOTDIR)/apps/apps.make
+
 FLAGS=-g -D__PCTOOL__ -DDEBUG -DROCKBOX_DIR_LEN=9 -DWPS_DIR=\".\" $(TARGET)
 
 SRC= $(call preprocess, $(TOOLSDIR)/checkwps/SOURCES)
@@ -16,7 +19,8 @@
            -I$(ROOTDIR)/firmware/export \
            -I$(ROOTDIR)/apps \
            -I$(ROOTDIR)/apps/recorder \
-           -I$(APPSDIR)
+           -I$(APPSDIR) \
+           -Ilang
 
 # Makes mkdepfile happy
 GCCOPTS+=-D__PCTOOL__
Index: tools/checkwps/SOURCES
===================================================================
--- tools/checkwps/SOURCES	(revision 22826)
+++ tools/checkwps/SOURCES	(working copy)
@@ -2,6 +2,7 @@
 ../../apps/gui/skin_engine/skin_parser.c
 ../../apps/gui/skin_engine/skin_buffer.c
 ../../apps/misc.c
+../../apps/language.c
 ../../firmware/common/strlcpy.c
 checkwps.c
 
Index: apps/language.c
===================================================================
--- apps/language.c	(revision 22826)
+++ apps/language.c	(working copy)
@@ -98,3 +98,16 @@
     close(fd);
     return retcode;
 }
+
+int lang_english_to_id(const char* english)
+{
+    int i;
+    unsigned char *ptr = (unsigned char *) language_builtin;
+    
+    for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) {
+        if (!strcmp(ptr, english))
+            return i;
+        ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */
+    }
+    return -1;
+}
Index: apps/language.h
===================================================================
--- apps/language.h	(revision 22826)
+++ apps/language.h	(working copy)
@@ -27,4 +27,7 @@
 /* load a given language file */
 int lang_load(const char *filename);
 
+/* get the ID of an english string so it can be localised */
+int lang_english_to_id(const char* english);
+
 #endif
Index: apps/lang/lang.make
===================================================================
--- apps/lang/lang.make	(revision 22826)
+++ apps/lang/lang.make	(working copy)
@@ -7,7 +7,7 @@
 # $Id$
 #
 
-LANGS := $(call preprocess, $(APPSDIR)/lang/SOURCES)
+LANGS := $(call preprocess, $(ROOTDIR)/apps/lang/SOURCES)
 LANGOBJ := $(LANGS:$(ROOTDIR)/%.lang=$(BUILDDIR)/%.lng)
 LANG_O = $(BUILDDIR)/lang/lang_core.o
 
@@ -22,7 +22,7 @@
 	$(call PRINTS,Create $(notdir $@))
 	$(SILENT)echo "#define MAX_LANGUAGE_SIZE `ls -ln $(BUILDDIR)/apps/lang/* | awk '{print $$5}' | sort -n | tail -1`" > $@
 
-$(BUILDDIR)/lang/lang_core.o: $(APPSDIR)/lang/$(LANGUAGE).lang $(BUILDDIR)/apps/features
+$(BUILDDIR)/lang/lang_core.o: $(ROOTDIR)/apps/lang/$(LANGUAGE).lang $(BUILDDIR)/apps/features
 	$(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done; \
 		perl -s $(TOOLSDIR)/genlang -p=$(BUILDDIR)/lang -t=$(MODELNAME)$$feat $<
 	$(call PRINTS,CC lang_core.c)$(CC) $(CFLAGS) -c $(BUILDDIR)/lang/lang_core.c -o $@
@@ -30,4 +30,4 @@
 $(BUILDDIR)/%.lng : $(ROOTDIR)/%.lang $(BUILDDIR)/apps/genlang-features
 	$(call PRINTS,GENLANG $(subst $(ROOTDIR)/,,$<))
 	$(SILENT)mkdir -p $(dir $@)
-	$(SILENT)$(TOOLSDIR)/genlang -e=$(APPSDIR)/lang/english.lang -t=$(MODELNAME)`cat $(BUILDDIR)/apps/genlang-features` -i=$(TARGET_ID) -b=$@ $<
+	$(SILENT)$(TOOLSDIR)/genlang -e=$(ROOTDIR)/apps/lang/english.lang -t=$(MODELNAME)`cat $(BUILDDIR)/apps/genlang-features` -i=$(TARGET_ID) -b=$@ $<
Index: apps/gui/skin_engine/wps_debug.c
===================================================================
--- apps/gui/skin_engine/wps_debug.c	(revision 22826)
+++ apps/gui/skin_engine/wps_debug.c	(working copy)
@@ -76,6 +76,9 @@
             snprintf(buf, bufsize, "String '%s'",
                      (char*)token->value.data);
             break;
+        case WPS_TOKEN_TRANSLATEDSTRING:
+            snprintf(buf, bufsize, "String ID '%d'", token->value.i);
+            break;
 
 #ifdef HAVE_LCD_BITMAP
         case WPS_TOKEN_ALIGN_LEFT:
Index: apps/gui/skin_engine/skin_parser.c
===================================================================
--- apps/gui/skin_engine/skin_parser.c	(revision 22826)
+++ apps/gui/skin_engine/skin_parser.c	(working copy)
@@ -27,6 +27,7 @@
 #include "misc.h"
 #include "plugin.h"
 #include "viewport.h"
+#include "language.h"
 
 #ifdef __PCTOOL__
 #ifdef WPSEDITOR
@@ -132,7 +133,7 @@
         struct wps_token *token, struct wps_data *wps_data);
 static int parse_dir_level(const char *wps_bufptr,
         struct wps_token *token, struct wps_data *wps_data);
-static int parse_setting(const char *wps_bufptr,
+static int parse_setting_and_lang(const char *wps_bufptr,
         struct wps_token *token, struct wps_data *wps_data);
 
 #ifdef HAVE_LCD_BITMAP
@@ -349,8 +350,11 @@
 #endif
 #endif
 
-    { WPS_TOKEN_SETTING,                  "St",  WPS_REFRESH_DYNAMIC, parse_setting },
-
+    { WPS_TOKEN_SETTING,                  "St",  WPS_REFRESH_DYNAMIC,
+                                                    parse_setting_and_lang },    
+    { WPS_TOKEN_TRANSLATEDSTRING,         "Sx",  WPS_REFRESH_STATIC,
+                                                    parse_setting_and_lang },
+                                                    
     { WPS_TOKEN_LASTTOUCH,                "Tl",  WPS_REFRESH_DYNAMIC, parse_timeout },
     { WPS_NO_TOKEN,                       "T",   0,    parse_touchregion      },
 
@@ -746,14 +750,15 @@
 
 #endif /* HAVE_LCD_BITMAP */
 
-static int parse_setting(const char *wps_bufptr,
-                         struct wps_token *token,
-                         struct wps_data *wps_data)
+static int parse_setting_and_lang(const char *wps_bufptr,
+                                 struct wps_token *token,
+                                 struct wps_data *wps_data)
 {
     (void)wps_data;
     const char *ptr = wps_bufptr;
     const char *end;
     int i;
+    char temp[64];
 
     /* Find the setting's cfg_name */
     if (*ptr != '|')
@@ -762,17 +767,26 @@
     end = strchr(ptr,'|');
     if (!end)
         return WPS_ERROR_INVALID_PARAM;
-
-    /* Find the setting */
-    for (i=0; i<nb_settings; i++)
-        if (settings[i].cfg_name &&
-            !strncmp(settings[i].cfg_name,ptr,end-ptr) &&
-            /* prevent matches on cfg_name prefixes */
-            strlen(settings[i].cfg_name)==(size_t)(end-ptr))
-            break;
-    if (i == nb_settings)
-        return WPS_ERROR_INVALID_PARAM;
-
+    strlcpy(temp, ptr,end-ptr+1);
+    
+    if (token->type == WPS_TOKEN_TRANSLATEDSTRING)
+    {
+        i = lang_english_to_id(temp);
+        if (i < 0)
+            return WPS_ERROR_INVALID_PARAM;
+    }
+    else
+    {
+        /* Find the setting */
+        for (i=0; i<nb_settings; i++)
+            if (settings[i].cfg_name &&
+                !strncmp(settings[i].cfg_name,ptr,end-ptr) &&
+                /* prevent matches on cfg_name prefixes */
+                strlen(settings[i].cfg_name)==(size_t)(end-ptr))
+                break;
+        if (i == nb_settings)
+            return WPS_ERROR_INVALID_PARAM;
+    }
     /* Store the setting number */
     token->value.i = i;
 
Index: apps/gui/skin_engine/skin_tokens.c
===================================================================
--- apps/gui/skin_engine/skin_tokens.c	(revision 22826)
+++ apps/gui/skin_engine/skin_tokens.c	(working copy)
@@ -170,6 +170,9 @@
 
         case WPS_TOKEN_STRING:
             return (char*)token->value.data;
+            
+        case WPS_TOKEN_TRANSLATEDSTRING:
+            return (char*)P2STR(ID2P(token->value.i));
 
         case WPS_TOKEN_TRACK_TIME_ELAPSED:
             format_time(buf, buf_size,
Index: apps/gui/skin_engine/skin_tokens.h
===================================================================
--- apps/gui/skin_engine/skin_tokens.h	(revision 22826)
+++ apps/gui/skin_engine/skin_tokens.h	(working copy)
@@ -32,6 +32,7 @@
     /* Markers */
     WPS_TOKEN_CHARACTER,
     WPS_TOKEN_STRING,
+    WPS_TOKEN_TRANSLATEDSTRING,
 
     /* Alignment */
     WPS_TOKEN_ALIGN_LEFT,
Index: apps/apps.make
===================================================================
--- apps/apps.make	(revision 22826)
+++ apps/apps.make	(working copy)
@@ -7,8 +7,8 @@
 # $Id$
 #
 
-INCLUDES += -I$(APPSDIR) $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
-SRC += $(call preprocess, $(APPSDIR)/SOURCES)
+INCLUDES += -I$(ROOTDIR)/apps $(patsubst %,-I$(ROOTDIR)/apps/%,$(subst :, ,$(APPEXTRA)))
+SRC += $(call preprocess, $(ROOTDIR)/apps/SOURCES)
 
 # apps/features.txt is a file that (is preprocessed and) lists named features
 # based on defines in the config-*.h files. The named features will be passed
@@ -17,7 +17,7 @@
 #
 # Kludge: depends on errno.o only to depend on config-*.h ...
 #
-features $(BUILDDIR)/apps/features $(BUILDDIR)/apps/genlang-features: $(APPSDIR)/features.txt $(BUILDDIR)/firmware/common/errno.o
+features $(BUILDDIR)/apps/features $(BUILDDIR)/apps/genlang-features: $(ROOTDIR)/apps/features.txt $(BUILDDIR)/firmware/common/errno.o
 	$(SILENT)mkdir -p $(BUILDDIR)/apps
 	$(SILENT)mkdir -p $(BUILDDIR)/lang
 	$(call PRINTS,PP $(<F))
@@ -27,4 +27,4 @@
 		for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
 		echo "$$feat" >$(BUILDDIR)/apps/genlang-features
 
-ASMDEFS_SRC += $(APPSDIR)/core_asmdefs.c
+ASMDEFS_SRC += $(ROOTDIR)/apps/core_asmdefs.c

Reply via email to