Try to translate items when using the STRINGCHOICE_SETTING() macro (fixes FS#7603)
[Rockbox.git] / apps / gui / wps_debug.c
blob58e6ab49aa580848f7c8385d7158c872bec3eb99
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
35 #if defined(SIMULATOR) || defined(__PCTOOL__)
36 extern bool debug_wps;
37 extern int wps_verbose_level;
38 #endif
40 static char *next_str(bool next) {
41 return next ? "next " : "";
44 static void dump_wps_tokens(struct wps_data *data)
46 struct wps_token *token;
47 int i, j;
48 int indent = 0;
49 char buf[64];
50 bool next;
51 int num_string_tokens = 0;
53 /* Dump parsed WPS */
54 for (i = 0, token = data->tokens; i < data->num_tokens; i++, token++) {
55 next = token->next;
57 switch(token->type) {
58 case WPS_TOKEN_UNKNOWN:
59 snprintf(buf, sizeof(buf), "Unknown token");
60 break;
61 case WPS_TOKEN_CHARACTER:
62 snprintf(buf, sizeof(buf), "Character '%c'",
63 token->value.c);
64 break;
66 case WPS_TOKEN_STRING:
67 snprintf(buf, sizeof(buf), "String '%s'",
68 data->strings[token->value.i]);
69 num_string_tokens++;
70 break;
72 #ifdef HAVE_LCD_BITMAP
73 case WPS_TOKEN_ALIGN_LEFT:
74 snprintf(buf, sizeof(buf), "align left");
75 break;
77 case WPS_TOKEN_ALIGN_CENTER:
78 snprintf(buf, sizeof(buf), "align center");
79 break;
81 case WPS_TOKEN_ALIGN_RIGHT:
82 snprintf(buf, sizeof(buf), "align right");
83 break;
84 #endif
86 case WPS_TOKEN_SUBLINE_TIMEOUT:
87 snprintf(buf, sizeof(buf), "subline timeout value: %d",
88 token->value.i);
89 break;
91 case WPS_TOKEN_CONDITIONAL:
92 snprintf(buf, sizeof(buf), "conditional, %d options",
93 token->value.i);
94 break;
96 case WPS_TOKEN_CONDITIONAL_START:
97 snprintf(buf, sizeof(buf), "conditional start, next cond: %d",
98 token->value.i);
99 indent++;
100 break;
102 case WPS_TOKEN_CONDITIONAL_OPTION:
103 snprintf(buf, sizeof(buf), "conditional option, next cond: %d",
104 token->value.i);
105 break;
107 case WPS_TOKEN_CONDITIONAL_END:
108 snprintf(buf, sizeof(buf), "conditional end");
109 indent--;
110 break;
112 #ifdef HAVE_LCD_BITMAP
113 case WPS_TOKEN_IMAGE_PRELOAD:
114 snprintf(buf, sizeof(buf), "preload image");
115 break;
117 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY:
118 snprintf(buf, sizeof(buf), "display preloaded image %d",
119 token->value.i);
120 break;
122 case WPS_TOKEN_IMAGE_DISPLAY:
123 snprintf(buf, sizeof(buf), "display image");
124 break;
125 #endif
127 #ifdef HAS_BUTTON_HOLD
128 case WPS_TOKEN_MAIN_HOLD:
129 snprintf(buf, sizeof(buf), "mode hold");
130 break;
131 #endif
133 #ifdef HAS_REMOTE_BUTTON_HOLD
134 case WPS_TOKEN_REMOTE_HOLD:
135 snprintf(buf, sizeof(buf), "mode remote hold");
136 break;
137 #endif
139 case WPS_TOKEN_REPEAT_MODE:
140 snprintf(buf, sizeof(buf), "mode repeat");
141 break;
143 case WPS_TOKEN_PLAYBACK_STATUS:
144 snprintf(buf, sizeof(buf), "mode playback");
145 break;
147 case WPS_TOKEN_RTC_DAY_OF_MONTH:
148 snprintf(buf, sizeof(buf), "rtc: day of month (01..31)");
149 break;
150 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED:
151 snprintf(buf, sizeof(buf),
152 "rtc: day of month, blank padded ( 1..31)");
153 break;
154 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED:
155 snprintf(buf, sizeof(buf), "rtc: hour (00..23)");
156 break;
157 case WPS_TOKEN_RTC_HOUR_24:
158 snprintf(buf, sizeof(buf), "rtc: hour ( 0..23)");
159 break;
160 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED:
161 snprintf(buf, sizeof(buf), "rtc: hour (01..12)");
162 break;
163 case WPS_TOKEN_RTC_HOUR_12:
164 snprintf(buf, sizeof(buf), "rtc: hour ( 1..12)");
165 break;
166 case WPS_TOKEN_RTC_MONTH:
167 snprintf(buf, sizeof(buf), "rtc: month (01..12)");
168 break;
169 case WPS_TOKEN_RTC_MINUTE:
170 snprintf(buf, sizeof(buf), "rtc: minute (00..59)");
171 break;
172 case WPS_TOKEN_RTC_SECOND:
173 snprintf(buf, sizeof(buf), "rtc: second (00..59)");
174 break;
175 case WPS_TOKEN_RTC_YEAR_2_DIGITS:
176 snprintf(buf, sizeof(buf),
177 "rtc: last two digits of year (00..99)");
178 break;
179 case WPS_TOKEN_RTC_YEAR_4_DIGITS:
180 snprintf(buf, sizeof(buf), "rtc: year (1970...)");
181 break;
182 case WPS_TOKEN_RTC_AM_PM_UPPER:
183 snprintf(buf, sizeof(buf),
184 "rtc: upper case AM or PM indicator");
185 break;
186 case WPS_TOKEN_RTC_AM_PM_LOWER:
187 snprintf(buf, sizeof(buf),
188 "rtc: lower case am or pm indicator");
189 break;
190 case WPS_TOKEN_RTC_WEEKDAY_NAME:
191 snprintf(buf, sizeof(buf),
192 "rtc: abbreviated weekday name (Sun..Sat)");
193 break;
194 case WPS_TOKEN_RTC_MONTH_NAME:
195 snprintf(buf, sizeof(buf),
196 "rtc: abbreviated month name (Jan..Dec)");
197 break;
198 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON:
199 snprintf(buf, sizeof(buf),
200 "rtc: day of week (1..7); 1 is Monday");
201 break;
202 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN:
203 snprintf(buf, sizeof(buf),
204 "rtc: day of week (0..6); 0 is Sunday");
205 break;
207 #if (CONFIG_CODEC == SWCODEC)
208 case WPS_TOKEN_CROSSFADE:
209 snprintf(buf, sizeof(buf), "crossfade");
210 break;
212 case WPS_TOKEN_REPLAYGAIN:
213 snprintf(buf, sizeof(buf), "replaygain");
214 break;
215 #endif
217 #ifdef HAVE_LCD_BITMAP
218 case WPS_TOKEN_IMAGE_BACKDROP:
219 snprintf(buf, sizeof(buf), "backdrop image");
220 break;
222 case WPS_TOKEN_IMAGE_PROGRESS_BAR:
223 snprintf(buf, sizeof(buf), "progressbar bitmap");
224 break;
226 case WPS_TOKEN_PEAKMETER:
227 snprintf(buf, sizeof(buf), "peakmeter");
228 break;
229 #endif
231 case WPS_TOKEN_PROGRESSBAR:
232 snprintf(buf, sizeof(buf), "progressbar");
233 break;
235 #ifdef HAVE_LCD_CHARCELLS
236 case WPS_TOKEN_PLAYER_PROGRESSBAR:
237 snprintf(buf, sizeof(buf), "full line progressbar");
238 break;
239 #endif
241 case WPS_TOKEN_TRACK_TIME_ELAPSED:
242 snprintf(buf, sizeof(buf), "time elapsed in track");
243 break;
245 case WPS_TOKEN_TRACK_ELAPSED_PERCENT:
246 snprintf(buf, sizeof(buf), "played percentage of track");
247 break;
249 case WPS_TOKEN_PLAYLIST_ENTRIES:
250 snprintf(buf, sizeof(buf), "number of entries in playlist");
251 break;
253 case WPS_TOKEN_PLAYLIST_NAME:
254 snprintf(buf, sizeof(buf), "playlist name");
255 break;
257 case WPS_TOKEN_PLAYLIST_POSITION:
258 snprintf(buf, sizeof(buf), "position in playlist");
259 break;
261 case WPS_TOKEN_TRACK_TIME_REMAINING:
262 snprintf(buf, sizeof(buf), "time remaining in track");
263 break;
265 case WPS_TOKEN_PLAYLIST_SHUFFLE:
266 snprintf(buf, sizeof(buf), "playlist shuffle mode");
267 break;
269 case WPS_TOKEN_TRACK_LENGTH:
270 snprintf(buf, sizeof(buf), "track length");
271 break;
273 case WPS_TOKEN_VOLUME:
274 snprintf(buf, sizeof(buf), "volume");
275 break;
277 case WPS_TOKEN_METADATA_ARTIST:
278 snprintf(buf, sizeof(buf), "%strack artist",
279 next_str(next));
280 break;
282 case WPS_TOKEN_METADATA_COMPOSER:
283 snprintf(buf, sizeof(buf), "%strack composer",
284 next_str(next));
285 break;
287 case WPS_TOKEN_METADATA_ALBUM:
288 snprintf(buf, sizeof(buf), "%strack album",
289 next_str(next));
290 break;
292 case WPS_TOKEN_METADATA_GROUPING:
293 snprintf(buf, sizeof(buf), "%strack grouping",
294 next_str(next));
295 break;
297 case WPS_TOKEN_METADATA_GENRE:
298 snprintf(buf, sizeof(buf), "%strack genre",
299 next_str(next));
300 break;
302 case WPS_TOKEN_METADATA_DISC_NUMBER:
303 snprintf(buf, sizeof(buf), "%strack disc", next_str(next));
304 break;
306 case WPS_TOKEN_METADATA_TRACK_NUMBER:
307 snprintf(buf, sizeof(buf), "%strack number",
308 next_str(next));
309 break;
311 case WPS_TOKEN_METADATA_TRACK_TITLE:
312 snprintf(buf, sizeof(buf), "%strack title",
313 next_str(next));
314 break;
316 case WPS_TOKEN_METADATA_VERSION:
317 snprintf(buf, sizeof(buf), "%strack ID3 version",
318 next_str(next));
319 break;
321 case WPS_TOKEN_METADATA_YEAR:
322 snprintf(buf, sizeof(buf), "%strack year", next_str(next));
323 break;
325 case WPS_TOKEN_BATTERY_PERCENT:
326 snprintf(buf, sizeof(buf), "battery percentage");
327 break;
329 case WPS_TOKEN_BATTERY_VOLTS:
330 snprintf(buf, sizeof(buf), "battery voltage");
331 break;
333 case WPS_TOKEN_BATTERY_TIME:
334 snprintf(buf, sizeof(buf), "battery time left");
335 break;
337 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED:
338 snprintf(buf, sizeof(buf), "battery charger connected");
339 break;
341 case WPS_TOKEN_BATTERY_CHARGING:
342 snprintf(buf, sizeof(buf), "battery charging");
343 break;
345 case WPS_TOKEN_FILE_BITRATE:
346 snprintf(buf, sizeof(buf), "%sfile bitrate", next_str(next));
347 break;
349 case WPS_TOKEN_FILE_CODEC:
350 snprintf(buf, sizeof(buf), "%sfile codec", next_str(next));
351 break;
353 case WPS_TOKEN_FILE_FREQUENCY:
354 snprintf(buf, sizeof(buf), "%sfile audio frequency in Hz",
355 next_str(next));
356 break;
358 case WPS_TOKEN_FILE_FREQUENCY_KHZ:
359 snprintf(buf, sizeof(buf), "%sfile audio frequency in KHz",
360 next_str(next));
361 break;
363 case WPS_TOKEN_FILE_NAME:
364 snprintf(buf, sizeof(buf), "%sfile name", next_str(next));
365 break;
367 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION:
368 snprintf(buf, sizeof(buf), "%sfile name with extension",
369 next_str(next));
370 break;
372 case WPS_TOKEN_FILE_PATH:
373 snprintf(buf, sizeof(buf), "%sfile path", next_str(next));
374 break;
376 case WPS_TOKEN_FILE_SIZE:
377 snprintf(buf, sizeof(buf), "%sfile size", next_str(next));
378 break;
380 case WPS_TOKEN_FILE_VBR:
381 snprintf(buf, sizeof(buf), "%sfile is vbr", next_str(next));
382 break;
384 case WPS_TOKEN_FILE_DIRECTORY:
385 snprintf(buf, sizeof(buf), "%sfile directory, level: %d",
386 next_str(next), token->value.i);
387 break;
389 default:
390 snprintf(buf, sizeof(buf), "FIXME (code: %d)",
391 token->type);
392 break;
395 if (wps_verbose_level > 2)
397 for(j = 0; j < indent; j++) {
398 DEBUGF("\t");
401 DEBUGF("[%3d] = (%2d) %s\n", i, token->type, buf);
405 if (wps_verbose_level > 0)
407 DEBUGF("\n");
408 DEBUGF("Number of string tokens: %d\n", num_string_tokens);
409 DEBUGF("\n");
413 static void print_line_info(struct wps_data *data)
415 int i, j;
416 struct wps_line *line;
417 struct wps_subline *subline;
419 if (wps_verbose_level > 0)
421 DEBUGF("Number of lines : %d\n", data->num_lines);
422 DEBUGF("Number of sublines: %d\n", data->num_sublines);
423 DEBUGF("Number of tokens : %d\n", data->num_tokens);
424 DEBUGF("\n");
427 if (wps_verbose_level > 1)
429 for (i = 0, line = data->lines; i < data->num_lines; i++,line++)
431 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
432 i, line->num_sublines, line->first_subline_idx);
434 for (j = 0, subline = data->sublines + line->first_subline_idx;
435 j < line->num_sublines; j++, subline++)
437 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
438 j, subline->first_token_idx,
439 wps_last_token_index(data, i, j));
441 if (subline->line_type & WPS_REFRESH_SCROLL)
442 DEBUGF(", scrolled");
443 else if (subline->line_type & WPS_REFRESH_PLAYER_PROGRESS)
444 DEBUGF(", progressbar");
445 else if (subline->line_type & WPS_REFRESH_PEAK_METER)
446 DEBUGF(", peakmeter");
448 DEBUGF("\n");
452 DEBUGF("\n");
456 static void print_wps_strings(struct wps_data *data)
458 int i, len, total_len = 0, buf_used = 0;
460 if (wps_verbose_level > 1) DEBUGF("Strings:\n");
461 for (i = 0; i < data->num_strings; i++)
463 len = strlen(data->strings[i]);
464 total_len += len;
465 buf_used += len + 1;
466 if (wps_verbose_level > 1)
467 DEBUGF("%2d: (%2d) '%s'\n", i, len, data->strings[i]);
469 if (wps_verbose_level > 1) DEBUGF("\n");
471 if (wps_verbose_level > 0)
473 DEBUGF("Number of unique strings: %d (max: %d)\n",
474 data->num_strings, WPS_MAX_STRINGS);
475 DEBUGF("Total string length: %d\n", total_len);
476 DEBUGF("String buffer used: %d out of %d bytes\n",
477 buf_used, STRING_BUFFER_SIZE);
478 DEBUGF("\n");
482 #ifdef HAVE_LCD_BITMAP
483 static void print_img_cond_indexes(struct wps_data *data)
485 DEBUGF("Image conditional indexes:\n");
486 int i;
487 for (i = 0; i < MAX_IMAGES; i++)
489 if (data->img[i].cond_index)
490 DEBUGF("%2d: %d\n", i, data->img[i].cond_index);
492 DEBUGF("\n");
494 #endif /*HAVE_LCD_BITMAP */
496 void print_debug_info(struct wps_data *data, int fail, int line)
498 #if defined(SIMULATOR) || defined(__PCTOOL__)
499 if (debug_wps && wps_verbose_level)
501 dump_wps_tokens(data);
502 print_wps_strings(data);
503 print_line_info(data);
504 #ifdef HAVE_LCD_BITMAP
505 if (wps_verbose_level > 2) print_img_cond_indexes(data);
506 #endif
508 #endif /* SIMULATOR */
510 if (data->num_tokens >= WPS_MAX_TOKENS - 1) {
511 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
512 WPS_MAX_TOKENS - 1);
515 if (fail)
517 DEBUGF("Failed parsing on line %d : ", line);
518 switch (fail)
520 case PARSE_FAIL_UNCLOSED_COND:
521 DEBUGF("Unclosed conditional");
522 break;
524 case PARSE_FAIL_INVALID_CHAR:
525 DEBUGF("Invalid conditional char (not in an open conditional)");
526 break;
528 case PARSE_FAIL_COND_SYNTAX_ERROR:
529 DEBUGF("Conditional syntax error");
530 break;
532 DEBUGF("\n");
536 #endif /* DEBUG */