1
0
Fork 0
forked from len0rd/rockbox

Theme Editor: Fixed a bug in the subline parser, added a LINE element to contain logical lines, working on data model

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26337 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-05-27 19:57:15 +00:00
parent deb1600bbc
commit 8ea056db4b
7 changed files with 58 additions and 27 deletions

View file

@ -19,14 +19,11 @@
* *
****************************************************************************/ ****************************************************************************/
namespace wps
{
extern "C" extern "C"
{ {
#include "skin_parser.h" #include "skin_parser.h"
#include "skin_debug.h" #include "skin_debug.h"
} }
}
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
@ -39,13 +36,14 @@ namespace wps
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
char* doc = "%Vd(U)\n\n%?bl(test,3,5,2,1)<param2|param3>"; char doc[] = "%Vd(U);Hey\n%?bl(test,3,5,2,1)<param2|param3>";
struct wps::skin_element* test = wps::skin_parse(doc); struct skin_element* test = skin_parse(doc);
wps::skin_debug_tree(test); skin_debug_tree(test);
skin_free_tree(test);
wps::skin_free_tree(test);
QApplication app(argc, argv); QApplication app(argc, argv);

View file

@ -27,7 +27,6 @@ ParseTreeModel::ParseTreeModel(char* wps, QObject* parent):
QAbstractItemModel(parent) QAbstractItemModel(parent)
{ {
this->wps = skin_parse(wps); this->wps = skin_parse(wps);
skin_debug_tree(this->wps);
this->root = new ParseTreeNode(this->wps, 0, true); this->root = new ParseTreeNode(this->wps, 0, true);
} }

View file

@ -1,15 +1,33 @@
#include "parsetreenode.h" #include "parsetreenode.h"
ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent,
bool stop): bool tree)
parentLink(parent), element(data)
{ {
if(stop) if(tree)
return; {
for(int i = 0; i < 5; i++) while(data)
appendChild(new ParseTreeNode(data, this, true)); {
appendChild(new ParseTreeNode(data, this, false));
data = data->next;
} }
parentLink = 0;
}
else
{
element = data;
parentLink = parent;
}
}
ParseTreeNode::ParseTreeNode(struct skin_tag_parameter* param,
ParseTreeNode* parent)
:parentLink(parent), element(0), param(param)
{
}
ParseTreeNode::~ParseTreeNode() ParseTreeNode::~ParseTreeNode()
{ {

View file

@ -13,7 +13,8 @@ extern "C"
class ParseTreeNode class ParseTreeNode
{ {
public: public:
ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, bool stop = false); ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, bool tree);
ParseTreeNode(struct skin_tag_parameter* param, ParseTreeNode* parent);
virtual ~ParseTreeNode(); virtual ~ParseTreeNode();
void appendChild(ParseTreeNode* child); void appendChild(ParseTreeNode* child);
@ -29,6 +30,7 @@ private:
ParseTreeNode* parentLink; ParseTreeNode* parentLink;
QList<ParseTreeNode*> children; QList<ParseTreeNode*> children;
struct skin_element* element; struct skin_element* element;
struct skin_tag_parameter* param;
}; };

View file

@ -129,17 +129,10 @@ void skin_debug_tree(struct skin_element* root)
debug_indent_level++; debug_indent_level++;
for(i = 0; i < current->children_count; i++) for(i = 0; i < current->children_count; i++)
{ {
skin_debug_indent();
printf("[ Subline %d\n", i);
debug_indent_level++;
skin_debug_tree(current->children[i]); skin_debug_tree(current->children[i]);
debug_indent_level--;
skin_debug_indent();
printf("]\n");
} }
debug_indent_level--; debug_indent_level--;
skin_debug_indent(); skin_debug_indent();
printf("]\n"); printf("]\n");
break; break;
@ -175,6 +168,16 @@ void skin_debug_tree(struct skin_element* root)
break; break;
case LINE:
printf("[ Logical line on line %d\n", current->line);
debug_indent_level++;
skin_debug_tree(current->children[0]);
debug_indent_level--;
skin_debug_indent();
printf("]\n");
break;
} }
current = current->next; current = current->next;

View file

@ -151,6 +151,14 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
struct skin_element* root = NULL; struct skin_element* root = NULL;
struct skin_element* current = NULL; struct skin_element* current = NULL;
struct skin_element* retval = NULL;
/* A wrapper for the line */
retval = skin_alloc_element();
retval->type = LINE;
retval->line = skin_line;
retval->children_count = 1;
retval->children = skin_alloc_children(1);
while(*cursor != '\n' && *cursor != '\0' && *cursor != MULTILINESYM while(*cursor != '\n' && *cursor != '\0' && *cursor != MULTILINESYM
&& !((*cursor == ARGLISTSEPERATESYM && !((*cursor == ARGLISTSEPERATESYM
@ -214,7 +222,8 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
/* Moving up the calling function's pointer */ /* Moving up the calling function's pointer */
*document = cursor; *document = cursor;
return root; retval->children[0] = root;
return retval;
} }
struct skin_element* skin_parse_sublines(char** document) struct skin_element* skin_parse_sublines(char** document)
@ -233,6 +242,7 @@ struct skin_element* skin_parse_sublines_optional(char** document,
retval = skin_alloc_element(); retval = skin_alloc_element();
retval->type = SUBLINES; retval->type = SUBLINES;
retval->next = NULL; retval->next = NULL;
retval->line = skin_line;
/* First we count the sublines */ /* First we count the sublines */
while(*cursor != '\0' && *cursor != '\n' while(*cursor != '\0' && *cursor != '\n'
@ -276,7 +286,7 @@ struct skin_element* skin_parse_sublines_optional(char** document,
skin_error(MULTILINE_EXPECTED); skin_error(MULTILINE_EXPECTED);
return NULL; return NULL;
} }
else else if(i != sublines - 1)
{ {
cursor++; cursor++;
} }

View file

@ -41,7 +41,8 @@ enum skin_element_type
COMMENT, COMMENT,
TAG, TAG,
CONDITIONAL, CONDITIONAL,
SUBLINES SUBLINES,
LINE
}; };
enum skin_errorcode enum skin_errorcode