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
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
;
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
;
53 snprintf(buf
, bufsize
, "No token");
56 case WPS_TOKEN_UNKNOWN
:
57 snprintf(buf
, bufsize
, "Unknown token");
60 case WPS_TOKEN_CHARACTER
:
61 snprintf(buf
, bufsize
, "Character '%c'",
65 case WPS_TOKEN_STRING
:
66 snprintf(buf
, bufsize
, "String '%s'",
67 data
->strings
[token
->value
.i
]);
70 #ifdef HAVE_LCD_BITMAP
71 case WPS_TOKEN_ALIGN_LEFT
:
72 snprintf(buf
, bufsize
, "align left");
75 case WPS_TOKEN_ALIGN_CENTER
:
76 snprintf(buf
, bufsize
, "align center");
79 case WPS_TOKEN_ALIGN_RIGHT
:
80 snprintf(buf
, bufsize
, "align right");
83 case WPS_TOKEN_LEFTMARGIN
:
84 snprintf(buf
, bufsize
, "left margin, value: %d",
89 case WPS_TOKEN_SUBLINE_TIMEOUT
:
90 snprintf(buf
, bufsize
, "subline timeout value: %d",
94 case WPS_TOKEN_CONDITIONAL
:
95 snprintf(buf
, bufsize
, "conditional, %d options",
99 case WPS_TOKEN_CONDITIONAL_START
:
100 snprintf(buf
, bufsize
, "conditional start, next cond: %d",
104 case WPS_TOKEN_CONDITIONAL_OPTION
:
105 snprintf(buf
, bufsize
, "conditional option, next cond: %d",
109 case WPS_TOKEN_CONDITIONAL_END
:
110 snprintf(buf
, bufsize
, "conditional end");
113 #ifdef HAVE_LCD_BITMAP
114 case WPS_TOKEN_IMAGE_PRELOAD
:
115 snprintf(buf
, bufsize
, "preload image");
118 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
:
119 snprintf(buf
, bufsize
, "display preloaded image %d",
123 case WPS_TOKEN_IMAGE_DISPLAY
:
124 snprintf(buf
, bufsize
, "display image");
128 #ifdef HAS_BUTTON_HOLD
129 case WPS_TOKEN_MAIN_HOLD
:
130 snprintf(buf
, bufsize
, "mode hold");
134 #ifdef HAS_REMOTE_BUTTON_HOLD
135 case WPS_TOKEN_REMOTE_HOLD
:
136 snprintf(buf
, bufsize
, "mode remote hold");
140 case WPS_TOKEN_REPEAT_MODE
:
141 snprintf(buf
, bufsize
, "mode repeat");
144 case WPS_TOKEN_PLAYBACK_STATUS
:
145 snprintf(buf
, bufsize
, "mode playback");
148 case WPS_TOKEN_RTC_DAY_OF_MONTH
:
149 snprintf(buf
, bufsize
, "rtc: day of month (01..31)");
151 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
152 snprintf(buf
, bufsize
,
153 "rtc: day of month, blank padded ( 1..31)");
155 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
156 snprintf(buf
, bufsize
, "rtc: hour (00..23)");
158 case WPS_TOKEN_RTC_HOUR_24
:
159 snprintf(buf
, bufsize
, "rtc: hour ( 0..23)");
161 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
162 snprintf(buf
, bufsize
, "rtc: hour (01..12)");
164 case WPS_TOKEN_RTC_HOUR_12
:
165 snprintf(buf
, bufsize
, "rtc: hour ( 1..12)");
167 case WPS_TOKEN_RTC_MONTH
:
168 snprintf(buf
, bufsize
, "rtc: month (01..12)");
170 case WPS_TOKEN_RTC_MINUTE
:
171 snprintf(buf
, bufsize
, "rtc: minute (00..59)");
173 case WPS_TOKEN_RTC_SECOND
:
174 snprintf(buf
, bufsize
, "rtc: second (00..59)");
176 case WPS_TOKEN_RTC_YEAR_2_DIGITS
:
177 snprintf(buf
, bufsize
,
178 "rtc: last two digits of year (00..99)");
180 case WPS_TOKEN_RTC_YEAR_4_DIGITS
:
181 snprintf(buf
, bufsize
, "rtc: year (1970...)");
183 case WPS_TOKEN_RTC_AM_PM_UPPER
:
184 snprintf(buf
, bufsize
,
185 "rtc: upper case AM or PM indicator");
187 case WPS_TOKEN_RTC_AM_PM_LOWER
:
188 snprintf(buf
, bufsize
,
189 "rtc: lower case am or pm indicator");
191 case WPS_TOKEN_RTC_WEEKDAY_NAME
:
192 snprintf(buf
, bufsize
,
193 "rtc: abbreviated weekday name (Sun..Sat)");
195 case WPS_TOKEN_RTC_MONTH_NAME
:
196 snprintf(buf
, bufsize
,
197 "rtc: abbreviated month name (Jan..Dec)");
199 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
200 snprintf(buf
, bufsize
,
201 "rtc: day of week (1..7); 1 is Monday");
203 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
204 snprintf(buf
, bufsize
,
205 "rtc: day of week (0..6); 0 is Sunday");
208 #if (CONFIG_CODEC == SWCODEC)
209 case WPS_TOKEN_CROSSFADE
:
210 snprintf(buf
, bufsize
, "crossfade");
213 case WPS_TOKEN_REPLAYGAIN
:
214 snprintf(buf
, bufsize
, "replaygain");
219 case WPS_TOKEN_ALBUMART_DISPLAY
:
220 snprintf(buf
, bufsize
, "album art display");
223 case WPS_TOKEN_ALBUMART_FOUND
:
224 snprintf(buf
, bufsize
, "%strack album art conditional",
229 #ifdef HAVE_LCD_BITMAP
230 case WPS_TOKEN_IMAGE_BACKDROP
:
231 snprintf(buf
, bufsize
, "backdrop image");
234 case WPS_TOKEN_IMAGE_PROGRESS_BAR
:
235 snprintf(buf
, bufsize
, "progressbar bitmap");
238 case WPS_TOKEN_PEAKMETER
:
239 snprintf(buf
, bufsize
, "peakmeter");
243 case WPS_TOKEN_PROGRESSBAR
:
244 snprintf(buf
, bufsize
, "progressbar");
247 #ifdef HAVE_LCD_CHARCELLS
248 case WPS_TOKEN_PLAYER_PROGRESSBAR
:
249 snprintf(buf
, bufsize
, "full line progressbar");
253 case WPS_TOKEN_TRACK_TIME_ELAPSED
:
254 snprintf(buf
, bufsize
, "time elapsed in track");
257 case WPS_TOKEN_TRACK_ELAPSED_PERCENT
:
258 snprintf(buf
, bufsize
, "played percentage of track");
261 case WPS_TOKEN_PLAYLIST_ENTRIES
:
262 snprintf(buf
, bufsize
, "number of entries in playlist");
265 case WPS_TOKEN_PLAYLIST_NAME
:
266 snprintf(buf
, bufsize
, "playlist name");
269 case WPS_TOKEN_PLAYLIST_POSITION
:
270 snprintf(buf
, bufsize
, "position in playlist");
273 case WPS_TOKEN_TRACK_TIME_REMAINING
:
274 snprintf(buf
, bufsize
, "time remaining in track");
277 case WPS_TOKEN_PLAYLIST_SHUFFLE
:
278 snprintf(buf
, bufsize
, "playlist shuffle mode");
281 case WPS_TOKEN_TRACK_LENGTH
:
282 snprintf(buf
, bufsize
, "track length");
285 case WPS_TOKEN_VOLUME
:
286 snprintf(buf
, bufsize
, "volume");
289 case WPS_TOKEN_METADATA_ARTIST
:
290 snprintf(buf
, bufsize
, "%strack artist",
294 case WPS_TOKEN_METADATA_COMPOSER
:
295 snprintf(buf
, bufsize
, "%strack composer",
299 case WPS_TOKEN_METADATA_ALBUM
:
300 snprintf(buf
, bufsize
, "%strack album",
304 case WPS_TOKEN_METADATA_GROUPING
:
305 snprintf(buf
, bufsize
, "%strack grouping",
309 case WPS_TOKEN_METADATA_GENRE
:
310 snprintf(buf
, bufsize
, "%strack genre",
314 case WPS_TOKEN_METADATA_DISC_NUMBER
:
315 snprintf(buf
, bufsize
, "%strack disc", next_str(next
));
318 case WPS_TOKEN_METADATA_TRACK_NUMBER
:
319 snprintf(buf
, bufsize
, "%strack number",
323 case WPS_TOKEN_METADATA_TRACK_TITLE
:
324 snprintf(buf
, bufsize
, "%strack title",
328 case WPS_TOKEN_METADATA_VERSION
:
329 snprintf(buf
, bufsize
, "%strack ID3 version",
333 case WPS_TOKEN_METADATA_ALBUM_ARTIST
:
334 snprintf(buf
, bufsize
, "%strack album artist",
338 case WPS_TOKEN_METADATA_COMMENT
:
339 snprintf(buf
, bufsize
, "%strack comment",
343 case WPS_TOKEN_METADATA_YEAR
:
344 snprintf(buf
, bufsize
, "%strack year", next_str(next
));
348 case WPS_TOKEN_DATABASE_PLAYCOUNT
:
349 snprintf(buf
, bufsize
, "track playcount (database)");
352 case WPS_TOKEN_DATABASE_RATING
:
353 snprintf(buf
, bufsize
, "track rating (database)");
356 case WPS_TOKEN_DATABASE_AUTOSCORE
:
357 snprintf(buf
, bufsize
, "track autoscore (database)");
361 case WPS_TOKEN_BATTERY_PERCENT
:
362 snprintf(buf
, bufsize
, "battery percentage");
365 case WPS_TOKEN_BATTERY_VOLTS
:
366 snprintf(buf
, bufsize
, "battery voltage");
369 case WPS_TOKEN_BATTERY_TIME
:
370 snprintf(buf
, bufsize
, "battery time left");
373 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED
:
374 snprintf(buf
, bufsize
, "battery charger connected");
377 case WPS_TOKEN_BATTERY_CHARGING
:
378 snprintf(buf
, bufsize
, "battery charging");
381 case WPS_TOKEN_BATTERY_SLEEPTIME
:
382 snprintf(buf
, bufsize
, "sleep timer");
385 case WPS_TOKEN_FILE_BITRATE
:
386 snprintf(buf
, bufsize
, "%sfile bitrate", next_str(next
));
389 case WPS_TOKEN_FILE_CODEC
:
390 snprintf(buf
, bufsize
, "%sfile codec", next_str(next
));
393 case WPS_TOKEN_FILE_FREQUENCY
:
394 snprintf(buf
, bufsize
, "%sfile audio frequency in Hz",
398 case WPS_TOKEN_FILE_FREQUENCY_KHZ
:
399 snprintf(buf
, bufsize
, "%sfile audio frequency in KHz",
403 case WPS_TOKEN_FILE_NAME
:
404 snprintf(buf
, bufsize
, "%sfile name", next_str(next
));
407 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION
:
408 snprintf(buf
, bufsize
, "%sfile name with extension",
412 case WPS_TOKEN_FILE_PATH
:
413 snprintf(buf
, bufsize
, "%sfile path", next_str(next
));
416 case WPS_TOKEN_FILE_SIZE
:
417 snprintf(buf
, bufsize
, "%sfile size", next_str(next
));
420 case WPS_TOKEN_FILE_VBR
:
421 snprintf(buf
, bufsize
, "%sfile is vbr", next_str(next
));
424 case WPS_TOKEN_FILE_DIRECTORY
:
425 snprintf(buf
, bufsize
, "%sfile directory, level: %d",
426 next_str(next
), token
->value
.i
);
429 #if (CONFIG_CODEC != MAS3507D)
430 case WPS_TOKEN_SOUND_PITCH
:
431 snprintf(buf
, bufsize
, "pitch value");
436 snprintf(buf
, bufsize
, "FIXME (code: %d)",
444 static void dump_wps_tokens(struct wps_data
*data
)
446 struct wps_token
*token
;
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
));
459 case WPS_TOKEN_STRING
:
463 case WPS_TOKEN_CONDITIONAL_START
:
467 case WPS_TOKEN_CONDITIONAL_END
:
475 if (wps_verbose_level
> 2)
477 for(j
= 0; j
< indent
; j
++) {
481 DEBUGF("[%3d] = (%2d) %s\n", i
, token
->type
, buf
);
485 if (wps_verbose_level
> 0)
488 DEBUGF("Number of string tokens: %d\n", num_string_tokens
);
493 static void print_line_info(struct wps_data
*data
)
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
);
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");
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
]);
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
);
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",
582 DEBUGF("Failed parsing on line %d : ", line
);
585 case PARSE_FAIL_UNCLOSED_COND
:
586 DEBUGF("Unclosed conditional");
589 case PARSE_FAIL_INVALID_CHAR
:
590 DEBUGF("unexpected conditional char after token %d: \"%s\"",
592 get_token_desc(&data
->tokens
[data
->num_tokens
-1], data
,
597 case PARSE_FAIL_COND_SYNTAX_ERROR
:
598 DEBUGF("Conditional syntax error after token %d: \"%s\"",
600 get_token_desc(&data
->tokens
[data
->num_tokens
-1], data
,
605 case PARSE_FAIL_COND_INVALID_PARAM
:
606 DEBUGF("Invalid parameter list for token %d: \"%s\"",
608 get_token_desc(&data
->tokens
[data
->num_tokens
], data
,