forked from len0rd/rockbox
Theme Editor: Applied FS#11389, switched conditional elements to use tag fields along with children, instead of holding the tag as the first child
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26751 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6c522624b3
commit
64321adf43
5 changed files with 112 additions and 131 deletions
|
@ -257,8 +257,8 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
if(element->type != COMMENT && element->type != TEXT)
|
if(element->type != COMMENT && element->type != TEXT)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
free(element->text);
|
free(element->data);
|
||||||
element->text = strdup(value.toString().trimmed().toAscii());
|
element->data = strdup(value.toString().trimmed().toAscii());
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
|
|
|
@ -56,8 +56,13 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* CONDITIONAL and SUBLINES fall through to the same code */
|
|
||||||
case CONDITIONAL:
|
case CONDITIONAL:
|
||||||
|
for(int i = 0; i < element->params_count; i++)
|
||||||
|
children.append(new ParseTreeNode(&data->params[i], this));
|
||||||
|
for(int i = 0; i < element->children_count; i++)
|
||||||
|
children.append(new ParseTreeNode(data->children[i], this));
|
||||||
|
break;
|
||||||
|
|
||||||
case SUBLINES:
|
case SUBLINES:
|
||||||
for(int i = 0; i < element->children_count; i++)
|
for(int i = 0; i < element->children_count; i++)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +178,7 @@ QString ParseTreeNode::genCode() const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEXT:
|
case TEXT:
|
||||||
for(char* cursor = element->text; *cursor; cursor++)
|
for(char* cursor = (char*)element->data; *cursor; cursor++)
|
||||||
{
|
{
|
||||||
if(find_escape_character(*cursor))
|
if(find_escape_character(*cursor))
|
||||||
buffer.append(TAGSYM);
|
buffer.append(TAGSYM);
|
||||||
|
@ -183,7 +188,7 @@ QString ParseTreeNode::genCode() const
|
||||||
|
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
buffer.append(COMMENTSYM);
|
buffer.append(COMMENTSYM);
|
||||||
buffer.append(element->text);
|
buffer.append((char*)element->data);
|
||||||
buffer.append('\n');
|
buffer.append('\n');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -228,6 +233,7 @@ QString ParseTreeNode::genCode() const
|
||||||
int ParseTreeNode::genHash() const
|
int ParseTreeNode::genHash() const
|
||||||
{
|
{
|
||||||
int hash = 0;
|
int hash = 0;
|
||||||
|
char *text;
|
||||||
|
|
||||||
if(element)
|
if(element)
|
||||||
{
|
{
|
||||||
|
@ -248,12 +254,13 @@ int ParseTreeNode::genHash() const
|
||||||
|
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
case TEXT:
|
case TEXT:
|
||||||
for(unsigned int i = 0; i < strlen(element->text); i++)
|
text = (char*)element->data;
|
||||||
|
for(unsigned int i = 0; i < strlen(text); i++)
|
||||||
{
|
{
|
||||||
if(i % 2)
|
if(i % 2)
|
||||||
hash += element->text[i] % element->type;
|
hash += text[i] % element->type;
|
||||||
else
|
else
|
||||||
hash += element->text[i] % element->type * 2;
|
hash += text[i] % element->type * 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -370,12 +377,14 @@ QVariant ParseTreeNode::data(int column) const
|
||||||
case VIEWPORT:
|
case VIEWPORT:
|
||||||
case LINE:
|
case LINE:
|
||||||
case SUBLINES:
|
case SUBLINES:
|
||||||
case CONDITIONAL:
|
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
|
case CONDITIONAL:
|
||||||
|
return QString(element->tag->name);
|
||||||
|
|
||||||
case TEXT:
|
case TEXT:
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
return QString(element->text);
|
return QString((char*)element->data);
|
||||||
|
|
||||||
case TAG:
|
case TAG:
|
||||||
return QString(element->tag->name);
|
return QString(element->tag->name);
|
||||||
|
|
|
@ -102,6 +102,7 @@ void skin_clear_errors()
|
||||||
void skin_debug_tree(struct skin_element* root)
|
void skin_debug_tree(struct skin_element* root)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *text;
|
||||||
|
|
||||||
struct skin_element* current = root;
|
struct skin_element* current = root;
|
||||||
|
|
||||||
|
@ -123,18 +124,19 @@ void skin_debug_tree(struct skin_element* root)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEXT:
|
case TEXT:
|
||||||
printf("[ Plain text on line %d : %s ]\n", current->line,
|
text = current->data;
|
||||||
current->text);
|
printf("[ Plain text on line %d : %s ]\n", current->line, text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
|
text = current->data;
|
||||||
printf("[ Comment on line %d: ", current->line);
|
printf("[ Comment on line %d: ", current->line);
|
||||||
for(i = 0; i < (int)strlen(current->text); i++)
|
for(i = 0; i < (int)strlen(text); i++)
|
||||||
{
|
{
|
||||||
if(current->text[i] == '\n')
|
if(text[i] == '\n')
|
||||||
printf("\\n");
|
printf("\\n");
|
||||||
else
|
else
|
||||||
printf("%c", current->text[i]);
|
printf("%c", text[i]);
|
||||||
}
|
}
|
||||||
printf(" ]\n");
|
printf(" ]\n");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,27 +30,32 @@
|
||||||
#include "symbols.h"
|
#include "symbols.h"
|
||||||
#include "skin_scan.h"
|
#include "skin_scan.h"
|
||||||
|
|
||||||
|
#ifdef ROCKBOX
|
||||||
/* Declaration of parse tree buffer */
|
/* Declaration of parse tree buffer */
|
||||||
char skin_parse_tree[SKIN_MAX_MEMORY];
|
#define SKIN_MAX_MEMORY (30*1024)
|
||||||
int skin_current_block = 0;
|
static char skin_parse_tree[SKIN_MAX_MEMORY];
|
||||||
|
static char *skin_buffer;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Global variables for the parser */
|
/* Global variables for the parser */
|
||||||
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);
|
static struct skin_element* skin_parse_viewport(char** document);
|
||||||
struct skin_element* skin_parse_line(char** document);
|
static struct skin_element* skin_parse_line(char** document);
|
||||||
struct skin_element* skin_parse_line_optional(char** document, int conditional);
|
static struct skin_element* skin_parse_line_optional(char** document,
|
||||||
struct skin_element* skin_parse_sublines(char** document);
|
int conditional);
|
||||||
struct skin_element* skin_parse_sublines_optional(char** document,
|
static struct skin_element* skin_parse_sublines(char** document);
|
||||||
int conditional);
|
static struct skin_element* skin_parse_sublines_optional(char** document,
|
||||||
|
int conditional);
|
||||||
|
|
||||||
int skin_parse_tag(struct skin_element* element, char** document);
|
static int skin_parse_tag(struct skin_element* element, char** document);
|
||||||
int skin_parse_text(struct skin_element* element, char** document,
|
static int skin_parse_text(struct skin_element* element, char** document,
|
||||||
int conditional);
|
int conditional);
|
||||||
int skin_parse_conditional(struct skin_element* element, char** document);
|
static int skin_parse_conditional(struct skin_element* element,
|
||||||
int skin_parse_comment(struct skin_element* element, char** document);
|
char** document);
|
||||||
struct skin_element* skin_parse_code_as_arg(char** document);
|
static int skin_parse_comment(struct skin_element* element, char** document);
|
||||||
|
static struct skin_element* skin_parse_code_as_arg(char** document);
|
||||||
|
|
||||||
struct skin_element* skin_parse(const char* document)
|
struct skin_element* skin_parse(const char* document)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +66,10 @@ struct skin_element* skin_parse(const char* document)
|
||||||
struct skin_element** to_write = 0;
|
struct skin_element** to_write = 0;
|
||||||
|
|
||||||
char* cursor = (char*)document; /*Keeps track of location in the document*/
|
char* cursor = (char*)document; /*Keeps track of location in the document*/
|
||||||
|
#ifdef ROCKBOX
|
||||||
|
/* FIXME */
|
||||||
|
skin_buffer = &skin_parse_tree[0];
|
||||||
|
#endif
|
||||||
|
|
||||||
skin_line = 1;
|
skin_line = 1;
|
||||||
|
|
||||||
|
@ -93,7 +102,7 @@ struct skin_element* skin_parse(const char* document)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct skin_element* skin_parse_viewport(char** document)
|
static struct skin_element* skin_parse_viewport(char** document)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct skin_element* root = NULL;
|
struct skin_element* root = NULL;
|
||||||
|
@ -218,7 +227,7 @@ struct skin_element* skin_parse_viewport(char** document)
|
||||||
|
|
||||||
/* Auxiliary Parsing Functions */
|
/* Auxiliary Parsing Functions */
|
||||||
|
|
||||||
struct skin_element* skin_parse_line(char**document)
|
static struct skin_element* skin_parse_line(char**document)
|
||||||
{
|
{
|
||||||
|
|
||||||
return skin_parse_line_optional(document, 0);
|
return skin_parse_line_optional(document, 0);
|
||||||
|
@ -231,7 +240,8 @@ struct skin_element* skin_parse_line(char**document)
|
||||||
* SEPERATESYM. This should only be used when parsing a line inside a
|
* SEPERATESYM. This should only be used when parsing a line inside a
|
||||||
* conditional, otherwise just use the wrapper function skin_parse_line()
|
* conditional, otherwise just use the wrapper function skin_parse_line()
|
||||||
*/
|
*/
|
||||||
struct skin_element* skin_parse_line_optional(char** document, int conditional)
|
static struct skin_element* skin_parse_line_optional(char** document,
|
||||||
|
int conditional)
|
||||||
{
|
{
|
||||||
char* cursor = *document;
|
char* cursor = *document;
|
||||||
|
|
||||||
|
@ -296,12 +306,12 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct skin_element* skin_parse_sublines(char** document)
|
static struct skin_element* skin_parse_sublines(char** document)
|
||||||
{
|
{
|
||||||
return skin_parse_sublines_optional(document, 0);
|
return skin_parse_sublines_optional(document, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct skin_element* skin_parse_sublines_optional(char** document,
|
static struct skin_element* skin_parse_sublines_optional(char** document,
|
||||||
int conditional)
|
int conditional)
|
||||||
{
|
{
|
||||||
struct skin_element* retval;
|
struct skin_element* retval;
|
||||||
|
@ -379,7 +389,7 @@ struct skin_element* skin_parse_sublines_optional(char** document,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int skin_parse_tag(struct skin_element* element, char** document)
|
static int skin_parse_tag(struct skin_element* element, char** document)
|
||||||
{
|
{
|
||||||
|
|
||||||
char* cursor = *document + 1;
|
char* cursor = *document + 1;
|
||||||
|
@ -422,7 +432,8 @@ int skin_parse_tag(struct skin_element* element, char** document)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copying basic tag info */
|
/* Copying basic tag info */
|
||||||
element->type = TAG;
|
if(element->type != CONDITIONAL)
|
||||||
|
element->type = TAG;
|
||||||
element->tag = tag;
|
element->tag = tag;
|
||||||
tag_args = tag->params;
|
tag_args = tag->params;
|
||||||
element->line = skin_line;
|
element->line = skin_line;
|
||||||
|
@ -606,14 +617,13 @@ int skin_parse_tag(struct skin_element* element, char** document)
|
||||||
* If the conditional flag is set true, then parsing text will stop at an
|
* If the conditional flag is set true, then parsing text will stop at an
|
||||||
* ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional
|
* ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional
|
||||||
*/
|
*/
|
||||||
int skin_parse_text(struct skin_element* element, char** document,
|
static int skin_parse_text(struct skin_element* element, char** document,
|
||||||
int conditional)
|
int conditional)
|
||||||
{
|
{
|
||||||
char* cursor = *document;
|
char* cursor = *document;
|
||||||
|
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
|
||||||
int dest;
|
int dest;
|
||||||
|
char *text = NULL;
|
||||||
|
|
||||||
/* First figure out how much text we're copying */
|
/* First figure out how much text we're copying */
|
||||||
while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM
|
while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM
|
||||||
|
@ -643,7 +653,7 @@ int skin_parse_text(struct skin_element* element, char** document,
|
||||||
element->type = TEXT;
|
element->type = TEXT;
|
||||||
element->line = skin_line;
|
element->line = skin_line;
|
||||||
element->next = NULL;
|
element->next = NULL;
|
||||||
element->text = skin_alloc_string(length);
|
element->data = text = skin_alloc_string(length);
|
||||||
|
|
||||||
for(dest = 0; dest < length; dest++)
|
for(dest = 0; dest < length; dest++)
|
||||||
{
|
{
|
||||||
|
@ -651,22 +661,21 @@ int skin_parse_text(struct skin_element* element, char** document,
|
||||||
if(*cursor == TAGSYM)
|
if(*cursor == TAGSYM)
|
||||||
cursor++;
|
cursor++;
|
||||||
|
|
||||||
element->text[dest] = *cursor;
|
text[dest] = *cursor;
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
element->text[length] = '\0';
|
text[length] = '\0';
|
||||||
|
|
||||||
*document = cursor;
|
*document = cursor;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int skin_parse_conditional(struct skin_element* element, char** document)
|
static int skin_parse_conditional(struct skin_element* element, char** document)
|
||||||
{
|
{
|
||||||
|
|
||||||
char* cursor = *document + 1; /* Starting past the "%" */
|
char* cursor = *document + 1; /* Starting past the "%" */
|
||||||
char* bookmark;
|
char* bookmark;
|
||||||
struct skin_element* tag = skin_alloc_element(); /* The tag to evaluate */
|
|
||||||
int children = 1;
|
int children = 1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -674,7 +683,7 @@ int skin_parse_conditional(struct skin_element* element, char** document)
|
||||||
element->line = skin_line;
|
element->line = skin_line;
|
||||||
|
|
||||||
/* Parsing the tag first */
|
/* Parsing the tag first */
|
||||||
if(!skin_parse_tag(tag, &cursor))
|
if(!skin_parse_tag(element, &cursor))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Counting the children */
|
/* Counting the children */
|
||||||
|
@ -714,21 +723,20 @@ int skin_parse_conditional(struct skin_element* element, char** document)
|
||||||
cursor = bookmark;
|
cursor = bookmark;
|
||||||
|
|
||||||
/* Parsing the children */
|
/* Parsing the children */
|
||||||
element->children_count = children + 1; /* Make sure to include the tag */
|
element->children = skin_alloc_children(children);
|
||||||
element->children = skin_alloc_children(children + 1);
|
element->children_count = children;
|
||||||
element->children[0] = tag;
|
|
||||||
|
|
||||||
for(i = 1; i < children + 1; i++)
|
for(i = 0; i < children; i++)
|
||||||
{
|
{
|
||||||
element->children[i] = skin_parse_code_as_arg(&cursor);
|
element->children[i] = skin_parse_code_as_arg(&cursor);
|
||||||
skip_whitespace(&cursor);
|
skip_whitespace(&cursor);
|
||||||
|
|
||||||
if(i < children && *cursor != ENUMLISTSEPERATESYM)
|
if(i < children - 1 && *cursor != ENUMLISTSEPERATESYM)
|
||||||
{
|
{
|
||||||
skin_error(SEPERATOR_EXPECTED);
|
skin_error(SEPERATOR_EXPECTED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(i == children && *cursor != ENUMLISTCLOSESYM)
|
else if(i == children - 1 && *cursor != ENUMLISTCLOSESYM)
|
||||||
{
|
{
|
||||||
skin_error(CLOSE_EXPECTED);
|
skin_error(CLOSE_EXPECTED);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -744,9 +752,10 @@ int skin_parse_conditional(struct skin_element* element, char** document)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int skin_parse_comment(struct skin_element* element, char** document)
|
static int skin_parse_comment(struct skin_element* element, char** document)
|
||||||
{
|
{
|
||||||
char* cursor = *document;
|
char* cursor = *document;
|
||||||
|
char* text = NULL;
|
||||||
|
|
||||||
int length;
|
int length;
|
||||||
/*
|
/*
|
||||||
|
@ -758,12 +767,15 @@ int skin_parse_comment(struct skin_element* element, char** document)
|
||||||
|
|
||||||
element->type = COMMENT;
|
element->type = COMMENT;
|
||||||
element->line = skin_line;
|
element->line = skin_line;
|
||||||
element->text = skin_alloc_string(length);
|
#ifdef ROCKBOX
|
||||||
|
element->data = NULL;
|
||||||
|
#else
|
||||||
|
element->data = text = skin_alloc_string(length);
|
||||||
/* We copy from one char past cursor to leave out the # */
|
/* We copy from one char past cursor to leave out the # */
|
||||||
memcpy((void*)(element->text), (void*)(cursor + 1),
|
memcpy((void*)text, (void*)(cursor + 1),
|
||||||
sizeof(char) * (length-1));
|
sizeof(char) * (length-1));
|
||||||
element->text[length - 1] = '\0';
|
text[length - 1] = '\0';
|
||||||
|
#endif
|
||||||
if(cursor[length] == '\n')
|
if(cursor[length] == '\n')
|
||||||
skin_line++;
|
skin_line++;
|
||||||
|
|
||||||
|
@ -774,7 +786,7 @@ int skin_parse_comment(struct skin_element* element, char** document)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct skin_element* skin_parse_code_as_arg(char** document)
|
static struct skin_element* skin_parse_code_as_arg(char** document)
|
||||||
{
|
{
|
||||||
|
|
||||||
int sublines = 0;
|
int sublines = 0;
|
||||||
|
@ -813,29 +825,21 @@ struct skin_element* skin_parse_code_as_arg(char** document)
|
||||||
|
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
|
char* skin_alloc(size_t size)
|
||||||
|
{
|
||||||
|
#ifdef ROCKBOX
|
||||||
|
char *retval = skin_buffer;
|
||||||
|
skin_buffer = (void *)(((unsigned long)skin_buffer + 3) & ~3);
|
||||||
|
return retval;
|
||||||
|
#else
|
||||||
|
return malloc(size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct skin_element* skin_alloc_element()
|
struct skin_element* skin_alloc_element()
|
||||||
{
|
{
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
char* retval = &skin_parse_tree[skin_current_block * 4];
|
|
||||||
|
|
||||||
int delta = sizeof(struct skin_element) / (sizeof(char) * 4);
|
|
||||||
|
|
||||||
/* If one block is partially filled, make sure to advance to the
|
|
||||||
* next one for the next allocation
|
|
||||||
*/
|
|
||||||
if(sizeof(struct skin_element) % (sizeof(char) * 4) != 0)
|
|
||||||
delta++;
|
|
||||||
|
|
||||||
skin_current_block += delta;
|
|
||||||
|
|
||||||
return (struct skin_element*)retval;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct skin_element* retval = (struct skin_element*)
|
struct skin_element* retval = (struct skin_element*)
|
||||||
malloc(sizeof(struct skin_element));
|
skin_alloc(sizeof(struct skin_element));
|
||||||
retval->next = NULL;
|
retval->next = NULL;
|
||||||
retval->params_count = 0;
|
retval->params_count = 0;
|
||||||
retval->children_count = 0;
|
retval->children_count = 0;
|
||||||
|
@ -846,60 +850,25 @@ struct skin_element* skin_alloc_element()
|
||||||
|
|
||||||
struct skin_tag_parameter* skin_alloc_params(int count)
|
struct skin_tag_parameter* skin_alloc_params(int count)
|
||||||
{
|
{
|
||||||
#if 0
|
size_t size = sizeof(struct skin_tag_parameter) * count;
|
||||||
|
return (struct skin_tag_parameter*)skin_alloc(size);
|
||||||
char* retval = &skin_parse_tree[skin_current_block * 4];
|
|
||||||
|
|
||||||
int delta = sizeof(struct skin_tag_parameter) / (sizeof(char) * 4);
|
|
||||||
delta *= count;
|
|
||||||
|
|
||||||
/* Correcting uneven alignment */
|
|
||||||
if(count * sizeof(struct skin_tag_parameter) % (sizeof(char) * 4) != 0)
|
|
||||||
delta++;
|
|
||||||
|
|
||||||
skin_current_block += delta;
|
|
||||||
|
|
||||||
return (struct skin_tag_parameter*) retval;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (struct skin_tag_parameter*)malloc(sizeof(struct skin_tag_parameter)
|
|
||||||
* count);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* skin_alloc_string(int length)
|
char* skin_alloc_string(int length)
|
||||||
{
|
{
|
||||||
|
return (char*)skin_alloc(sizeof(char) * (length + 1));
|
||||||
#if 0
|
|
||||||
char* retval = &skin_parse_tree[skin_current_block * 4];
|
|
||||||
|
|
||||||
/* Checking alignment */
|
|
||||||
length++; /* Accounting for the null terminator */
|
|
||||||
int delta = length / 4;
|
|
||||||
if(length % 4 != 0)
|
|
||||||
delta++;
|
|
||||||
|
|
||||||
skin_current_block += delta;
|
|
||||||
|
|
||||||
if(skin_current_block >= SKIN_MAX_MEMORY / 4)
|
|
||||||
skin_error(MEMORY_LIMIT_EXCEEDED);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (char*)malloc(sizeof(char) * (length + 1));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct skin_element** skin_alloc_children(int count)
|
struct skin_element** skin_alloc_children(int count)
|
||||||
{
|
{
|
||||||
return (struct skin_element**) malloc(sizeof(struct skin_element*) * count);
|
return (struct skin_element**)
|
||||||
|
skin_alloc(sizeof(struct skin_element*) * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void skin_free_tree(struct skin_element* root)
|
void skin_free_tree(struct skin_element* root)
|
||||||
{
|
{
|
||||||
|
#ifndef ROCKBOX
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* First make the recursive call */
|
/* First make the recursive call */
|
||||||
|
@ -908,8 +877,8 @@ void skin_free_tree(struct skin_element* root)
|
||||||
skin_free_tree(root->next);
|
skin_free_tree(root->next);
|
||||||
|
|
||||||
/* Free any text */
|
/* Free any text */
|
||||||
if(root->type == TEXT)
|
if(root->type == TEXT || root->type == COMMENT)
|
||||||
free(root->text);
|
free(root->data);
|
||||||
|
|
||||||
/* Then recursively free any children, before freeing their pointers */
|
/* Then recursively free any children, before freeing their pointers */
|
||||||
for(i = 0; i < root->children_count; i++)
|
for(i = 0; i < root->children_count; i++)
|
||||||
|
@ -926,4 +895,7 @@ void skin_free_tree(struct skin_element* root)
|
||||||
|
|
||||||
/* Finally, delete root's memory */
|
/* Finally, delete root's memory */
|
||||||
free(root);
|
free(root);
|
||||||
|
#else
|
||||||
|
(void)root;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,7 @@
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define SKIN_MAX_MEMORY 1048576
|
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
****** A global buffer will be used to store the parse tree *******
|
|
||||||
*******************************************************************/
|
|
||||||
extern char skin_parse_tree[];
|
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
****** Data Structures *********************************************
|
****** Data Structures *********************************************
|
||||||
|
@ -98,8 +91,11 @@ struct skin_element
|
||||||
/* The line on which it's defined in the source file */
|
/* The line on which it's defined in the source file */
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
/* Text for comments and plaintext */
|
/* Placeholder for element data
|
||||||
char* text;
|
* TEXT and COMMENT uses it for the text string
|
||||||
|
* TAG, VIEWPORT, LINE, etc may use it for post parse extra storage
|
||||||
|
*/
|
||||||
|
void* data;
|
||||||
|
|
||||||
/* The tag or conditional name */
|
/* The tag or conditional name */
|
||||||
struct tag_info *tag;
|
struct tag_info *tag;
|
||||||
|
@ -125,6 +121,7 @@ struct skin_element
|
||||||
struct skin_element* skin_parse(const char* document);
|
struct skin_element* skin_parse(const char* document);
|
||||||
|
|
||||||
/* Memory management functions */
|
/* Memory management functions */
|
||||||
|
char *skin_alloc(size_t size);
|
||||||
struct skin_element* skin_alloc_element();
|
struct skin_element* skin_alloc_element();
|
||||||
struct skin_element** skin_alloc_children(int count);
|
struct skin_element** skin_alloc_children(int count);
|
||||||
struct skin_tag_parameter* skin_alloc_params(int count);
|
struct skin_tag_parameter* skin_alloc_params(int count);
|
||||||
|
@ -132,6 +129,7 @@ char* skin_alloc_string(int length);
|
||||||
|
|
||||||
void skin_free_tree(struct skin_element* root);
|
void skin_free_tree(struct skin_element* root);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue