From 91008d88af66bc32049856fbcb5e196cafeac025 Mon Sep 17 00:00:00 2001 From: jdgordon Date: Tue, 3 Aug 2010 12:14:50 +0000 Subject: [PATCH] make -vvv display the parse tree in checkwps. Fix a potential bug in the parser where recursive tags (the playlist viewier) would share params with its parant which meant bad things git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27677 a1c6a512-1295-4272-9138-f99709370657 --- lib/skin_parser/skin_debug.c | 5 +++-- lib/skin_parser/skin_parser.c | 12 +++++++++--- lib/skin_parser/skin_parser.h | 3 ++- tools/checkwps/checkwps.c | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/skin_parser/skin_debug.c b/lib/skin_parser/skin_debug.c index 803a673f2..3a5a5a744 100644 --- a/lib/skin_parser/skin_debug.c +++ b/lib/skin_parser/skin_debug.c @@ -120,7 +120,7 @@ void skin_clear_errors() error_message = NULL; } -#ifndef ROCKBOX +#if !defined(ROCKBOX) || defined(__PCTOOL__) void skin_debug_tree(struct skin_element* root) { int i; @@ -227,7 +227,8 @@ void skin_debug_tree(struct skin_element* root) printf("[ Logical line on line %d\n", current->line); debug_indent_level++; - skin_debug_tree(current->children[0]); + if (current->children) + skin_debug_tree(current->children[0]); debug_indent_level--; skin_debug_indent(); diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c index 355462960..f92a52774 100644 --- a/lib/skin_parser/skin_parser.c +++ b/lib/skin_parser/skin_parser.c @@ -38,6 +38,8 @@ int skin_line = 0; char* skin_start = 0; int viewport_line = 0; +static int tag_recursion_level = 0; + #ifdef ROCKBOX static skin_callback callback = NULL; static void* callback_data; @@ -121,6 +123,8 @@ static struct skin_element* skin_parse_viewport(const char** document) struct skin_element* root = NULL; struct skin_element* last = NULL; struct skin_element* retval = NULL; + + tag_recursion_level = 0; retval = skin_alloc_element(); if (!retval) @@ -467,6 +471,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) int req_args; /* To mark when we enter optional arguments */ int optional = 0; + tag_recursion_level++; /* Checking the tag name */ tag_name[0] = cursor[0]; @@ -567,7 +572,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) cursor = bookmark; /* Restoring the cursor */ element->params_count = num_args; - element->params = skin_alloc_params(num_args); + element->params = skin_alloc_params(num_args, tag_recursion_level<=1); if (!element->params) return 0; @@ -712,6 +717,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) } #endif *document = cursor; + tag_recursion_level--; return 1; } @@ -1014,11 +1020,11 @@ struct skin_element* skin_alloc_element() * enough for any tag. params should be used straight away by the callback * so this is safe. */ -struct skin_tag_parameter* skin_alloc_params(int count) +struct skin_tag_parameter* skin_alloc_params(int count, bool use_shared_params) { #ifdef ROCKBOX static struct skin_tag_parameter params[MAX_TAG_PARAMS]; - if (count <= MAX_TAG_PARAMS) + if (use_shared_params && count <= MAX_TAG_PARAMS) { memset(params, 0, sizeof(params)); return params; diff --git a/lib/skin_parser/skin_parser.h b/lib/skin_parser/skin_parser.h index 6ccf31a0e..7cef0107a 100644 --- a/lib/skin_parser/skin_parser.h +++ b/lib/skin_parser/skin_parser.h @@ -27,6 +27,7 @@ extern "C" { #endif #include +#include /******************************************************************** ****** Data Structures ********************************************* @@ -139,7 +140,7 @@ struct skin_element* skin_parse(const char* document); /* Memory management functions */ struct skin_element* skin_alloc_element(void); struct skin_element** skin_alloc_children(int count); -struct skin_tag_parameter* skin_alloc_params(int count); +struct skin_tag_parameter* skin_alloc_params(int count, bool use_shared_params); char* skin_alloc_string(int length); void skin_free_tree(struct skin_element* root); diff --git a/tools/checkwps/checkwps.c b/tools/checkwps/checkwps.c index e00fb724b..7b1aa2476 100644 --- a/tools/checkwps/checkwps.c +++ b/tools/checkwps/checkwps.c @@ -300,6 +300,8 @@ int main(int argc, char **argv) } printf("WPS parsed OK\n\n"); + if (wps_verbose_level>2) + skin_debug_tree(wps.tree); filearg++; } return 0; -- 2.11.4.GIT