get the skin debug output working again, add a line to say how much of the buffer...
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blobb42da6b3153fb7b76478aa6ca967810e2d202687
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 #ifdef __PCTOOL__
30 #ifdef WPSEDITOR
31 #include "proxy.h"
32 #else
33 #define DEBUGF printf
34 #endif
35 #else
36 #include "debug.h"
37 #endif
39 #if defined(SIMULATOR) || defined(__PCTOOL__)
40 extern bool debug_wps;
41 extern int wps_verbose_level;
42 #endif
44 static char *next_str(bool next) {
45 return next ? "next " : "";
48 static char *get_token_desc(struct wps_token *token, char *buf, int bufsize)
50 bool next = token->next;
52 switch(token->type)
54 case WPS_NO_TOKEN:
55 snprintf(buf, bufsize, "No token");
56 break;
58 case WPS_TOKEN_UNKNOWN:
59 snprintf(buf, bufsize, "Unknown token");
60 break;
62 case WPS_TOKEN_CHARACTER:
63 snprintf(buf, bufsize, "Character '%c'",
64 token->value.c);
65 break;
67 case WPS_TOKEN_STRING:
68 snprintf(buf, bufsize, "String '%s'",
69 (char*)token->value.data);
70 break;
72 #ifdef HAVE_LCD_BITMAP
73 case WPS_TOKEN_ALIGN_LEFT:
74 snprintf(buf, bufsize, "align left");
75 break;
77 case WPS_TOKEN_ALIGN_CENTER:
78 snprintf(buf, bufsize, "align center");
79 break;
81 case WPS_TOKEN_ALIGN_RIGHT:
82 snprintf(buf, bufsize, "align right");
83 break;
84 #endif
86 case WPS_TOKEN_SUBLINE_TIMEOUT:
87 snprintf(buf, bufsize, "subline timeout value: %d",
88 token->value.i);
89 break;
91 case WPS_TOKEN_CONDITIONAL:
92 snprintf(buf, bufsize, "conditional, %d options",
93 token->value.i);
94 break;
96 case WPS_TOKEN_CONDITIONAL_START:
97 snprintf(buf, bufsize, "conditional start, next cond: %d",
98 token->value.i);
99 break;
101 case WPS_TOKEN_CONDITIONAL_OPTION:
102 snprintf(buf, bufsize, "conditional option, next cond: %d",
103 token->value.i);
104 break;
106 case WPS_TOKEN_CONDITIONAL_END:
107 snprintf(buf, bufsize, "conditional end");
108 break;
110 #ifdef HAVE_LCD_BITMAP
111 case WPS_TOKEN_IMAGE_PRELOAD:
112 snprintf(buf, bufsize, "preload image");
113 break;
115 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
116 snprintf(buf, bufsize, "display preloaded image '%c'",
117 token->value.i&0xFF);
118 break;
120 case WPS_TOKEN_IMAGE_DISPLAY:
121 snprintf(buf, bufsize, "display image");
122 break;
123 #endif
125 #ifdef HAS_BUTTON_HOLD
126 case WPS_TOKEN_MAIN_HOLD:
127 snprintf(buf, bufsize, "mode hold");
128 break;
129 #endif
131 #ifdef HAS_REMOTE_BUTTON_HOLD
132 case WPS_TOKEN_REMOTE_HOLD:
133 snprintf(buf, bufsize, "mode remote hold");
134 break;
135 #endif
137 case WPS_TOKEN_REPEAT_MODE:
138 snprintf(buf, bufsize, "mode repeat");
139 break;
141 case WPS_TOKEN_PLAYBACK_STATUS:
142 snprintf(buf, bufsize, "mode playback");
143 break;
145 case WPS_TOKEN_RTC_DAY_OF_MONTH:
146 snprintf(buf, bufsize, "rtc: day of month (01..31)");
147 break;
148 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
149 snprintf(buf, bufsize,
150 "rtc: day of month, blank padded ( 1..31)");
151 break;
152 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
153 snprintf(buf, bufsize, "rtc: hour (00..23)");
154 break;
155 case WPS_TOKEN_RTC_HOUR_24:
156 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
157 break;
158 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
159 snprintf(buf, bufsize, "rtc: hour (01..12)");
160 break;
161 case WPS_TOKEN_RTC_HOUR_12:
162 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
163 break;
164 case WPS_TOKEN_RTC_MONTH:
165 snprintf(buf, bufsize, "rtc: month (01..12)");
166 break;
167 case WPS_TOKEN_RTC_MINUTE:
168 snprintf(buf, bufsize, "rtc: minute (00..59)");
169 break;
170 case WPS_TOKEN_RTC_SECOND:
171 snprintf(buf, bufsize, "rtc: second (00..59)");
172 break;
173 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
174 snprintf(buf, bufsize,
175 "rtc: last two digits of year (00..99)");
176 break;
177 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
178 snprintf(buf, bufsize, "rtc: year (1970...)");
179 break;
180 case WPS_TOKEN_RTC_AM_PM_UPPER:
181 snprintf(buf, bufsize,
182 "rtc: upper case AM or PM indicator");
183 break;
184 case WPS_TOKEN_RTC_AM_PM_LOWER:
185 snprintf(buf, bufsize,
186 "rtc: lower case am or pm indicator");
187 break;
188 case WPS_TOKEN_RTC_WEEKDAY_NAME:
189 snprintf(buf, bufsize,
190 "rtc: abbreviated weekday name (Sun..Sat)");
191 break;
192 case WPS_TOKEN_RTC_MONTH_NAME:
193 snprintf(buf, bufsize,
194 "rtc: abbreviated month name (Jan..Dec)");
195 break;
196 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
197 snprintf(buf, bufsize,
198 "rtc: day of week (1..7); 1 is Monday");
199 break;
200 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
201 snprintf(buf, bufsize,
202 "rtc: day of week (0..6); 0 is Sunday");
203 break;
205 #if (CONFIG_CODEC == SWCODEC)
206 case WPS_TOKEN_CROSSFADE:
207 snprintf(buf, bufsize, "crossfade");
208 break;
210 case WPS_TOKEN_REPLAYGAIN:
211 snprintf(buf, bufsize, "replaygain");
212 break;
213 #endif
215 #ifdef HAVE_ALBUMART
216 case WPS_TOKEN_ALBUMART_DISPLAY:
217 snprintf(buf, bufsize, "album art display");
218 break;
220 case WPS_TOKEN_ALBUMART_FOUND:
221 snprintf(buf, bufsize, "%strack album art conditional",
222 next_str(next));
223 break;
224 #endif
226 #ifdef HAVE_LCD_BITMAP
227 case WPS_TOKEN_IMAGE_BACKDROP:
228 snprintf(buf, bufsize, "backdrop image");
229 break;
231 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
232 snprintf(buf, bufsize, "progressbar bitmap");
233 break;
235 case WPS_TOKEN_PEAKMETER:
236 snprintf(buf, bufsize, "peakmeter");
237 break;
238 #endif
240 case WPS_TOKEN_PROGRESSBAR:
241 snprintf(buf, bufsize, "progressbar");
242 break;
244 #ifdef HAVE_LCD_CHARCELLS
245 case WPS_TOKEN_PLAYER_PROGRESSBAR:
246 snprintf(buf, bufsize, "full line progressbar");
247 break;
248 #endif
250 case WPS_TOKEN_TRACK_TIME_ELAPSED:
251 snprintf(buf, bufsize, "time elapsed in track");
252 break;
254 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
255 snprintf(buf, bufsize, "played percentage of track");
256 break;
258 case WPS_TOKEN_PLAYLIST_ENTRIES:
259 snprintf(buf, bufsize, "number of entries in playlist");
260 break;
262 case WPS_TOKEN_PLAYLIST_NAME:
263 snprintf(buf, bufsize, "playlist name");
264 break;
266 case WPS_TOKEN_PLAYLIST_POSITION:
267 snprintf(buf, bufsize, "position in playlist");
268 break;
270 case WPS_TOKEN_TRACK_TIME_REMAINING:
271 snprintf(buf, bufsize, "time remaining in track");
272 break;
274 case WPS_TOKEN_PLAYLIST_SHUFFLE:
275 snprintf(buf, bufsize, "playlist shuffle mode");
276 break;
278 case WPS_TOKEN_TRACK_LENGTH:
279 snprintf(buf, bufsize, "track length");
280 break;
282 case WPS_TOKEN_VOLUME:
283 snprintf(buf, bufsize, "volume");
284 break;
286 case WPS_TOKEN_METADATA_ARTIST:
287 snprintf(buf, bufsize, "%strack artist",
288 next_str(next));
289 break;
291 case WPS_TOKEN_METADATA_COMPOSER:
292 snprintf(buf, bufsize, "%strack composer",
293 next_str(next));
294 break;
296 case WPS_TOKEN_METADATA_ALBUM:
297 snprintf(buf, bufsize, "%strack album",
298 next_str(next));
299 break;
301 case WPS_TOKEN_METADATA_GROUPING:
302 snprintf(buf, bufsize, "%strack grouping",
303 next_str(next));
304 break;
306 case WPS_TOKEN_METADATA_GENRE:
307 snprintf(buf, bufsize, "%strack genre",
308 next_str(next));
309 break;
311 case WPS_TOKEN_METADATA_DISC_NUMBER:
312 snprintf(buf, bufsize, "%strack disc", next_str(next));
313 break;
315 case WPS_TOKEN_METADATA_TRACK_NUMBER:
316 snprintf(buf, bufsize, "%strack number",
317 next_str(next));
318 break;
320 case WPS_TOKEN_METADATA_TRACK_TITLE:
321 snprintf(buf, bufsize, "%strack title",
322 next_str(next));
323 break;
325 case WPS_TOKEN_METADATA_VERSION:
326 snprintf(buf, bufsize, "%strack ID3 version",
327 next_str(next));
328 break;
330 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
331 snprintf(buf, bufsize, "%strack album artist",
332 next_str(next));
333 break;
335 case WPS_TOKEN_METADATA_COMMENT:
336 snprintf(buf, bufsize, "%strack comment",
337 next_str(next));
338 break;
340 case WPS_TOKEN_METADATA_YEAR:
341 snprintf(buf, bufsize, "%strack year", next_str(next));
342 break;
344 #ifdef HAVE_TAGCACHE
345 case WPS_TOKEN_DATABASE_PLAYCOUNT:
346 snprintf(buf, bufsize, "track playcount (database)");
347 break;
349 case WPS_TOKEN_DATABASE_RATING:
350 snprintf(buf, bufsize, "track rating (database)");
351 break;
353 case WPS_TOKEN_DATABASE_AUTOSCORE:
354 snprintf(buf, bufsize, "track autoscore (database)");
355 break;
356 #endif
358 case WPS_TOKEN_BATTERY_PERCENT:
359 snprintf(buf, bufsize, "battery percentage");
360 break;
362 case WPS_TOKEN_BATTERY_VOLTS:
363 snprintf(buf, bufsize, "battery voltage");
364 break;
366 case WPS_TOKEN_BATTERY_TIME:
367 snprintf(buf, bufsize, "battery time left");
368 break;
370 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
371 snprintf(buf, bufsize, "battery charger connected");
372 break;
374 case WPS_TOKEN_BATTERY_CHARGING:
375 snprintf(buf, bufsize, "battery charging");
376 break;
378 case WPS_TOKEN_BATTERY_SLEEPTIME:
379 snprintf(buf, bufsize, "sleep timer");
380 break;
382 case WPS_TOKEN_FILE_BITRATE:
383 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
384 break;
386 case WPS_TOKEN_FILE_CODEC:
387 snprintf(buf, bufsize, "%sfile codec", next_str(next));
388 break;
390 case WPS_TOKEN_FILE_FREQUENCY:
391 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
392 next_str(next));
393 break;
395 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
396 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
397 next_str(next));
398 break;
400 case WPS_TOKEN_FILE_NAME:
401 snprintf(buf, bufsize, "%sfile name", next_str(next));
402 break;
404 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
405 snprintf(buf, bufsize, "%sfile name with extension",
406 next_str(next));
407 break;
409 case WPS_TOKEN_FILE_PATH:
410 snprintf(buf, bufsize, "%sfile path", next_str(next));
411 break;
413 case WPS_TOKEN_FILE_SIZE:
414 snprintf(buf, bufsize, "%sfile size", next_str(next));
415 break;
417 case WPS_TOKEN_FILE_VBR:
418 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
419 break;
421 case WPS_TOKEN_FILE_DIRECTORY:
422 snprintf(buf, bufsize, "%sfile directory, level: %d",
423 next_str(next), token->value.i);
424 break;
426 #if (CONFIG_CODEC != MAS3507D)
427 case WPS_TOKEN_SOUND_PITCH:
428 snprintf(buf, bufsize, "pitch value");
429 break;
430 #endif
431 case WPS_VIEWPORT_ENABLE:
432 snprintf(buf, bufsize, "enable VP:%d",
433 token->value.i);
434 break;
435 case WPS_TOKEN_BUTTON_VOLUME:
436 snprintf(buf, bufsize, "Volume button timeout:%d",
437 token->value.i);
438 break;
439 default:
440 snprintf(buf, bufsize, "FIXME (code: %d)",
441 token->type);
442 break;
445 return buf;
448 #if defined(SIMULATOR) || defined(__PCTOOL__)
449 static void dump_wps_tokens(struct wps_data *data)
451 struct wps_token *token;
452 int i, j;
453 int indent = 0;
454 char buf[64];
456 /* Dump parsed WPS */
457 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++)
459 get_token_desc(token, buf, sizeof(buf));
461 switch(token->type)
464 case WPS_TOKEN_CONDITIONAL_START:
465 indent++;
466 break;
468 case WPS_TOKEN_CONDITIONAL_END:
469 indent--;
470 break;
472 default:
473 break;
476 if (wps_verbose_level > 2)
478 for(j = 0; j < indent; j++) {
479 DEBUGF("\t");
482 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
487 static void print_line_info(struct wps_data *data)
489 int i, j;
490 struct wps_line *line;
491 struct wps_subline *subline;
492 if (wps_verbose_level > 0)
494 struct skin_token_list *viewport_list;
495 for (viewport_list = data->viewports;
496 viewport_list; viewport_list = viewport_list->next)
498 struct skin_viewport *v =
499 (struct skin_viewport *)viewport_list->token->value.data;
500 DEBUGF("vp Label:'%c' Hidden flags:%x\n", v->label, v->hidden_flags);
501 DEBUGF(" First line: %d\n", v->first_line);
502 DEBUGF(" Last line: %d\n", v->last_line);
504 DEBUGF("Number of sublines : %d\n", data->num_sublines);
505 DEBUGF("Number of tokens : %d\n", data->num_tokens);
506 DEBUGF("\n");
509 if (wps_verbose_level > 1)
511 struct skin_token_list *viewport_list;
512 for (viewport_list = data->viewports;
513 viewport_list; viewport_list = viewport_list->next)
515 struct skin_viewport *v =
516 (struct skin_viewport *)viewport_list->token->value.data;
517 DEBUGF("Viewport '%c' - +%d+%d (%dx%d)\n",v->label, v->vp.x, v->vp.y,
518 v->vp.width, v->vp.height);
519 for (i = v->first_line, line = &data->lines[v->first_line]; i <= v->last_line; i++,line++)
521 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
522 i, line->num_sublines, line->first_subline_idx);
524 for (j = 0, subline = data->sublines + line->first_subline_idx;
525 j < line->num_sublines; j++, subline++)
527 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
528 j, subline->first_token_idx,
529 skin_last_token_index(data, i, j));
531 if (subline->line_type & WPS_REFRESH_SCROLL)
532 DEBUGF(", scrolled");
533 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
534 DEBUGF(", progressbar");
535 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
536 DEBUGF(", peakmeter");
538 DEBUGF("\n");
543 DEBUGF("\n");
546 #endif
548 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
550 #if defined(SIMULATOR) || defined(__PCTOOL__)
551 if (debug_wps && wps_verbose_level)
553 dump_wps_tokens(data);
554 print_line_info(data);
556 #endif /* SIMULATOR */
558 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
559 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
560 WPS_MAX_TOKENS - 1);
563 if (fail != PARSE_OK)
565 char buf[64];
567 DEBUGF("ERR: Failed parsing on line %d : ", line);
568 switch (fail)
570 case PARSE_OK:
571 break;
573 case PARSE_FAIL_UNCLOSED_COND:
574 DEBUGF("ERR: Unclosed conditional");
575 break;
577 case PARSE_FAIL_INVALID_CHAR:
578 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
579 data->num_tokens-1,
580 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf))
582 break;
584 case PARSE_FAIL_COND_SYNTAX_ERROR:
585 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
586 data->num_tokens-1,
587 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf))
589 break;
591 case PARSE_FAIL_COND_INVALID_PARAM:
592 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
593 data->num_tokens,
594 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf))
596 break;
598 case PARSE_FAIL_LIMITS_EXCEEDED:
599 DEBUGF("ERR: Limits exceeded");
600 break;
602 DEBUGF("\n");
606 void debug_skin_usage(void)
608 if (wps_verbose_level > 1)
609 DEBUGF("Skin buffer usage: %ld/%ld\n", skin_buffer_usage(),
610 skin_buffer_usage() + skin_buffer_freespace());
614 #endif /* DEBUG || SIMULATOR */