From 17c348432553d80089014cabaf8784f16519faa8 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Sun, 13 Jun 2010 14:42:09 +0000 Subject: [PATCH] Start dealing with LINE elements... setup a flag which lets tags tell the renderer to not start a new line in the viewport (i.e %we/d/i %X/x/xd etc) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26833 a1c6a512-1295-4272-9138-f99709370657 --- utils/newparser/handle_tags.c | 28 ++++++++++++++++++++++------ utils/newparser/newparser.c | 4 ++-- utils/newparser/skin_render.c | 11 ++++++++--- utils/newparser/skin_structs.h | 5 +++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/utils/newparser/handle_tags.c b/utils/newparser/handle_tags.c index 67b5516419..3e49960686 100644 --- a/utils/newparser/handle_tags.c +++ b/utils/newparser/handle_tags.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -78,8 +79,11 @@ struct tag_handler_table { int flags; tag_handler *func; }; +#define EAT_LINE_ENDING 0x01 struct tag_handler_table table[] = { + { SKIN_TOKEN_ENABLE_THEME, EAT_LINE_ENDING, NULL }, + { SKIN_TOKEN_DISABLE_THEME, EAT_LINE_ENDING, NULL }, /* file tags */ { SKIN_TOKEN_FILE_BITRATE , 0, handle_this_or_next_track }, { SKIN_TOKEN_FILE_CODEC , 0, handle_this_or_next_track }, @@ -108,31 +112,43 @@ struct tag_handler_table table[] = { { SKIN_TOKEN_TRANSLATEDSTRING, 0, handle_translate_string}, }; -int handle_tree(struct skin *skin, struct skin_element* tree) +int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line) { /* for later.. do this in two steps * 1) count how much skin buffer is needed * 2) do the actual tree->skin conversion */ struct skin_element* element = tree; + struct line *current_line = line; int counter; while (element) { - if (element->type == SUBLINES) + if (element->type == LINE) + { + struct line *line = (struct line*)malloc(sizeof(struct line)); + line->update_mode = 0; + line->eat_line_ending = false; + element->data = line; + current_line = line; + } + else if (element->type == SUBLINES) { struct subline *subline = malloc(sizeof(struct subline)); subline->current_line = -1; subline->last_change_tick = 0; element->data = subline; } - if (element->type == TAG) + else if (element->type == TAG) { - int i; + int i; for(i=0;itag->type) { - table[i].func(skin, element, false); + if (table[i].func) + table[i].func(skin, element, false); + if (table[i].flags&EAT_LINE_ENDING) + line->eat_line_ending = true; break; } } @@ -145,7 +161,7 @@ int handle_tree(struct skin *skin, struct skin_element* tree) counter = 0; while (counter < element->children_count) { - int ret = handle_tree(skin, element->children[counter]); + int ret = handle_tree(skin, element->children[counter], current_line); counter++; } element = element->next; diff --git a/utils/newparser/newparser.c b/utils/newparser/newparser.c index 4baf4aec03..f56fe6db84 100644 --- a/utils/newparser/newparser.c +++ b/utils/newparser/newparser.c @@ -29,7 +29,7 @@ #include "tag_table.h" #include "skin_structs.h" -int handle_tree(struct skin *skin, struct skin_element* tree); +int handle_tree(struct skin *skin, struct skin_element* tree, struct line* line); void skin_render(struct skin_element* root); int main(int argc, char* argv[]) @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) struct skin_element* tree = skin_parse(buffer); struct skin skin; - handle_tree(&skin, tree); + handle_tree(&skin, tree, NULL); skin_render(tree); skin_free_tree(tree); diff --git a/utils/newparser/skin_render.c b/utils/newparser/skin_render.c index 03324665a1..8c581134a8 100644 --- a/utils/newparser/skin_render.c +++ b/utils/newparser/skin_render.c @@ -94,11 +94,12 @@ void skin_render_alternator(struct skin_element* alternator, buf, buf_size, line_number); } -void skin_render_viewport(struct skin_element* line, bool draw_tags) +void skin_render_viewport(struct skin_element* viewport, bool draw_tags) { int line_number = 0; char linebuf[MAX_LINE]; skin_render_func func = skin_render_line; + struct skin_element* line = viewport; while (line) { linebuf[0] = '\0'; @@ -107,10 +108,14 @@ void skin_render_viewport(struct skin_element* line, bool draw_tags) else if (line->type == LINE) func = skin_render_line; - func (line, linebuf, sizeof(linebuf), line_number); + func(line, linebuf, sizeof(linebuf), line_number); if (draw_tags) { - printf("%s\n", linebuf); + printf("%s", linebuf); + if (!((struct line*)line->data)->eat_line_ending) + { + printf("\n"); + } } line_number++; line = line->next; diff --git a/utils/newparser/skin_structs.h b/utils/newparser/skin_structs.h index 7dec7f85dc..5755120e74 100644 --- a/utils/newparser/skin_structs.h +++ b/utils/newparser/skin_structs.h @@ -51,6 +51,11 @@ struct progressbar { bool have_bitmap_pb; }; +struct line { + unsigned update_mode; + bool eat_line_ending; +}; + struct subline { int timeout; int current_line;