From 839b52302dba5fb9e5802d85634dc8f53b0db30f Mon Sep 17 00:00:00 2001 From: bieber Date: Mon, 7 Jun 2010 23:49:06 +0000 Subject: [PATCH] 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 --- utils/themeeditor/skin_parser.c | 112 +++++++++++++++++++--------------------- utils/themeeditor/skin_scan.c | 59 ++++++++++++++++++++- utils/themeeditor/skin_scan.h | 2 + 3 files changed, 111 insertions(+), 62 deletions(-) diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index 58acafb56..8cf23bd11 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 19e959b5b..79f7162aa 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 6aea92c8a..b1d04a6e3 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 */ -- 2.11.4.GIT