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
diff --git a/lib/skin_parser/skin_debug.c b/lib/skin_parser/skin_debug.c
index 803a673..3a5a5a7 100644
--- a/lib/skin_parser/skin_debug.c
+++ b/lib/skin_parser/skin_debug.c
@@ -120,7 +120,7 @@
     error_message = NULL;
 }
 
-#ifndef ROCKBOX
+#if !defined(ROCKBOX) || defined(__PCTOOL__)
 void skin_debug_tree(struct skin_element* root)
 {
     int i;
@@ -227,7 +227,8 @@
             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 3554629..f92a527 100644
--- a/lib/skin_parser/skin_parser.c
+++ b/lib/skin_parser/skin_parser.c
@@ -38,6 +38,8 @@
 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 @@
     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 @@
     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 @@
 
     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 @@
     }
 #endif
     *document = cursor;
+    tag_recursion_level--;
 
     return 1;
 }
@@ -1014,11 +1020,11 @@
  * 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 6ccf31a..7cef010 100644
--- a/lib/skin_parser/skin_parser.h
+++ b/lib/skin_parser/skin_parser.h
@@ -27,6 +27,7 @@
 {
 #endif
 #include <stdlib.h>
+#include <stdbool.h>
 
 /********************************************************************
  ****** Data Structures *********************************************
@@ -139,7 +140,7 @@
 /* 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 e00fb72..7b1aa24 100644
--- a/tools/checkwps/checkwps.c
+++ b/tools/checkwps/checkwps.c
@@ -300,6 +300,8 @@
         }
 
         printf("WPS parsed OK\n\n");
+        if (wps_verbose_level>2)
+            skin_debug_tree(wps.tree);
         filearg++;
     }
     return 0;