added degree symbol
[Rockbox.git] / apps / gui / wps_debug.c
blob4fa39dcf351ba4d9f90a1acf5618df008376c0c7
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 static void dump_wps_tokens(struct wps_data *data)
446 struct wps_token *token;
447 int i, j;
448 int indent = 0;
449 char buf[64];
450 int num_string_tokens = 0;
452 /* Dump parsed WPS */
453 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++)
455 get_token_desc(token, data, buf, sizeof(buf));
457 switch(token->type)
459 case WPS_TOKEN_STRING:
460 num_string_tokens++;
461 break;
463 case WPS_TOKEN_CONDITIONAL_START:
464 indent++;
465 break;
467 case WPS_TOKEN_CONDITIONAL_END:
468 indent--;
469 break;
471 default:
472 break;
475 if (wps_verbose_level > 2)
477 for(j = 0; j < indent; j++) {
478 DEBUGF("\t");
481 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
485 if (wps_verbose_level > 0)
487 DEBUGF("\n");
488 DEBUGF("Number of string tokens: %d\n", num_string_tokens);
489 DEBUGF("\n");
493 static void print_line_info(struct wps_data *data)
495 int i, j;
496 struct wps_line *line;
497 struct wps_subline *subline;
499 if (wps_verbose_level > 0)
501 DEBUGF("Number of lines : %d\n", data->num_lines);
502 DEBUGF("Number of sublines: %d\n", data->num_sublines);
503 DEBUGF("Number of tokens : %d\n", data->num_tokens);
504 DEBUGF("\n");
507 if (wps_verbose_level > 1)
509 for (i = 0, line = data->lines; i < data->num_lines; i++,line++)
511 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
512 i, line->num_sublines, line->first_subline_idx);
514 for (j = 0, subline = data->sublines + line->first_subline_idx;
515 j < line->num_sublines; j++, subline++)
517 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
518 j, subline->first_token_idx,
519 wps_last_token_index(data, i, j));
521 if (subline->line_type & WPS_REFRESH_SCROLL)
522 DEBUGF(", scrolled");
523 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
524 DEBUGF(", progressbar");
525 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
526 DEBUGF(", peakmeter");
528 DEBUGF("\n");
532 DEBUGF("\n");
536 static void print_wps_strings(struct wps_data *data)
538 int i, len, total_len = 0, buf_used = 0;
540 if (wps_verbose_level > 1) DEBUGF("Strings:\n");
541 for (i = 0; i < data->num_strings; i++)
543 len = strlen(data->strings[i]);
544 total_len += len;
545 buf_used += len + 1;
546 if (wps_verbose_level > 1)
547 DEBUGF("%2d: (%2d) '%s'\n", i, len, data->strings[i]);
549 if (wps_verbose_level > 1) DEBUGF("\n");
551 if (wps_verbose_level > 0)
553 DEBUGF("Number of unique strings: %d (max: %d)\n",
554 data->num_strings, WPS_MAX_STRINGS);
555 DEBUGF("Total string length: %d\n", total_len);
556 DEBUGF("String buffer used: %d out of %d bytes\n",
557 buf_used, STRING_BUFFER_SIZE);
558 DEBUGF("\n");
562 void print_debug_info(struct wps_data *data, int fail, int line)
564 #if defined(SIMULATOR) || defined(__PCTOOL__)
565 if (debug_wps && wps_verbose_level)
567 dump_wps_tokens(data);
568 print_wps_strings(data);
569 print_line_info(data);
571 #endif /* SIMULATOR */
573 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
574 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
575 WPS_MAX_TOKENS - 1);
578 if (fail)
580 char buf[64];
582 DEBUGF("Failed parsing on line %d : ", line);
583 switch (fail)
585 case PARSE_FAIL_UNCLOSED_COND:
586 DEBUGF("Unclosed conditional");
587 break;
589 case PARSE_FAIL_INVALID_CHAR:
590 DEBUGF("unexpected conditional char after token %d: \"%s\"",
591 data->num_tokens-1,
592 get_token_desc(&data->tokens[data->num_tokens-1], data,
593 buf, sizeof(buf))
595 break;
597 case PARSE_FAIL_COND_SYNTAX_ERROR:
598 DEBUGF("Conditional syntax error after token %d: \"%s\"",
599 data->num_tokens-1,
600 get_token_desc(&data->tokens[data->num_tokens-1], data,
601 buf, sizeof(buf))
603 break;
605 case PARSE_FAIL_COND_INVALID_PARAM:
606 DEBUGF("Invalid parameter list for token %d: \"%s\"",
607 data->num_tokens,
608 get_token_desc(&data->tokens[data->num_tokens], data,
609 buf, sizeof(buf))
611 break;
613 DEBUGF("\n");
617 #endif /* DEBUG */