get the renderer working more better! "handle" sublines correctly, dont "draw" in...
[kugel-rb.git] / utils / newparser / handle_tags.c
blob67b5516419285847621cc3651bf9672627e741f8
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 <string.h>
26 #include <ctype.h>
28 #include "symbols.h"
29 #include "skin_parser.h"
30 #include "tag_table.h"
31 #include "skin_structs.h"
33 typedef int (tag_handler)(struct skin *skin, struct skin_element* element, bool size_only);
37 int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only)
39 return 0;
42 int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only)
44 if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY)
46 if (element->params_count != 1 || element->params[0].type_code != NUMERIC)
47 return -1;
48 //token->value.i = element->params[0].data.numeric;
50 return 0;
53 int handle_bar(struct skin *skin, struct skin_element* element, bool size_only)
55 struct progressbar bar;
56 /* %bar with no params is different for each one so handle that! */
57 if (element->params_count == 0)
59 if (size_only)
61 if (element->tag->type == SKIN_TOKEN_PROGRESSBAR)
62 return sizeof(struct progressbar);
63 else
64 return 0;
67 else
69 if (size_only)
70 return sizeof(struct progressbar);
73 return 0;
76 struct tag_handler_table {
77 enum skin_token_type type;
78 int flags;
79 tag_handler *func;
82 struct tag_handler_table table[] = {
83 /* file tags */
84 { SKIN_TOKEN_FILE_BITRATE , 0, handle_this_or_next_track },
85 { SKIN_TOKEN_FILE_CODEC , 0, handle_this_or_next_track },
86 { SKIN_TOKEN_FILE_FREQUENCY , 0, handle_this_or_next_track },
87 { SKIN_TOKEN_FILE_FREQUENCY_KHZ , 0, handle_this_or_next_track },
88 { SKIN_TOKEN_FILE_NAME_WITH_EXTENSION , 0, handle_this_or_next_track },
89 { SKIN_TOKEN_FILE_NAME , 0, handle_this_or_next_track },
90 { SKIN_TOKEN_FILE_PATH , 0, handle_this_or_next_track },
91 { SKIN_TOKEN_FILE_SIZE , 0, handle_this_or_next_track },
92 { SKIN_TOKEN_FILE_VBR , 0, handle_this_or_next_track },
93 { SKIN_TOKEN_FILE_DIRECTORY , 0, handle_this_or_next_track },
94 /* track metadata */
95 { SKIN_TOKEN_METADATA_ARTIST , 0, handle_this_or_next_track },
96 { SKIN_TOKEN_METADATA_COMPOSER , 0, handle_this_or_next_track },
97 { SKIN_TOKEN_METADATA_ALBUM , 0, handle_this_or_next_track },
98 { SKIN_TOKEN_METADATA_ALBUM_ARTIST , 0, handle_this_or_next_track },
99 { SKIN_TOKEN_METADATA_GROUPING , 0, handle_this_or_next_track },
100 { SKIN_TOKEN_METADATA_GENRE , 0, handle_this_or_next_track },
101 { SKIN_TOKEN_METADATA_DISC_NUMBER , 0, handle_this_or_next_track },
102 { SKIN_TOKEN_METADATA_TRACK_NUMBER , 0, handle_this_or_next_track },
103 { SKIN_TOKEN_METADATA_TRACK_TITLE , 0, handle_this_or_next_track },
104 { SKIN_TOKEN_METADATA_VERSION , 0, handle_this_or_next_track },
105 { SKIN_TOKEN_METADATA_YEAR , 0, handle_this_or_next_track },
106 { SKIN_TOKEN_METADATA_COMMENT , 0, handle_this_or_next_track },
107 /* misc */
108 { SKIN_TOKEN_TRANSLATEDSTRING, 0, handle_translate_string},
111 int handle_tree(struct skin *skin, struct skin_element* tree)
113 /* for later.. do this in two steps
114 * 1) count how much skin buffer is needed
115 * 2) do the actual tree->skin conversion
117 struct skin_element* element = tree;
118 int counter;
119 while (element)
121 if (element->type == SUBLINES)
123 struct subline *subline = malloc(sizeof(struct subline));
124 subline->current_line = -1;
125 subline->last_change_tick = 0;
126 element->data = subline;
128 if (element->type == TAG)
130 int i;
131 for(i=0;i<sizeof(table)/sizeof(*table);i++)
133 if (table[i].type == element->tag->type)
135 table[i].func(skin, element, false);
136 break;
140 else if (element->type == TEXT)
142 /* handle */
145 counter = 0;
146 while (counter < element->children_count)
148 int ret = handle_tree(skin, element->children[counter]);
149 counter++;
151 element = element->next;
153 return 0;