text viewer: reworks screen access logics and some bugs fix.
[kugel-rb.git] / utils / newparser / handle_tags.c
blobc7c1289183d3274406ec2108f1e979b9c002db74
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <ctype.h>
29 #include "symbols.h"
30 #include "skin_parser.h"
31 #include "tag_table.h"
32 #include "skin_structs.h"
34 typedef int (tag_handler)(struct skin *skin, struct skin_element* element, bool size_only);
38 int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only)
40 return 0;
43 int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only)
45 if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY)
47 if (element->params_count != 1 || element->params[0].type_code != NUMERIC)
48 return -1;
49 //token->value.i = element->params[0].data.numeric;
51 return 0;
54 int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
56 struct progressbar bar;
57 /* %bar with no params is different for each one so handle that! */
58 if (element->params_count == 0)
60 if (size_only)
62 if (element->tag->type == SKIN_TOKEN_PROGRESSBAR)
63 return sizeof(struct progressbar);
64 else
65 return 0;
68 else
70 if (size_only)
71 return sizeof(struct progressbar);
74 return 0;
77 struct tag_handler_table {
78 enum skin_token_type type;
79 int flags;
80 tag_handler *func;
82 #define EAT_LINE_ENDING 0x01
84 struct tag_handler_table table[] = {
85 { SKIN_TOKEN_ENABLE_THEME, EAT_LINE_ENDING, NULL },
86 { SKIN_TOKEN_DISABLE_THEME, EAT_LINE_ENDING, NULL },
87 /* file tags */
88 { SKIN_TOKEN_FILE_BITRATE , 0, handle_this_or_next_track },
89 { SKIN_TOKEN_FILE_CODEC , 0, handle_this_or_next_track },
90 { SKIN_TOKEN_FILE_FREQUENCY , 0, handle_this_or_next_track },
91 { SKIN_TOKEN_FILE_FREQUENCY_KHZ , 0, handle_this_or_next_track },
92 { SKIN_TOKEN_FILE_NAME_WITH_EXTENSION , 0, handle_this_or_next_track },
93 { SKIN_TOKEN_FILE_NAME , 0, handle_this_or_next_track },
94 { SKIN_TOKEN_FILE_PATH , 0, handle_this_or_next_track },
95 { SKIN_TOKEN_FILE_SIZE , 0, handle_this_or_next_track },
96 { SKIN_TOKEN_FILE_VBR , 0, handle_this_or_next_track },
97 { SKIN_TOKEN_FILE_DIRECTORY , 0, handle_this_or_next_track },
98 /* track metadata */
99 { SKIN_TOKEN_METADATA_ARTIST , 0, handle_this_or_next_track },
100 { SKIN_TOKEN_METADATA_COMPOSER , 0, handle_this_or_next_track },
101 { SKIN_TOKEN_METADATA_ALBUM , 0, handle_this_or_next_track },
102 { SKIN_TOKEN_METADATA_ALBUM_ARTIST , 0, handle_this_or_next_track },
103 { SKIN_TOKEN_METADATA_GROUPING , 0, handle_this_or_next_track },
104 { SKIN_TOKEN_METADATA_GENRE , 0, handle_this_or_next_track },
105 { SKIN_TOKEN_METADATA_DISC_NUMBER , 0, handle_this_or_next_track },
106 { SKIN_TOKEN_METADATA_TRACK_NUMBER , 0, handle_this_or_next_track },
107 { SKIN_TOKEN_METADATA_TRACK_TITLE , 0, handle_this_or_next_track },
108 { SKIN_TOKEN_METADATA_VERSION , 0, handle_this_or_next_track },
109 { SKIN_TOKEN_METADATA_YEAR , 0, handle_this_or_next_track },
110 { SKIN_TOKEN_METADATA_COMMENT , 0, handle_this_or_next_track },
111 /* misc */
112 { SKIN_TOKEN_TRANSLATEDSTRING, 0, handle_translate_string},
115 int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line)
117 /* for later.. do this in two steps
118 * 1) count how much skin buffer is needed
119 * 2) do the actual tree->skin conversion
121 struct skin_element* element = tree;
122 struct line *current_line = line;
123 int counter;
124 while (element)
126 if (element->type == VIEWPORT)
128 struct skin_element *next;
129 /* parse the viewport */
130 /* if the next element is a LINE we need to set it to eat the line ending */
131 next = element->children[0];
132 if (element->tag && next->type == LINE &&
133 element->line == next->line)
135 struct line *newline = (struct line*)skin_alloc(sizeof(struct line));
136 newline->update_mode = 0;
137 newline->eat_line_ending = true;
138 next->data = newline;
141 else if (element->type == LINE && !element->data)
143 struct line *line = (struct line*)skin_alloc(sizeof(struct line));
144 line->update_mode = 0;
145 line->eat_line_ending = false;
146 element->data = line;
147 current_line = line;
149 else if (element->type == SUBLINES)
151 struct subline *subline = skin_alloc(sizeof(struct subline));
152 subline->current_line = -1;
153 subline->last_change_tick = 0;
154 element->data = subline;
156 else if (element->type == CONDITIONAL)
158 struct conditional *cond = skin_alloc(sizeof(struct conditional));
159 cond->last_value = element->children_count;
160 element->data = cond;
162 else if (element->type == TAG)
164 int i;
165 for(i=0;i<sizeof(table)/sizeof(*table);i++)
167 if (table[i].type == element->tag->type)
169 if (table[i].func)
170 table[i].func(skin, element, false);
171 if (table[i].flags&EAT_LINE_ENDING)
172 line->eat_line_ending = true;
173 break;
177 else if (element->type == TEXT)
179 /* handle */
182 counter = 0;
183 while (counter < element->children_count)
185 int ret = handle_tree(skin, element->children[counter], current_line);
186 counter++;
188 /* *probably* set current_line to NULL here */
189 element = element->next;
191 return 0;