Theme Editor: Made Viewport the top level parse tree element, along with a bugfix to the tag parsing function

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26442 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-01 07:11:23 +00:00
parent acb524e51a
commit d1659d69df
7 changed files with 114 additions and 13 deletions

View file

@ -35,7 +35,11 @@ int main(int argc, char* argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)<param2|param3>"; char doc[] = "#Comment\n"
"%Vd(U);Hey\n"
"%?bl(test,3,5,2,1)<param2|param3>\n"
"%V(1,2,3,4,5)%pS(5)\n"
"Some more stuff here";
ParseTreeModel tree(doc); ParseTreeModel tree(doc);

View file

@ -64,6 +64,7 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent)
} }
break; break;
case VIEWPORT:
case LINE: case LINE:
for(struct skin_element* current = data->children[0]; current; for(struct skin_element* current = data->children[0]; current;
current = current->next) current = current->next)
@ -92,6 +93,10 @@ QString ParseTreeNode::genCode() const
{ {
switch(element->type) switch(element->type)
{ {
case VIEWPORT:
buffer.append(children[0]->genCode());
case LINE: case LINE:
for(int i = 0; i < children.count(); i++) for(int i = 0; i < children.count(); i++)
{ {
@ -220,6 +225,9 @@ QVariant ParseTreeNode::data(int column) const
{ {
switch(element->type) switch(element->type)
{ {
case VIEWPORT:
return QObject::tr("Viewport");
case LINE: case LINE:
return QObject::tr("Logical Line"); return QObject::tr("Logical Line");
@ -272,6 +280,7 @@ QVariant ParseTreeNode::data(int column) const
{ {
switch(element->type) switch(element->type)
{ {
case VIEWPORT:
case LINE: case LINE:
case SUBLINES: case SUBLINES:
case CONDITIONAL: case CONDITIONAL:

View file

@ -91,6 +91,16 @@ void skin_debug_tree(struct skin_element* root)
switch(current->type) switch(current->type)
{ {
case VIEWPORT:
printf("[ Viewport \n");
debug_indent_level++;
skin_debug_tree(current->children[0]);
debug_indent_level--;
printf("]");
break;
case TEXT: case TEXT:
printf("[ Plain text on line %d : %s ]\n", current->line, printf("[ Plain text on line %d : %s ]\n", current->line,
current->text); current->text);

View file

@ -38,6 +38,7 @@ int skin_current_block = 0;
int skin_line = 0; int skin_line = 0;
/* Auxiliary parsing functions (not visible at global scope) */ /* Auxiliary parsing functions (not visible at global scope) */
struct skin_element* skin_parse_viewport(char** document);
struct skin_element* skin_parse_line(char** document); struct skin_element* skin_parse_line(char** document);
struct skin_element* skin_parse_line_optional(char** document, int conditional); struct skin_element* skin_parse_line_optional(char** document, int conditional);
struct skin_element* skin_parse_sublines(char** document); struct skin_element* skin_parse_sublines(char** document);
@ -54,26 +55,68 @@ struct skin_element* skin_parse_code_as_arg(char** document);
struct skin_element* skin_parse(char* document) struct skin_element* skin_parse(char* document)
{ {
struct skin_element* root = NULL; struct skin_element* root = NULL;
struct skin_element* last = NULL; struct skin_element* last = NULL;
struct skin_element** to_write = 0; struct skin_element** to_write = 0;
char* cursor = document; /* Keeps track of location in the document */
char* bookmark; /* Used when we need to look ahead */
int sublines = 0; /* Flag for parsing sublines */ char* cursor = document; /* Keeps track of location in the document */
skin_line = 1; skin_line = 1;
while(*cursor != '\0') while(*cursor != '\0')
{
if(!root)
to_write = &root;
else
to_write = &(last->next);
*to_write = skin_parse_viewport(&cursor);
last = *to_write;
if(!last)
return NULL;
/* Making sure last is at the end */
while(last->next)
last = last->next;
}
return root;
}
struct skin_element* skin_parse_viewport(char** document)
{
struct skin_element* root = NULL;
struct skin_element* last = NULL;
struct skin_element* retval = NULL;
retval = skin_alloc_element();
retval->type = VIEWPORT;
retval->children = skin_alloc_children(1);
retval->children_count = 1;
retval->line = skin_line;
struct skin_element** to_write = 0;
char* cursor = *document; /* Keeps track of location in the document */
char* bookmark; /* Used when we need to look ahead */
int sublines = 0; /* Flag for parsing sublines */
while(*cursor != '\0' && !(check_viewport(cursor) && cursor != *document))
{ {
/* First, we check to see if this line will contain sublines */ /* First, we check to see if this line will contain sublines */
bookmark = cursor; bookmark = cursor;
sublines = 0; sublines = 0;
while(*cursor != '\n' && *cursor != '\0') while(*cursor != '\n' && *cursor != '\0'
&& !(check_viewport(cursor) && cursor != *document))
{ {
if(*cursor == MULTILINESYM) if(*cursor == MULTILINESYM)
{ {
@ -135,10 +178,13 @@ struct skin_element* skin_parse(char* document)
while(last->next) while(last->next)
last = last->next; last = last->next;
} }
*document = cursor;
retval->children[0] = root;
return retval;
return root;
} }
/* Auxiliary Parsing Functions */ /* Auxiliary Parsing Functions */
@ -176,7 +222,8 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
|| *cursor == ARGLISTCLOSESYM || *cursor == ARGLISTCLOSESYM
|| *cursor == ENUMLISTSEPERATESYM || *cursor == ENUMLISTSEPERATESYM
|| *cursor == ENUMLISTCLOSESYM) || *cursor == ENUMLISTCLOSESYM)
&& conditional)) && conditional)
&& !(check_viewport(cursor) && cursor != *document))
{ {
/* Allocating memory if necessary */ /* Allocating memory if necessary */
if(root) if(root)
@ -244,7 +291,8 @@ struct skin_element* skin_parse_sublines_optional(char** document,
|| *cursor == ARGLISTCLOSESYM || *cursor == ARGLISTCLOSESYM
|| *cursor == ENUMLISTSEPERATESYM || *cursor == ENUMLISTSEPERATESYM
|| *cursor == ENUMLISTCLOSESYM) || *cursor == ENUMLISTCLOSESYM)
&& conditional)) && conditional)
&& !(check_viewport(cursor) && cursor != *document))
{ {
if(*cursor == COMMENTSYM) if(*cursor == COMMENTSYM)
skip_comment(&cursor); skip_comment(&cursor);
@ -405,7 +453,7 @@ int skin_parse_tag(struct skin_element* element, char** document)
if(*tag_args == '|') if(*tag_args == '|')
{ {
optional = 1; optional = 1;
req_args = i - 1; req_args = i;
tag_args++; tag_args++;
} }
@ -478,6 +526,14 @@ int skin_parse_tag(struct skin_element* element, char** document)
tag_args++; tag_args++;
/* Checking for the optional bar */
if(*tag_args == '|')
{
optional = 1;
req_args = i + 1;
tag_args++;
}
} }
/* Checking for a premature end */ /* Checking for a premature end */

View file

@ -42,6 +42,7 @@ extern char skin_parse_tree[];
/* Possible types of element in a WPS file */ /* Possible types of element in a WPS file */
enum skin_element_type enum skin_element_type
{ {
VIEWPORT,
LINE, LINE,
SUBLINES, SUBLINES,
CONDITIONAL, CONDITIONAL,

View file

@ -22,6 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "skin_scan.h" #include "skin_scan.h"
#include "skin_debug.h" #include "skin_debug.h"
@ -136,3 +137,22 @@ int scan_int(char** document)
*document = cursor; *document = cursor;
return retval; return retval;
} }
int check_viewport(char* document)
{
if(strlen(document) < 3)
return 0;
if(document[0] != TAGSYM)
return 0;
if(document[1] != 'V')
return 0;
if(document[2] != ARGLISTOPENSYM
&& document[2] != 'l'
&& document[2] != 'i')
return 0;
return 1;
}

View file

@ -33,6 +33,7 @@ void skip_comment(char** document);
void skip_whitespace(char** document); void skip_whitespace(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 */
#ifdef __cplusplus #ifdef __cplusplus
} }