skin engine: fix simulator builds
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blob59e8542eff8805500147506712f2b1c6eb10fe86
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 #include "wps.h"
23 #include "wps_internals.h"
25 #ifdef DEBUG_SKIN_ENGINE
27 #include <stdio.h>
28 #include <string.h>
29 #include "skin_buffer.h"
30 #include "settings_list.h"
31 #ifdef __PCTOOL__
32 #ifdef WPSEDITOR
33 #include "proxy.h"
34 #else
35 #define DEBUGF printf
36 #endif
37 #else
38 #include "debug.h"
39 #endif
41 #if defined(SIMULATOR) || defined(__PCTOOL__)
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_TUNER) },
65 { X(TOKEN_MARKER_END) },
67 #undef X
69 static char *next_str(bool next) {
70 return next ? "next " : "";
73 static char *get_token_desc(struct wps_token *token, char *buf,
74 int bufsize, struct wps_data *data)
76 unsigned i;
77 #ifndef HAVE_LCD_BITMAP
78 (void)data; /* kill charcell warning */
79 #endif
80 bool next = token->next;
81 switch(token->type)
83 case WPS_NO_TOKEN:
84 snprintf(buf, bufsize, "No token");
85 break;
87 case WPS_TOKEN_UNKNOWN:
88 snprintf(buf, bufsize, "Unknown token");
89 break;
91 case WPS_TOKEN_CHARACTER:
92 if (token->value.c == '\n')
93 snprintf(buf, bufsize, "Character '\\n'");
94 else
95 snprintf(buf, bufsize, "Character '%c'",
96 token->value.c);
97 break;
99 case WPS_TOKEN_STRING:
100 snprintf(buf, bufsize, "String '%s'",
101 (char*)token->value.data);
102 break;
103 case WPS_TOKEN_TRANSLATEDSTRING:
104 snprintf(buf, bufsize, "String ID '%d'", token->value.i);
105 break;
107 #ifdef HAVE_LCD_BITMAP
108 case WPS_TOKEN_ALIGN_LEFT:
109 snprintf(buf, bufsize, "align left");
110 break;
112 case WPS_TOKEN_ALIGN_CENTER:
113 snprintf(buf, bufsize, "align center");
114 break;
116 case WPS_TOKEN_ALIGN_RIGHT:
117 snprintf(buf, bufsize, "align right");
118 break;
119 #endif
121 case WPS_TOKEN_SUBLINE_TIMEOUT:
122 snprintf(buf, bufsize, "subline timeout value: %d",
123 token->value.i);
124 break;
126 case WPS_TOKEN_CONDITIONAL:
127 snprintf(buf, bufsize, "conditional, %d options",
128 token->value.i);
129 break;
131 case WPS_TOKEN_CONDITIONAL_START:
132 snprintf(buf, bufsize, "conditional start, next cond: %d",
133 token->value.i);
134 break;
136 case WPS_TOKEN_CONDITIONAL_OPTION:
137 snprintf(buf, bufsize, "conditional option, next cond: %d",
138 token->value.i);
139 break;
141 case WPS_TOKEN_CONDITIONAL_END:
142 snprintf(buf, bufsize, "conditional end");
143 break;
145 #ifdef HAVE_LCD_BITMAP
146 case WPS_TOKEN_LIST_TITLE_TEXT:
147 snprintf(buf, bufsize, "list title text");
148 break;
149 case WPS_TOKEN_LIST_TITLE_ICON:
150 snprintf(buf, bufsize, "list title icon");
151 break;
152 case WPS_TOKEN_IMAGE_PRELOAD:
153 snprintf(buf, bufsize, "preload image");
154 break;
156 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
158 char subimage = '\0';
159 char label = token->value.i&0xFF;
160 struct gui_img *img = find_image(label, data);
161 if (img && img->num_subimages > 1)
163 int item = token->value.i>>8;
164 if (item >= 26)
165 subimage = 'A' + item-26;
166 else
167 subimage = 'a' + item;
169 snprintf(buf, bufsize, "display preloaded image '%c%c'",
170 label, subimage);
172 break;
174 case WPS_TOKEN_IMAGE_DISPLAY:
175 snprintf(buf, bufsize, "display image");
176 break;
177 #endif
179 #ifdef HAS_BUTTON_HOLD
180 case WPS_TOKEN_MAIN_HOLD:
181 snprintf(buf, bufsize, "mode hold");
182 break;
183 #endif
185 #ifdef HAS_REMOTE_BUTTON_HOLD
186 case WPS_TOKEN_REMOTE_HOLD:
187 snprintf(buf, bufsize, "mode remote hold");
188 break;
189 #endif
191 case WPS_TOKEN_REPEAT_MODE:
192 snprintf(buf, bufsize, "mode repeat");
193 break;
195 case WPS_TOKEN_PLAYBACK_STATUS:
196 snprintf(buf, bufsize, "mode playback");
197 break;
199 case WPS_TOKEN_RTC_PRESENT:
200 snprintf(buf, bufsize, "rtc: present?");
201 break;
202 case WPS_TOKEN_RTC_DAY_OF_MONTH:
203 snprintf(buf, bufsize, "rtc: day of month (01..31)");
204 break;
205 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
206 snprintf(buf, bufsize,
207 "rtc: day of month, blank padded ( 1..31)");
208 break;
209 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
210 snprintf(buf, bufsize, "rtc: hour (00..23)");
211 break;
212 case WPS_TOKEN_RTC_HOUR_24:
213 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
214 break;
215 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
216 snprintf(buf, bufsize, "rtc: hour (01..12)");
217 break;
218 case WPS_TOKEN_RTC_HOUR_12:
219 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
220 break;
221 case WPS_TOKEN_RTC_MONTH:
222 snprintf(buf, bufsize, "rtc: month (01..12)");
223 break;
224 case WPS_TOKEN_RTC_MINUTE:
225 snprintf(buf, bufsize, "rtc: minute (00..59)");
226 break;
227 case WPS_TOKEN_RTC_SECOND:
228 snprintf(buf, bufsize, "rtc: second (00..59)");
229 break;
230 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
231 snprintf(buf, bufsize,
232 "rtc: last two digits of year (00..99)");
233 break;
234 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
235 snprintf(buf, bufsize, "rtc: year (1970...)");
236 break;
237 case WPS_TOKEN_RTC_AM_PM_UPPER:
238 snprintf(buf, bufsize,
239 "rtc: upper case AM or PM indicator");
240 break;
241 case WPS_TOKEN_RTC_AM_PM_LOWER:
242 snprintf(buf, bufsize,
243 "rtc: lower case am or pm indicator");
244 break;
245 case WPS_TOKEN_RTC_WEEKDAY_NAME:
246 snprintf(buf, bufsize,
247 "rtc: abbreviated weekday name (Sun..Sat)");
248 break;
249 case WPS_TOKEN_RTC_MONTH_NAME:
250 snprintf(buf, bufsize,
251 "rtc: abbreviated month name (Jan..Dec)");
252 break;
253 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
254 snprintf(buf, bufsize,
255 "rtc: day of week (1..7); 1 is Monday");
256 break;
257 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
258 snprintf(buf, bufsize,
259 "rtc: day of week (0..6); 0 is Sunday");
260 break;
262 #if (CONFIG_CODEC == SWCODEC)
263 case WPS_TOKEN_CROSSFADE:
264 snprintf(buf, bufsize, "crossfade");
265 break;
267 case WPS_TOKEN_REPLAYGAIN:
268 snprintf(buf, bufsize, "replaygain");
269 break;
270 #endif
272 #ifdef HAVE_ALBUMART
273 case WPS_TOKEN_ALBUMART_DISPLAY:
274 snprintf(buf, bufsize, "album art display");
275 break;
277 case WPS_TOKEN_ALBUMART_FOUND:
278 snprintf(buf, bufsize, "%strack album art conditional",
279 next_str(next));
280 break;
281 #endif
283 #ifdef HAVE_LCD_BITMAP
284 case WPS_TOKEN_IMAGE_BACKDROP:
285 snprintf(buf, bufsize, "backdrop image");
286 break;
288 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
289 snprintf(buf, bufsize, "progressbar bitmap");
290 break;
292 case WPS_TOKEN_PEAKMETER:
293 snprintf(buf, bufsize, "peakmeter");
294 break;
295 #endif
297 case WPS_TOKEN_PROGRESSBAR:
298 snprintf(buf, bufsize, "progressbar");
299 break;
301 #ifdef HAVE_LCD_CHARCELLS
302 case WPS_TOKEN_PLAYER_PROGRESSBAR:
303 snprintf(buf, bufsize, "full line progressbar");
304 break;
305 #endif
307 case WPS_TOKEN_TRACK_TIME_ELAPSED:
308 snprintf(buf, bufsize, "time elapsed in track");
309 break;
311 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
312 snprintf(buf, bufsize, "played percentage of track");
313 break;
315 case WPS_TOKEN_PLAYLIST_ENTRIES:
316 snprintf(buf, bufsize, "number of entries in playlist");
317 break;
319 case WPS_TOKEN_PLAYLIST_NAME:
320 snprintf(buf, bufsize, "playlist name");
321 break;
323 case WPS_TOKEN_PLAYLIST_POSITION:
324 snprintf(buf, bufsize, "position in playlist");
325 break;
327 case WPS_TOKEN_TRACK_TIME_REMAINING:
328 snprintf(buf, bufsize, "time remaining in track");
329 break;
331 case WPS_TOKEN_PLAYLIST_SHUFFLE:
332 snprintf(buf, bufsize, "playlist shuffle mode");
333 break;
335 case WPS_TOKEN_TRACK_LENGTH:
336 snprintf(buf, bufsize, "track length");
337 break;
339 case WPS_TOKEN_VOLUME:
340 snprintf(buf, bufsize, "volume");
341 break;
343 case WPS_TOKEN_METADATA_ARTIST:
344 snprintf(buf, bufsize, "%strack artist",
345 next_str(next));
346 break;
348 case WPS_TOKEN_METADATA_COMPOSER:
349 snprintf(buf, bufsize, "%strack composer",
350 next_str(next));
351 break;
353 case WPS_TOKEN_METADATA_ALBUM:
354 snprintf(buf, bufsize, "%strack album",
355 next_str(next));
356 break;
358 case WPS_TOKEN_METADATA_GROUPING:
359 snprintf(buf, bufsize, "%strack grouping",
360 next_str(next));
361 break;
363 case WPS_TOKEN_METADATA_GENRE:
364 snprintf(buf, bufsize, "%strack genre",
365 next_str(next));
366 break;
368 case WPS_TOKEN_METADATA_DISC_NUMBER:
369 snprintf(buf, bufsize, "%strack disc", next_str(next));
370 break;
372 case WPS_TOKEN_METADATA_TRACK_NUMBER:
373 snprintf(buf, bufsize, "%strack number",
374 next_str(next));
375 break;
377 case WPS_TOKEN_METADATA_TRACK_TITLE:
378 snprintf(buf, bufsize, "%strack title",
379 next_str(next));
380 break;
382 case WPS_TOKEN_METADATA_VERSION:
383 snprintf(buf, bufsize, "%strack ID3 version",
384 next_str(next));
385 break;
387 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
388 snprintf(buf, bufsize, "%strack album artist",
389 next_str(next));
390 break;
392 case WPS_TOKEN_METADATA_COMMENT:
393 snprintf(buf, bufsize, "%strack comment",
394 next_str(next));
395 break;
397 case WPS_TOKEN_METADATA_YEAR:
398 snprintf(buf, bufsize, "%strack year", next_str(next));
399 break;
401 #ifdef HAVE_TAGCACHE
402 case WPS_TOKEN_DATABASE_PLAYCOUNT:
403 snprintf(buf, bufsize, "track playcount (database)");
404 break;
406 case WPS_TOKEN_DATABASE_RATING:
407 snprintf(buf, bufsize, "track rating (database)");
408 break;
410 case WPS_TOKEN_DATABASE_AUTOSCORE:
411 snprintf(buf, bufsize, "track autoscore (database)");
412 break;
413 #endif
415 case WPS_TOKEN_BATTERY_PERCENT:
416 snprintf(buf, bufsize, "battery percentage");
417 break;
419 case WPS_TOKEN_BATTERY_VOLTS:
420 snprintf(buf, bufsize, "battery voltage");
421 break;
423 case WPS_TOKEN_BATTERY_TIME:
424 snprintf(buf, bufsize, "battery time left");
425 break;
427 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
428 snprintf(buf, bufsize, "battery charger connected");
429 break;
431 case WPS_TOKEN_BATTERY_CHARGING:
432 snprintf(buf, bufsize, "battery charging");
433 break;
435 case WPS_TOKEN_BATTERY_SLEEPTIME:
436 snprintf(buf, bufsize, "sleep timer");
437 break;
439 case WPS_TOKEN_FILE_BITRATE:
440 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
441 break;
443 case WPS_TOKEN_FILE_CODEC:
444 snprintf(buf, bufsize, "%sfile codec", next_str(next));
445 break;
447 case WPS_TOKEN_FILE_FREQUENCY:
448 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
449 next_str(next));
450 break;
452 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
453 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
454 next_str(next));
455 break;
457 case WPS_TOKEN_FILE_NAME:
458 snprintf(buf, bufsize, "%sfile name", next_str(next));
459 break;
461 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
462 snprintf(buf, bufsize, "%sfile name with extension",
463 next_str(next));
464 break;
466 case WPS_TOKEN_FILE_PATH:
467 snprintf(buf, bufsize, "%sfile path", next_str(next));
468 break;
470 case WPS_TOKEN_FILE_SIZE:
471 snprintf(buf, bufsize, "%sfile size", next_str(next));
472 break;
474 case WPS_TOKEN_FILE_VBR:
475 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
476 break;
478 case WPS_TOKEN_FILE_DIRECTORY:
479 snprintf(buf, bufsize, "%sfile directory, level: %d",
480 next_str(next), token->value.i);
481 break;
483 #if (CONFIG_CODEC != MAS3507D)
484 case WPS_TOKEN_SOUND_PITCH:
485 snprintf(buf, bufsize, "pitch value");
486 break;
487 #endif
489 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
490 case WPS_TOKEN_VLED_HDD:
491 snprintf(buf, bufsize, "display virtual HDD LED");
492 break;
493 #endif
494 case WPS_VIEWPORT_ENABLE:
495 case WPS_TOKEN_UIVIEWPORT_ENABLE:
496 snprintf(buf, bufsize, "enable %sVP: %c",
497 token->type == WPS_TOKEN_UIVIEWPORT_ENABLE ? "UI " : "",
498 (char)token->value.i);
499 break;
500 case WPS_TOKEN_BUTTON_VOLUME:
501 snprintf(buf, bufsize, "Volume button timeout: %d",
502 token->value.i);
503 break;
504 case WPS_TOKEN_SETTING:
505 snprintf(buf, bufsize, "Setting value: '%s'",
506 settings[token->value.i].cfg_name);
507 break;
508 case WPS_TOKEN_LANG_IS_RTL:
509 snprintf(buf, bufsize, "lang: is_rtl?");
510 break;
512 case WPS_TOKEN_TRACK_STARTING:
513 snprintf(buf, bufsize, "first %d seconds of track", token->value.i);
514 break;
515 case WPS_TOKEN_TRACK_ENDING:
516 snprintf(buf, bufsize, "last %d seconds of track", token->value.i);
517 break;
518 default:
519 for(i=1; i<sizeof(tokens)/sizeof(*token); i++)
521 if (token->type < tokens[i].start_marker)
523 snprintf(buf, bufsize, "FIXME: %s + %d\n", tokens[i-1].desc,
524 token->type - tokens[i-1].start_marker);
525 break;
528 break;
531 return buf;
534 #if defined(SIMULATOR) || defined(__PCTOOL__)
535 static void dump_skin(struct wps_data *data)
537 int indent = 0;
538 char buf[64];
539 int i, j;
541 struct skin_token_list *viewport_list;
542 for (viewport_list = data->viewports;
543 viewport_list; viewport_list = viewport_list->next)
545 struct skin_viewport *skin_viewport =
546 (struct skin_viewport *)viewport_list->token->value.data;
547 indent = 0;
548 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
549 struct skin_line *line;
550 for (line = skin_viewport->lines; line; line = line->next)
552 struct skin_subline *subline;
553 indent = 1;
554 for(subline = &line->sublines; subline; subline = subline->next)
556 DEBUGF(" Subline: tokens %d => %d",
557 subline->first_token_idx,subline->last_token_idx);
558 if (subline->line_type & WPS_REFRESH_SCROLL)
559 DEBUGF(", scrolled");
560 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
561 DEBUGF(", progressbar");
562 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
563 DEBUGF(", peakmeter");
564 DEBUGF("\n");
566 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
568 struct wps_token *token = &data->tokens[i];
569 get_token_desc(token, buf, sizeof(buf), data);
571 switch(token->type)
574 case WPS_TOKEN_CONDITIONAL_START:
575 indent++;
576 break;
578 case WPS_TOKEN_CONDITIONAL_END:
579 indent--;
580 break;
582 default:
583 break;
586 if (wps_verbose_level > 2)
588 for(j = 0; j < indent; j++) {
589 DEBUGF("\t");
592 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
599 #endif
601 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
603 #if defined(SIMULATOR) || defined(__PCTOOL__)
604 if (debug_wps && wps_verbose_level)
606 dump_skin(data);
608 #endif /* SIMULATOR */
610 if (fail != PARSE_OK)
612 char buf[64];
614 DEBUGF("ERR: Failed parsing on line %d : ", line);
615 switch (fail)
617 case PARSE_OK:
618 break;
620 case PARSE_FAIL_UNCLOSED_COND:
621 DEBUGF("ERR: Unclosed conditional");
622 break;
624 case PARSE_FAIL_INVALID_CHAR:
625 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
626 data->num_tokens-1,
627 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
629 break;
631 case PARSE_FAIL_COND_SYNTAX_ERROR:
632 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
633 data->num_tokens-1,
634 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
636 break;
638 case PARSE_FAIL_COND_INVALID_PARAM:
639 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
640 data->num_tokens,
641 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
643 break;
645 case PARSE_FAIL_LIMITS_EXCEEDED:
646 DEBUGF("ERR: Limits exceeded");
647 break;
649 DEBUGF("\n");
653 void debug_skin_usage(void)
655 #if defined(SIMULATOR) || defined(__PCTOOL__)
656 if (wps_verbose_level > 1)
657 #endif
658 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
659 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
662 #endif /* DEBUG || SIMULATOR */