summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/newparser/Makefile2
-rw-r--r--utils/newparser/handle_tags.c21
-rw-r--r--utils/newparser/newparser.c2
-rw-r--r--utils/newparser/skin_render.c65
-rw-r--r--utils/newparser/skin_structs.h29
5 files changed, 70 insertions, 49 deletions
diff --git a/utils/newparser/Makefile b/utils/newparser/Makefile
index 5a0e76f140..581a18f66a 100644
--- a/utils/newparser/Makefile
+++ b/utils/newparser/Makefile
@@ -1,3 +1,3 @@
1all: 1all:
2 gcc -I../themeeditor -g -Wall -o newparser newparser.c skin_render.c handle_tags.c ../themeeditor/skin_parser.c ../themeeditor/skin_scan.c ../themeeditor/skin_debug.c ../themeeditor/tag_table.c 2 gcc -I. -I../themeeditor -g -Wall -o newparser newparser.c handle_tags.c skin_render.c ../themeeditor/skin_parser.c ../themeeditor/skin_scan.c ../themeeditor/skin_debug.c ../themeeditor/tag_table.c
3 3
diff --git a/utils/newparser/handle_tags.c b/utils/newparser/handle_tags.c
index 9047e0bae4..67b5516419 100644
--- a/utils/newparser/handle_tags.c
+++ b/utils/newparser/handle_tags.c
@@ -25,6 +25,7 @@
25#include <string.h> 25#include <string.h>
26#include <ctype.h> 26#include <ctype.h>
27 27
28#include "symbols.h"
28#include "skin_parser.h" 29#include "skin_parser.h"
29#include "tag_table.h" 30#include "tag_table.h"
30#include "skin_structs.h" 31#include "skin_structs.h"
@@ -35,32 +36,22 @@ typedef int (tag_handler)(struct skin *skin, struct skin_element* element, bool
35 36
36int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only) 37int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only)
37{ 38{
38 struct skin_token *token = &skin->tokens[skin->token_count++];
39 token->type = element->tag->type;
40 token->next = false;
41 token->value.i = 1; /* actually need to fix this */
42 return 0; 39 return 0;
43} 40}
44 41
45int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only) 42int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only)
46{ 43{
47 struct skin_token *token = &skin->tokens[skin->token_count++];
48 token->type = element->tag->type;
49 token->next = element->tag->name[0] == 'D'
50 || element->tag->name[0] == 'I'
51 || element->tag->name[0] == 'F';
52 if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY) 44 if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY)
53 { 45 {
54 if (element->params_count != 1 || element->params[0].type_code != NUMERIC) 46 if (element->params_count != 1 || element->params[0].type_code != NUMERIC)
55 return -1; 47 return -1;
56 token->value.i = element->params[0].data.numeric; 48 //token->value.i = element->params[0].data.numeric;
57 } 49 }
58 return 0; 50 return 0;
59} 51}
60 52
61int handle_bar(struct skin *skin, struct skin_element* element, bool size_only) 53int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
62{ 54{
63 struct skin_token *token = &skin->tokens[skin->token_count++];
64 struct progressbar bar; 55 struct progressbar bar;
65 /* %bar with no params is different for each one so handle that! */ 56 /* %bar with no params is different for each one so handle that! */
66 if (element->params_count == 0) 57 if (element->params_count == 0)
@@ -79,7 +70,6 @@ int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
79 return sizeof(struct progressbar); 70 return sizeof(struct progressbar);
80 } 71 }
81 72
82 token->type = element->tag->type;
83 return 0; 73 return 0;
84} 74}
85 75
@@ -128,6 +118,13 @@ int handle_tree(struct skin *skin, struct skin_element* tree)
128 int counter; 118 int counter;
129 while (element) 119 while (element)
130 { 120 {
121 if (element->type == SUBLINES)
122 {
123 struct subline *subline = malloc(sizeof(struct subline));
124 subline->current_line = -1;
125 subline->last_change_tick = 0;
126 element->data = subline;
127 }
131 if (element->type == TAG) 128 if (element->type == TAG)
132 { 129 {
133 int i; 130 int i;
diff --git a/utils/newparser/newparser.c b/utils/newparser/newparser.c
index 2f58b64d15..4baf4aec03 100644
--- a/utils/newparser/newparser.c
+++ b/utils/newparser/newparser.c
@@ -73,8 +73,8 @@ int main(int argc, char* argv[])
73 73
74 struct skin_element* tree = skin_parse(buffer); 74 struct skin_element* tree = skin_parse(buffer);
75 struct skin skin; 75 struct skin skin;
76 handle_tree(&skin, tree);
76 skin_render(tree); 77 skin_render(tree);
77 //handle_tree(&skin, tree);
78 78
79 skin_free_tree(tree); 79 skin_free_tree(tree);
80 return 0; 80 return 0;
diff --git a/utils/newparser/skin_render.c b/utils/newparser/skin_render.c
index e71a867130..03324665a1 100644
--- a/utils/newparser/skin_render.c
+++ b/utils/newparser/skin_render.c
@@ -22,25 +22,37 @@
22#include <stdlib.h> 22#include <stdlib.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <string.h> 24#include <string.h>
25#include <stdbool.h>
25#include <ctype.h> 26#include <ctype.h>
27#include <string.h>
26 28
27#include "skin_parser.h" 29#include "skin_parser.h"
28#include "skin_debug.h" 30#include "skin_debug.h"
29#include "tag_table.h" 31#include "tag_table.h"
30#include "symbols.h" 32#include "symbols.h"
31#include "skin_scan.h" 33#include "skin_scan.h"
34#include "skin_structs.h"
35
36#define MAX_LINE 1024
32 37
33void skin_render_alternator(struct skin_element* alternator, int line_number); 38typedef void (*skin_render_func)(struct skin_element* alternator,
39 char* buf, size_t buf_size, int line_number);
40void skin_render_alternator(struct skin_element* alternator,
41 char* buf, size_t buf_size, int line_number);
34 42
35/* Draw a LINE element onto the display */ 43/* Draw a LINE element onto the display */
36void skin_render_line(struct skin_element* line, int line_number) 44void skin_render_line(struct skin_element* line,
45 char* buf, size_t buf_size, int line_number)
37{ 46{
38 int i=0, value; 47 int value;
39 if (line->children_count == 0) 48 if (line->children_count == 0)
40 return; /* empty line, do nothing */ 49 return; /* empty line, do nothing */
41 struct skin_element *child = line->children[0]; 50 struct skin_element *child = line->children[0];
51 skin_render_func func = skin_render_line;
52 char tempbuf[128];
42 while (child) 53 while (child)
43 { 54 {
55 tempbuf[0] = '\0';
44 switch (child->type) 56 switch (child->type)
45 { 57 {
46 case CONDITIONAL: 58 case CONDITIONAL:
@@ -48,41 +60,58 @@ void skin_render_line(struct skin_element* line, int line_number)
48 if (value >= child->children_count) 60 if (value >= child->children_count)
49 value = child->children_count-1; 61 value = child->children_count-1;
50 if (child->children[value]->type == SUBLINES) 62 if (child->children[value]->type == SUBLINES)
51 skin_render_alternator(child->children[value], line_number); 63 func = skin_render_alternator;
52 else if (child->children[value]->type == LINE) 64 else if (child->children[value]->type == LINE)
53 skin_render_line(child->children[value], line_number); 65 func = skin_render_line;
66 func(child->children[value], buf, buf_size, line_number);
54 break; 67 break;
55 case TAG: 68 case TAG:
56 printf("%%%s", child->tag->name); 69 snprintf(tempbuf, sizeof(tempbuf), "%%%s", child->tag->name);
57 break; 70 break;
58 case TEXT: 71 case TEXT:
59 printf("%s", (char*)(child->data)); 72 snprintf(tempbuf, sizeof(tempbuf), "%s", (char*)(child->data));
60 break; 73 break;
61 case COMMENT: 74 case COMMENT:
62 default: 75 default:
63 break; 76 break;
64 } 77 }
78 strcat(buf, tempbuf);
65 child = child->next; 79 child = child->next;
66 } 80 }
67} 81}
68 82#define TIME_AFTER(a,b) 1
69void skin_render_alternator(struct skin_element* alternator, int line_number) 83void skin_render_alternator(struct skin_element* alternator,
84 char* buf, size_t buf_size, int line_number)
70{ 85{
71 /*TODO Choose which subline to draw */ 86 struct subline *subline = (struct subline*)alternator->data;
72 skin_render_line(alternator->children[0], line_number); 87 if (TIME_AFTER(subline->last_change_tick + subline->timeout, 0/*FIXME*/))
88 {
89 subline->current_line++;
90 if (subline->current_line >= alternator->children_count)
91 subline->current_line = 0;
92 }
93 skin_render_line(alternator->children[subline->current_line],
94 buf, buf_size, line_number);
73} 95}
74 96
75void skin_render_viewport(struct skin_element* viewport) 97void skin_render_viewport(struct skin_element* line, bool draw_tags)
76{ 98{
77 struct skin_element *line = viewport;
78 int line_number = 0; 99 int line_number = 0;
100 char linebuf[MAX_LINE];
101 skin_render_func func = skin_render_line;
79 while (line) 102 while (line)
80 { 103 {
81 printf("\n[%d]", line_number); /* might be incorrect */ 104 linebuf[0] = '\0';
82 if (line->type == SUBLINES) 105 if (line->type == SUBLINES)
83 skin_render_alternator(line, line_number); 106 func = skin_render_alternator;
84 else if (line->type == LINE) 107 else if (line->type == LINE)
85 skin_render_line(line, line_number); 108 func = skin_render_line;
109
110 func (line, linebuf, sizeof(linebuf), line_number);
111 if (draw_tags)
112 {
113 printf("%s\n", linebuf);
114 }
86 line_number++; 115 line_number++;
87 line = line->next; 116 line = line->next;
88 } 117 }
@@ -91,9 +120,11 @@ void skin_render_viewport(struct skin_element* viewport)
91void skin_render(struct skin_element* root) 120void skin_render(struct skin_element* root)
92{ 121{
93 struct skin_element* viewport = root; 122 struct skin_element* viewport = root;
123 bool draw_tags = viewport->next ? false : true;
94 while (viewport) 124 while (viewport)
95 { 125 {
96 skin_render_viewport(viewport->children[0]); 126 skin_render_viewport(viewport->children[0], draw_tags);
127 draw_tags = true;
97 viewport = viewport->next; 128 viewport = viewport->next;
98 } 129 }
99} 130}
diff --git a/utils/newparser/skin_structs.h b/utils/newparser/skin_structs.h
index c86e683589..7dec7f85dc 100644
--- a/utils/newparser/skin_structs.h
+++ b/utils/newparser/skin_structs.h
@@ -27,26 +27,10 @@
27 27
28#include "skin_parser.h" 28#include "skin_parser.h"
29#include "tag_table.h" 29#include "tag_table.h"
30 30#ifndef SKIN_STRUCTS_H_
31struct skin_token { 31#define SKIN_STRUCTS_H_
32 enum skin_token_type type; /* enough to store the token type */
33
34 /* Whether the tag (e.g. track name or the album) refers the
35 current or the next song (false=current, true=next) */
36 bool next;
37
38 union {
39 char c;
40 unsigned int i;
41 void* data;
42 } value;
43};
44
45#define MAX_TOKENS 10000
46struct skin 32struct skin
47{ 33{
48 int token_count;
49 struct skin_token tokens[MAX_TOKENS];
50}; 34};
51 35
52 36
@@ -66,3 +50,12 @@ struct progressbar {
66 // struct bitmap bm; 50 // struct bitmap bm;
67 bool have_bitmap_pb; 51 bool have_bitmap_pb;
68}; 52};
53
54struct subline {
55 int timeout;
56 int current_line;
57 unsigned long last_change_tick;
58};
59
60
61#endif