FS#10365 - Optional debug output for albumart.c
[kugel-rb.git] / apps / gui / wps_debug.c
blob727d9078c685fb7d15519263365f1e355cdad852
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 "gwps.h"
27 #ifdef __PCTOOL__
28 #ifdef WPSEDITOR
29 #include "proxy.h"
30 #else
31 #define DEBUGF printf
32 #endif
33 #else
34 #include "debug.h"
35 #endif
37 #if defined(SIMULATOR) || defined(__PCTOOL__)
38 extern bool debug_wps;
39 extern int wps_verbose_level;
40 #endif
42 static char *next_str(bool next) {
43 return next ? "next " : "";
46 static char *get_token_desc(struct wps_token *token, struct wps_data *data,
47 char *buf, int bufsize)
49 bool next = token->next;
51 switch(token->type)
53 case WPS_NO_TOKEN:
54 snprintf(buf, bufsize, "No token");
55 break;
57 case WPS_TOKEN_UNKNOWN:
58 snprintf(buf, bufsize, "Unknown token");
59 break;
61 case WPS_TOKEN_CHARACTER:
62 snprintf(buf, bufsize, "Character '%c'",
63 token->value.c);
64 break;
66 case WPS_TOKEN_STRING:
67 snprintf(buf, bufsize, "String '%s'",
68 data->strings[token->value.i]);
69 break;
71 #ifdef HAVE_LCD_BITMAP
72 case WPS_TOKEN_ALIGN_LEFT:
73 snprintf(buf, bufsize, "align left");
74 break;
76 case WPS_TOKEN_ALIGN_CENTER:
77 snprintf(buf, bufsize, "align center");
78 break;
80 case WPS_TOKEN_ALIGN_RIGHT:
81 snprintf(buf, bufsize, "align right");
82 break;
83 #endif
85 case WPS_TOKEN_SUBLINE_TIMEOUT:
86 snprintf(buf, bufsize, "subline timeout value: %d",
87 token->value.i);
88 break;
90 case WPS_TOKEN_CONDITIONAL:
91 snprintf(buf, bufsize, "conditional, %d options",
92 token->value.i);
93 break;
95 case WPS_TOKEN_CONDITIONAL_START:
96 snprintf(buf, bufsize, "conditional start, next cond: %d",
97 token->value.i);
98 break;
100 case WPS_TOKEN_CONDITIONAL_OPTION:
101 snprintf(buf, bufsize, "conditional option, next cond: %d",
102 token->value.i);
103 break;
105 case WPS_TOKEN_CONDITIONAL_END:
106 snprintf(buf, bufsize, "conditional end");
107 break;
109 #ifdef HAVE_LCD_BITMAP
110 case WPS_TOKEN_IMAGE_PRELOAD:
111 snprintf(buf, bufsize, "preload image");
112 break;
114 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
115 snprintf(buf, bufsize, "display preloaded image %d",
116 token->value.i);
117 break;
119 case WPS_TOKEN_IMAGE_DISPLAY:
120 snprintf(buf, bufsize, "display image");
121 break;
122 #endif
124 #ifdef HAS_BUTTON_HOLD
125 case WPS_TOKEN_MAIN_HOLD:
126 snprintf(buf, bufsize, "mode hold");
127 break;
128 #endif
130 #ifdef HAS_REMOTE_BUTTON_HOLD
131 case WPS_TOKEN_REMOTE_HOLD:
132 snprintf(buf, bufsize, "mode remote hold");
133 break;
134 #endif
136 case WPS_TOKEN_REPEAT_MODE:
137 snprintf(buf, bufsize, "mode repeat");
138 break;
140 case WPS_TOKEN_PLAYBACK_STATUS:
141 snprintf(buf, bufsize, "mode playback");
142 break;
144 case WPS_TOKEN_RTC_DAY_OF_MONTH:
145 snprintf(buf, bufsize, "rtc: day of month (01..31)");
146 break;
147 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
148 snprintf(buf, bufsize,
149 "rtc: day of month, blank padded ( 1..31)");
150 break;
151 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
152 snprintf(buf, bufsize, "rtc: hour (00..23)");
153 break;
154 case WPS_TOKEN_RTC_HOUR_24:
155 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
156 break;
157 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
158 snprintf(buf, bufsize, "rtc: hour (01..12)");
159 break;
160 case WPS_TOKEN_RTC_HOUR_12:
161 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
162 break;
163 case WPS_TOKEN_RTC_MONTH:
164 snprintf(buf, bufsize, "rtc: month (01..12)");
165 break;
166 case WPS_TOKEN_RTC_MINUTE:
167 snprintf(buf, bufsize, "rtc: minute (00..59)");
168 break;
169 case WPS_TOKEN_RTC_SECOND:
170 snprintf(buf, bufsize, "rtc: second (00..59)");
171 break;
172 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
173 snprintf(buf, bufsize,
174 "rtc: last two digits of year (00..99)");
175 break;
176 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
177 snprintf(buf, bufsize, "rtc: year (1970...)");
178 break;
179 case WPS_TOKEN_RTC_AM_PM_UPPER:
180 snprintf(buf, bufsize,
181 "rtc: upper case AM or PM indicator");
182 break;
183 case WPS_TOKEN_RTC_AM_PM_LOWER:
184 snprintf(buf, bufsize,
185 "rtc: lower case am or pm indicator");
186 break;
187 case WPS_TOKEN_RTC_WEEKDAY_NAME:
188 snprintf(buf, bufsize,
189 "rtc: abbreviated weekday name (Sun..Sat)");
190 break;
191 case WPS_TOKEN_RTC_MONTH_NAME:
192 snprintf(buf, bufsize,
193 "rtc: abbreviated month name (Jan..Dec)");
194 break;
195 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
196 snprintf(buf, bufsize,
197 "rtc: day of week (1..7); 1 is Monday");
198 break;
199 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
200 snprintf(buf, bufsize,
201 "rtc: day of week (0..6); 0 is Sunday");
202 break;
204 #if (CONFIG_CODEC == SWCODEC)
205 case WPS_TOKEN_CROSSFADE:
206 snprintf(buf, bufsize, "crossfade");
207 break;
209 case WPS_TOKEN_REPLAYGAIN:
210 snprintf(buf, bufsize, "replaygain");
211 break;
212 #endif
214 #ifdef HAVE_ALBUMART
215 case WPS_TOKEN_ALBUMART_DISPLAY:
216 snprintf(buf, bufsize, "album art display");
217 break;
219 case WPS_TOKEN_ALBUMART_FOUND:
220 snprintf(buf, bufsize, "%strack album art conditional",
221 next_str(next));
222 break;
223 #endif
225 #ifdef HAVE_LCD_BITMAP
226 case WPS_TOKEN_IMAGE_BACKDROP:
227 snprintf(buf, bufsize, "backdrop image");
228 break;
230 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
231 snprintf(buf, bufsize, "progressbar bitmap");
232 break;
234 case WPS_TOKEN_PEAKMETER:
235 snprintf(buf, bufsize, "peakmeter");
236 break;
237 #endif
239 case WPS_TOKEN_PROGRESSBAR:
240 snprintf(buf, bufsize, "progressbar");
241 break;
243 #ifdef HAVE_LCD_CHARCELLS
244 case WPS_TOKEN_PLAYER_PROGRESSBAR:
245 snprintf(buf, bufsize, "full line progressbar");
246 break;
247 #endif
249 case WPS_TOKEN_TRACK_TIME_ELAPSED:
250 snprintf(buf, bufsize, "time elapsed in track");
251 break;
253 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
254 snprintf(buf, bufsize, "played percentage of track");
255 break;
257 case WPS_TOKEN_PLAYLIST_ENTRIES:
258 snprintf(buf, bufsize, "number of entries in playlist");
259 break;
261 case WPS_TOKEN_PLAYLIST_NAME:
262 snprintf(buf, bufsize, "playlist name");
263 break;
265 case WPS_TOKEN_PLAYLIST_POSITION:
266 snprintf(buf, bufsize, "position in playlist");
267 break;
269 case WPS_TOKEN_TRACK_TIME_REMAINING:
270 snprintf(buf, bufsize, "time remaining in track");
271 break;
273 case WPS_TOKEN_PLAYLIST_SHUFFLE:
274 snprintf(buf, bufsize, "playlist shuffle mode");
275 break;
277 case WPS_TOKEN_TRACK_LENGTH:
278 snprintf(buf, bufsize, "track length");
279 break;
281 case WPS_TOKEN_VOLUME:
282 snprintf(buf, bufsize, "volume");
283 break;
285 case WPS_TOKEN_METADATA_ARTIST:
286 snprintf(buf, bufsize, "%strack artist",
287 next_str(next));
288 break;
290 case WPS_TOKEN_METADATA_COMPOSER:
291 snprintf(buf, bufsize, "%strack composer",
292 next_str(next));
293 break;
295 case WPS_TOKEN_METADATA_ALBUM:
296 snprintf(buf, bufsize, "%strack album",
297 next_str(next));
298 break;
300 case WPS_TOKEN_METADATA_GROUPING:
301 snprintf(buf, bufsize, "%strack grouping",
302 next_str(next));
303 break;
305 case WPS_TOKEN_METADATA_GENRE:
306 snprintf(buf, bufsize, "%strack genre",
307 next_str(next));
308 break;
310 case WPS_TOKEN_METADATA_DISC_NUMBER:
311 snprintf(buf, bufsize, "%strack disc", next_str(next));
312 break;
314 case WPS_TOKEN_METADATA_TRACK_NUMBER:
315 snprintf(buf, bufsize, "%strack number",
316 next_str(next));
317 break;
319 case WPS_TOKEN_METADATA_TRACK_TITLE:
320 snprintf(buf, bufsize, "%strack title",
321 next_str(next));
322 break;
324 case WPS_TOKEN_METADATA_VERSION:
325 snprintf(buf, bufsize, "%strack ID3 version",
326 next_str(next));
327 break;
329 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
330 snprintf(buf, bufsize, "%strack album artist",
331 next_str(next));
332 break;
334 case WPS_TOKEN_METADATA_COMMENT:
335 snprintf(buf, bufsize, "%strack comment",
336 next_str(next));
337 break;
339 case WPS_TOKEN_METADATA_YEAR:
340 snprintf(buf, bufsize, "%strack year", next_str(next));
341 break;
343 #ifdef HAVE_TAGCACHE
344 case WPS_TOKEN_DATABASE_PLAYCOUNT:
345 snprintf(buf, bufsize, "track playcount (database)");
346 break;
348 case WPS_TOKEN_DATABASE_RATING:
349 snprintf(buf, bufsize, "track rating (database)");
350 break;
352 case WPS_TOKEN_DATABASE_AUTOSCORE:
353 snprintf(buf, bufsize, "track autoscore (database)");
354 break;
355 #endif
357 case WPS_TOKEN_BATTERY_PERCENT:
358 snprintf(buf, bufsize, "battery percentage");
359 break;
361 case WPS_TOKEN_BATTERY_VOLTS:
362 snprintf(buf, bufsize, "battery voltage");
363 break;
365 case WPS_TOKEN_BATTERY_TIME:
366 snprintf(buf, bufsize, "battery time left");
367 break;
369 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
370 snprintf(buf, bufsize, "battery charger connected");
371 break;
373 case WPS_TOKEN_BATTERY_CHARGING:
374 snprintf(buf, bufsize, "battery charging");
375 break;
377 case WPS_TOKEN_BATTERY_SLEEPTIME:
378 snprintf(buf, bufsize, "sleep timer");
379 break;
381 case WPS_TOKEN_FILE_BITRATE:
382 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
383 break;
385 case WPS_TOKEN_FILE_CODEC:
386 snprintf(buf, bufsize, "%sfile codec", next_str(next));
387 break;
389 case WPS_TOKEN_FILE_FREQUENCY:
390 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
391 next_str(next));
392 break;
394 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
395 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
396 next_str(next));
397 break;
399 case WPS_TOKEN_FILE_NAME:
400 snprintf(buf, bufsize, "%sfile name", next_str(next));
401 break;
403 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
404 snprintf(buf, bufsize, "%sfile name with extension",
405 next_str(next));
406 break;
408 case WPS_TOKEN_FILE_PATH:
409 snprintf(buf, bufsize, "%sfile path", next_str(next));
410 break;
412 case WPS_TOKEN_FILE_SIZE:
413 snprintf(buf, bufsize, "%sfile size", next_str(next));
414 break;
416 case WPS_TOKEN_FILE_VBR:
417 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
418 break;
420 case WPS_TOKEN_FILE_DIRECTORY:
421 snprintf(buf, bufsize, "%sfile directory, level: %d",
422 next_str(next), token->value.i);
423 break;
425 #if (CONFIG_CODEC != MAS3507D)
426 case WPS_TOKEN_SOUND_PITCH:
427 snprintf(buf, bufsize, "pitch value");
428 break;
429 #endif
430 case WPS_VIEWPORT_ENABLE:
431 snprintf(buf, bufsize, "enable VP:%d",
432 token->value.i);
433 break;
434 case WPS_TOKEN_BUTTON_VOLUME:
435 snprintf(buf, bufsize, "Volume button timeout:%d",
436 token->value.i);
437 break;
438 default:
439 snprintf(buf, bufsize, "FIXME (code: %d)",
440 token->type);
441 break;
444 return buf;
447 #if defined(SIMULATOR) || defined(__PCTOOL__)
448 static void dump_wps_tokens(struct wps_data *data)
450 struct wps_token *token;
451 int i, j;
452 int indent = 0;
453 char buf[64];
454 int num_string_tokens = 0;
456 /* Dump parsed WPS */
457 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++)
459 get_token_desc(token, data, buf, sizeof(buf));
461 switch(token->type)
463 case WPS_TOKEN_STRING:
464 num_string_tokens++;
465 break;
467 case WPS_TOKEN_CONDITIONAL_START:
468 indent++;
469 break;
471 case WPS_TOKEN_CONDITIONAL_END:
472 indent--;
473 break;
475 default:
476 break;
479 if (wps_verbose_level > 2)
481 for(j = 0; j < indent; j++) {
482 DEBUGF("\t");
485 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
489 if (wps_verbose_level > 0)
491 DEBUGF("\n");
492 DEBUGF("Number of string tokens: %d\n", num_string_tokens);
493 DEBUGF("\n");
497 static void print_line_info(struct wps_data *data)
499 int i, j, v;
500 struct wps_line *line;
501 struct wps_subline *subline;
503 if (wps_verbose_level > 0)
505 DEBUGF("Number of viewports : %d\n", data->num_viewports);
506 for (v = 0; v < data->num_viewports; v++)
508 DEBUGF("vp %d: First line: %d\n", v, data->viewports[v].first_line);
509 DEBUGF("vp %d: Last line: %d\n", v, data->viewports[v].last_line);
511 DEBUGF("Number of sublines : %d\n", data->num_sublines);
512 DEBUGF("Number of tokens : %d\n", data->num_tokens);
513 DEBUGF("\n");
516 if (wps_verbose_level > 1)
518 for (v = 0; v < data->num_viewports; v++)
520 DEBUGF("Viewport %d - +%d+%d (%dx%d)\n",v,data->viewports[v].vp.x,
521 data->viewports[v].vp.y,
522 data->viewports[v].vp.width,
523 data->viewports[v].vp.height);
524 for (i = data->viewports[v].first_line, line = &data->lines[data->viewports[v].first_line]; i <= data->viewports[v].last_line; i++,line++)
526 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
527 i, line->num_sublines, line->first_subline_idx);
529 for (j = 0, subline = data->sublines + line->first_subline_idx;
530 j < line->num_sublines; j++, subline++)
532 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
533 j, subline->first_token_idx,
534 wps_last_token_index(data, i, j));
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");
543 DEBUGF("\n");
548 DEBUGF("\n");
552 static void print_wps_strings(struct wps_data *data)
554 int i, len, total_len = 0, buf_used = 0;
556 if (wps_verbose_level > 1) DEBUGF("Strings:\n");
557 for (i = 0; i < data->num_strings; i++)
559 len = strlen(data->strings[i]);
560 total_len += len;
561 buf_used += len + 1;
562 if (wps_verbose_level > 1)
563 DEBUGF("%2d: (%2d) '%s'\n", i, len, data->strings[i]);
565 if (wps_verbose_level > 1) DEBUGF("\n");
567 if (wps_verbose_level > 0)
569 DEBUGF("Number of unique strings: %d (max: %d)\n",
570 data->num_strings, WPS_MAX_STRINGS);
571 DEBUGF("Total string length: %d\n", total_len);
572 DEBUGF("String buffer used: %d out of %d bytes\n",
573 buf_used, STRING_BUFFER_SIZE);
574 DEBUGF("\n");
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_wps_tokens(data);
585 print_wps_strings(data);
586 print_line_info(data);
588 #endif /* SIMULATOR */
590 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
591 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
592 WPS_MAX_TOKENS - 1);
595 if (fail != PARSE_OK)
597 char buf[64];
599 DEBUGF("ERR: Failed parsing on line %d : ", line);
600 switch (fail)
602 case PARSE_OK:
603 break;
605 case PARSE_FAIL_UNCLOSED_COND:
606 DEBUGF("ERR: Unclosed conditional");
607 break;
609 case PARSE_FAIL_INVALID_CHAR:
610 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
611 data->num_tokens-1,
612 get_token_desc(&data->tokens[data->num_tokens-1], data,
613 buf, sizeof(buf))
615 break;
617 case PARSE_FAIL_COND_SYNTAX_ERROR:
618 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
619 data->num_tokens-1,
620 get_token_desc(&data->tokens[data->num_tokens-1], data,
621 buf, sizeof(buf))
623 break;
625 case PARSE_FAIL_COND_INVALID_PARAM:
626 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
627 data->num_tokens,
628 get_token_desc(&data->tokens[data->num_tokens], data,
629 buf, sizeof(buf))
631 break;
633 case PARSE_FAIL_LIMITS_EXCEEDED:
634 DEBUGF("ERR: Limits exceeded");
635 break;
637 DEBUGF("\n");
641 #endif /* DEBUG || SIMULATOR */