* code police on a macro which has no reason for being
[kugel-rb.git] / apps / gui / skin_engine / wps_debug.c
blob86f929ad235273dc13b1df5330f3092cb83cabb7
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 bool debug_wps;
42 extern int wps_verbose_level;
43 #endif
45 static char *next_str(bool next) {
46 return next ? "next " : "";
49 static char *get_token_desc(struct wps_token *token, char *buf,
50 int bufsize, struct wps_data *data)
52 #ifndef HAVE_LCD_BITMAP
53 (void)data; /* kill charcell warning */
54 #endif
55 bool next = token->next;
57 switch(token->type)
59 case WPS_NO_TOKEN:
60 snprintf(buf, bufsize, "No token");
61 break;
63 case WPS_TOKEN_UNKNOWN:
64 snprintf(buf, bufsize, "Unknown token");
65 break;
67 case WPS_TOKEN_CHARACTER:
68 if (token->value.c == '\n')
69 snprintf(buf, bufsize, "Character '\\n'");
70 else
71 snprintf(buf, bufsize, "Character '%c'",
72 token->value.c);
73 break;
75 case WPS_TOKEN_STRING:
76 snprintf(buf, bufsize, "String '%s'",
77 (char*)token->value.data);
78 break;
79 case WPS_TOKEN_TRANSLATEDSTRING:
80 snprintf(buf, bufsize, "String ID '%d'", token->value.i);
81 break;
83 #ifdef HAVE_LCD_BITMAP
84 case WPS_TOKEN_ALIGN_LEFT:
85 snprintf(buf, bufsize, "align left");
86 break;
88 case WPS_TOKEN_ALIGN_CENTER:
89 snprintf(buf, bufsize, "align center");
90 break;
92 case WPS_TOKEN_ALIGN_RIGHT:
93 snprintf(buf, bufsize, "align right");
94 break;
95 #endif
97 case WPS_TOKEN_SUBLINE_TIMEOUT:
98 snprintf(buf, bufsize, "subline timeout value: %d",
99 token->value.i);
100 break;
102 case WPS_TOKEN_CONDITIONAL:
103 snprintf(buf, bufsize, "conditional, %d options",
104 token->value.i);
105 break;
107 case WPS_TOKEN_CONDITIONAL_START:
108 snprintf(buf, bufsize, "conditional start, next cond: %d",
109 token->value.i);
110 break;
112 case WPS_TOKEN_CONDITIONAL_OPTION:
113 snprintf(buf, bufsize, "conditional option, next cond: %d",
114 token->value.i);
115 break;
117 case WPS_TOKEN_CONDITIONAL_END:
118 snprintf(buf, bufsize, "conditional end");
119 break;
121 #ifdef HAVE_LCD_BITMAP
122 case WPS_TOKEN_IMAGE_PRELOAD:
123 snprintf(buf, bufsize, "preload image");
124 break;
126 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
128 char subimage = '\0';
129 char label = token->value.i&0xFF;
130 struct gui_img *img = find_image(label, data);
131 if (img && img->num_subimages > 1)
132 subimage = 'a' + (token->value.i>>8);
133 snprintf(buf, bufsize, "display preloaded image '%c%c'",
134 label, subimage);
136 break;
138 case WPS_TOKEN_IMAGE_DISPLAY:
139 snprintf(buf, bufsize, "display image");
140 break;
141 #endif
143 #ifdef HAS_BUTTON_HOLD
144 case WPS_TOKEN_MAIN_HOLD:
145 snprintf(buf, bufsize, "mode hold");
146 break;
147 #endif
149 #ifdef HAS_REMOTE_BUTTON_HOLD
150 case WPS_TOKEN_REMOTE_HOLD:
151 snprintf(buf, bufsize, "mode remote hold");
152 break;
153 #endif
155 case WPS_TOKEN_REPEAT_MODE:
156 snprintf(buf, bufsize, "mode repeat");
157 break;
159 case WPS_TOKEN_PLAYBACK_STATUS:
160 snprintf(buf, bufsize, "mode playback");
161 break;
163 case WPS_TOKEN_RTC_PRESENT:
164 snprintf(buf, bufsize, "rtc: present?");
165 break;
166 case WPS_TOKEN_RTC_DAY_OF_MONTH:
167 snprintf(buf, bufsize, "rtc: day of month (01..31)");
168 break;
169 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
170 snprintf(buf, bufsize,
171 "rtc: day of month, blank padded ( 1..31)");
172 break;
173 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
174 snprintf(buf, bufsize, "rtc: hour (00..23)");
175 break;
176 case WPS_TOKEN_RTC_HOUR_24:
177 snprintf(buf, bufsize, "rtc: hour ( 0..23)");
178 break;
179 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
180 snprintf(buf, bufsize, "rtc: hour (01..12)");
181 break;
182 case WPS_TOKEN_RTC_HOUR_12:
183 snprintf(buf, bufsize, "rtc: hour ( 1..12)");
184 break;
185 case WPS_TOKEN_RTC_MONTH:
186 snprintf(buf, bufsize, "rtc: month (01..12)");
187 break;
188 case WPS_TOKEN_RTC_MINUTE:
189 snprintf(buf, bufsize, "rtc: minute (00..59)");
190 break;
191 case WPS_TOKEN_RTC_SECOND:
192 snprintf(buf, bufsize, "rtc: second (00..59)");
193 break;
194 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
195 snprintf(buf, bufsize,
196 "rtc: last two digits of year (00..99)");
197 break;
198 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
199 snprintf(buf, bufsize, "rtc: year (1970...)");
200 break;
201 case WPS_TOKEN_RTC_AM_PM_UPPER:
202 snprintf(buf, bufsize,
203 "rtc: upper case AM or PM indicator");
204 break;
205 case WPS_TOKEN_RTC_AM_PM_LOWER:
206 snprintf(buf, bufsize,
207 "rtc: lower case am or pm indicator");
208 break;
209 case WPS_TOKEN_RTC_WEEKDAY_NAME:
210 snprintf(buf, bufsize,
211 "rtc: abbreviated weekday name (Sun..Sat)");
212 break;
213 case WPS_TOKEN_RTC_MONTH_NAME:
214 snprintf(buf, bufsize,
215 "rtc: abbreviated month name (Jan..Dec)");
216 break;
217 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
218 snprintf(buf, bufsize,
219 "rtc: day of week (1..7); 1 is Monday");
220 break;
221 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
222 snprintf(buf, bufsize,
223 "rtc: day of week (0..6); 0 is Sunday");
224 break;
226 #if (CONFIG_CODEC == SWCODEC)
227 case WPS_TOKEN_CROSSFADE:
228 snprintf(buf, bufsize, "crossfade");
229 break;
231 case WPS_TOKEN_REPLAYGAIN:
232 snprintf(buf, bufsize, "replaygain");
233 break;
234 #endif
236 #ifdef HAVE_ALBUMART
237 case WPS_TOKEN_ALBUMART_DISPLAY:
238 snprintf(buf, bufsize, "album art display");
239 break;
241 case WPS_TOKEN_ALBUMART_FOUND:
242 snprintf(buf, bufsize, "%strack album art conditional",
243 next_str(next));
244 break;
245 #endif
247 #ifdef HAVE_LCD_BITMAP
248 case WPS_TOKEN_IMAGE_BACKDROP:
249 snprintf(buf, bufsize, "backdrop image");
250 break;
252 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
253 snprintf(buf, bufsize, "progressbar bitmap");
254 break;
256 case WPS_TOKEN_PEAKMETER:
257 snprintf(buf, bufsize, "peakmeter");
258 break;
259 #endif
261 case WPS_TOKEN_PROGRESSBAR:
262 snprintf(buf, bufsize, "progressbar");
263 break;
265 #ifdef HAVE_LCD_CHARCELLS
266 case WPS_TOKEN_PLAYER_PROGRESSBAR:
267 snprintf(buf, bufsize, "full line progressbar");
268 break;
269 #endif
271 case WPS_TOKEN_TRACK_TIME_ELAPSED:
272 snprintf(buf, bufsize, "time elapsed in track");
273 break;
275 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
276 snprintf(buf, bufsize, "played percentage of track");
277 break;
279 case WPS_TOKEN_PLAYLIST_ENTRIES:
280 snprintf(buf, bufsize, "number of entries in playlist");
281 break;
283 case WPS_TOKEN_PLAYLIST_NAME:
284 snprintf(buf, bufsize, "playlist name");
285 break;
287 case WPS_TOKEN_PLAYLIST_POSITION:
288 snprintf(buf, bufsize, "position in playlist");
289 break;
291 case WPS_TOKEN_TRACK_TIME_REMAINING:
292 snprintf(buf, bufsize, "time remaining in track");
293 break;
295 case WPS_TOKEN_PLAYLIST_SHUFFLE:
296 snprintf(buf, bufsize, "playlist shuffle mode");
297 break;
299 case WPS_TOKEN_TRACK_LENGTH:
300 snprintf(buf, bufsize, "track length");
301 break;
303 case WPS_TOKEN_VOLUME:
304 snprintf(buf, bufsize, "volume");
305 break;
307 case WPS_TOKEN_METADATA_ARTIST:
308 snprintf(buf, bufsize, "%strack artist",
309 next_str(next));
310 break;
312 case WPS_TOKEN_METADATA_COMPOSER:
313 snprintf(buf, bufsize, "%strack composer",
314 next_str(next));
315 break;
317 case WPS_TOKEN_METADATA_ALBUM:
318 snprintf(buf, bufsize, "%strack album",
319 next_str(next));
320 break;
322 case WPS_TOKEN_METADATA_GROUPING:
323 snprintf(buf, bufsize, "%strack grouping",
324 next_str(next));
325 break;
327 case WPS_TOKEN_METADATA_GENRE:
328 snprintf(buf, bufsize, "%strack genre",
329 next_str(next));
330 break;
332 case WPS_TOKEN_METADATA_DISC_NUMBER:
333 snprintf(buf, bufsize, "%strack disc", next_str(next));
334 break;
336 case WPS_TOKEN_METADATA_TRACK_NUMBER:
337 snprintf(buf, bufsize, "%strack number",
338 next_str(next));
339 break;
341 case WPS_TOKEN_METADATA_TRACK_TITLE:
342 snprintf(buf, bufsize, "%strack title",
343 next_str(next));
344 break;
346 case WPS_TOKEN_METADATA_VERSION:
347 snprintf(buf, bufsize, "%strack ID3 version",
348 next_str(next));
349 break;
351 case WPS_TOKEN_METADATA_ALBUM_ARTIST:
352 snprintf(buf, bufsize, "%strack album artist",
353 next_str(next));
354 break;
356 case WPS_TOKEN_METADATA_COMMENT:
357 snprintf(buf, bufsize, "%strack comment",
358 next_str(next));
359 break;
361 case WPS_TOKEN_METADATA_YEAR:
362 snprintf(buf, bufsize, "%strack year", next_str(next));
363 break;
365 #ifdef HAVE_TAGCACHE
366 case WPS_TOKEN_DATABASE_PLAYCOUNT:
367 snprintf(buf, bufsize, "track playcount (database)");
368 break;
370 case WPS_TOKEN_DATABASE_RATING:
371 snprintf(buf, bufsize, "track rating (database)");
372 break;
374 case WPS_TOKEN_DATABASE_AUTOSCORE:
375 snprintf(buf, bufsize, "track autoscore (database)");
376 break;
377 #endif
379 case WPS_TOKEN_BATTERY_PERCENT:
380 snprintf(buf, bufsize, "battery percentage");
381 break;
383 case WPS_TOKEN_BATTERY_VOLTS:
384 snprintf(buf, bufsize, "battery voltage");
385 break;
387 case WPS_TOKEN_BATTERY_TIME:
388 snprintf(buf, bufsize, "battery time left");
389 break;
391 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
392 snprintf(buf, bufsize, "battery charger connected");
393 break;
395 case WPS_TOKEN_BATTERY_CHARGING:
396 snprintf(buf, bufsize, "battery charging");
397 break;
399 case WPS_TOKEN_BATTERY_SLEEPTIME:
400 snprintf(buf, bufsize, "sleep timer");
401 break;
403 case WPS_TOKEN_FILE_BITRATE:
404 snprintf(buf, bufsize, "%sfile bitrate", next_str(next));
405 break;
407 case WPS_TOKEN_FILE_CODEC:
408 snprintf(buf, bufsize, "%sfile codec", next_str(next));
409 break;
411 case WPS_TOKEN_FILE_FREQUENCY:
412 snprintf(buf, bufsize, "%sfile audio frequency in Hz",
413 next_str(next));
414 break;
416 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
417 snprintf(buf, bufsize, "%sfile audio frequency in KHz",
418 next_str(next));
419 break;
421 case WPS_TOKEN_FILE_NAME:
422 snprintf(buf, bufsize, "%sfile name", next_str(next));
423 break;
425 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
426 snprintf(buf, bufsize, "%sfile name with extension",
427 next_str(next));
428 break;
430 case WPS_TOKEN_FILE_PATH:
431 snprintf(buf, bufsize, "%sfile path", next_str(next));
432 break;
434 case WPS_TOKEN_FILE_SIZE:
435 snprintf(buf, bufsize, "%sfile size", next_str(next));
436 break;
438 case WPS_TOKEN_FILE_VBR:
439 snprintf(buf, bufsize, "%sfile is vbr", next_str(next));
440 break;
442 case WPS_TOKEN_FILE_DIRECTORY:
443 snprintf(buf, bufsize, "%sfile directory, level: %d",
444 next_str(next), token->value.i);
445 break;
447 #if (CONFIG_CODEC != MAS3507D)
448 case WPS_TOKEN_SOUND_PITCH:
449 snprintf(buf, bufsize, "pitch value");
450 break;
451 #endif
453 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
454 case WPS_TOKEN_VLED_HDD:
455 snprintf(buf, bufsize, "display virtual HDD LED");
456 break;
457 #endif
458 case WPS_VIEWPORT_ENABLE:
459 snprintf(buf, bufsize, "enable VP: %c",
460 (char)token->value.i);
461 break;
462 case WPS_TOKEN_BUTTON_VOLUME:
463 snprintf(buf, bufsize, "Volume button timeout: %d",
464 token->value.i);
465 break;
466 case WPS_TOKEN_SETTING:
467 snprintf(buf, bufsize, "Setting value: '%s'",
468 settings[token->value.i].cfg_name);
469 break;
470 default:
471 snprintf(buf, bufsize, "FIXME (code: %d)",
472 token->type);
473 break;
476 return buf;
479 #if defined(SIMULATOR) || defined(__PCTOOL__)
480 static void dump_skin(struct wps_data *data)
482 int indent = 0;
483 char buf[64];
484 int i, j;
486 struct skin_token_list *viewport_list;
487 for (viewport_list = data->viewports;
488 viewport_list; viewport_list = viewport_list->next)
490 struct skin_viewport *skin_viewport =
491 (struct skin_viewport *)viewport_list->token->value.data;
492 indent = 0;
493 DEBUGF("Viewport: '%c'\n", skin_viewport->label);
494 struct skin_line *line;
495 for (line = skin_viewport->lines; line; line = line->next)
497 struct skin_subline *subline;
498 indent = 1;
499 for(subline = &line->sublines; subline; subline = subline->next)
501 DEBUGF(" Subline: tokens %d => %d",
502 subline->first_token_idx,subline->last_token_idx);
503 if (subline->line_type & WPS_REFRESH_SCROLL)
504 DEBUGF(", scrolled");
505 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
506 DEBUGF(", progressbar");
507 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
508 DEBUGF(", peakmeter");
509 DEBUGF("\n");
511 for (i = subline->first_token_idx; i <= subline->last_token_idx; i++)
513 struct wps_token *token = &data->tokens[i];
514 get_token_desc(token, buf, sizeof(buf), data);
516 switch(token->type)
519 case WPS_TOKEN_CONDITIONAL_START:
520 indent++;
521 break;
523 case WPS_TOKEN_CONDITIONAL_END:
524 indent--;
525 break;
527 default:
528 break;
531 if (wps_verbose_level > 2)
533 for(j = 0; j < indent; j++) {
534 DEBUGF("\t");
537 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
544 #endif
546 void print_debug_info(struct wps_data *data, enum wps_parse_error fail, int line)
548 #if defined(SIMULATOR) || defined(__PCTOOL__)
549 if (debug_wps && wps_verbose_level)
551 dump_skin(data);
553 #endif /* SIMULATOR */
555 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
556 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
557 WPS_MAX_TOKENS - 1);
560 if (fail != PARSE_OK)
562 char buf[64];
564 DEBUGF("ERR: Failed parsing on line %d : ", line);
565 switch (fail)
567 case PARSE_OK:
568 break;
570 case PARSE_FAIL_UNCLOSED_COND:
571 DEBUGF("ERR: Unclosed conditional");
572 break;
574 case PARSE_FAIL_INVALID_CHAR:
575 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
576 data->num_tokens-1,
577 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
579 break;
581 case PARSE_FAIL_COND_SYNTAX_ERROR:
582 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
583 data->num_tokens-1,
584 get_token_desc(&data->tokens[data->num_tokens-1], buf, sizeof(buf), data)
586 break;
588 case PARSE_FAIL_COND_INVALID_PARAM:
589 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
590 data->num_tokens,
591 get_token_desc(&data->tokens[data->num_tokens], buf, sizeof(buf), data)
593 break;
595 case PARSE_FAIL_LIMITS_EXCEEDED:
596 DEBUGF("ERR: Limits exceeded");
597 break;
599 DEBUGF("\n");
603 void debug_skin_usage(void)
605 if (wps_verbose_level > 1)
606 DEBUGF("Skin buffer usage: %lu/%lu\n", (unsigned long)skin_buffer_usage(),
607 (unsigned long)(skin_buffer_usage() + skin_buffer_freespace()));
611 #endif /* DEBUG || SIMULATOR */