Use nice quotation marks
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
bloba1ebb837d0b3a18ff642d51bc84ee47eae7d703e
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_TUNER) },
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 case WPS_TOKEN_UIVIEWPORT_ENABLE:
495 snprintf(buf, bufsize, "enable %sVP: %c",
496 token->type == WPS_TOKEN_UIVIEWPORT_ENABLE ? "UI " : "",
497 (char)token->value.i);
498 break;
499 case WPS_TOKEN_BUTTON_VOLUME:
500 snprintf(buf, bufsize, "Volume button timeout: %d",
501 token->value.i);
502 break;
503 case WPS_TOKEN_SETTING:
504 snprintf(buf, bufsize, "Setting value: '%s'",
505 settings[token->value.i].cfg_name);
506 break;
507 case WPS_TOKEN_LANG_IS_RTL:
508 snprintf(buf, bufsize, "lang: is_rtl?");
509 break;
511 case WPS_TOKEN_TRACK_STARTING:
512 snprintf(buf, bufsize, "first %d seconds of track", token->value.i);
513 break;
514 case WPS_TOKEN_TRACK_ENDING:
515 snprintf(buf, bufsize, "last %d seconds of track", token->value.i);
516 break;
517 default:
518 for(i=1; i<sizeof(tokens)/sizeof(*token); i++)
520 if (token->type < tokens[i].start_marker)
522 snprintf(buf, bufsize, "FIXME: %s + %d\n", tokens[i-1].desc,
523 token->type - tokens[i-1].start_marker);
524 break;
527 break;
530 return buf;
533 #if defined(SIMULATOR) || defined(__PCTOOL__)
534 static void dump_skin(struct wps_data *data)
536 int indent = 0;
537 char buf[64];
538 int i, j;
540 struct skin_token_list *viewport_list;
541 for (viewport_list = data->viewports;
542 viewport_list; viewport_list = viewport_list->next)
544 struct skin_viewport *skin_viewport =
545 (struct skin_viewport *)viewport_list->token->value.data;
546 indent = 0;
547 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
548 struct skin_line *line;
549 for (line = skin_viewport->lines; line; line = line->next)
551 struct skin_subline *subline;
552 indent = 1;
553 for(subline = &line->sublines; subline; subline = subline->next)
555 DEBUGF(" Subline: tokens %d => %d",
556 subline->first_token_idx,subline->last_token_idx);
557 if (subline->line_type & WPS_REFRESH_SCROLL)
558 DEBUGF(", scrolled");
559 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
560 DEBUGF(", progressbar");
561 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
562 DEBUGF(", peakmeter");
563 DEBUGF("\n");
565 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
567 struct wps_token *token = &data->tokens[i];
568 get_token_desc(token, buf, sizeof(buf), data);
570 switch(token->type)
573 case WPS_TOKEN_CONDITIONAL_START:
574 indent++;
575 break;
577 case WPS_TOKEN_CONDITIONAL_END:
578 indent--;
579 break;
581 default:
582 break;
585 if (wps_verbose_level > 2)
587 for(j = 0; j < indent; j++) {
588 DEBUGF("\t");
591 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
598 #endif
600 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
602 #if defined(SIMULATOR) || defined(__PCTOOL__)
603 if (debug_wps && wps_verbose_level)
605 dump_skin(data);
607 #endif /* SIMULATOR */
609 if (fail != PARSE_OK)
611 char buf[64];
613 DEBUGF("ERR: Failed parsing on line %d : ", line);
614 switch (fail)
616 case PARSE_OK:
617 break;
619 case PARSE_FAIL_UNCLOSED_COND:
620 DEBUGF("ERR: Unclosed conditional");
621 break;
623 case PARSE_FAIL_INVALID_CHAR:
624 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
625 data->num_tokens-1,
626 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
628 break;
630 case PARSE_FAIL_COND_SYNTAX_ERROR:
631 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
632 data->num_tokens-1,
633 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
635 break;
637 case PARSE_FAIL_COND_INVALID_PARAM:
638 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
639 data->num_tokens,
640 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
642 break;
644 case PARSE_FAIL_LIMITS_EXCEEDED:
645 DEBUGF("ERR: Limits exceeded");
646 break;
648 DEBUGF("\n");
652 void debug_skin_usage(void)
654 #if defined(SIMULATOR) || defined(__PCTOOL__)
655 if (wps_verbose_level > 1)
656 #endif
657 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
658 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
661 #endif /* DEBUG || SIMULATOR */