summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-07 23:49:06 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-07 23:49:06 +0000
commit06ea93da8269ada1b19ce28791a05e57fbb453ac (patch)
tree248c075289f84a4a880080dac131be39e983ef1a
parentee1feb63f316dee184283fdf54039223e8b66073 (diff)
downloadrockbox-06ea93da8269ada1b19ce28791a05e57fbb453ac.tar.gz
rockbox-06ea93da8269ada1b19ce28791a05e57fbb453ac.tar.bz2
rockbox-06ea93da8269ada1b19ce28791a05e57fbb453ac.zip
Theme Editor: Factored out code to skip over enum/arg lists while scanning for children counts, and fixed all of the parsing bugs caused by innacurate children counts
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26679 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/themeeditor/skin_parser.c112
-rw-r--r--utils/themeeditor/skin_scan.c59
-rw-r--r--utils/themeeditor/skin_scan.h2
3 files changed, 111 insertions, 62 deletions
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c
index 58acafb56a..8cf23bd11a 100644
--- a/utils/themeeditor/skin_parser.c
+++ b/utils/themeeditor/skin_parser.c
@@ -157,6 +157,14 @@ struct skin_element* skin_parse_viewport(char** document)
{
skip_comment(&cursor);
}
+ else if(*cursor == ARGLISTOPENSYM)
+ {
+ skip_arglist(&cursor);
+ }
+ else if(*cursor == ENUMLISTOPENSYM)
+ {
+ skip_arglist(&cursor);
+ }
else
{
/* Advancing the cursor as normal */
@@ -297,7 +305,6 @@ struct skin_element* skin_parse_sublines_optional(char** document,
char* cursor = *document;
int sublines = 1;
int i;
- int nested = 0;
retval = skin_alloc_element();
retval->type = SUBLINES;
@@ -316,36 +323,31 @@ struct skin_element* skin_parse_sublines_optional(char** document,
if(*cursor == COMMENTSYM)
{
skip_comment(&cursor);
- continue;
}
-
- if(*cursor == ENUMLISTOPENSYM && conditional)
+ else if(*cursor == ENUMLISTOPENSYM)
{
- nested++;
- cursor++;
- while(nested)
- {
- if(*cursor == ENUMLISTOPENSYM)
- nested++;
- if(*cursor == ENUMLISTCLOSESYM)
- nested--;
- cursor++;
- }
+ skip_enumlist(&cursor);
}
- /* Accounting for escaped subline symbols */
- if(*cursor == TAGSYM)
+ else if(*cursor == ARGLISTOPENSYM)
+ {
+ skip_arglist(&cursor);
+ }
+ else if(*cursor == TAGSYM)
{
cursor++;
if(*cursor == '\0' || *cursor == '\n')
break;
+ cursor++;
}
-
- if(*cursor == MULTILINESYM)
+ else if(*cursor == MULTILINESYM)
{
sublines++;
+ cursor++;
+ }
+ else
+ {
+ cursor++;
}
-
- cursor++;
}
/* ...and then we parse them */
@@ -449,8 +451,8 @@ int skin_parse_tag(struct skin_element* element, char** document)
cursor++;
}
- for(bookmark = cursor; *cursor != '\n' && *cursor != '\0' &&
- *cursor != ARGLISTCLOSESYM; cursor++)
+ bookmark = cursor;
+ while(*cursor != '\n' && *cursor != '\0' && *cursor != ARGLISTCLOSESYM)
{
/* Skipping over escaped characters */
if(*cursor == TAGSYM)
@@ -458,21 +460,27 @@ int skin_parse_tag(struct skin_element* element, char** document)
cursor++;
if(*cursor == '\0')
break;
+ cursor++;
}
-
- /* Skipping comments */
- if(*cursor == COMMENTSYM)
+ else if(*cursor == COMMENTSYM)
+ {
skip_comment(&cursor);
-
- /* Commas inside of contained lists don't count */
- if(*cursor == ARGLISTOPENSYM)
- while(*cursor != ARGLISTCLOSESYM && *cursor != '\0')
- cursor++;
-
- if(*cursor == ARGLISTSEPERATESYM)
+ }
+ else if(*cursor == ARGLISTOPENSYM)
+ {
+ skip_arglist(&cursor);
+ }
+ else if(*cursor == ARGLISTSEPERATESYM)
+ {
num_args++;
-
+ cursor++;
+ }
+ else
+ {
+ cursor++;
+ }
}
+
cursor = bookmark; /* Restoring the cursor */
element->params_count = num_args;
element->params = skin_alloc_params(num_args);
@@ -656,7 +664,6 @@ int skin_parse_conditional(struct skin_element* element, char** document)
struct skin_element* tag = skin_alloc_element(); /* The tag to evaluate */
int children = 1;
int i;
- int nested = 0;
element->type = CONDITIONAL;
element->line = skin_line;
@@ -677,42 +684,27 @@ int skin_parse_conditional(struct skin_element* element, char** document)
if(*cursor == COMMENTSYM)
{
skip_comment(&cursor);
- continue;
}
-
- if(*cursor == ENUMLISTOPENSYM)
+ else if(*cursor == ENUMLISTOPENSYM)
{
- nested++;
- cursor++;
- while(nested)
- {
- if(*cursor == ENUMLISTOPENSYM)
- {
- nested++;
- }
- else if(*cursor == ENUMLISTCLOSESYM)
- {
- nested--;
- if(nested == 0)
- break;
- }
- cursor++;
- }
+ skip_enumlist(&cursor);
}
-
- if(*cursor == TAGSYM)
+ else if(*cursor == TAGSYM)
{
cursor++;
if(*cursor == '\0' || *cursor == '\n')
break;
cursor++;
- continue;
}
-
- if(*cursor == ENUMLISTSEPERATESYM)
+ else if(*cursor == ENUMLISTSEPERATESYM)
+ {
children++;
-
- cursor++;
+ cursor++;
+ }
+ else
+ {
+ cursor++;
+ }
}
cursor = bookmark;
diff --git a/utils/themeeditor/skin_scan.c b/utils/themeeditor/skin_scan.c
index 19e959b5b8..79f7162aab 100644
--- a/utils/themeeditor/skin_scan.c
+++ b/utils/themeeditor/skin_scan.c
@@ -34,14 +34,69 @@
/* Simple function to advance a char* past a comment */
void skip_comment(char** document)
{
- for(/*NO INIT*/;**document != '\n' && **document != '\0'; (*document)++);
+ while(**document != '\n' && **document != '\0')
+ (*document)++;
if(**document == '\n')
(*document)++;
}
void skip_whitespace(char** document)
{
- for(/*NO INIT*/; **document == ' ' || **document == '\t'; (*document)++);
+ while(**document == ' ' || **document == '\t')
+ (*document)++;
+}
+
+void skip_arglist(char** document)
+{
+ if(**document == ARGLISTOPENSYM)
+ (*document)++;
+ while(**document && **document != ARGLISTCLOSESYM)
+ {
+ if(**document == TAGSYM)
+ {
+ (*document)++;
+ if(**document == '\0')
+ break;
+ (*document)++;
+ }
+ else if(**document == ARGLISTOPENSYM)
+ skip_arglist(document);
+ else if(**document == ENUMLISTOPENSYM)
+ skip_enumlist(document);
+ else if(**document == COMMENTSYM)
+ skip_comment(document);
+ else
+ (*document)++;
+ }
+ if(**document == ARGLISTCLOSESYM)
+ (*document)++;
+}
+
+void skip_enumlist(char** document)
+{
+ if(**document == ENUMLISTOPENSYM)
+ (*document)++;
+ while(**document && **document != ENUMLISTCLOSESYM)
+ {
+ if(**document == TAGSYM)
+ {
+ (*document)++;
+ if(**document == '\0')
+ break;
+ (*document)++;
+ }
+ else if(**document == ARGLISTOPENSYM)
+ skip_arglist(document);
+ else if(**document == ENUMLISTOPENSYM)
+ skip_enumlist(document);
+ else if(**document == COMMENTSYM)
+ skip_comment(document);
+ else
+ (*document)++;
+ }
+
+ if(**document == ENUMLISTCLOSESYM)
+ (*document)++;
}
char* scan_string(char** document)
diff --git a/utils/themeeditor/skin_scan.h b/utils/themeeditor/skin_scan.h
index 6aea92c8a9..b1d04a6e34 100644
--- a/utils/themeeditor/skin_scan.h
+++ b/utils/themeeditor/skin_scan.h
@@ -31,6 +31,8 @@ extern "C"
/* Scanning functions */
void skip_comment(char** document);
void skip_whitespace(char** document);
+void skip_arglist(char** document);
+void skip_enumlist(char** document);
char* scan_string(char** document);
int scan_int(char** document);
int check_viewport(char* document); /* Checks for a viewport declaration */