fix yelllow and add those tags to the debug output
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blob26554b1db6faec8e60f12dd5227db175696120c2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
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 #if defined(DEBUG) || defined(SIMULATOR)
24 #include <stdio.h>
25 #include <string.h>
26 #include "wps.h"
27 #include "wps_internals.h"
28 #include "skin_buffer.h"
29 #include "settings_list.h"
30 #ifdef __PCTOOL__
31 #ifdef WPSEDITOR
32 #include "proxy.h"
33 #else
34 #define DEBUGF printf
35 #endif
36 #else
37 #include "debug.h"
38 #endif
40 #if defined(SIMULATOR) || defined(__PCTOOL__)
41 extern int wps_verbose_level;
42 #endif
44 struct debug_token_table
46 enum wps_token_type start_marker;
47 char *desc;
49 #define X(name) name, #name
50 struct debug_token_table tokens[] = {
51 { X(TOKEN_MARKER_CONTROL_TOKENS) },
52 { X(TOKEN_MARKER_BATTERY) },
53 { X(TOKEN_MARKER_SOUND) },
54 { X(TOKEN_MARKER_RTC) },
55 { X(TOKEN_MARKER_DATABASE) },
56 { X(TOKEN_MARKER_FILE) },
57 { X(TOKEN_MARKER_IMAGES) },
58 { X(TOKEN_MARKER_METADATA) },
59 { X(TOKEN_MARKER_PLAYBACK_INFO) },
60 { X(TOKEN_MARKER_PLAYLIST) },
61 { X(TOKEN_MARKER_MISC) },
62 { X(TOKEN_MARKER_RECORDING) },
63 { X(TOKEN_MARKER_END) },
65 #undef X
67 static char *next_str(bool next) {
68 return next ? "next " : "";
71 static char *get_token_desc(struct wps_token *token, char *buf,
72 int bufsize, struct wps_data *data)
74 unsigned i;
75 #ifndef HAVE_LCD_BITMAP
76 (void)data; /* kill charcell warning */
77 #endif
78 bool next = token->next;
79 switch(token->type)
81 case WPS_NO_TOKEN:
82 snprintf(buf, bufsize, "No token");
83 break;
85 case WPS_TOKEN_UNKNOWN:
86 snprintf(buf, bufsize, "Unknown token");
87 break;
89 case WPS_TOKEN_CHARACTER:
90 if (token->value.c == '\n')
91 snprintf(buf, bufsize, "Character '\\n'");
92 else
93 snprintf(buf, bufsize, "Character '%c'",
94 token->value.c);
95 break;
97 case WPS_TOKEN_STRING:
98 snprintf(buf, bufsize, "String '%s'",
99 (char*)token->value.data);
100 break;
101 case WPS_TOKEN_TRANSLATEDSTRING:
102 snprintf(buf, bufsize, "String ID '%d'", token->value.i);
103 break;
105 #ifdef HAVE_LCD_BITMAP
106 case WPS_TOKEN_ALIGN_LEFT:
107 snprintf(buf, bufsize, "align left");
108 break;
110 case WPS_TOKEN_ALIGN_CENTER:
111 snprintf(buf, bufsize, "align center");
112 break;
114 case WPS_TOKEN_ALIGN_RIGHT:
115 snprintf(buf, bufsize, "align right");
116 break;
117 #endif
119 case WPS_TOKEN_SUBLINE_TIMEOUT:
120 snprintf(buf, bufsize, "subline timeout value: %d",
121 token->value.i);
122 break;
124 case WPS_TOKEN_CONDITIONAL:
125 snprintf(buf, bufsize, "conditional, %d options",
126 token->value.i);
127 break;
129 case WPS_TOKEN_CONDITIONAL_START:
130 snprintf(buf, bufsize, "conditional start, next cond: %d",
131 token->value.i);
132 break;
134 case WPS_TOKEN_CONDITIONAL_OPTION:
135 snprintf(buf, bufsize, "conditional option, next cond: %d",
136 token->value.i);
137 break;
139 case WPS_TOKEN_CONDITIONAL_END:
140 snprintf(buf, bufsize, "conditional end");
141 break;
143 #ifdef HAVE_LCD_BITMAP
144 case WPS_TOKEN_LIST_TITLE_TEXT:
145 snprintf(buf, bufsize, "list title text");
146 break;
147 case WPS_TOKEN_LIST_TITLE_ICON:
148 snprintf(buf, bufsize, "list title icon");
149 break;
150 case WPS_TOKEN_IMAGE_PRELOAD:
151 snprintf(buf, bufsize, "preload image");
152 break;
154 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
156 char subimage = '\0';
157 char label = token->value.i&0xFF;
158 struct gui_img *img = find_image(label, data);
159 if (img && img->num_subimages > 1)
161 int item = token->value.i>>8;
162 if (item >= 26)
163 subimage = 'A' + item-26;
164 else
165 subimage = 'a' + item;
167 snprintf(buf, bufsize, "display preloaded image '%c%c'",
168 label, subimage);
170 break;
172 case WPS_TOKEN_IMAGE_DISPLAY:
173 snprintf(buf, bufsize, "display image");
174 break;
175 #endif
177 #ifdef HAS_BUTTON_HOLD
178 case WPS_TOKEN_MAIN_HOLD:
179 snprintf(buf, bufsize, "mode hold");
180 break;
181 #endif
183 #ifdef HAS_REMOTE_BUTTON_HOLD
184 case WPS_TOKEN_REMOTE_HOLD:
185 snprintf(buf, bufsize, "mode remote hold");
186 break;
187 #endif
189 case WPS_TOKEN_REPEAT_MODE:
190 snprintf(buf, bufsize, "mode repeat");
191 break;
193 case WPS_TOKEN_PLAYBACK_STATUS:
194 snprintf(buf, bufsize, "mode playback");
195 break;
197 case WPS_TOKEN_RTC_PRESENT:
198 snprintf(buf, bufsize, "rtc: present?");
199 break;
200 case WPS_TOKEN_RTC_DAY_OF_MONTH:
201 snprintf(buf, bufsize, "rtc: day of month (01..31)");
202 break;
203 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
204 snprintf(buf, bufsize,
205 "rtc: day of month, blank padded ( 1..31)");
206 break;
207 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
208 snprintf(buf, bufsize, "rtc: hour (00..23)");
209 break;
210 case WPS_TOKEN_RTC_HOUR_24:
211 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
212 break;
213 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
214 snprintf(buf, bufsize, "rtc: hour (01..12)");
215 break;
216 case WPS_TOKEN_RTC_HOUR_12:
217 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
218 break;
219 case WPS_TOKEN_RTC_MONTH:
220 snprintf(buf, bufsize, "rtc: month (01..12)");
221 break;
222 case WPS_TOKEN_RTC_MINUTE:
223 snprintf(buf, bufsize, "rtc: minute (00..59)");
224 break;
225 case WPS_TOKEN_RTC_SECOND:
226 snprintf(buf, bufsize, "rtc: second (00..59)");
227 break;
228 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
229 snprintf(buf, bufsize,
230 "rtc: last two digits of year (00..99)");
231 break;
232 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
233 snprintf(buf, bufsize, "rtc: year (1970...)");
234 break;
235 case WPS_TOKEN_RTC_AM_PM_UPPER:
236 snprintf(buf, bufsize,
237 "rtc: upper case AM or PM indicator");
238 break;
239 case WPS_TOKEN_RTC_AM_PM_LOWER:
240 snprintf(buf, bufsize,
241 "rtc: lower case am or pm indicator");
242 break;
243 case WPS_TOKEN_RTC_WEEKDAY_NAME:
244 snprintf(buf, bufsize,
245 "rtc: abbreviated weekday name (Sun..Sat)");
246 break;
247 case WPS_TOKEN_RTC_MONTH_NAME:
248 snprintf(buf, bufsize,
249 "rtc: abbreviated month name (Jan..Dec)");
250 break;
251 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
252 snprintf(buf, bufsize,
253 "rtc: day of week (1..7); 1 is Monday");
254 break;
255 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
256 snprintf(buf, bufsize,
257 "rtc: day of week (0..6); 0 is Sunday");
258 break;
260 #if (CONFIG_CODEC == SWCODEC)
261 case WPS_TOKEN_CROSSFADE:
262 snprintf(buf, bufsize, "crossfade");
263 break;
265 case WPS_TOKEN_REPLAYGAIN:
266 snprintf(buf, bufsize, "replaygain");
267 break;
268 #endif
270 #ifdef HAVE_ALBUMART
271 case WPS_TOKEN_ALBUMART_DISPLAY:
272 snprintf(buf, bufsize, "album art display");
273 break;
275 case WPS_TOKEN_ALBUMART_FOUND:
276 snprintf(buf, bufsize, "%strack album art conditional",
277 next_str(next));
278 break;
279 #endif
281 #ifdef HAVE_LCD_BITMAP
282 case WPS_TOKEN_IMAGE_BACKDROP:
283 snprintf(buf, bufsize, "backdrop image");
284 break;
286 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
287 snprintf(buf, bufsize, "progressbar bitmap");
288 break;
290 case WPS_TOKEN_PEAKMETER:
291 snprintf(buf, bufsize, "peakmeter");
292 break;
293 #endif
295 case WPS_TOKEN_PROGRESSBAR:
296 snprintf(buf, bufsize, "progressbar");
297 break;
299 #ifdef HAVE_LCD_CHARCELLS
300 case WPS_TOKEN_PLAYER_PROGRESSBAR:
301 snprintf(buf, bufsize, "full line progressbar");
302 break;
303 #endif
305 case WPS_TOKEN_TRACK_TIME_ELAPSED:
306 snprintf(buf, bufsize, "time elapsed in track");
307 break;
309 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
310 snprintf(buf, bufsize, "played percentage of track");
311 break;
313 case WPS_TOKEN_PLAYLIST_ENTRIES:
314 snprintf(buf, bufsize, "number of entries in playlist");
315 break;
317 case WPS_TOKEN_PLAYLIST_NAME:
318 snprintf(buf, bufsize, "playlist name");
319 break;
321 case WPS_TOKEN_PLAYLIST_POSITION:
322 snprintf(buf, bufsize, "position in playlist");
323 break;
325 case WPS_TOKEN_TRACK_TIME_REMAINING:
326 snprintf(buf, bufsize, "time remaining in track");
327 break;
329 case WPS_TOKEN_PLAYLIST_SHUFFLE:
330 snprintf(buf, bufsize, "playlist shuffle mode");
331 break;
333 case WPS_TOKEN_TRACK_LENGTH:
334 snprintf(buf, bufsize, "track length");
335 break;
337 case WPS_TOKEN_VOLUME:
338 snprintf(buf, bufsize, "volume");
339 break;
341 case WPS_TOKEN_METADATA_ARTIST:
342 snprintf(buf, bufsize, "%strack artist",
343 next_str(next));
344 break;
346 case WPS_TOKEN_METADATA_COMPOSER:
347 snprintf(buf, bufsize, "%strack composer",
348 next_str(next));
349 break;
351 case WPS_TOKEN_METADATA_ALBUM:
352 snprintf(buf, bufsize, "%strack album",
353 next_str(next));
354 break;
356 case WPS_TOKEN_METADATA_GROUPING:
357 snprintf(buf, bufsize, "%strack grouping",
358 next_str(next));
359 break;
361 case WPS_TOKEN_METADATA_GENRE:
362 snprintf(buf, bufsize, "%strack genre",
363 next_str(next));
364 break;
366 case WPS_TOKEN_METADATA_DISC_NUMBER:
367 snprintf(buf, bufsize, "%strack disc", next_str(next));
368 break;
370 case WPS_TOKEN_METADATA_TRACK_NUMBER:
371 snprintf(buf, bufsize, "%strack number",
372 next_str(next));
373 break;
375 case WPS_TOKEN_METADATA_TRACK_TITLE:
376 snprintf(buf, bufsize, "%strack title",
377 next_str(next));
378 break;
380 case WPS_TOKEN_METADATA_VERSION:
381 snprintf(buf, bufsize, "%strack ID3 version",
382 next_str(next));
383 break;
385 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
386 snprintf(buf, bufsize, "%strack album artist",
387 next_str(next));
388 break;
390 case WPS_TOKEN_METADATA_COMMENT:
391 snprintf(buf, bufsize, "%strack comment",
392 next_str(next));
393 break;
395 case WPS_TOKEN_METADATA_YEAR:
396 snprintf(buf, bufsize, "%strack year", next_str(next));
397 break;
399 #ifdef HAVE_TAGCACHE
400 case WPS_TOKEN_DATABASE_PLAYCOUNT:
401 snprintf(buf, bufsize, "track playcount (database)");
402 break;
404 case WPS_TOKEN_DATABASE_RATING:
405 snprintf(buf, bufsize, "track rating (database)");
406 break;
408 case WPS_TOKEN_DATABASE_AUTOSCORE:
409 snprintf(buf, bufsize, "track autoscore (database)");
410 break;
411 #endif
413 case WPS_TOKEN_BATTERY_PERCENT:
414 snprintf(buf, bufsize, "battery percentage");
415 break;
417 case WPS_TOKEN_BATTERY_VOLTS:
418 snprintf(buf, bufsize, "battery voltage");
419 break;
421 case WPS_TOKEN_BATTERY_TIME:
422 snprintf(buf, bufsize, "battery time left");
423 break;
425 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
426 snprintf(buf, bufsize, "battery charger connected");
427 break;
429 case WPS_TOKEN_BATTERY_CHARGING:
430 snprintf(buf, bufsize, "battery charging");
431 break;
433 case WPS_TOKEN_BATTERY_SLEEPTIME:
434 snprintf(buf, bufsize, "sleep timer");
435 break;
437 case WPS_TOKEN_FILE_BITRATE:
438 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
439 break;
441 case WPS_TOKEN_FILE_CODEC:
442 snprintf(buf, bufsize, "%sfile codec", next_str(next));
443 break;
445 case WPS_TOKEN_FILE_FREQUENCY:
446 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
447 next_str(next));
448 break;
450 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
451 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
452 next_str(next));
453 break;
455 case WPS_TOKEN_FILE_NAME:
456 snprintf(buf, bufsize, "%sfile name", next_str(next));
457 break;
459 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
460 snprintf(buf, bufsize, "%sfile name with extension",
461 next_str(next));
462 break;
464 case WPS_TOKEN_FILE_PATH:
465 snprintf(buf, bufsize, "%sfile path", next_str(next));
466 break;
468 case WPS_TOKEN_FILE_SIZE:
469 snprintf(buf, bufsize, "%sfile size", next_str(next));
470 break;
472 case WPS_TOKEN_FILE_VBR:
473 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
474 break;
476 case WPS_TOKEN_FILE_DIRECTORY:
477 snprintf(buf, bufsize, "%sfile directory, level: %d",
478 next_str(next), token->value.i);
479 break;
481 #if (CONFIG_CODEC != MAS3507D)
482 case WPS_TOKEN_SOUND_PITCH:
483 snprintf(buf, bufsize, "pitch value");
484 break;
485 #endif
487 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
488 case WPS_TOKEN_VLED_HDD:
489 snprintf(buf, bufsize, "display virtual HDD LED");
490 break;
491 #endif
492 case WPS_VIEWPORT_ENABLE:
493 snprintf(buf, bufsize, "enable VP: %c",
494 (char)token->value.i);
495 break;
496 case WPS_TOKEN_BUTTON_VOLUME:
497 snprintf(buf, bufsize, "Volume button timeout: %d",
498 token->value.i);
499 break;
500 case WPS_TOKEN_SETTING:
501 snprintf(buf, bufsize, "Setting value: '%s'",
502 settings[token->value.i].cfg_name);
503 break;
504 case WPS_TOKEN_LANG_IS_RTL:
505 snprintf(buf, bufsize, "lang: is_rtl?");
506 break;
508 case WPS_TOKEN_TRACK_STARTING:
509 snprintf(buf, bufsize, "first %d seconds of track", token->value.i);
510 break;
511 case WPS_TOKEN_TRACK_ENDING:
512 snprintf(buf, bufsize, "last %d seconds of track", token->value.i);
513 break;
514 default:
515 for(i=1; i<sizeof(tokens)/sizeof(*token); i++)
517 if (token->type < tokens[i].start_marker)
519 snprintf(buf, bufsize, "FIXME: %s + %d\n", tokens[i-1].desc,
520 token->type - tokens[i-1].start_marker);
521 break;
524 break;
527 return buf;
530 #if defined(SIMULATOR) || defined(__PCTOOL__)
531 static void dump_skin(struct wps_data *data)
533 int indent = 0;
534 char buf[64];
535 int i, j;
537 struct skin_token_list *viewport_list;
538 for (viewport_list = data->viewports;
539 viewport_list; viewport_list = viewport_list->next)
541 struct skin_viewport *skin_viewport =
542 (struct skin_viewport *)viewport_list->token->value.data;
543 indent = 0;
544 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
545 struct skin_line *line;
546 for (line = skin_viewport->lines; line; line = line->next)
548 struct skin_subline *subline;
549 indent = 1;
550 for(subline = &line->sublines; subline; subline = subline->next)
552 DEBUGF(" Subline: tokens %d => %d",
553 subline->first_token_idx,subline->last_token_idx);
554 if (subline->line_type & WPS_REFRESH_SCROLL)
555 DEBUGF(", scrolled");
556 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
557 DEBUGF(", progressbar");
558 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
559 DEBUGF(", peakmeter");
560 DEBUGF("\n");
562 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
564 struct wps_token *token = &data->tokens[i];
565 get_token_desc(token, buf, sizeof(buf), data);
567 switch(token->type)
570 case WPS_TOKEN_CONDITIONAL_START:
571 indent++;
572 break;
574 case WPS_TOKEN_CONDITIONAL_END:
575 indent--;
576 break;
578 default:
579 break;
582 if (wps_verbose_level > 2)
584 for(j = 0; j < indent; j++) {
585 DEBUGF("\t");
588 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
595 #endif
597 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
599 #if defined(SIMULATOR) || defined(__PCTOOL__)
600 if (debug_wps && wps_verbose_level)
602 dump_skin(data);
604 #endif /* SIMULATOR */
606 if (fail != PARSE_OK)
608 char buf[64];
610 DEBUGF("ERR: Failed parsing on line %d : ", line);
611 switch (fail)
613 case PARSE_OK:
614 break;
616 case PARSE_FAIL_UNCLOSED_COND:
617 DEBUGF("ERR: Unclosed conditional");
618 break;
620 case PARSE_FAIL_INVALID_CHAR:
621 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
622 data->num_tokens-1,
623 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
625 break;
627 case PARSE_FAIL_COND_SYNTAX_ERROR:
628 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
629 data->num_tokens-1,
630 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
632 break;
634 case PARSE_FAIL_COND_INVALID_PARAM:
635 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
636 data->num_tokens,
637 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
639 break;
641 case PARSE_FAIL_LIMITS_EXCEEDED:
642 DEBUGF("ERR: Limits exceeded");
643 break;
645 DEBUGF("\n");
649 void debug_skin_usage(void)
651 #if defined(SIMULATOR) || defined(__PCTOOL__)
652 if (wps_verbose_level > 1)
653 #endif
654 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
655 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
658 #endif /* DEBUG || SIMULATOR */