1
0
Fork 0
forked from len0rd/rockbox

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); skip_comment(&cursor);
} }
else if(*cursor == ARGLISTOPENSYM)
{
skip_arglist(&cursor);
}
else if(*cursor == ENUMLISTOPENSYM)
{
skip_arglist(&cursor);
}
else else
{ {
/* Advancing the cursor as normal */ /* Advancing the cursor as normal */
@ -297,7 +305,6 @@ struct skin_element* skin_parse_sublines_optional(char** document,
char* cursor = *document; char* cursor = *document;
int sublines = 1; int sublines = 1;
int i; int i;
int nested = 0;
retval = skin_alloc_element(); retval = skin_alloc_element();
retval->type = SUBLINES; retval->type = SUBLINES;
@ -316,36 +323,31 @@ struct skin_element* skin_parse_sublines_optional(char** document,
if(*cursor == COMMENTSYM) if(*cursor == COMMENTSYM)
{ {
skip_comment(&cursor); skip_comment(&cursor);
continue;
} }
else if(*cursor == ENUMLISTOPENSYM)
if(*cursor == ENUMLISTOPENSYM && conditional)
{ {
nested++; skip_enumlist(&cursor);
cursor++;
while(nested)
{
if(*cursor == ENUMLISTOPENSYM)
nested++;
if(*cursor == ENUMLISTCLOSESYM)
nested--;
cursor++;
}
} }
/* Accounting for escaped subline symbols */ else if(*cursor == ARGLISTOPENSYM)
if(*cursor == TAGSYM) {
skip_arglist(&cursor);
}
else if(*cursor == TAGSYM)
{ {
cursor++; cursor++;
if(*cursor == '\0' || *cursor == '\n') if(*cursor == '\0' || *cursor == '\n')
break; break;
cursor++;
} }
else if(*cursor == MULTILINESYM)
if(*cursor == MULTILINESYM)
{ {
sublines++; sublines++;
cursor++;
}
else
{
cursor++;
} }
cursor++;
} }
/* ...and then we parse them */ /* ...and then we parse them */
@ -449,8 +451,8 @@ int skin_parse_tag(struct skin_element* element, char** document)
cursor++; cursor++;
} }
for(bookmark = cursor; *cursor != '\n' && *cursor != '\0' && bookmark = cursor;
*cursor != ARGLISTCLOSESYM; cursor++) while(*cursor != '\n' && *cursor != '\0' && *cursor != ARGLISTCLOSESYM)
{ {
/* Skipping over escaped characters */ /* Skipping over escaped characters */
if(*cursor == TAGSYM) if(*cursor == TAGSYM)
@ -458,21 +460,27 @@ int skin_parse_tag(struct skin_element* element, char** document)
cursor++; cursor++;
if(*cursor == '\0') if(*cursor == '\0')
break; break;
cursor++;
} }
else if(*cursor == COMMENTSYM)
/* Skipping comments */ {
if(*cursor == COMMENTSYM)
skip_comment(&cursor); skip_comment(&cursor);
}
/* Commas inside of contained lists don't count */ else if(*cursor == ARGLISTOPENSYM)
if(*cursor == ARGLISTOPENSYM) {
while(*cursor != ARGLISTCLOSESYM && *cursor != '\0') skip_arglist(&cursor);
cursor++; }
else if(*cursor == ARGLISTSEPERATESYM)
if(*cursor == ARGLISTSEPERATESYM) {
num_args++; num_args++;
cursor++;
}
else
{
cursor++;
}
} }
cursor = bookmark; /* Restoring the cursor */ cursor = bookmark; /* Restoring the cursor */
element->params_count = num_args; element->params_count = num_args;
element->params = skin_alloc_params(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 */ struct skin_element* tag = skin_alloc_element(); /* The tag to evaluate */
int children = 1; int children = 1;
int i; int i;
int nested = 0;
element->type = CONDITIONAL; element->type = CONDITIONAL;
element->line = skin_line; element->line = skin_line;
@ -677,42 +684,27 @@ int skin_parse_conditional(struct skin_element* element, char** document)
if(*cursor == COMMENTSYM) if(*cursor == COMMENTSYM)
{ {
skip_comment(&cursor); skip_comment(&cursor);
continue;
} }
else if(*cursor == ENUMLISTOPENSYM)
if(*cursor == ENUMLISTOPENSYM)
{ {
nested++; skip_enumlist(&cursor);
cursor++;
while(nested)
{
if(*cursor == ENUMLISTOPENSYM)
{
nested++;
}
else if(*cursor == ENUMLISTCLOSESYM)
{
nested--;
if(nested == 0)
break;
}
cursor++;
}
} }
else if(*cursor == TAGSYM)
if(*cursor == TAGSYM)
{ {
cursor++; cursor++;
if(*cursor == '\0' || *cursor == '\n') if(*cursor == '\0' || *cursor == '\n')
break; break;
cursor++; cursor++;
continue;
} }
else if(*cursor == ENUMLISTSEPERATESYM)
if(*cursor == ENUMLISTSEPERATESYM) {
children++; children++;
cursor++;
cursor++; }
else
{
cursor++;
}
} }
cursor = bookmark; cursor = bookmark;

View file

@ -34,14 +34,69 @@
/* Simple function to advance a char* past a comment */ /* Simple function to advance a char* past a comment */
void skip_comment(char** document) void skip_comment(char** document)
{ {
for(/*NO INIT*/;**document != '\n' && **document != '\0'; (*document)++); while(**document != '\n' && **document != '\0')
(*document)++;
if(**document == '\n') if(**document == '\n')
(*document)++; (*document)++;
} }
void skip_whitespace(char** 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) char* scan_string(char** document)

View file

@ -31,6 +31,8 @@ extern "C"
/* Scanning functions */ /* Scanning functions */
void skip_comment(char** document); void skip_comment(char** document);
void skip_whitespace(char** document); void skip_whitespace(char** document);
void skip_arglist(char** document);
void skip_enumlist(char** document);
char* scan_string(char** document); char* scan_string(char** document);
int scan_int(char** document); int scan_int(char** document);
int check_viewport(char* document); /* Checks for a viewport declaration */ int check_viewport(char* document); /* Checks for a viewport declaration */