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
This commit is contained in:
Robert Bieber 2010-06-07 23:49:06 +00:00
parent ee1feb63f3
commit 06ea93da82
3 changed files with 111 additions and 62 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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 */