quiet the masses...
[Rockbox.git] / apps / gui / wps_debug.c
blob0f69c769387de7a7c5faeef0ca0d3957e49fa1d0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifdef DEBUG
22 #include <stdio.h>
23 #include <string.h>
24 #include "gwps.h"
25 #ifdef __PCTOOL__
26 #define DEBUGF printf
27 #else
28 #include "debug.h"
29 #endif
31 #define PARSE_FAIL_UNCLOSED_COND 1
32 #define PARSE_FAIL_INVALID_CHAR 2
33 #define PARSE_FAIL_COND_SYNTAX_ERROR 3
34 #define PARSE_FAIL_COND_INVALID_PARAM 4
36 #if defined(SIMULATOR) || defined(__PCTOOL__)
37 extern bool debug_wps;
38 extern int wps_verbose_level;
39 #endif
41 static char *next_str(bool next) {
42 return next ? "next " : "";
45 static char *get_token_desc(struct wps_token *token, struct wps_data *data,
46 char *buf, int bufsize)
48 bool next = token->next;
50 switch(token->type)
52 case WPS_NO_TOKEN:
53 snprintf(buf, bufsize, "No token");
54 break;
56 case WPS_TOKEN_UNKNOWN:
57 snprintf(buf, bufsize, "Unknown token");
58 break;
60 case WPS_TOKEN_CHARACTER:
61 snprintf(buf, bufsize, "Character '%c'",
62 token->value.c);
63 break;
65 case WPS_TOKEN_STRING:
66 snprintf(buf, bufsize, "String '%s'",
67 data->strings[token->value.i]);
68 break;
70 #ifdef HAVE_LCD_BITMAP
71 case WPS_TOKEN_ALIGN_LEFT:
72 snprintf(buf, bufsize, "align left");
73 break;
75 case WPS_TOKEN_ALIGN_CENTER:
76 snprintf(buf, bufsize, "align center");
77 break;
79 case WPS_TOKEN_ALIGN_RIGHT:
80 snprintf(buf, bufsize, "align right");
81 break;
83 case WPS_TOKEN_LEFTMARGIN:
84 snprintf(buf, bufsize, "left margin, value: %d",
85 token->value.i);
86 break;
87 #endif
89 case WPS_TOKEN_SUBLINE_TIMEOUT:
90 snprintf(buf, bufsize, "subline timeout value: %d",
91 token->value.i);
92 break;
94 case WPS_TOKEN_CONDITIONAL:
95 snprintf(buf, bufsize, "conditional, %d options",
96 token->value.i);
97 break;
99 case WPS_TOKEN_CONDITIONAL_START:
100 snprintf(buf, bufsize, "conditional start, next cond: %d",
101 token->value.i);
102 break;
104 case WPS_TOKEN_CONDITIONAL_OPTION:
105 snprintf(buf, bufsize, "conditional option, next cond: %d",
106 token->value.i);
107 break;
109 case WPS_TOKEN_CONDITIONAL_END:
110 snprintf(buf, bufsize, "conditional end");
111 break;
113 #ifdef HAVE_LCD_BITMAP
114 case WPS_TOKEN_IMAGE_PRELOAD:
115 snprintf(buf, bufsize, "preload image");
116 break;
118 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
119 snprintf(buf, bufsize, "display preloaded image %d",
120 token->value.i);
121 break;
123 case WPS_TOKEN_IMAGE_DISPLAY:
124 snprintf(buf, bufsize, "display image");
125 break;
126 #endif
128 #ifdef HAS_BUTTON_HOLD
129 case WPS_TOKEN_MAIN_HOLD:
130 snprintf(buf, bufsize, "mode hold");
131 break;
132 #endif
134 #ifdef HAS_REMOTE_BUTTON_HOLD
135 case WPS_TOKEN_REMOTE_HOLD:
136 snprintf(buf, bufsize, "mode remote hold");
137 break;
138 #endif
140 case WPS_TOKEN_REPEAT_MODE:
141 snprintf(buf, bufsize, "mode repeat");
142 break;
144 case WPS_TOKEN_PLAYBACK_STATUS:
145 snprintf(buf, bufsize, "mode playback");
146 break;
148 case WPS_TOKEN_RTC_DAY_OF_MONTH:
149 snprintf(buf, bufsize, "rtc: day of month (01..31)");
150 break;
151 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
152 snprintf(buf, bufsize,
153 "rtc: day of month, blank padded ( 1..31)");
154 break;
155 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
156 snprintf(buf, bufsize, "rtc: hour (00..23)");
157 break;
158 case WPS_TOKEN_RTC_HOUR_24:
159 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
160 break;
161 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
162 snprintf(buf, bufsize, "rtc: hour (01..12)");
163 break;
164 case WPS_TOKEN_RTC_HOUR_12:
165 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
166 break;
167 case WPS_TOKEN_RTC_MONTH:
168 snprintf(buf, bufsize, "rtc: month (01..12)");
169 break;
170 case WPS_TOKEN_RTC_MINUTE:
171 snprintf(buf, bufsize, "rtc: minute (00..59)");
172 break;
173 case WPS_TOKEN_RTC_SECOND:
174 snprintf(buf, bufsize, "rtc: second (00..59)");
175 break;
176 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
177 snprintf(buf, bufsize,
178 "rtc: last two digits of year (00..99)");
179 break;
180 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
181 snprintf(buf, bufsize, "rtc: year (1970...)");
182 break;
183 case WPS_TOKEN_RTC_AM_PM_UPPER:
184 snprintf(buf, bufsize,
185 "rtc: upper case AM or PM indicator");
186 break;
187 case WPS_TOKEN_RTC_AM_PM_LOWER:
188 snprintf(buf, bufsize,
189 "rtc: lower case am or pm indicator");
190 break;
191 case WPS_TOKEN_RTC_WEEKDAY_NAME:
192 snprintf(buf, bufsize,
193 "rtc: abbreviated weekday name (Sun..Sat)");
194 break;
195 case WPS_TOKEN_RTC_MONTH_NAME:
196 snprintf(buf, bufsize,
197 "rtc: abbreviated month name (Jan..Dec)");
198 break;
199 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
200 snprintf(buf, bufsize,
201 "rtc: day of week (1..7); 1 is Monday");
202 break;
203 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
204 snprintf(buf, bufsize,
205 "rtc: day of week (0..6); 0 is Sunday");
206 break;
208 #if (CONFIG_CODEC == SWCODEC)
209 case WPS_TOKEN_CROSSFADE:
210 snprintf(buf, bufsize, "crossfade");
211 break;
213 case WPS_TOKEN_REPLAYGAIN:
214 snprintf(buf, bufsize, "replaygain");
215 break;
216 #endif
218 #ifdef HAVE_ALBUMART
219 case WPS_TOKEN_ALBUMART_DISPLAY:
220 snprintf(buf, bufsize, "album art display");
221 break;
223 case WPS_TOKEN_ALBUMART_FOUND:
224 snprintf(buf, bufsize, "%strack album art conditional",
225 next_str(next));
226 break;
227 #endif
229 #ifdef HAVE_LCD_BITMAP
230 case WPS_TOKEN_IMAGE_BACKDROP:
231 snprintf(buf, bufsize, "backdrop image");
232 break;
234 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
235 snprintf(buf, bufsize, "progressbar bitmap");
236 break;
238 case WPS_TOKEN_PEAKMETER:
239 snprintf(buf, bufsize, "peakmeter");
240 break;
241 #endif
243 case WPS_TOKEN_PROGRESSBAR:
244 snprintf(buf, bufsize, "progressbar");
245 break;
247 #ifdef HAVE_LCD_CHARCELLS
248 case WPS_TOKEN_PLAYER_PROGRESSBAR:
249 snprintf(buf, bufsize, "full line progressbar");
250 break;
251 #endif
253 case WPS_TOKEN_TRACK_TIME_ELAPSED:
254 snprintf(buf, bufsize, "time elapsed in track");
255 break;
257 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
258 snprintf(buf, bufsize, "played percentage of track");
259 break;
261 case WPS_TOKEN_PLAYLIST_ENTRIES:
262 snprintf(buf, bufsize, "number of entries in playlist");
263 break;
265 case WPS_TOKEN_PLAYLIST_NAME:
266 snprintf(buf, bufsize, "playlist name");
267 break;
269 case WPS_TOKEN_PLAYLIST_POSITION:
270 snprintf(buf, bufsize, "position in playlist");
271 break;
273 case WPS_TOKEN_TRACK_TIME_REMAINING:
274 snprintf(buf, bufsize, "time remaining in track");
275 break;
277 case WPS_TOKEN_PLAYLIST_SHUFFLE:
278 snprintf(buf, bufsize, "playlist shuffle mode");
279 break;
281 case WPS_TOKEN_TRACK_LENGTH:
282 snprintf(buf, bufsize, "track length");
283 break;
285 case WPS_TOKEN_VOLUME:
286 snprintf(buf, bufsize, "volume");
287 break;
289 case WPS_TOKEN_METADATA_ARTIST:
290 snprintf(buf, bufsize, "%strack artist",
291 next_str(next));
292 break;
294 case WPS_TOKEN_METADATA_COMPOSER:
295 snprintf(buf, bufsize, "%strack composer",
296 next_str(next));
297 break;
299 case WPS_TOKEN_METADATA_ALBUM:
300 snprintf(buf, bufsize, "%strack album",
301 next_str(next));
302 break;
304 case WPS_TOKEN_METADATA_GROUPING:
305 snprintf(buf, bufsize, "%strack grouping",
306 next_str(next));
307 break;
309 case WPS_TOKEN_METADATA_GENRE:
310 snprintf(buf, bufsize, "%strack genre",
311 next_str(next));
312 break;
314 case WPS_TOKEN_METADATA_DISC_NUMBER:
315 snprintf(buf, bufsize, "%strack disc", next_str(next));
316 break;
318 case WPS_TOKEN_METADATA_TRACK_NUMBER:
319 snprintf(buf, bufsize, "%strack number",
320 next_str(next));
321 break;
323 case WPS_TOKEN_METADATA_TRACK_TITLE:
324 snprintf(buf, bufsize, "%strack title",
325 next_str(next));
326 break;
328 case WPS_TOKEN_METADATA_VERSION:
329 snprintf(buf, bufsize, "%strack ID3 version",
330 next_str(next));
331 break;
333 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
334 snprintf(buf, bufsize, "%strack album artist",
335 next_str(next));
336 break;
338 case WPS_TOKEN_METADATA_COMMENT:
339 snprintf(buf, bufsize, "%strack comment",
340 next_str(next));
341 break;
343 case WPS_TOKEN_METADATA_YEAR:
344 snprintf(buf, bufsize, "%strack year", next_str(next));
345 break;
347 #ifdef HAVE_TAGCACHE
348 case WPS_TOKEN_DATABASE_PLAYCOUNT:
349 snprintf(buf, bufsize, "track playcount (database)");
350 break;
352 case WPS_TOKEN_DATABASE_RATING:
353 snprintf(buf, bufsize, "track rating (database)");
354 break;
356 case WPS_TOKEN_DATABASE_AUTOSCORE:
357 snprintf(buf, bufsize, "track autoscore (database)");
358 break;
359 #endif
361 case WPS_TOKEN_BATTERY_PERCENT:
362 snprintf(buf, bufsize, "battery percentage");
363 break;
365 case WPS_TOKEN_BATTERY_VOLTS:
366 snprintf(buf, bufsize, "battery voltage");
367 break;
369 case WPS_TOKEN_BATTERY_TIME:
370 snprintf(buf, bufsize, "battery time left");
371 break;
373 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
374 snprintf(buf, bufsize, "battery charger connected");
375 break;
377 case WPS_TOKEN_BATTERY_CHARGING:
378 snprintf(buf, bufsize, "battery charging");
379 break;
381 case WPS_TOKEN_BATTERY_SLEEPTIME:
382 snprintf(buf, bufsize, "sleep timer");
383 break;
385 case WPS_TOKEN_FILE_BITRATE:
386 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
387 break;
389 case WPS_TOKEN_FILE_CODEC:
390 snprintf(buf, bufsize, "%sfile codec", next_str(next));
391 break;
393 case WPS_TOKEN_FILE_FREQUENCY:
394 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
395 next_str(next));
396 break;
398 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
399 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
400 next_str(next));
401 break;
403 case WPS_TOKEN_FILE_NAME:
404 snprintf(buf, bufsize, "%sfile name", next_str(next));
405 break;
407 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
408 snprintf(buf, bufsize, "%sfile name with extension",
409 next_str(next));
410 break;
412 case WPS_TOKEN_FILE_PATH:
413 snprintf(buf, bufsize, "%sfile path", next_str(next));
414 break;
416 case WPS_TOKEN_FILE_SIZE:
417 snprintf(buf, bufsize, "%sfile size", next_str(next));
418 break;
420 case WPS_TOKEN_FILE_VBR:
421 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
422 break;
424 case WPS_TOKEN_FILE_DIRECTORY:
425 snprintf(buf, bufsize, "%sfile directory, level: %d",
426 next_str(next), token->value.i);
427 break;
429 #if (CONFIG_CODEC != MAS3507D)
430 case WPS_TOKEN_SOUND_PITCH:
431 snprintf(buf, bufsize, "pitch value");
432 break;
433 #endif
435 default:
436 snprintf(buf, bufsize, "FIXME (code: %d)",
437 token->type);
438 break;
441 return buf;
444 #if defined(SIMULATOR) || defined(__PCTOOL__)
445 static void dump_wps_tokens(struct wps_data *data)
447 struct wps_token *token;
448 int i, j;
449 int indent = 0;
450 char buf[64];
451 int num_string_tokens = 0;
453 /* Dump parsed WPS */
454 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++)
456 get_token_desc(token, data, buf, sizeof(buf));
458 switch(token->type)
460 case WPS_TOKEN_STRING:
461 num_string_tokens++;
462 break;
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);
486 if (wps_verbose_level > 0)
488 DEBUGF("\n");
489 DEBUGF("Number of string tokens: %d\n", num_string_tokens);
490 DEBUGF("\n");
494 static void print_line_info(struct wps_data *data)
496 int i, j;
497 struct wps_line *line;
498 struct wps_subline *subline;
500 if (wps_verbose_level > 0)
502 DEBUGF("Number of lines : %d\n", data->num_lines);
503 DEBUGF("Number of sublines: %d\n", data->num_sublines);
504 DEBUGF("Number of tokens : %d\n", data->num_tokens);
505 DEBUGF("\n");
508 if (wps_verbose_level > 1)
510 for (i = 0, line = data->lines; i < data->num_lines; i++,line++)
512 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
513 i, line->num_sublines, line->first_subline_idx);
515 for (j = 0, subline = data->sublines + line->first_subline_idx;
516 j < line->num_sublines; j++, subline++)
518 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
519 j, subline->first_token_idx,
520 wps_last_token_index(data, i, j));
522 if (subline->line_type & WPS_REFRESH_SCROLL)
523 DEBUGF(", scrolled");
524 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
525 DEBUGF(", progressbar");
526 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
527 DEBUGF(", peakmeter");
529 DEBUGF("\n");
533 DEBUGF("\n");
537 static void print_wps_strings(struct wps_data *data)
539 int i, len, total_len = 0, buf_used = 0;
541 if (wps_verbose_level > 1) DEBUGF("Strings:\n");
542 for (i = 0; i < data->num_strings; i++)
544 len = strlen(data->strings[i]);
545 total_len += len;
546 buf_used += len + 1;
547 if (wps_verbose_level > 1)
548 DEBUGF("%2d: (%2d) '%s'\n", i, len, data->strings[i]);
550 if (wps_verbose_level > 1) DEBUGF("\n");
552 if (wps_verbose_level > 0)
554 DEBUGF("Number of unique strings: %d (max: %d)\n",
555 data->num_strings, WPS_MAX_STRINGS);
556 DEBUGF("Total string length: %d\n", total_len);
557 DEBUGF("String buffer used: %d out of %d bytes\n",
558 buf_used, STRING_BUFFER_SIZE);
559 DEBUGF("\n");
562 #endif
564 void print_debug_info(struct wps_data *data, int fail, int line)
566 #if defined(SIMULATOR) || defined(__PCTOOL__)
567 if (debug_wps && wps_verbose_level)
569 dump_wps_tokens(data);
570 print_wps_strings(data);
571 print_line_info(data);
573 #endif /* SIMULATOR */
575 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
576 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
577 WPS_MAX_TOKENS - 1);
580 if (fail)
582 char buf[64];
584 DEBUGF("Failed parsing on line %d : ", line);
585 switch (fail)
587 case PARSE_FAIL_UNCLOSED_COND:
588 DEBUGF("Unclosed conditional");
589 break;
591 case PARSE_FAIL_INVALID_CHAR:
592 DEBUGF("unexpected conditional char after token %d: \"%s\"",
593 data->num_tokens-1,
594 get_token_desc(&data->tokens[data->num_tokens-1], data,
595 buf, sizeof(buf))
597 break;
599 case PARSE_FAIL_COND_SYNTAX_ERROR:
600 DEBUGF("Conditional syntax error after token %d: \"%s\"",
601 data->num_tokens-1,
602 get_token_desc(&data->tokens[data->num_tokens-1], data,
603 buf, sizeof(buf))
605 break;
607 case PARSE_FAIL_COND_INVALID_PARAM:
608 DEBUGF("Invalid parameter list for token %d: \"%s\"",
609 data->num_tokens,
610 get_token_desc(&data->tokens[data->num_tokens], data,
611 buf, sizeof(buf))
613 break;
615 DEBUGF("\n");
619 #endif /* DEBUG */