1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
)
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
)
49 //token->value.i = element->params[0].data.numeric;
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)
62 if (element
->tag
->type
== SKIN_TOKEN_PROGRESSBAR
)
63 return sizeof(struct progressbar
);
71 return sizeof(struct progressbar
);
77 struct tag_handler_table
{
78 enum skin_token_type type
;
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
},
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
},
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
},
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
;
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
;
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
)
165 for(i
=0;i
<sizeof(table
)/sizeof(*table
);i
++)
167 if (table
[i
].type
== element
->tag
->type
)
170 table
[i
].func(skin
, element
, false);
171 if (table
[i
].flags
&EAT_LINE_ENDING
)
172 line
->eat_line_ending
= true;
177 else if (element
->type
== TEXT
)
183 while (counter
< element
->children_count
)
185 int ret
= handle_tree(skin
, element
->children
[counter
], current_line
);
188 /* *probably* set current_line to NULL here */
189 element
= element
->next
;