some small debug info fixes, add %Li and %lt and make uppercase subimage labels displ...
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blob59bc5edc43732cc8dd993b1164310bda5845c27c
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 bool debug_wps;
42 extern int wps_verbose_level;
43 #endif
45 struct debug_token_table
47 enum wps_token_type start_marker;
48 char *desc;
50 #define X(name) name, #name
51 struct debug_token_table tokens[] = {
52 { X(TOKEN_MARKER_CONTROL_TOKENS) },
53 { X(TOKEN_MARKER_BATTERY) },
54 { X(TOKEN_MARKER_SOUND) },
55 { X(TOKEN_MARKER_RTC) },
56 { X(TOKEN_MARKER_DATABASE) },
57 { X(TOKEN_MARKER_FILE) },
58 { X(TOKEN_MARKER_IMAGES) },
59 { X(TOKEN_MARKER_METADATA) },
60 { X(TOKEN_MARKER_PLAYBACK_INFO) },
61 { X(TOKEN_MARKER_PLAYLIST) },
62 { X(TOKEN_MARKER_MISC) },
63 { X(TOKEN_MARKER_RECORDING) },
64 { X(TOKEN_MARKER_END) },
66 #undef X
68 static char *next_str(bool next) {
69 return next ? "next " : "";
72 static char *get_token_desc(struct wps_token *token, char *buf,
73 int bufsize, struct wps_data *data)
75 unsigned i;
76 #ifndef HAVE_LCD_BITMAP
77 (void)data; /* kill charcell warning */
78 #endif
79 bool next = token->next;
80 switch(token->type)
82 case WPS_NO_TOKEN:
83 snprintf(buf, bufsize, "No token");
84 break;
86 case WPS_TOKEN_UNKNOWN:
87 snprintf(buf, bufsize, "Unknown token");
88 break;
90 case WPS_TOKEN_CHARACTER:
91 if (token->value.c == '\n')
92 snprintf(buf, bufsize, "Character '\\n'");
93 else
94 snprintf(buf, bufsize, "Character '%c'",
95 token->value.c);
96 break;
98 case WPS_TOKEN_STRING:
99 snprintf(buf, bufsize, "String '%s'",
100 (char*)token->value.data);
101 break;
102 case WPS_TOKEN_TRANSLATEDSTRING:
103 snprintf(buf, bufsize, "String ID '%d'", token->value.i);
104 break;
106 #ifdef HAVE_LCD_BITMAP
107 case WPS_TOKEN_ALIGN_LEFT:
108 snprintf(buf, bufsize, "align left");
109 break;
111 case WPS_TOKEN_ALIGN_CENTER:
112 snprintf(buf, bufsize, "align center");
113 break;
115 case WPS_TOKEN_ALIGN_RIGHT:
116 snprintf(buf, bufsize, "align right");
117 break;
118 #endif
120 case WPS_TOKEN_SUBLINE_TIMEOUT:
121 snprintf(buf, bufsize, "subline timeout value: %d",
122 token->value.i);
123 break;
125 case WPS_TOKEN_CONDITIONAL:
126 snprintf(buf, bufsize, "conditional, %d options",
127 token->value.i);
128 break;
130 case WPS_TOKEN_CONDITIONAL_START:
131 snprintf(buf, bufsize, "conditional start, next cond: %d",
132 token->value.i);
133 break;
135 case WPS_TOKEN_CONDITIONAL_OPTION:
136 snprintf(buf, bufsize, "conditional option, next cond: %d",
137 token->value.i);
138 break;
140 case WPS_TOKEN_CONDITIONAL_END:
141 snprintf(buf, bufsize, "conditional end");
142 break;
144 #ifdef HAVE_LCD_BITMAP
145 case WPS_TOKEN_LIST_TITLE_TEXT:
146 snprintf(buf, bufsize, "list title text");
147 break;
148 case WPS_TOKEN_LIST_TITLE_ICON:
149 snprintf(buf, bufsize, "list title icon");
150 break;
151 case WPS_TOKEN_IMAGE_PRELOAD:
152 snprintf(buf, bufsize, "preload image");
153 break;
155 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
157 char subimage = '\0';
158 char label = token->value.i&0xFF;
159 struct gui_img *img = find_image(label, data);
160 if (img && img->num_subimages > 1)
162 int item = token->value.i>>8;
163 if (item >= 26)
164 subimage = 'A' + item-26;
165 else
166 subimage = 'a' + item;
168 snprintf(buf, bufsize, "display preloaded image '%c%c'",
169 label, subimage);
171 break;
173 case WPS_TOKEN_IMAGE_DISPLAY:
174 snprintf(buf, bufsize, "display image");
175 break;
176 #endif
178 #ifdef HAS_BUTTON_HOLD
179 case WPS_TOKEN_MAIN_HOLD:
180 snprintf(buf, bufsize, "mode hold");
181 break;
182 #endif
184 #ifdef HAS_REMOTE_BUTTON_HOLD
185 case WPS_TOKEN_REMOTE_HOLD:
186 snprintf(buf, bufsize, "mode remote hold");
187 break;
188 #endif
190 case WPS_TOKEN_REPEAT_MODE:
191 snprintf(buf, bufsize, "mode repeat");
192 break;
194 case WPS_TOKEN_PLAYBACK_STATUS:
195 snprintf(buf, bufsize, "mode playback");
196 break;
198 case WPS_TOKEN_RTC_PRESENT:
199 snprintf(buf, bufsize, "rtc: present?");
200 break;
201 case WPS_TOKEN_RTC_DAY_OF_MONTH:
202 snprintf(buf, bufsize, "rtc: day of month (01..31)");
203 break;
204 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
205 snprintf(buf, bufsize,
206 "rtc: day of month, blank padded ( 1..31)");
207 break;
208 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
209 snprintf(buf, bufsize, "rtc: hour (00..23)");
210 break;
211 case WPS_TOKEN_RTC_HOUR_24:
212 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
213 break;
214 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
215 snprintf(buf, bufsize, "rtc: hour (01..12)");
216 break;
217 case WPS_TOKEN_RTC_HOUR_12:
218 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
219 break;
220 case WPS_TOKEN_RTC_MONTH:
221 snprintf(buf, bufsize, "rtc: month (01..12)");
222 break;
223 case WPS_TOKEN_RTC_MINUTE:
224 snprintf(buf, bufsize, "rtc: minute (00..59)");
225 break;
226 case WPS_TOKEN_RTC_SECOND:
227 snprintf(buf, bufsize, "rtc: second (00..59)");
228 break;
229 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
230 snprintf(buf, bufsize,
231 "rtc: last two digits of year (00..99)");
232 break;
233 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
234 snprintf(buf, bufsize, "rtc: year (1970...)");
235 break;
236 case WPS_TOKEN_RTC_AM_PM_UPPER:
237 snprintf(buf, bufsize,
238 "rtc: upper case AM or PM indicator");
239 break;
240 case WPS_TOKEN_RTC_AM_PM_LOWER:
241 snprintf(buf, bufsize,
242 "rtc: lower case am or pm indicator");
243 break;
244 case WPS_TOKEN_RTC_WEEKDAY_NAME:
245 snprintf(buf, bufsize,
246 "rtc: abbreviated weekday name (Sun..Sat)");
247 break;
248 case WPS_TOKEN_RTC_MONTH_NAME:
249 snprintf(buf, bufsize,
250 "rtc: abbreviated month name (Jan..Dec)");
251 break;
252 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
253 snprintf(buf, bufsize,
254 "rtc: day of week (1..7); 1 is Monday");
255 break;
256 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
257 snprintf(buf, bufsize,
258 "rtc: day of week (0..6); 0 is Sunday");
259 break;
261 #if (CONFIG_CODEC == SWCODEC)
262 case WPS_TOKEN_CROSSFADE:
263 snprintf(buf, bufsize, "crossfade");
264 break;
266 case WPS_TOKEN_REPLAYGAIN:
267 snprintf(buf, bufsize, "replaygain");
268 break;
269 #endif
271 #ifdef HAVE_ALBUMART
272 case WPS_TOKEN_ALBUMART_DISPLAY:
273 snprintf(buf, bufsize, "album art display");
274 break;
276 case WPS_TOKEN_ALBUMART_FOUND:
277 snprintf(buf, bufsize, "%strack album art conditional",
278 next_str(next));
279 break;
280 #endif
282 #ifdef HAVE_LCD_BITMAP
283 case WPS_TOKEN_IMAGE_BACKDROP:
284 snprintf(buf, bufsize, "backdrop image");
285 break;
287 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
288 snprintf(buf, bufsize, "progressbar bitmap");
289 break;
291 case WPS_TOKEN_PEAKMETER:
292 snprintf(buf, bufsize, "peakmeter");
293 break;
294 #endif
296 case WPS_TOKEN_PROGRESSBAR:
297 snprintf(buf, bufsize, "progressbar");
298 break;
300 #ifdef HAVE_LCD_CHARCELLS
301 case WPS_TOKEN_PLAYER_PROGRESSBAR:
302 snprintf(buf, bufsize, "full line progressbar");
303 break;
304 #endif
306 case WPS_TOKEN_TRACK_TIME_ELAPSED:
307 snprintf(buf, bufsize, "time elapsed in track");
308 break;
310 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
311 snprintf(buf, bufsize, "played percentage of track");
312 break;
314 case WPS_TOKEN_PLAYLIST_ENTRIES:
315 snprintf(buf, bufsize, "number of entries in playlist");
316 break;
318 case WPS_TOKEN_PLAYLIST_NAME:
319 snprintf(buf, bufsize, "playlist name");
320 break;
322 case WPS_TOKEN_PLAYLIST_POSITION:
323 snprintf(buf, bufsize, "position in playlist");
324 break;
326 case WPS_TOKEN_TRACK_TIME_REMAINING:
327 snprintf(buf, bufsize, "time remaining in track");
328 break;
330 case WPS_TOKEN_PLAYLIST_SHUFFLE:
331 snprintf(buf, bufsize, "playlist shuffle mode");
332 break;
334 case WPS_TOKEN_TRACK_LENGTH:
335 snprintf(buf, bufsize, "track length");
336 break;
338 case WPS_TOKEN_VOLUME:
339 snprintf(buf, bufsize, "volume");
340 break;
342 case WPS_TOKEN_METADATA_ARTIST:
343 snprintf(buf, bufsize, "%strack artist",
344 next_str(next));
345 break;
347 case WPS_TOKEN_METADATA_COMPOSER:
348 snprintf(buf, bufsize, "%strack composer",
349 next_str(next));
350 break;
352 case WPS_TOKEN_METADATA_ALBUM:
353 snprintf(buf, bufsize, "%strack album",
354 next_str(next));
355 break;
357 case WPS_TOKEN_METADATA_GROUPING:
358 snprintf(buf, bufsize, "%strack grouping",
359 next_str(next));
360 break;
362 case WPS_TOKEN_METADATA_GENRE:
363 snprintf(buf, bufsize, "%strack genre",
364 next_str(next));
365 break;
367 case WPS_TOKEN_METADATA_DISC_NUMBER:
368 snprintf(buf, bufsize, "%strack disc", next_str(next));
369 break;
371 case WPS_TOKEN_METADATA_TRACK_NUMBER:
372 snprintf(buf, bufsize, "%strack number",
373 next_str(next));
374 break;
376 case WPS_TOKEN_METADATA_TRACK_TITLE:
377 snprintf(buf, bufsize, "%strack title",
378 next_str(next));
379 break;
381 case WPS_TOKEN_METADATA_VERSION:
382 snprintf(buf, bufsize, "%strack ID3 version",
383 next_str(next));
384 break;
386 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
387 snprintf(buf, bufsize, "%strack album artist",
388 next_str(next));
389 break;
391 case WPS_TOKEN_METADATA_COMMENT:
392 snprintf(buf, bufsize, "%strack comment",
393 next_str(next));
394 break;
396 case WPS_TOKEN_METADATA_YEAR:
397 snprintf(buf, bufsize, "%strack year", next_str(next));
398 break;
400 #ifdef HAVE_TAGCACHE
401 case WPS_TOKEN_DATABASE_PLAYCOUNT:
402 snprintf(buf, bufsize, "track playcount (database)");
403 break;
405 case WPS_TOKEN_DATABASE_RATING:
406 snprintf(buf, bufsize, "track rating (database)");
407 break;
409 case WPS_TOKEN_DATABASE_AUTOSCORE:
410 snprintf(buf, bufsize, "track autoscore (database)");
411 break;
412 #endif
414 case WPS_TOKEN_BATTERY_PERCENT:
415 snprintf(buf, bufsize, "battery percentage");
416 break;
418 case WPS_TOKEN_BATTERY_VOLTS:
419 snprintf(buf, bufsize, "battery voltage");
420 break;
422 case WPS_TOKEN_BATTERY_TIME:
423 snprintf(buf, bufsize, "battery time left");
424 break;
426 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
427 snprintf(buf, bufsize, "battery charger connected");
428 break;
430 case WPS_TOKEN_BATTERY_CHARGING:
431 snprintf(buf, bufsize, "battery charging");
432 break;
434 case WPS_TOKEN_BATTERY_SLEEPTIME:
435 snprintf(buf, bufsize, "sleep timer");
436 break;
438 case WPS_TOKEN_FILE_BITRATE:
439 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
440 break;
442 case WPS_TOKEN_FILE_CODEC:
443 snprintf(buf, bufsize, "%sfile codec", next_str(next));
444 break;
446 case WPS_TOKEN_FILE_FREQUENCY:
447 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
448 next_str(next));
449 break;
451 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
452 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
453 next_str(next));
454 break;
456 case WPS_TOKEN_FILE_NAME:
457 snprintf(buf, bufsize, "%sfile name", next_str(next));
458 break;
460 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
461 snprintf(buf, bufsize, "%sfile name with extension",
462 next_str(next));
463 break;
465 case WPS_TOKEN_FILE_PATH:
466 snprintf(buf, bufsize, "%sfile path", next_str(next));
467 break;
469 case WPS_TOKEN_FILE_SIZE:
470 snprintf(buf, bufsize, "%sfile size", next_str(next));
471 break;
473 case WPS_TOKEN_FILE_VBR:
474 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
475 break;
477 case WPS_TOKEN_FILE_DIRECTORY:
478 snprintf(buf, bufsize, "%sfile directory, level: %d",
479 next_str(next), token->value.i);
480 break;
482 #if (CONFIG_CODEC != MAS3507D)
483 case WPS_TOKEN_SOUND_PITCH:
484 snprintf(buf, bufsize, "pitch value");
485 break;
486 #endif
488 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
489 case WPS_TOKEN_VLED_HDD:
490 snprintf(buf, bufsize, "display virtual HDD LED");
491 break;
492 #endif
493 case WPS_VIEWPORT_ENABLE:
494 snprintf(buf, bufsize, "enable VP: %c",
495 (char)token->value.i);
496 break;
497 case WPS_TOKEN_BUTTON_VOLUME:
498 snprintf(buf, bufsize, "Volume button timeout: %d",
499 token->value.i);
500 break;
501 case WPS_TOKEN_SETTING:
502 snprintf(buf, bufsize, "Setting value: '%s'",
503 settings[token->value.i].cfg_name);
504 break;
505 case WPS_TOKEN_LANG_IS_RTL:
506 snprintf(buf, bufsize, "lang: is_rtl?");
507 break;
508 default:
509 for(i=1; i<sizeof(tokens)/sizeof(*token); i++)
511 if (token->type < tokens[i].start_marker)
513 snprintf(buf, bufsize, "FIXME: %s + %d\n", tokens[i-1].desc,
514 token->type - tokens[i-1].start_marker);
515 break;
518 break;
521 return buf;
524 #if defined(SIMULATOR) || defined(__PCTOOL__)
525 static void dump_skin(struct wps_data *data)
527 int indent = 0;
528 char buf[64];
529 int i, j;
531 struct skin_token_list *viewport_list;
532 for (viewport_list = data->viewports;
533 viewport_list; viewport_list = viewport_list->next)
535 struct skin_viewport *skin_viewport =
536 (struct skin_viewport *)viewport_list->token->value.data;
537 indent = 0;
538 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
539 struct skin_line *line;
540 for (line = skin_viewport->lines; line; line = line->next)
542 struct skin_subline *subline;
543 indent = 1;
544 for(subline = &line->sublines; subline; subline = subline->next)
546 DEBUGF(" Subline: tokens %d => %d",
547 subline->first_token_idx,subline->last_token_idx);
548 if (subline->line_type & WPS_REFRESH_SCROLL)
549 DEBUGF(", scrolled");
550 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
551 DEBUGF(", progressbar");
552 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
553 DEBUGF(", peakmeter");
554 DEBUGF("\n");
556 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
558 struct wps_token *token = &data->tokens[i];
559 get_token_desc(token, buf, sizeof(buf), data);
561 switch(token->type)
564 case WPS_TOKEN_CONDITIONAL_START:
565 indent++;
566 break;
568 case WPS_TOKEN_CONDITIONAL_END:
569 indent--;
570 break;
572 default:
573 break;
576 if (wps_verbose_level > 2)
578 for(j = 0; j < indent; j++) {
579 DEBUGF("\t");
582 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
589 #endif
591 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
593 #if defined(SIMULATOR) || defined(__PCTOOL__)
594 if (debug_wps && wps_verbose_level)
596 dump_skin(data);
598 #endif /* SIMULATOR */
600 if (fail != PARSE_OK)
602 char buf[64];
604 DEBUGF("ERR: Failed parsing on line %d : ", line);
605 switch (fail)
607 case PARSE_OK:
608 break;
610 case PARSE_FAIL_UNCLOSED_COND:
611 DEBUGF("ERR: Unclosed conditional");
612 break;
614 case PARSE_FAIL_INVALID_CHAR:
615 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
616 data->num_tokens-1,
617 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
619 break;
621 case PARSE_FAIL_COND_SYNTAX_ERROR:
622 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
623 data->num_tokens-1,
624 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
626 break;
628 case PARSE_FAIL_COND_INVALID_PARAM:
629 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
630 data->num_tokens,
631 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
633 break;
635 case PARSE_FAIL_LIMITS_EXCEEDED:
636 DEBUGF("ERR: Limits exceeded");
637 break;
639 DEBUGF("\n");
643 void debug_skin_usage(void)
645 #if defined(SIMULATOR) || defined(__PCTOOL__)
646 if (wps_verbose_level > 1)
647 #endif
648 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
649 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
653 #endif /* DEBUG || SIMULATOR */