1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
;
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
;
51 int num_string_tokens
= 0;
54 for (i
= 0, token
= data
->tokens
; i
< data
->num_tokens
; i
++, token
++) {
58 case WPS_TOKEN_UNKNOWN
:
59 snprintf(buf
, sizeof(buf
), "Unknown token");
61 case WPS_TOKEN_CHARACTER
:
62 snprintf(buf
, sizeof(buf
), "Character '%c'",
66 case WPS_TOKEN_STRING
:
67 snprintf(buf
, sizeof(buf
), "String '%s'",
68 data
->strings
[token
->value
.i
]);
72 #ifdef HAVE_LCD_BITMAP
73 case WPS_TOKEN_ALIGN_LEFT
:
74 snprintf(buf
, sizeof(buf
), "align left");
77 case WPS_TOKEN_ALIGN_CENTER
:
78 snprintf(buf
, sizeof(buf
), "align center");
81 case WPS_TOKEN_ALIGN_RIGHT
:
82 snprintf(buf
, sizeof(buf
), "align right");
86 case WPS_TOKEN_SUBLINE_TIMEOUT
:
87 snprintf(buf
, sizeof(buf
), "subline timeout value: %d",
91 case WPS_TOKEN_CONDITIONAL
:
92 snprintf(buf
, sizeof(buf
), "conditional, %d options",
96 case WPS_TOKEN_CONDITIONAL_START
:
97 snprintf(buf
, sizeof(buf
), "conditional start, next cond: %d",
102 case WPS_TOKEN_CONDITIONAL_OPTION
:
103 snprintf(buf
, sizeof(buf
), "conditional option, next cond: %d",
107 case WPS_TOKEN_CONDITIONAL_END
:
108 snprintf(buf
, sizeof(buf
), "conditional end");
112 #ifdef HAVE_LCD_BITMAP
113 case WPS_TOKEN_IMAGE_PRELOAD
:
114 snprintf(buf
, sizeof(buf
), "preload image");
117 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
:
118 snprintf(buf
, sizeof(buf
), "display preloaded image %d",
122 case WPS_TOKEN_IMAGE_DISPLAY
:
123 snprintf(buf
, sizeof(buf
), "display image");
127 #ifdef HAS_BUTTON_HOLD
128 case WPS_TOKEN_MAIN_HOLD
:
129 snprintf(buf
, sizeof(buf
), "mode hold");
133 #ifdef HAS_REMOTE_BUTTON_HOLD
134 case WPS_TOKEN_REMOTE_HOLD
:
135 snprintf(buf
, sizeof(buf
), "mode remote hold");
139 case WPS_TOKEN_REPEAT_MODE
:
140 snprintf(buf
, sizeof(buf
), "mode repeat");
143 case WPS_TOKEN_PLAYBACK_STATUS
:
144 snprintf(buf
, sizeof(buf
), "mode playback");
147 case WPS_TOKEN_RTC_DAY_OF_MONTH
:
148 snprintf(buf
, sizeof(buf
), "rtc: day of month (01..31)");
150 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
151 snprintf(buf
, sizeof(buf
),
152 "rtc: day of month, blank padded ( 1..31)");
154 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
155 snprintf(buf
, sizeof(buf
), "rtc: hour (00..23)");
157 case WPS_TOKEN_RTC_HOUR_24
:
158 snprintf(buf
, sizeof(buf
), "rtc: hour ( 0..23)");
160 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
161 snprintf(buf
, sizeof(buf
), "rtc: hour (01..12)");
163 case WPS_TOKEN_RTC_HOUR_12
:
164 snprintf(buf
, sizeof(buf
), "rtc: hour ( 1..12)");
166 case WPS_TOKEN_RTC_MONTH
:
167 snprintf(buf
, sizeof(buf
), "rtc: month (01..12)");
169 case WPS_TOKEN_RTC_MINUTE
:
170 snprintf(buf
, sizeof(buf
), "rtc: minute (00..59)");
172 case WPS_TOKEN_RTC_SECOND
:
173 snprintf(buf
, sizeof(buf
), "rtc: second (00..59)");
175 case WPS_TOKEN_RTC_YEAR_2_DIGITS
:
176 snprintf(buf
, sizeof(buf
),
177 "rtc: last two digits of year (00..99)");
179 case WPS_TOKEN_RTC_YEAR_4_DIGITS
:
180 snprintf(buf
, sizeof(buf
), "rtc: year (1970...)");
182 case WPS_TOKEN_RTC_AM_PM_UPPER
:
183 snprintf(buf
, sizeof(buf
),
184 "rtc: upper case AM or PM indicator");
186 case WPS_TOKEN_RTC_AM_PM_LOWER
:
187 snprintf(buf
, sizeof(buf
),
188 "rtc: lower case am or pm indicator");
190 case WPS_TOKEN_RTC_WEEKDAY_NAME
:
191 snprintf(buf
, sizeof(buf
),
192 "rtc: abbreviated weekday name (Sun..Sat)");
194 case WPS_TOKEN_RTC_MONTH_NAME
:
195 snprintf(buf
, sizeof(buf
),
196 "rtc: abbreviated month name (Jan..Dec)");
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");
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");
207 #if (CONFIG_CODEC == SWCODEC)
208 case WPS_TOKEN_CROSSFADE
:
209 snprintf(buf
, sizeof(buf
), "crossfade");
212 case WPS_TOKEN_REPLAYGAIN
:
213 snprintf(buf
, sizeof(buf
), "replaygain");
217 #ifdef HAVE_LCD_BITMAP
218 case WPS_TOKEN_IMAGE_BACKDROP
:
219 snprintf(buf
, sizeof(buf
), "backdrop image");
222 case WPS_TOKEN_IMAGE_PROGRESS_BAR
:
223 snprintf(buf
, sizeof(buf
), "progressbar bitmap");
226 case WPS_TOKEN_PEAKMETER
:
227 snprintf(buf
, sizeof(buf
), "peakmeter");
231 case WPS_TOKEN_PROGRESSBAR
:
232 snprintf(buf
, sizeof(buf
), "progressbar");
235 #ifdef HAVE_LCD_CHARCELLS
236 case WPS_TOKEN_PLAYER_PROGRESSBAR
:
237 snprintf(buf
, sizeof(buf
), "full line progressbar");
241 case WPS_TOKEN_TRACK_TIME_ELAPSED
:
242 snprintf(buf
, sizeof(buf
), "time elapsed in track");
245 case WPS_TOKEN_TRACK_ELAPSED_PERCENT
:
246 snprintf(buf
, sizeof(buf
), "played percentage of track");
249 case WPS_TOKEN_PLAYLIST_ENTRIES
:
250 snprintf(buf
, sizeof(buf
), "number of entries in playlist");
253 case WPS_TOKEN_PLAYLIST_NAME
:
254 snprintf(buf
, sizeof(buf
), "playlist name");
257 case WPS_TOKEN_PLAYLIST_POSITION
:
258 snprintf(buf
, sizeof(buf
), "position in playlist");
261 case WPS_TOKEN_TRACK_TIME_REMAINING
:
262 snprintf(buf
, sizeof(buf
), "time remaining in track");
265 case WPS_TOKEN_PLAYLIST_SHUFFLE
:
266 snprintf(buf
, sizeof(buf
), "playlist shuffle mode");
269 case WPS_TOKEN_TRACK_LENGTH
:
270 snprintf(buf
, sizeof(buf
), "track length");
273 case WPS_TOKEN_VOLUME
:
274 snprintf(buf
, sizeof(buf
), "volume");
277 case WPS_TOKEN_METADATA_ARTIST
:
278 snprintf(buf
, sizeof(buf
), "%strack artist",
282 case WPS_TOKEN_METADATA_COMPOSER
:
283 snprintf(buf
, sizeof(buf
), "%strack composer",
287 case WPS_TOKEN_METADATA_ALBUM
:
288 snprintf(buf
, sizeof(buf
), "%strack album",
292 case WPS_TOKEN_METADATA_GROUPING
:
293 snprintf(buf
, sizeof(buf
), "%strack grouping",
297 case WPS_TOKEN_METADATA_GENRE
:
298 snprintf(buf
, sizeof(buf
), "%strack genre",
302 case WPS_TOKEN_METADATA_DISC_NUMBER
:
303 snprintf(buf
, sizeof(buf
), "%strack disc", next_str(next
));
306 case WPS_TOKEN_METADATA_TRACK_NUMBER
:
307 snprintf(buf
, sizeof(buf
), "%strack number",
311 case WPS_TOKEN_METADATA_TRACK_TITLE
:
312 snprintf(buf
, sizeof(buf
), "%strack title",
316 case WPS_TOKEN_METADATA_VERSION
:
317 snprintf(buf
, sizeof(buf
), "%strack ID3 version",
321 case WPS_TOKEN_METADATA_YEAR
:
322 snprintf(buf
, sizeof(buf
), "%strack year", next_str(next
));
325 case WPS_TOKEN_BATTERY_PERCENT
:
326 snprintf(buf
, sizeof(buf
), "battery percentage");
329 case WPS_TOKEN_BATTERY_VOLTS
:
330 snprintf(buf
, sizeof(buf
), "battery voltage");
333 case WPS_TOKEN_BATTERY_TIME
:
334 snprintf(buf
, sizeof(buf
), "battery time left");
337 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED
:
338 snprintf(buf
, sizeof(buf
), "battery charger connected");
341 case WPS_TOKEN_BATTERY_CHARGING
:
342 snprintf(buf
, sizeof(buf
), "battery charging");
345 case WPS_TOKEN_FILE_BITRATE
:
346 snprintf(buf
, sizeof(buf
), "%sfile bitrate", next_str(next
));
349 case WPS_TOKEN_FILE_CODEC
:
350 snprintf(buf
, sizeof(buf
), "%sfile codec", next_str(next
));
353 case WPS_TOKEN_FILE_FREQUENCY
:
354 snprintf(buf
, sizeof(buf
), "%sfile audio frequency in Hz",
358 case WPS_TOKEN_FILE_FREQUENCY_KHZ
:
359 snprintf(buf
, sizeof(buf
), "%sfile audio frequency in KHz",
363 case WPS_TOKEN_FILE_NAME
:
364 snprintf(buf
, sizeof(buf
), "%sfile name", next_str(next
));
367 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION
:
368 snprintf(buf
, sizeof(buf
), "%sfile name with extension",
372 case WPS_TOKEN_FILE_PATH
:
373 snprintf(buf
, sizeof(buf
), "%sfile path", next_str(next
));
376 case WPS_TOKEN_FILE_SIZE
:
377 snprintf(buf
, sizeof(buf
), "%sfile size", next_str(next
));
380 case WPS_TOKEN_FILE_VBR
:
381 snprintf(buf
, sizeof(buf
), "%sfile is vbr", next_str(next
));
384 case WPS_TOKEN_FILE_DIRECTORY
:
385 snprintf(buf
, sizeof(buf
), "%sfile directory, level: %d",
386 next_str(next
), token
->value
.i
);
390 snprintf(buf
, sizeof(buf
), "FIXME (code: %d)",
395 if (wps_verbose_level
> 2)
397 for(j
= 0; j
< indent
; j
++) {
401 DEBUGF("[%3d] = (%2d) %s\n", i
, token
->type
, buf
);
405 if (wps_verbose_level
> 0)
408 DEBUGF("Number of string tokens: %d\n", num_string_tokens
);
413 static void print_line_info(struct wps_data
*data
)
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
);
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");
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
]);
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
);
482 #ifdef HAVE_LCD_BITMAP
483 static void print_img_cond_indexes(struct wps_data
*data
)
485 DEBUGF("Image conditional indexes:\n");
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
);
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
);
508 #endif /* SIMULATOR */
510 if (data
->num_tokens
>= WPS_MAX_TOKENS
- 1) {
511 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
517 DEBUGF("Failed parsing on line %d : ", line
);
520 case PARSE_FAIL_UNCLOSED_COND
:
521 DEBUGF("Unclosed conditional");
524 case PARSE_FAIL_INVALID_CHAR
:
525 DEBUGF("Invalid conditional char (not in an open conditional)");
528 case PARSE_FAIL_COND_SYNTAX_ERROR
:
529 DEBUGF("Conditional syntax error");