and actually fix multifont on remote lcd targets also
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blobe7277e847cc1c4b6f5866ab32ce810da881437fd
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_IMAGE_PRELOAD:
146 snprintf(buf, bufsize, "preload image");
147 break;
149 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
151 char subimage = '\0';
152 char label = token->value.i&0xFF;
153 struct gui_img *img = find_image(label, data);
154 if (img && img->num_subimages > 1)
155 subimage = 'a' + (token->value.i>>8);
156 snprintf(buf, bufsize, "display preloaded image '%c%c'",
157 label, subimage);
159 break;
161 case WPS_TOKEN_IMAGE_DISPLAY:
162 snprintf(buf, bufsize, "display image");
163 break;
164 #endif
166 #ifdef HAS_BUTTON_HOLD
167 case WPS_TOKEN_MAIN_HOLD:
168 snprintf(buf, bufsize, "mode hold");
169 break;
170 #endif
172 #ifdef HAS_REMOTE_BUTTON_HOLD
173 case WPS_TOKEN_REMOTE_HOLD:
174 snprintf(buf, bufsize, "mode remote hold");
175 break;
176 #endif
178 case WPS_TOKEN_REPEAT_MODE:
179 snprintf(buf, bufsize, "mode repeat");
180 break;
182 case WPS_TOKEN_PLAYBACK_STATUS:
183 snprintf(buf, bufsize, "mode playback");
184 break;
186 case WPS_TOKEN_RTC_PRESENT:
187 snprintf(buf, bufsize, "rtc: present?");
188 break;
189 case WPS_TOKEN_RTC_DAY_OF_MONTH:
190 snprintf(buf, bufsize, "rtc: day of month (01..31)");
191 break;
192 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
193 snprintf(buf, bufsize,
194 "rtc: day of month, blank padded ( 1..31)");
195 break;
196 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
197 snprintf(buf, bufsize, "rtc: hour (00..23)");
198 break;
199 case WPS_TOKEN_RTC_HOUR_24:
200 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
201 break;
202 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
203 snprintf(buf, bufsize, "rtc: hour (01..12)");
204 break;
205 case WPS_TOKEN_RTC_HOUR_12:
206 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
207 break;
208 case WPS_TOKEN_RTC_MONTH:
209 snprintf(buf, bufsize, "rtc: month (01..12)");
210 break;
211 case WPS_TOKEN_RTC_MINUTE:
212 snprintf(buf, bufsize, "rtc: minute (00..59)");
213 break;
214 case WPS_TOKEN_RTC_SECOND:
215 snprintf(buf, bufsize, "rtc: second (00..59)");
216 break;
217 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
218 snprintf(buf, bufsize,
219 "rtc: last two digits of year (00..99)");
220 break;
221 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
222 snprintf(buf, bufsize, "rtc: year (1970...)");
223 break;
224 case WPS_TOKEN_RTC_AM_PM_UPPER:
225 snprintf(buf, bufsize,
226 "rtc: upper case AM or PM indicator");
227 break;
228 case WPS_TOKEN_RTC_AM_PM_LOWER:
229 snprintf(buf, bufsize,
230 "rtc: lower case am or pm indicator");
231 break;
232 case WPS_TOKEN_RTC_WEEKDAY_NAME:
233 snprintf(buf, bufsize,
234 "rtc: abbreviated weekday name (Sun..Sat)");
235 break;
236 case WPS_TOKEN_RTC_MONTH_NAME:
237 snprintf(buf, bufsize,
238 "rtc: abbreviated month name (Jan..Dec)");
239 break;
240 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
241 snprintf(buf, bufsize,
242 "rtc: day of week (1..7); 1 is Monday");
243 break;
244 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
245 snprintf(buf, bufsize,
246 "rtc: day of week (0..6); 0 is Sunday");
247 break;
249 #if (CONFIG_CODEC == SWCODEC)
250 case WPS_TOKEN_CROSSFADE:
251 snprintf(buf, bufsize, "crossfade");
252 break;
254 case WPS_TOKEN_REPLAYGAIN:
255 snprintf(buf, bufsize, "replaygain");
256 break;
257 #endif
259 #ifdef HAVE_ALBUMART
260 case WPS_TOKEN_ALBUMART_DISPLAY:
261 snprintf(buf, bufsize, "album art display");
262 break;
264 case WPS_TOKEN_ALBUMART_FOUND:
265 snprintf(buf, bufsize, "%strack album art conditional",
266 next_str(next));
267 break;
268 #endif
270 #ifdef HAVE_LCD_BITMAP
271 case WPS_TOKEN_IMAGE_BACKDROP:
272 snprintf(buf, bufsize, "backdrop image");
273 break;
275 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
276 snprintf(buf, bufsize, "progressbar bitmap");
277 break;
279 case WPS_TOKEN_PEAKMETER:
280 snprintf(buf, bufsize, "peakmeter");
281 break;
282 #endif
284 case WPS_TOKEN_PROGRESSBAR:
285 snprintf(buf, bufsize, "progressbar");
286 break;
288 #ifdef HAVE_LCD_CHARCELLS
289 case WPS_TOKEN_PLAYER_PROGRESSBAR:
290 snprintf(buf, bufsize, "full line progressbar");
291 break;
292 #endif
294 case WPS_TOKEN_TRACK_TIME_ELAPSED:
295 snprintf(buf, bufsize, "time elapsed in track");
296 break;
298 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
299 snprintf(buf, bufsize, "played percentage of track");
300 break;
302 case WPS_TOKEN_PLAYLIST_ENTRIES:
303 snprintf(buf, bufsize, "number of entries in playlist");
304 break;
306 case WPS_TOKEN_PLAYLIST_NAME:
307 snprintf(buf, bufsize, "playlist name");
308 break;
310 case WPS_TOKEN_PLAYLIST_POSITION:
311 snprintf(buf, bufsize, "position in playlist");
312 break;
314 case WPS_TOKEN_TRACK_TIME_REMAINING:
315 snprintf(buf, bufsize, "time remaining in track");
316 break;
318 case WPS_TOKEN_PLAYLIST_SHUFFLE:
319 snprintf(buf, bufsize, "playlist shuffle mode");
320 break;
322 case WPS_TOKEN_TRACK_LENGTH:
323 snprintf(buf, bufsize, "track length");
324 break;
326 case WPS_TOKEN_VOLUME:
327 snprintf(buf, bufsize, "volume");
328 break;
330 case WPS_TOKEN_METADATA_ARTIST:
331 snprintf(buf, bufsize, "%strack artist",
332 next_str(next));
333 break;
335 case WPS_TOKEN_METADATA_COMPOSER:
336 snprintf(buf, bufsize, "%strack composer",
337 next_str(next));
338 break;
340 case WPS_TOKEN_METADATA_ALBUM:
341 snprintf(buf, bufsize, "%strack album",
342 next_str(next));
343 break;
345 case WPS_TOKEN_METADATA_GROUPING:
346 snprintf(buf, bufsize, "%strack grouping",
347 next_str(next));
348 break;
350 case WPS_TOKEN_METADATA_GENRE:
351 snprintf(buf, bufsize, "%strack genre",
352 next_str(next));
353 break;
355 case WPS_TOKEN_METADATA_DISC_NUMBER:
356 snprintf(buf, bufsize, "%strack disc", next_str(next));
357 break;
359 case WPS_TOKEN_METADATA_TRACK_NUMBER:
360 snprintf(buf, bufsize, "%strack number",
361 next_str(next));
362 break;
364 case WPS_TOKEN_METADATA_TRACK_TITLE:
365 snprintf(buf, bufsize, "%strack title",
366 next_str(next));
367 break;
369 case WPS_TOKEN_METADATA_VERSION:
370 snprintf(buf, bufsize, "%strack ID3 version",
371 next_str(next));
372 break;
374 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
375 snprintf(buf, bufsize, "%strack album artist",
376 next_str(next));
377 break;
379 case WPS_TOKEN_METADATA_COMMENT:
380 snprintf(buf, bufsize, "%strack comment",
381 next_str(next));
382 break;
384 case WPS_TOKEN_METADATA_YEAR:
385 snprintf(buf, bufsize, "%strack year", next_str(next));
386 break;
388 #ifdef HAVE_TAGCACHE
389 case WPS_TOKEN_DATABASE_PLAYCOUNT:
390 snprintf(buf, bufsize, "track playcount (database)");
391 break;
393 case WPS_TOKEN_DATABASE_RATING:
394 snprintf(buf, bufsize, "track rating (database)");
395 break;
397 case WPS_TOKEN_DATABASE_AUTOSCORE:
398 snprintf(buf, bufsize, "track autoscore (database)");
399 break;
400 #endif
402 case WPS_TOKEN_BATTERY_PERCENT:
403 snprintf(buf, bufsize, "battery percentage");
404 break;
406 case WPS_TOKEN_BATTERY_VOLTS:
407 snprintf(buf, bufsize, "battery voltage");
408 break;
410 case WPS_TOKEN_BATTERY_TIME:
411 snprintf(buf, bufsize, "battery time left");
412 break;
414 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
415 snprintf(buf, bufsize, "battery charger connected");
416 break;
418 case WPS_TOKEN_BATTERY_CHARGING:
419 snprintf(buf, bufsize, "battery charging");
420 break;
422 case WPS_TOKEN_BATTERY_SLEEPTIME:
423 snprintf(buf, bufsize, "sleep timer");
424 break;
426 case WPS_TOKEN_FILE_BITRATE:
427 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
428 break;
430 case WPS_TOKEN_FILE_CODEC:
431 snprintf(buf, bufsize, "%sfile codec", next_str(next));
432 break;
434 case WPS_TOKEN_FILE_FREQUENCY:
435 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
436 next_str(next));
437 break;
439 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
440 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
441 next_str(next));
442 break;
444 case WPS_TOKEN_FILE_NAME:
445 snprintf(buf, bufsize, "%sfile name", next_str(next));
446 break;
448 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
449 snprintf(buf, bufsize, "%sfile name with extension",
450 next_str(next));
451 break;
453 case WPS_TOKEN_FILE_PATH:
454 snprintf(buf, bufsize, "%sfile path", next_str(next));
455 break;
457 case WPS_TOKEN_FILE_SIZE:
458 snprintf(buf, bufsize, "%sfile size", next_str(next));
459 break;
461 case WPS_TOKEN_FILE_VBR:
462 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
463 break;
465 case WPS_TOKEN_FILE_DIRECTORY:
466 snprintf(buf, bufsize, "%sfile directory, level: %d",
467 next_str(next), token->value.i);
468 break;
470 #if (CONFIG_CODEC != MAS3507D)
471 case WPS_TOKEN_SOUND_PITCH:
472 snprintf(buf, bufsize, "pitch value");
473 break;
474 #endif
476 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
477 case WPS_TOKEN_VLED_HDD:
478 snprintf(buf, bufsize, "display virtual HDD LED");
479 break;
480 #endif
481 case WPS_VIEWPORT_ENABLE:
482 snprintf(buf, bufsize, "enable VP: %c",
483 (char)token->value.i);
484 break;
485 case WPS_TOKEN_BUTTON_VOLUME:
486 snprintf(buf, bufsize, "Volume button timeout: %d",
487 token->value.i);
488 break;
489 case WPS_TOKEN_SETTING:
490 snprintf(buf, bufsize, "Setting value: '%s'",
491 settings[token->value.i].cfg_name);
492 break;
493 case WPS_TOKEN_LANG_IS_RTL:
494 snprintf(buf, bufsize, "lang: is_rtl?");
495 break;
496 default:
497 for(i=1; i<sizeof(tokens)/sizeof(*token); i++)
499 if (token->type < tokens[i].start_marker)
501 snprintf(buf, bufsize, "FIXME: %s + %d\n", tokens[i-1].desc,
502 token->type - tokens[i-1].start_marker);
503 break;
506 break;
509 return buf;
512 #if defined(SIMULATOR) || defined(__PCTOOL__)
513 static void dump_skin(struct wps_data *data)
515 int indent = 0;
516 char buf[64];
517 int i, j;
519 struct skin_token_list *viewport_list;
520 for (viewport_list = data->viewports;
521 viewport_list; viewport_list = viewport_list->next)
523 struct skin_viewport *skin_viewport =
524 (struct skin_viewport *)viewport_list->token->value.data;
525 indent = 0;
526 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
527 struct skin_line *line;
528 for (line = skin_viewport->lines; line; line = line->next)
530 struct skin_subline *subline;
531 indent = 1;
532 for(subline = &line->sublines; subline; subline = subline->next)
534 DEBUGF(" Subline: tokens %d => %d",
535 subline->first_token_idx,subline->last_token_idx);
536 if (subline->line_type & WPS_REFRESH_SCROLL)
537 DEBUGF(", scrolled");
538 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
539 DEBUGF(", progressbar");
540 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
541 DEBUGF(", peakmeter");
542 DEBUGF("\n");
544 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
546 struct wps_token *token = &data->tokens[i];
547 get_token_desc(token, buf, sizeof(buf), data);
549 switch(token->type)
552 case WPS_TOKEN_CONDITIONAL_START:
553 indent++;
554 break;
556 case WPS_TOKEN_CONDITIONAL_END:
557 indent--;
558 break;
560 default:
561 break;
564 if (wps_verbose_level > 2)
566 for(j = 0; j < indent; j++) {
567 DEBUGF("\t");
570 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
577 #endif
579 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
581 #if defined(SIMULATOR) || defined(__PCTOOL__)
582 if (debug_wps && wps_verbose_level)
584 dump_skin(data);
586 #endif /* SIMULATOR */
588 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
589 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
590 WPS_MAX_TOKENS - 1);
593 if (fail != PARSE_OK)
595 char buf[64];
597 DEBUGF("ERR: Failed parsing on line %d : ", line);
598 switch (fail)
600 case PARSE_OK:
601 break;
603 case PARSE_FAIL_UNCLOSED_COND:
604 DEBUGF("ERR: Unclosed conditional");
605 break;
607 case PARSE_FAIL_INVALID_CHAR:
608 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
609 data->num_tokens-1,
610 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
612 break;
614 case PARSE_FAIL_COND_SYNTAX_ERROR:
615 DEBUGF("ERR: Conditional syntax error 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_INVALID_PARAM:
622 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
623 data->num_tokens,
624 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
626 break;
628 case PARSE_FAIL_LIMITS_EXCEEDED:
629 DEBUGF("ERR: Limits exceeded");
630 break;
632 DEBUGF("\n");
636 void debug_skin_usage(void)
638 #if defined(SIMULATOR) || defined(__PCTOOL__)
639 if (wps_verbose_level > 1)
640 #endif
641 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
642 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
646 #endif /* DEBUG || SIMULATOR */