From d1659d69df55501f2cda82ccddde00b4018681c1 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Tue, 1 Jun 2010 07:11:23 +0000 Subject: 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 --- utils/themeeditor/main.cpp | 6 ++- utils/themeeditor/parsetreenode.cpp | 9 +++++ utils/themeeditor/skin_debug.c | 10 +++++ utils/themeeditor/skin_parser.c | 80 +++++++++++++++++++++++++++++++------ utils/themeeditor/skin_parser.h | 1 + utils/themeeditor/skin_scan.c | 20 ++++++++++ utils/themeeditor/skin_scan.h | 1 + 7 files changed, 114 insertions(+), 13 deletions(-) (limited to 'utils/themeeditor') diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp index a3a5daaa6c..87d38b861d 100644 --- a/utils/themeeditor/main.cpp +++ b/utils/themeeditor/main.cpp @@ -35,7 +35,11 @@ int main(int argc, char* argv[]) { QApplication app(argc, argv); - char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)"; + char doc[] = "#Comment\n" + "%Vd(U);Hey\n" + "%?bl(test,3,5,2,1)\n" + "%V(1,2,3,4,5)%pS(5)\n" + "Some more stuff here"; ParseTreeModel tree(doc); diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp index caafff5f43..7b77b62ecc 100644 --- a/utils/themeeditor/parsetreenode.cpp +++ b/utils/themeeditor/parsetreenode.cpp @@ -64,6 +64,7 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent) } break; + case VIEWPORT: case LINE: for(struct skin_element* current = data->children[0]; current; current = current->next) @@ -92,6 +93,10 @@ QString ParseTreeNode::genCode() const { switch(element->type) { + + case VIEWPORT: + buffer.append(children[0]->genCode()); + case LINE: for(int i = 0; i < children.count(); i++) { @@ -220,6 +225,9 @@ QVariant ParseTreeNode::data(int column) const { switch(element->type) { + case VIEWPORT: + return QObject::tr("Viewport"); + case LINE: return QObject::tr("Logical Line"); @@ -272,6 +280,7 @@ QVariant ParseTreeNode::data(int column) const { switch(element->type) { + case VIEWPORT: case LINE: case SUBLINES: case CONDITIONAL: diff --git a/utils/themeeditor/skin_debug.c b/utils/themeeditor/skin_debug.c index 5d37f64a11..06764f9053 100644 --- a/utils/themeeditor/skin_debug.c +++ b/utils/themeeditor/skin_debug.c @@ -91,6 +91,16 @@ void skin_debug_tree(struct skin_element* root) switch(current->type) { + case VIEWPORT: + printf("[ Viewport \n"); + + debug_indent_level++; + skin_debug_tree(current->children[0]); + debug_indent_level--; + + printf("]"); + break; + case TEXT: printf("[ Plain text on line %d : %s ]\n", current->line, current->text); diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index 655c3d18a5..74ba7bd71d 100644 --- a/utils/themeeditor/skin_parser.c +++ b/utils/themeeditor/skin_parser.c @@ -38,6 +38,7 @@ int skin_current_block = 0; int skin_line = 0; /* 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_optional(char** document, int conditional); 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* root = NULL; struct skin_element* last = NULL; 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; 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 */ bookmark = cursor; sublines = 0; - while(*cursor != '\n' && *cursor != '\0') + while(*cursor != '\n' && *cursor != '\0' + && !(check_viewport(cursor) && cursor != *document)) { if(*cursor == MULTILINESYM) { @@ -135,10 +178,13 @@ struct skin_element* skin_parse(char* document) while(last->next) last = last->next; - } + } + + *document = cursor; + + retval->children[0] = root; + return retval; - return root; - } /* Auxiliary Parsing Functions */ @@ -176,7 +222,8 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional) || *cursor == ARGLISTCLOSESYM || *cursor == ENUMLISTSEPERATESYM || *cursor == ENUMLISTCLOSESYM) - && conditional)) + && conditional) + && !(check_viewport(cursor) && cursor != *document)) { /* Allocating memory if necessary */ if(root) @@ -244,7 +291,8 @@ struct skin_element* skin_parse_sublines_optional(char** document, || *cursor == ARGLISTCLOSESYM || *cursor == ENUMLISTSEPERATESYM || *cursor == ENUMLISTCLOSESYM) - && conditional)) + && conditional) + && !(check_viewport(cursor) && cursor != *document)) { if(*cursor == COMMENTSYM) skip_comment(&cursor); @@ -405,7 +453,7 @@ int skin_parse_tag(struct skin_element* element, char** document) if(*tag_args == '|') { optional = 1; - req_args = i - 1; + req_args = i; tag_args++; } @@ -478,6 +526,14 @@ int skin_parse_tag(struct skin_element* element, char** document) tag_args++; + /* Checking for the optional bar */ + if(*tag_args == '|') + { + optional = 1; + req_args = i + 1; + tag_args++; + } + } /* Checking for a premature end */ diff --git a/utils/themeeditor/skin_parser.h b/utils/themeeditor/skin_parser.h index 201e06c257..77b4ed1158 100644 --- a/utils/themeeditor/skin_parser.h +++ b/utils/themeeditor/skin_parser.h @@ -42,6 +42,7 @@ extern char skin_parse_tree[]; /* Possible types of element in a WPS file */ enum skin_element_type { + VIEWPORT, LINE, SUBLINES, CONDITIONAL, diff --git a/utils/themeeditor/skin_scan.c b/utils/themeeditor/skin_scan.c index dfe5d008e5..37c948fb3c 100644 --- a/utils/themeeditor/skin_scan.c +++ b/utils/themeeditor/skin_scan.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "skin_scan.h" #include "skin_debug.h" @@ -136,3 +137,22 @@ int scan_int(char** document) *document = cursor; 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; +} diff --git a/utils/themeeditor/skin_scan.h b/utils/themeeditor/skin_scan.h index 682e32b3af..6aea92c8a9 100644 --- a/utils/themeeditor/skin_scan.h +++ b/utils/themeeditor/skin_scan.h @@ -33,6 +33,7 @@ void skip_comment(char** document); void skip_whitespace(char** document); char* scan_string(char** document); int scan_int(char** document); +int check_viewport(char* document); /* Checks for a viewport declaration */ #ifdef __cplusplus } -- cgit v1.2.3