1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
48 #include "settings_list.h"
50 #ifdef HAVE_LCD_BITMAP
56 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
57 #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
59 #define WPS_ERROR_INVALID_PARAM -1
61 /* level of current conditional.
62 -1 means we're not in a conditional. */
63 static int level
= -1;
65 /* index of the last WPS_TOKEN_CONDITIONAL_OPTION
66 or WPS_TOKEN_CONDITIONAL_START in current level */
67 static int lastcond
[WPS_MAX_COND_LEVEL
];
69 /* index of the WPS_TOKEN_CONDITIONAL in current level */
70 static int condindex
[WPS_MAX_COND_LEVEL
];
72 /* number of condtional options in current level */
73 static int numoptions
[WPS_MAX_COND_LEVEL
];
75 /* the current line in the file */
78 #ifdef HAVE_LCD_BITMAP
81 #define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS+1) /* WPS images + pbar bitmap + backdrop */
83 #define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS) /* WPS images + pbar bitmap */
86 #define PROGRESSBAR_BMP MAX_IMAGES
87 #define BACKDROP_BMP (MAX_BITMAPS-1)
89 /* pointers to the bitmap filenames in the WPS source */
90 static const char *bmp_names
[MAX_BITMAPS
];
92 #endif /* HAVE_LCD_BITMAP */
94 #if defined(DEBUG) || defined(SIMULATOR)
95 /* debugging function */
96 extern void print_debug_info(struct wps_data
*data
, int fail
, int line
);
99 static void wps_reset(struct wps_data
*data
);
101 /* Function for parsing of details for a token. At the moment the
102 function is called, the token type has already been set. The
103 function must fill in the details and possibly add more tokens
104 to the token array. It should return the number of chars that
107 wps_bufptr points to the char following the tag (i.e. where
109 token is the pointer to the 'main' token being parsed
111 typedef int (*wps_tag_parse_func
)(const char *wps_bufptr
,
112 struct wps_token
*token
, struct wps_data
*wps_data
);
115 enum wps_token_type type
;
117 unsigned char refresh_type
;
118 const wps_tag_parse_func parse_func
;
120 static int skip_end_of_line(const char *wps_bufptr
);
121 /* prototypes of all special parse functions : */
122 static int parse_timeout(const char *wps_bufptr
,
123 struct wps_token
*token
, struct wps_data
*wps_data
);
124 static int parse_progressbar(const char *wps_bufptr
,
125 struct wps_token
*token
, struct wps_data
*wps_data
);
126 static int parse_dir_level(const char *wps_bufptr
,
127 struct wps_token
*token
, struct wps_data
*wps_data
);
128 static int parse_setting(const char *wps_bufptr
,
129 struct wps_token
*token
, struct wps_data
*wps_data
);
131 #ifdef HAVE_LCD_BITMAP
132 static int parse_viewport_display(const char *wps_bufptr
,
133 struct wps_token
*token
, struct wps_data
*wps_data
);
134 static int parse_viewport(const char *wps_bufptr
,
135 struct wps_token
*token
, struct wps_data
*wps_data
);
136 static int parse_statusbar_enable(const char *wps_bufptr
,
137 struct wps_token
*token
, struct wps_data
*wps_data
);
138 static int parse_statusbar_disable(const char *wps_bufptr
,
139 struct wps_token
*token
, struct wps_data
*wps_data
);
140 static int parse_image_display(const char *wps_bufptr
,
141 struct wps_token
*token
, struct wps_data
*wps_data
);
142 static int parse_image_load(const char *wps_bufptr
,
143 struct wps_token
*token
, struct wps_data
*wps_data
);
144 #endif /*HAVE_LCD_BITMAP */
145 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
146 static int parse_image_special(const char *wps_bufptr
,
147 struct wps_token
*token
, struct wps_data
*wps_data
);
150 static int parse_albumart_load(const char *wps_bufptr
,
151 struct wps_token
*token
, struct wps_data
*wps_data
);
152 static int parse_albumart_conditional(const char *wps_bufptr
,
153 struct wps_token
*token
, struct wps_data
*wps_data
);
154 #endif /* HAVE_ALBUMART */
155 #ifdef HAVE_TOUCHSCREEN
156 static int parse_touchregion(const char *wps_bufptr
,
157 struct wps_token
*token
, struct wps_data
*wps_data
);
159 static int fulline_tag_not_supported(const char *wps_bufptr
,
160 struct wps_token
*token
, struct wps_data
*wps_data
)
162 (void)token
; (void)wps_data
;
163 return skip_end_of_line(wps_bufptr
);
165 #define parse_touchregion fulline_tag_not_supported
168 #define WPS_RTC_REFRESH WPS_REFRESH_DYNAMIC
170 #define WPS_RTC_REFRESH WPS_REFRESH_STATIC
173 /* array of available tags - those with more characters have to go first
174 (e.g. "xl" and "xd" before "x"). It needs to end with the unknown token. */
175 static const struct wps_tag all_tags
[] = {
177 { WPS_TOKEN_ALIGN_CENTER
, "ac", 0, NULL
},
178 { WPS_TOKEN_ALIGN_LEFT
, "al", 0, NULL
},
179 { WPS_TOKEN_ALIGN_RIGHT
, "ar", 0, NULL
},
181 { WPS_TOKEN_BATTERY_PERCENT
, "bl", WPS_REFRESH_DYNAMIC
, NULL
},
182 { WPS_TOKEN_BATTERY_VOLTS
, "bv", WPS_REFRESH_DYNAMIC
, NULL
},
183 { WPS_TOKEN_BATTERY_TIME
, "bt", WPS_REFRESH_DYNAMIC
, NULL
},
184 { WPS_TOKEN_BATTERY_SLEEPTIME
, "bs", WPS_REFRESH_DYNAMIC
, NULL
},
185 #if CONFIG_CHARGING >= CHARGING_MONITOR
186 { WPS_TOKEN_BATTERY_CHARGING
, "bc", WPS_REFRESH_DYNAMIC
, NULL
},
189 { WPS_TOKEN_BATTERY_CHARGER_CONNECTED
,"bp", WPS_REFRESH_DYNAMIC
, NULL
},
192 { WPS_TOKEN_RTC_PRESENT
, "cc", WPS_REFRESH_STATIC
, NULL
},
193 { WPS_TOKEN_RTC_DAY_OF_MONTH
, "cd", WPS_RTC_REFRESH
, NULL
},
194 { WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
,"ce", WPS_RTC_REFRESH
, NULL
},
195 { WPS_TOKEN_RTC_12HOUR_CFG
, "cf", WPS_RTC_REFRESH
, NULL
},
196 { WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED
, "cH", WPS_RTC_REFRESH
, NULL
},
197 { WPS_TOKEN_RTC_HOUR_24
, "ck", WPS_RTC_REFRESH
, NULL
},
198 { WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED
, "cI", WPS_RTC_REFRESH
, NULL
},
199 { WPS_TOKEN_RTC_HOUR_12
, "cl", WPS_RTC_REFRESH
, NULL
},
200 { WPS_TOKEN_RTC_MONTH
, "cm", WPS_RTC_REFRESH
, NULL
},
201 { WPS_TOKEN_RTC_MINUTE
, "cM", WPS_RTC_REFRESH
, NULL
},
202 { WPS_TOKEN_RTC_SECOND
, "cS", WPS_RTC_REFRESH
, NULL
},
203 { WPS_TOKEN_RTC_YEAR_2_DIGITS
, "cy", WPS_RTC_REFRESH
, NULL
},
204 { WPS_TOKEN_RTC_YEAR_4_DIGITS
, "cY", WPS_RTC_REFRESH
, NULL
},
205 { WPS_TOKEN_RTC_AM_PM_UPPER
, "cP", WPS_RTC_REFRESH
, NULL
},
206 { WPS_TOKEN_RTC_AM_PM_LOWER
, "cp", WPS_RTC_REFRESH
, NULL
},
207 { WPS_TOKEN_RTC_WEEKDAY_NAME
, "ca", WPS_RTC_REFRESH
, NULL
},
208 { WPS_TOKEN_RTC_MONTH_NAME
, "cb", WPS_RTC_REFRESH
, NULL
},
209 { WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON
, "cu", WPS_RTC_REFRESH
, NULL
},
210 { WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN
, "cw", WPS_RTC_REFRESH
, NULL
},
213 { WPS_TOKEN_FILE_BITRATE
, "fb", WPS_REFRESH_STATIC
, NULL
},
214 { WPS_TOKEN_FILE_CODEC
, "fc", WPS_REFRESH_STATIC
, NULL
},
215 { WPS_TOKEN_FILE_FREQUENCY
, "ff", WPS_REFRESH_STATIC
, NULL
},
216 { WPS_TOKEN_FILE_FREQUENCY_KHZ
, "fk", WPS_REFRESH_STATIC
, NULL
},
217 { WPS_TOKEN_FILE_NAME_WITH_EXTENSION
, "fm", WPS_REFRESH_STATIC
, NULL
},
218 { WPS_TOKEN_FILE_NAME
, "fn", WPS_REFRESH_STATIC
, NULL
},
219 { WPS_TOKEN_FILE_PATH
, "fp", WPS_REFRESH_STATIC
, NULL
},
220 { WPS_TOKEN_FILE_SIZE
, "fs", WPS_REFRESH_STATIC
, NULL
},
221 { WPS_TOKEN_FILE_VBR
, "fv", WPS_REFRESH_STATIC
, NULL
},
222 { WPS_TOKEN_FILE_DIRECTORY
, "d", WPS_REFRESH_STATIC
,
226 { WPS_TOKEN_FILE_BITRATE
, "Fb", WPS_REFRESH_STATIC
, NULL
},
227 { WPS_TOKEN_FILE_CODEC
, "Fc", WPS_REFRESH_STATIC
, NULL
},
228 { WPS_TOKEN_FILE_FREQUENCY
, "Ff", WPS_REFRESH_STATIC
, NULL
},
229 { WPS_TOKEN_FILE_FREQUENCY_KHZ
, "Fk", WPS_REFRESH_STATIC
, NULL
},
230 { WPS_TOKEN_FILE_NAME_WITH_EXTENSION
, "Fm", WPS_REFRESH_STATIC
, NULL
},
231 { WPS_TOKEN_FILE_NAME
, "Fn", WPS_REFRESH_STATIC
, NULL
},
232 { WPS_TOKEN_FILE_PATH
, "Fp", WPS_REFRESH_STATIC
, NULL
},
233 { WPS_TOKEN_FILE_SIZE
, "Fs", WPS_REFRESH_STATIC
, NULL
},
234 { WPS_TOKEN_FILE_VBR
, "Fv", WPS_REFRESH_STATIC
, NULL
},
235 { WPS_TOKEN_FILE_DIRECTORY
, "D", WPS_REFRESH_STATIC
,
238 /* current metadata */
239 { WPS_TOKEN_METADATA_ARTIST
, "ia", WPS_REFRESH_STATIC
, NULL
},
240 { WPS_TOKEN_METADATA_COMPOSER
, "ic", WPS_REFRESH_STATIC
, NULL
},
241 { WPS_TOKEN_METADATA_ALBUM
, "id", WPS_REFRESH_STATIC
, NULL
},
242 { WPS_TOKEN_METADATA_ALBUM_ARTIST
, "iA", WPS_REFRESH_STATIC
, NULL
},
243 { WPS_TOKEN_METADATA_GROUPING
, "iG", WPS_REFRESH_STATIC
, NULL
},
244 { WPS_TOKEN_METADATA_GENRE
, "ig", WPS_REFRESH_STATIC
, NULL
},
245 { WPS_TOKEN_METADATA_DISC_NUMBER
, "ik", WPS_REFRESH_STATIC
, NULL
},
246 { WPS_TOKEN_METADATA_TRACK_NUMBER
, "in", WPS_REFRESH_STATIC
, NULL
},
247 { WPS_TOKEN_METADATA_TRACK_TITLE
, "it", WPS_REFRESH_STATIC
, NULL
},
248 { WPS_TOKEN_METADATA_VERSION
, "iv", WPS_REFRESH_STATIC
, NULL
},
249 { WPS_TOKEN_METADATA_YEAR
, "iy", WPS_REFRESH_STATIC
, NULL
},
250 { WPS_TOKEN_METADATA_COMMENT
, "iC", WPS_REFRESH_STATIC
, NULL
},
253 { WPS_TOKEN_METADATA_ARTIST
, "Ia", WPS_REFRESH_STATIC
, NULL
},
254 { WPS_TOKEN_METADATA_COMPOSER
, "Ic", WPS_REFRESH_STATIC
, NULL
},
255 { WPS_TOKEN_METADATA_ALBUM
, "Id", WPS_REFRESH_STATIC
, NULL
},
256 { WPS_TOKEN_METADATA_ALBUM_ARTIST
, "IA", WPS_REFRESH_STATIC
, NULL
},
257 { WPS_TOKEN_METADATA_GROUPING
, "IG", WPS_REFRESH_STATIC
, NULL
},
258 { WPS_TOKEN_METADATA_GENRE
, "Ig", WPS_REFRESH_STATIC
, NULL
},
259 { WPS_TOKEN_METADATA_DISC_NUMBER
, "Ik", WPS_REFRESH_STATIC
, NULL
},
260 { WPS_TOKEN_METADATA_TRACK_NUMBER
, "In", WPS_REFRESH_STATIC
, NULL
},
261 { WPS_TOKEN_METADATA_TRACK_TITLE
, "It", WPS_REFRESH_STATIC
, NULL
},
262 { WPS_TOKEN_METADATA_VERSION
, "Iv", WPS_REFRESH_STATIC
, NULL
},
263 { WPS_TOKEN_METADATA_YEAR
, "Iy", WPS_REFRESH_STATIC
, NULL
},
264 { WPS_TOKEN_METADATA_COMMENT
, "IC", WPS_REFRESH_STATIC
, NULL
},
266 #if (CONFIG_CODEC != MAS3507D)
267 { WPS_TOKEN_SOUND_PITCH
, "Sp", WPS_REFRESH_DYNAMIC
, NULL
},
270 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
271 { WPS_TOKEN_VLED_HDD
, "lh", WPS_REFRESH_DYNAMIC
, NULL
},
274 { WPS_TOKEN_MAIN_HOLD
, "mh", WPS_REFRESH_DYNAMIC
, NULL
},
276 #ifdef HAS_REMOTE_BUTTON_HOLD
277 { WPS_TOKEN_REMOTE_HOLD
, "mr", WPS_REFRESH_DYNAMIC
, NULL
},
279 { WPS_TOKEN_UNKNOWN
, "mr", 0, NULL
},
282 { WPS_TOKEN_REPEAT_MODE
, "mm", WPS_REFRESH_DYNAMIC
, NULL
},
283 { WPS_TOKEN_PLAYBACK_STATUS
, "mp", WPS_REFRESH_DYNAMIC
, NULL
},
284 { WPS_TOKEN_BUTTON_VOLUME
, "mv", WPS_REFRESH_DYNAMIC
,
287 #ifdef HAVE_LCD_BITMAP
288 { WPS_TOKEN_PEAKMETER
, "pm", WPS_REFRESH_PEAK_METER
, NULL
},
290 { WPS_TOKEN_PLAYER_PROGRESSBAR
, "pf",
291 WPS_REFRESH_DYNAMIC
| WPS_REFRESH_PLAYER_PROGRESS
, parse_progressbar
},
293 { WPS_TOKEN_PROGRESSBAR
, "pb", WPS_REFRESH_PLAYER_PROGRESS
,
296 { WPS_TOKEN_VOLUME
, "pv", WPS_REFRESH_DYNAMIC
, NULL
},
298 { WPS_TOKEN_TRACK_ELAPSED_PERCENT
, "px", WPS_REFRESH_DYNAMIC
, NULL
},
299 { WPS_TOKEN_TRACK_TIME_ELAPSED
, "pc", WPS_REFRESH_DYNAMIC
, NULL
},
300 { WPS_TOKEN_TRACK_TIME_REMAINING
, "pr", WPS_REFRESH_DYNAMIC
, NULL
},
301 { WPS_TOKEN_TRACK_LENGTH
, "pt", WPS_REFRESH_STATIC
, NULL
},
303 { WPS_TOKEN_PLAYLIST_POSITION
, "pp", WPS_REFRESH_STATIC
, NULL
},
304 { WPS_TOKEN_PLAYLIST_ENTRIES
, "pe", WPS_REFRESH_STATIC
, NULL
},
305 { WPS_TOKEN_PLAYLIST_NAME
, "pn", WPS_REFRESH_STATIC
, NULL
},
306 { WPS_TOKEN_PLAYLIST_SHUFFLE
, "ps", WPS_REFRESH_DYNAMIC
, NULL
},
309 { WPS_TOKEN_DATABASE_PLAYCOUNT
, "rp", WPS_REFRESH_DYNAMIC
, NULL
},
310 { WPS_TOKEN_DATABASE_RATING
, "rr", WPS_REFRESH_DYNAMIC
, NULL
},
311 { WPS_TOKEN_DATABASE_AUTOSCORE
, "ra", WPS_REFRESH_DYNAMIC
, NULL
},
314 #if CONFIG_CODEC == SWCODEC
315 { WPS_TOKEN_REPLAYGAIN
, "rg", WPS_REFRESH_STATIC
, NULL
},
316 { WPS_TOKEN_CROSSFADE
, "xf", WPS_REFRESH_DYNAMIC
, NULL
},
319 { WPS_NO_TOKEN
, "s", WPS_REFRESH_SCROLL
, NULL
},
320 { WPS_TOKEN_SUBLINE_TIMEOUT
, "t", 0, parse_timeout
},
322 #ifdef HAVE_LCD_BITMAP
323 { WPS_NO_TOKEN
, "we", 0, parse_statusbar_enable
},
324 { WPS_NO_TOKEN
, "wd", 0, parse_statusbar_disable
},
326 { WPS_NO_TOKEN
, "xl", 0, parse_image_load
},
328 { WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
, "xd", WPS_REFRESH_STATIC
,
329 parse_image_display
},
331 { WPS_TOKEN_IMAGE_DISPLAY
, "x", 0, parse_image_load
},
333 { WPS_NO_TOKEN
, "Cl", 0, parse_albumart_load
},
334 { WPS_TOKEN_ALBUMART_DISPLAY
, "C", WPS_REFRESH_STATIC
,
335 parse_albumart_conditional
},
338 { WPS_VIEWPORT_ENABLE
, "Vd", WPS_REFRESH_DYNAMIC
,
339 parse_viewport_display
},
340 { WPS_NO_TOKEN
, "V", 0, parse_viewport
},
342 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
343 { WPS_TOKEN_IMAGE_BACKDROP
, "X", 0, parse_image_special
},
347 { WPS_TOKEN_SETTING
, "St", WPS_REFRESH_DYNAMIC
, parse_setting
},
349 { WPS_TOKEN_LASTTOUCH
, "Tl", WPS_REFRESH_DYNAMIC
, parse_timeout
},
350 { WPS_NO_TOKEN
, "T", 0, parse_touchregion
},
352 { WPS_TOKEN_UNKNOWN
, "", 0, NULL
}
353 /* the array MUST end with an empty string (first char is \0) */
356 /* Returns the number of chars that should be skipped to jump
357 immediately after the first eol, i.e. to the start of the next line */
358 static int skip_end_of_line(const char *wps_bufptr
)
362 while(*(wps_bufptr
+ skip
) != '\n')
367 /* Starts a new subline in the current line during parsing */
368 static void wps_start_new_subline(struct wps_data
*data
)
370 data
->num_sublines
++;
371 data
->sublines
[data
->num_sublines
].first_token_idx
= data
->num_tokens
;
372 data
->lines
[data
->num_lines
].num_sublines
++;
375 #ifdef HAVE_LCD_BITMAP
377 static int parse_statusbar_enable(const char *wps_bufptr
,
378 struct wps_token
*token
,
379 struct wps_data
*wps_data
)
381 (void)token
; /* Kill warnings */
382 wps_data
->wps_sb_tag
= true;
383 wps_data
->show_sb_on_wps
= true;
384 if (wps_data
->viewports
[0].vp
.y
== 0)
386 wps_data
->viewports
[0].vp
.y
= STATUSBAR_HEIGHT
;
387 wps_data
->viewports
[0].vp
.height
-= STATUSBAR_HEIGHT
;
389 return skip_end_of_line(wps_bufptr
);
392 static int parse_statusbar_disable(const char *wps_bufptr
,
393 struct wps_token
*token
,
394 struct wps_data
*wps_data
)
396 (void)token
; /* Kill warnings */
397 wps_data
->wps_sb_tag
= true;
398 wps_data
->show_sb_on_wps
= false;
399 if (wps_data
->viewports
[0].vp
.y
== STATUSBAR_HEIGHT
)
401 wps_data
->viewports
[0].vp
.y
= 0;
402 wps_data
->viewports
[0].vp
.height
+= STATUSBAR_HEIGHT
;
404 return skip_end_of_line(wps_bufptr
);
407 static bool load_bitmap(struct wps_data
*wps_data
,
412 #ifdef HAVE_REMOTE_LCD
413 if (wps_data
->remote_wps
)
414 format
= FORMAT_ANY
|FORMAT_REMOTE
;
417 format
= FORMAT_ANY
|FORMAT_TRANSPARENT
;
419 int ret
= read_bmp_file(filename
, bm
,
420 wps_data
->img_buf_free
,
427 /* Always consume an even number of bytes */
429 wps_data
->img_buf_ptr
+= ret
;
430 wps_data
->img_buf_free
-= ret
;
438 static int get_image_id(int c
)
440 if(c
>= 'a' && c
<= 'z')
442 else if(c
>= 'A' && c
<= 'Z')
448 static char *get_image_filename(const char *start
, const char* bmpdir
,
449 char *buf
, int buf_size
)
451 const char *end
= strchr(start
, '|');
453 if ( !end
|| (end
- start
) >= (buf_size
- (int)ROCKBOX_DIR_LEN
- 2) )
459 int bmpdirlen
= strlen(bmpdir
);
462 buf
[bmpdirlen
] = '/';
463 memcpy( &buf
[bmpdirlen
+ 1], start
, end
- start
);
464 buf
[bmpdirlen
+ 1 + end
- start
] = 0;
469 static int parse_image_display(const char *wps_bufptr
,
470 struct wps_token
*token
,
471 struct wps_data
*wps_data
)
474 int n
= get_image_id(wps_bufptr
[0]);
479 /* invalid picture display tag */
480 return WPS_ERROR_INVALID_PARAM
;
483 if ((subimage
= get_image_id(wps_bufptr
[1])) != -1)
486 if (subimage
>= wps_data
->img
[n
].num_subimages
)
487 return WPS_ERROR_INVALID_PARAM
;
489 /* Store sub-image number to display in high bits */
490 token
->value
.i
= n
| (subimage
<< 8);
491 return 2; /* We have consumed 2 bytes */
494 return 1; /* We have consumed 1 byte */
498 static int parse_image_load(const char *wps_bufptr
,
499 struct wps_token
*token
,
500 struct wps_data
*wps_data
)
503 const char *ptr
= wps_bufptr
;
505 const char* filename
;
510 /* format: %x|n|filename.bmp|x|y|
511 or %xl|n|filename.bmp|x|y|
512 or %xl|n|filename.bmp|x|y|num_subimages|
516 return WPS_ERROR_INVALID_PARAM
;
520 if (!(ptr
= parse_list("ssdd", NULL
, '|', ptr
, &id
, &filename
, &x
, &y
)))
521 return WPS_ERROR_INVALID_PARAM
;
523 /* Check there is a terminating | */
525 return WPS_ERROR_INVALID_PARAM
;
527 /* get the image ID */
528 n
= get_image_id(*id
);
530 /* check the image number and load state */
531 if(n
< 0 || n
>= MAX_IMAGES
|| wps_data
->img
[n
].loaded
)
533 /* Invalid image ID */
534 return WPS_ERROR_INVALID_PARAM
;
537 /* save a pointer to the filename */
538 bmp_names
[n
] = filename
;
540 wps_data
->img
[n
].x
= x
;
541 wps_data
->img
[n
].y
= y
;
543 /* save current viewport */
544 wps_data
->img
[n
].vp
= &wps_data
->viewports
[wps_data
->num_viewports
].vp
;
546 if (token
->type
== WPS_TOKEN_IMAGE_DISPLAY
)
548 wps_data
->img
[n
].always_display
= true;
552 /* Parse the (optional) number of sub-images */
554 newline
= strchr(ptr
, '\n');
555 pos
= strchr(ptr
, '|');
556 if (pos
&& pos
< newline
)
557 wps_data
->img
[n
].num_subimages
= atoi(ptr
);
559 if (wps_data
->img
[n
].num_subimages
<= 0)
560 return WPS_ERROR_INVALID_PARAM
;
563 /* Skip the rest of the line */
564 return skip_end_of_line(wps_bufptr
);
567 static int parse_viewport_display(const char *wps_bufptr
,
568 struct wps_token
*token
,
569 struct wps_data
*wps_data
)
572 char letter
= wps_bufptr
[0];
574 if (letter
< 'a' || letter
> 'z')
576 /* invalid viewport tag */
577 return WPS_ERROR_INVALID_PARAM
;
579 token
->value
.i
= letter
;
583 static int parse_viewport(const char *wps_bufptr
,
584 struct wps_token
*token
,
585 struct wps_data
*wps_data
)
587 (void)token
; /* Kill warnings */
588 const char *ptr
= wps_bufptr
;
601 int lcd_width
= LCD_WIDTH
, lcd_height
= LCD_HEIGHT
;
602 #ifdef HAVE_REMOTE_LCD
603 if (wps_data
->remote_wps
)
605 lcd_width
= LCD_REMOTE_WIDTH
;
606 lcd_height
= LCD_REMOTE_HEIGHT
;
610 if (wps_data
->num_viewports
>= WPS_MAX_VIEWPORTS
)
611 return WPS_ERROR_INVALID_PARAM
;
613 wps_data
->num_viewports
++;
614 /* check for the optional letter to signify its a hideable viewport */
615 /* %Vl|<label>|<rest of tags>| */
616 wps_data
->viewports
[wps_data
->num_viewports
].hidden_flags
= 0;
622 char label
= *(ptr
+2);
623 if (label
>= 'a' && label
<= 'z')
625 wps_data
->viewports
[wps_data
->num_viewports
].hidden_flags
= VP_DRAW_HIDEABLE
;
626 wps_data
->viewports
[wps_data
->num_viewports
].label
= label
;
629 return WPS_ERROR_INVALID_PARAM
; /* malformed token: e.g. %Cl7 */
634 return WPS_ERROR_INVALID_PARAM
;
637 vp
= &wps_data
->viewports
[wps_data
->num_viewports
].vp
;
638 /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */
640 /* Set the defaults for fields not user-specified */
641 vp
->drawmode
= DRMODE_SOLID
;
643 /* Work out the depth of this display */
644 #ifdef HAVE_REMOTE_LCD
645 depth
= (wps_data
->remote_wps
? LCD_REMOTE_DEPTH
: LCD_DEPTH
);
650 #ifdef HAVE_LCD_COLOR
653 if (!(ptr
= parse_list("dddddcc", &set
, '|', ptr
, &vp
->x
, &vp
->y
, &vp
->width
,
654 &vp
->height
, &vp
->font
, &vp
->fg_pattern
,&vp
->bg_pattern
)))
655 return WPS_ERROR_INVALID_PARAM
;
659 #if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
661 /* Default to black on white */
664 if (!(ptr
= parse_list("dddddgg", &set
, '|', ptr
, &vp
->x
, &vp
->y
, &vp
->width
,
665 &vp
->height
, &vp
->font
, &vp
->fg_pattern
, &vp
->bg_pattern
)))
666 return WPS_ERROR_INVALID_PARAM
;
670 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
673 if (!(ptr
= parse_list("ddddd", &set
, '|', ptr
, &vp
->x
, &vp
->y
,
674 &vp
->width
, &vp
->height
, &vp
->font
)))
675 return WPS_ERROR_INVALID_PARAM
;
681 /* Check for trailing | */
683 return WPS_ERROR_INVALID_PARAM
;
685 if (!LIST_VALUE_PARSED(set
, PL_X
) || !LIST_VALUE_PARSED(set
, PL_Y
))
686 return WPS_ERROR_INVALID_PARAM
;
689 if (!LIST_VALUE_PARSED(set
, PL_WIDTH
))
690 vp
->width
= lcd_width
- vp
->x
;
691 if (!LIST_VALUE_PARSED(set
, PL_HEIGHT
))
692 vp
->height
= lcd_height
- vp
->y
;
694 /* Default to using the user font if the font was an invalid number */
695 if (!LIST_VALUE_PARSED(set
, PL_FONT
) ||
696 ((vp
->font
!= FONT_SYSFIXED
) && (vp
->font
!= FONT_UI
)))
699 /* Validate the viewport dimensions - we know that the numbers are
700 non-negative integers */
701 if ((vp
->x
>= lcd_width
) ||
702 ((vp
->x
+ vp
->width
) > lcd_width
) ||
703 (vp
->y
>= lcd_height
) ||
704 ((vp
->y
+ vp
->height
) > lcd_height
))
706 return WPS_ERROR_INVALID_PARAM
;
709 #ifdef HAVE_LCD_COLOR
712 if (!LIST_VALUE_PARSED(set
, PL_FG
))
713 vp
->fg_pattern
= global_settings
.fg_color
;
714 if (!LIST_VALUE_PARSED(set
, PL_BG
))
715 vp
->bg_pattern
= global_settings
.bg_color
;
719 wps_data
->viewports
[wps_data
->num_viewports
-1].last_line
= wps_data
->num_lines
- 1;
721 wps_data
->viewports
[wps_data
->num_viewports
].first_line
= wps_data
->num_lines
;
723 if (wps_data
->num_sublines
< WPS_MAX_SUBLINES
)
725 wps_data
->lines
[wps_data
->num_lines
].first_subline_idx
=
726 wps_data
->num_sublines
;
728 wps_data
->sublines
[wps_data
->num_sublines
].first_token_idx
=
729 wps_data
->num_tokens
;
732 /* Skip the rest of the line */
733 return skip_end_of_line(wps_bufptr
);
736 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
737 static int parse_image_special(const char *wps_bufptr
,
738 struct wps_token
*token
,
739 struct wps_data
*wps_data
)
741 (void)wps_data
; /* kill warning */
743 const char *pos
= NULL
;
746 pos
= strchr(wps_bufptr
+ 1, '|');
747 newline
= strchr(wps_bufptr
, '\n');
750 return WPS_ERROR_INVALID_PARAM
;
752 if (token
->type
== WPS_TOKEN_IMAGE_BACKDROP
)
754 /* format: %X|filename.bmp| */
755 bmp_names
[BACKDROP_BMP
] = wps_bufptr
+ 1;
759 /* Skip the rest of the line */
760 return skip_end_of_line(wps_bufptr
);
764 #endif /* HAVE_LCD_BITMAP */
766 static int parse_setting(const char *wps_bufptr
,
767 struct wps_token
*token
,
768 struct wps_data
*wps_data
)
771 const char *ptr
= wps_bufptr
;
775 /* Find the setting's cfg_name */
777 return WPS_ERROR_INVALID_PARAM
;
779 end
= strchr(ptr
,'|');
781 return WPS_ERROR_INVALID_PARAM
;
783 /* Find the setting */
784 for (i
=0; i
<nb_settings
; i
++)
785 if (settings
[i
].cfg_name
&&
786 !strncmp(settings
[i
].cfg_name
,ptr
,end
-ptr
) &&
787 /* prevent matches on cfg_name prefixes */
788 strlen(settings
[i
].cfg_name
)==(size_t)(end
-ptr
))
790 if (i
== nb_settings
)
791 return WPS_ERROR_INVALID_PARAM
;
793 /* Store the setting number */
796 /* Skip the rest of the line */
801 static int parse_dir_level(const char *wps_bufptr
,
802 struct wps_token
*token
,
803 struct wps_data
*wps_data
)
805 char val
[] = { *wps_bufptr
, '\0' };
806 token
->value
.i
= atoi(val
);
807 (void)wps_data
; /* Kill warnings */
811 static int parse_timeout(const char *wps_bufptr
,
812 struct wps_token
*token
,
813 struct wps_data
*wps_data
)
817 bool have_point
= false;
818 bool have_tenth
= false;
820 (void)wps_data
; /* Kill the warning */
822 while ( isdigit(*wps_bufptr
) || *wps_bufptr
== '.' )
824 if (*wps_bufptr
!= '.')
827 val
+= *wps_bufptr
- '0';
843 if (have_tenth
== false)
846 if (val
== 0 && skip
== 0)
848 /* decide what to do if no value was specified */
851 case WPS_TOKEN_SUBLINE_TIMEOUT
:
853 case WPS_TOKEN_BUTTON_VOLUME
:
858 token
->value
.i
= val
;
863 static int parse_progressbar(const char *wps_bufptr
,
864 struct wps_token
*token
,
865 struct wps_data
*wps_data
)
867 (void)token
; /* Kill warnings */
868 /* %pb or %pb|filename|x|y|width|height|
869 using - for any of the params uses "sane" values */
870 #ifdef HAVE_LCD_BITMAP
878 const char *filename
;
879 int x
, y
, height
, width
;
881 const char *ptr
= wps_bufptr
;
882 struct progressbar
*pb
;
883 struct viewport
*vp
= &wps_data
->viewports
[wps_data
->num_viewports
].vp
;
885 int font_height
= font_get(vp
->font
)->height
;
889 int line_num
= wps_data
->num_lines
-
890 wps_data
->viewports
[wps_data
->num_viewports
].first_line
;
892 if (wps_data
->progressbar_count
>= MAX_PROGRESSBARS
)
893 return WPS_ERROR_INVALID_PARAM
;
895 pb
= &wps_data
->progressbar
[wps_data
->progressbar_count
];
896 pb
->have_bitmap_pb
= false;
898 if (*wps_bufptr
!= '|') /* regular old style */
901 pb
->width
= vp
->width
;
902 pb
->height
= SYSFONT_HEIGHT
-2;
903 pb
->y
= -line_num
- 1; /* Will be computed during the rendering */
905 wps_data
->viewports
[wps_data
->num_viewports
].pb
= pb
;
906 wps_data
->progressbar_count
++;
909 ptr
= wps_bufptr
+ 1;
911 if (!(ptr
= parse_list("sdddd", &set
, '|', ptr
, &filename
,
912 &x
, &y
, &width
, &height
)))
913 return WPS_ERROR_INVALID_PARAM
;
915 if (LIST_VALUE_PARSED(set
, PB_FILENAME
)) /* filename */
916 bmp_names
[PROGRESSBAR_BMP
+wps_data
->progressbar_count
] = filename
;
918 if (LIST_VALUE_PARSED(set
, PB_X
)) /* x */
923 if (LIST_VALUE_PARSED(set
, PB_WIDTH
)) /* width */
925 /* A zero width causes a divide-by-zero error later, so reject it */
927 return WPS_ERROR_INVALID_PARAM
;
932 pb
->width
= vp
->width
- pb
->x
;
934 if (LIST_VALUE_PARSED(set
, PB_HEIGHT
)) /* height, default to font height */
936 /* A zero height makes no sense - reject it */
938 return WPS_ERROR_INVALID_PARAM
;
943 pb
->height
= font_height
;
945 if (LIST_VALUE_PARSED(set
, PB_Y
)) /* y */
948 pb
->y
= -line_num
- 1; /* Will be computed during the rendering */
950 wps_data
->viewports
[wps_data
->num_viewports
].pb
= pb
;
951 wps_data
->progressbar_count
++;
953 /* Skip the rest of the line */
954 return skip_end_of_line(wps_bufptr
)-1;
957 if (*(wps_bufptr
-1) == 'f')
958 wps_data
->full_line_progressbar
= true;
960 wps_data
->full_line_progressbar
= false;
968 static int parse_albumart_load(const char *wps_bufptr
,
969 struct wps_token
*token
,
970 struct wps_data
*wps_data
)
972 const char *_pos
, *newline
;
974 (void)token
; /* silence warning */
976 /* reset albumart info in wps */
977 wps_data
->albumart_max_width
= -1;
978 wps_data
->albumart_max_height
= -1;
979 wps_data
->albumart_xalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
980 wps_data
->albumart_yalign
= WPS_ALBUMART_ALIGN_CENTER
; /* default */
982 /* format: %Cl|x|y|[[l|c|r]mwidth]|[[t|c|b]mheight]| */
984 newline
= strchr(wps_bufptr
, '\n');
986 /* initial validation and parsing of x and y components */
987 if (*wps_bufptr
!= '|')
988 return WPS_ERROR_INVALID_PARAM
; /* malformed token: e.g. %Cl7 */
990 _pos
= wps_bufptr
+ 1;
992 return WPS_ERROR_INVALID_PARAM
; /* malformed token: e.g. %Cl|@ */
993 wps_data
->albumart_x
= atoi(_pos
);
995 _pos
= strchr(_pos
, '|');
996 if (!_pos
|| _pos
> newline
|| !isdigit(*(++_pos
)))
997 return WPS_ERROR_INVALID_PARAM
; /* malformed token: e.g. %Cl|7\n or %Cl|7|@ */
999 wps_data
->albumart_y
= atoi(_pos
);
1001 _pos
= strchr(_pos
, '|');
1002 if (!_pos
|| _pos
> newline
)
1003 return WPS_ERROR_INVALID_PARAM
; /* malformed token: no | after y coordinate
1006 /* parsing width field */
1010 /* apply each modifier in turn */
1017 wps_data
->albumart_xalign
= WPS_ALBUMART_ALIGN_LEFT
;
1021 wps_data
->albumart_xalign
= WPS_ALBUMART_ALIGN_CENTER
;
1026 wps_data
->albumart_xalign
= WPS_ALBUMART_ALIGN_RIGHT
;
1034 /* simply ignored */
1041 /* extract max width data */
1044 if (!isdigit(*_pos
)) /* malformed token: e.g. %Cl|7|59|# */
1045 return WPS_ERROR_INVALID_PARAM
;
1047 wps_data
->albumart_max_width
= atoi(_pos
);
1049 _pos
= strchr(_pos
, '|');
1050 if (!_pos
|| _pos
> newline
)
1051 return WPS_ERROR_INVALID_PARAM
; /* malformed token: no | after width field
1052 e.g. %Cl|7|59|200\n */
1055 /* parsing height field */
1059 /* apply each modifier in turn */
1066 wps_data
->albumart_yalign
= WPS_ALBUMART_ALIGN_TOP
;
1070 wps_data
->albumart_yalign
= WPS_ALBUMART_ALIGN_CENTER
;
1075 wps_data
->albumart_yalign
= WPS_ALBUMART_ALIGN_BOTTOM
;
1083 /* simply ignored */
1090 /* extract max height data */
1093 if (!isdigit(*_pos
))
1094 return WPS_ERROR_INVALID_PARAM
; /* malformed token e.g. %Cl|7|59|200|@ */
1096 wps_data
->albumart_max_height
= atoi(_pos
);
1098 _pos
= strchr(_pos
, '|');
1099 if (!_pos
|| _pos
> newline
)
1100 return WPS_ERROR_INVALID_PARAM
; /* malformed token: no closing |
1101 e.g. %Cl|7|59|200|200\n */
1104 /* if we got here, we parsed everything ok .. ! */
1105 if (wps_data
->albumart_max_width
< 0)
1106 wps_data
->albumart_max_width
= 0;
1107 else if (wps_data
->albumart_max_width
> LCD_WIDTH
)
1108 wps_data
->albumart_max_width
= LCD_WIDTH
;
1110 if (wps_data
->albumart_max_height
< 0)
1111 wps_data
->albumart_max_height
= 0;
1112 else if (wps_data
->albumart_max_height
> LCD_HEIGHT
)
1113 wps_data
->albumart_max_height
= LCD_HEIGHT
;
1115 wps_data
->wps_uses_albumart
= WPS_ALBUMART_LOAD
;
1117 /* Skip the rest of the line */
1118 return skip_end_of_line(wps_bufptr
);
1121 static int parse_albumart_conditional(const char *wps_bufptr
,
1122 struct wps_token
*token
,
1123 struct wps_data
*wps_data
)
1125 struct wps_token
*prevtoken
= token
;
1127 if (wps_data
->num_tokens
>= 1 && prevtoken
->type
== WPS_TOKEN_CONDITIONAL
)
1129 /* This %C is part of a %?C construct.
1130 It's either %?C<blah> or %?Cn<blah> */
1131 token
->type
= WPS_TOKEN_ALBUMART_FOUND
;
1132 if (*wps_bufptr
== 'n' && *(wps_bufptr
+ 1) == '<')
1137 else if (*wps_bufptr
== '<')
1143 token
->type
= WPS_NO_TOKEN
;
1149 /* This %C tag is in a conditional construct. */
1150 wps_data
->albumart_cond_index
= condindex
[level
];
1154 #endif /* HAVE_ALBUMART */
1156 #ifdef HAVE_TOUCHSCREEN
1158 struct touchaction
{char* s
; int action
;};
1159 static struct touchaction touchactions
[] = {
1160 {"play", ACTION_WPS_PLAY
}, {"stop", ACTION_WPS_STOP
},
1161 {"prev", ACTION_WPS_SKIPPREV
}, {"next", ACTION_WPS_SKIPNEXT
},
1162 {"ffwd", ACTION_WPS_SEEKFWD
}, {"rwd", ACTION_WPS_SEEKBACK
},
1163 {"menu", ACTION_WPS_MENU
}, {"browse", ACTION_WPS_BROWSE
},
1164 {"shuffle", ACTION_TOUCH_SHUFFLE
}, {"repmode", ACTION_TOUCH_REPMODE
},
1165 {"quickscreen", ACTION_WPS_QUICKSCREEN
},{"contextmenu", ACTION_WPS_CONTEXT
},
1167 static int parse_touchregion(const char *wps_bufptr
,
1168 struct wps_token
*token
, struct wps_data
*wps_data
)
1172 struct touchregion
*region
;
1173 const char *ptr
= wps_bufptr
;
1177 /* format: %T|x|y|width|height|action|
1178 * if action starts with & the area must be held to happen
1180 * play - play/pause playback
1181 * stop - stop playback, exit the wps
1184 * ffwd - seek forward
1185 * rwd - seek backwards
1186 * menu - go back to the main menu
1187 * browse - go back to the file/db browser
1188 * shuffle - toggle shuffle mode
1189 * repmode - cycle the repeat mode
1190 * quickscreen - go into the quickscreen
1191 * contextmenu - open the context menu
1194 if ((wps_data
->touchregion_count
+1 >= MAX_TOUCHREGIONS
) || (*ptr
!= '|'))
1195 return WPS_ERROR_INVALID_PARAM
;
1198 if (!(ptr
= parse_list("dddds", NULL
, '|', ptr
, &x
, &y
, &w
, &h
, &action
)))
1199 return WPS_ERROR_INVALID_PARAM
;
1201 /* Check there is a terminating | */
1203 return WPS_ERROR_INVALID_PARAM
;
1205 /* should probably do some bounds checking here with the viewport... but later */
1206 region
= &wps_data
->touchregion
[wps_data
->touchregion_count
];
1207 region
->action
= ACTION_NONE
;
1212 region
->wvp
= &wps_data
->viewports
[wps_data
->num_viewports
];
1217 region
->repeat
= true;
1220 region
->repeat
= false;
1222 while ((region
->action
== ACTION_NONE
) &&
1223 (i
< sizeof(touchactions
)/sizeof(*touchactions
)))
1225 if (!strncmp(touchactions
[i
].s
, action
, strlen(touchactions
[i
].s
)))
1226 region
->action
= touchactions
[i
].action
;
1229 if (region
->action
== ACTION_NONE
)
1230 return WPS_ERROR_INVALID_PARAM
;
1231 wps_data
->touchregion_count
++;
1232 return skip_end_of_line(wps_bufptr
);
1236 /* Parse a generic token from the given string. Return the length read */
1237 static int parse_token(const char *wps_bufptr
, struct wps_data
*wps_data
)
1239 int skip
= 0, taglen
= 0, ret
;
1240 struct wps_token
*token
= wps_data
->tokens
+ wps_data
->num_tokens
;
1241 const struct wps_tag
*tag
;
1252 /* escaped characters */
1253 token
->type
= WPS_TOKEN_CHARACTER
;
1254 token
->value
.c
= *wps_bufptr
;
1256 wps_data
->num_tokens
++;
1260 /* conditional tag */
1261 token
->type
= WPS_TOKEN_CONDITIONAL
;
1263 condindex
[level
] = wps_data
->num_tokens
;
1264 numoptions
[level
] = 1;
1265 wps_data
->num_tokens
++;
1266 ret
= parse_token(wps_bufptr
+ 1, wps_data
);
1267 if (ret
< 0) return ret
;
1272 /* find what tag we have */
1273 for (tag
= all_tags
;
1274 strncmp(wps_bufptr
, tag
->name
, strlen(tag
->name
)) != 0;
1277 taglen
= (tag
->type
!= WPS_TOKEN_UNKNOWN
) ? strlen(tag
->name
) : 2;
1278 token
->type
= tag
->type
;
1279 wps_data
->sublines
[wps_data
->num_sublines
].line_type
|=
1282 /* if the tag has a special parsing function, we call it */
1283 if (tag
->parse_func
)
1285 ret
= tag
->parse_func(wps_bufptr
+ taglen
, token
, wps_data
);
1286 if (ret
< 0) return ret
;
1290 /* Some tags we don't want to save as tokens */
1291 if (tag
->type
== WPS_NO_TOKEN
)
1294 /* tags that start with 'F', 'I' or 'D' are for the next file */
1295 if ( *(tag
->name
) == 'I' || *(tag
->name
) == 'F' ||
1296 *(tag
->name
) == 'D')
1299 wps_data
->num_tokens
++;
1308 data is the pointer to the structure where the parsed WPS should be stored.
1310 wps_bufptr points to the string containing the WPS tags */
1311 static bool wps_parse(struct wps_data
*data
, const char *wps_bufptr
)
1313 if (!data
|| !wps_bufptr
|| !*wps_bufptr
)
1316 char *stringbuf
= data
->string_buffer
;
1317 int stringbuf_used
= 0;
1318 enum wps_parse_error fail
= PARSE_OK
;
1323 while(*wps_bufptr
&& !fail
&& data
->num_tokens
< WPS_MAX_TOKENS
- 1
1324 && data
->num_viewports
< WPS_MAX_VIEWPORTS
1325 && data
->num_lines
< WPS_MAX_LINES
)
1327 switch(*wps_bufptr
++)
1332 if ((ret
= parse_token(wps_bufptr
, data
)) < 0)
1334 fail
= PARSE_FAIL_COND_INVALID_PARAM
;
1337 else if (level
>= WPS_MAX_COND_LEVEL
- 1)
1339 fail
= PARSE_FAIL_LIMITS_EXCEEDED
;
1345 /* Alternating sublines separator */
1347 if (level
>= 0) /* there are unclosed conditionals */
1349 fail
= PARSE_FAIL_UNCLOSED_COND
;
1353 if (data
->num_sublines
+1 < WPS_MAX_SUBLINES
)
1354 wps_start_new_subline(data
);
1356 fail
= PARSE_FAIL_LIMITS_EXCEEDED
;
1360 /* Conditional list start */
1362 if (data
->tokens
[data
->num_tokens
-2].type
!= WPS_TOKEN_CONDITIONAL
)
1364 fail
= PARSE_FAIL_COND_SYNTAX_ERROR
;
1368 data
->tokens
[data
->num_tokens
].type
= WPS_TOKEN_CONDITIONAL_START
;
1369 lastcond
[level
] = data
->num_tokens
++;
1372 /* Conditional list end */
1374 if (level
< 0) /* not in a conditional, invalid char */
1376 fail
= PARSE_FAIL_INVALID_CHAR
;
1380 data
->tokens
[data
->num_tokens
].type
= WPS_TOKEN_CONDITIONAL_END
;
1381 if (lastcond
[level
])
1382 data
->tokens
[lastcond
[level
]].value
.i
= data
->num_tokens
;
1385 fail
= PARSE_FAIL_COND_SYNTAX_ERROR
;
1389 lastcond
[level
] = 0;
1391 data
->tokens
[condindex
[level
]].value
.i
= numoptions
[level
];
1395 /* Conditional list option */
1397 if (level
< 0) /* not in a conditional, invalid char */
1399 fail
= PARSE_FAIL_INVALID_CHAR
;
1403 data
->tokens
[data
->num_tokens
].type
= WPS_TOKEN_CONDITIONAL_OPTION
;
1404 if (lastcond
[level
])
1405 data
->tokens
[lastcond
[level
]].value
.i
= data
->num_tokens
;
1408 fail
= PARSE_FAIL_COND_SYNTAX_ERROR
;
1412 lastcond
[level
] = data
->num_tokens
;
1413 numoptions
[level
]++;
1419 if (level
>= 0) /* there are unclosed conditionals */
1421 fail
= PARSE_FAIL_UNCLOSED_COND
;
1425 wps_bufptr
+= skip_end_of_line(wps_bufptr
);
1428 /* End of this line */
1430 if (level
>= 0) /* there are unclosed conditionals */
1432 fail
= PARSE_FAIL_UNCLOSED_COND
;
1437 wps_start_new_subline(data
);
1438 data
->num_lines
++; /* Start a new line */
1440 if ((data
->num_lines
< WPS_MAX_LINES
) &&
1441 (data
->num_sublines
< WPS_MAX_SUBLINES
))
1443 data
->lines
[data
->num_lines
].first_subline_idx
=
1446 data
->sublines
[data
->num_sublines
].first_token_idx
=
1455 unsigned int len
= 1;
1456 const char *string_start
= wps_bufptr
- 1;
1458 /* find the length of the string */
1459 while (*wps_bufptr
&& *wps_bufptr
!= '#' &&
1460 *wps_bufptr
!= '%' && *wps_bufptr
!= ';' &&
1461 *wps_bufptr
!= '<' && *wps_bufptr
!= '>' &&
1462 *wps_bufptr
!= '|' && *wps_bufptr
!= '\n')
1468 /* look if we already have that string */
1472 for (i
= 0, str
= data
->strings
, found
= false;
1473 i
< data
->num_strings
&&
1474 !(found
= (strlen(*str
) == len
&&
1475 strncmp(string_start
, *str
, len
) == 0));
1477 /* If a matching string is found, found is true and i is
1478 the index of the string. If not, found is false */
1484 if (stringbuf_used
+ len
> STRING_BUFFER_SIZE
- 1
1485 || data
->num_strings
>= WPS_MAX_STRINGS
)
1487 /* too many strings or characters */
1488 fail
= PARSE_FAIL_LIMITS_EXCEEDED
;
1492 strncpy(stringbuf
, string_start
, len
);
1493 *(stringbuf
+ len
) = '\0';
1495 data
->strings
[data
->num_strings
] = stringbuf
;
1496 stringbuf
+= len
+ 1;
1497 stringbuf_used
+= len
+ 1;
1498 data
->tokens
[data
->num_tokens
].value
.i
=
1500 data
->num_strings
++;
1504 /* another occurrence of an existing string */
1505 data
->tokens
[data
->num_tokens
].value
.i
= i
;
1507 data
->tokens
[data
->num_tokens
].type
= WPS_TOKEN_STRING
;
1514 if (!fail
&& level
>= 0) /* there are unclosed conditionals */
1515 fail
= PARSE_FAIL_UNCLOSED_COND
;
1517 if (*wps_bufptr
&& !fail
)
1518 /* one of the limits of the while loop was exceeded */
1519 fail
= PARSE_FAIL_LIMITS_EXCEEDED
;
1521 data
->viewports
[data
->num_viewports
].last_line
= data
->num_lines
- 1;
1523 /* We have finished with the last viewport, so increment count */
1524 data
->num_viewports
++;
1526 #if defined(DEBUG) || defined(SIMULATOR)
1527 print_debug_info(data
, fail
, line
);
1533 #ifdef HAVE_LCD_BITMAP
1534 /* Clear the WPS image cache */
1535 static void wps_images_clear(struct wps_data
*data
)
1538 /* set images to unloaded and not displayed */
1539 for (i
= 0; i
< MAX_IMAGES
; i
++)
1541 data
->img
[i
].loaded
= false;
1542 data
->img
[i
].display
= -1;
1543 data
->img
[i
].always_display
= false;
1544 data
->img
[i
].num_subimages
= 1;
1549 /* initial setup of wps_data */
1550 void wps_data_init(struct wps_data
*wps_data
)
1552 #ifdef HAVE_LCD_BITMAP
1553 wps_images_clear(wps_data
);
1554 wps_data
->wps_sb_tag
= false;
1555 wps_data
->show_sb_on_wps
= false;
1556 wps_data
->img_buf_ptr
= wps_data
->img_buf
; /* where in image buffer */
1557 wps_data
->img_buf_free
= IMG_BUFSIZE
; /* free space in image buffer */
1558 wps_data
->peak_meter_enabled
= false;
1560 wps_data
->progressbar_count
= 0;
1561 #else /* HAVE_LCD_CHARCELLS */
1563 for (i
= 0; i
< 8; i
++)
1565 wps_data
->wps_progress_pat
[i
] = 0;
1567 wps_data
->full_line_progressbar
= false;
1569 wps_data
->button_time_volume
= 0;
1570 wps_data
->wps_loaded
= false;
1573 static void wps_reset(struct wps_data
*data
)
1575 #ifdef HAVE_REMOTE_LCD
1576 bool rwps
= data
->remote_wps
; /* remember whether the data is for a RWPS */
1578 memset(data
, 0, sizeof(*data
));
1579 wps_data_init(data
);
1580 #ifdef HAVE_REMOTE_LCD
1581 data
->remote_wps
= rwps
;
1585 #ifdef HAVE_LCD_BITMAP
1587 static bool load_wps_bitmaps(struct wps_data
*wps_data
, char *bmpdir
)
1589 char img_path
[MAX_PATH
];
1590 struct bitmap
*bitmap
;
1593 for (n
= 0; n
< BACKDROP_BMP
; n
++)
1597 get_image_filename(bmp_names
[n
], bmpdir
,
1598 img_path
, sizeof(img_path
));
1600 if (n
>= PROGRESSBAR_BMP
) {
1601 /* progressbar bitmap */
1602 bitmap
= &wps_data
->progressbar
[n
-PROGRESSBAR_BMP
].bm
;
1603 loaded
= &wps_data
->progressbar
[n
-PROGRESSBAR_BMP
].have_bitmap_pb
;
1605 /* regular bitmap */
1606 bitmap
= &wps_data
->img
[n
].bm
;
1607 loaded
= &wps_data
->img
[n
].loaded
;
1610 /* load the image */
1611 bitmap
->data
= wps_data
->img_buf_ptr
;
1612 if (load_bitmap(wps_data
, img_path
, bitmap
))
1616 /* Calculate and store height if this image has sub-images */
1618 wps_data
->img
[n
].subimage_height
= wps_data
->img
[n
].bm
.height
/
1619 wps_data
->img
[n
].num_subimages
;
1623 /* Abort if we can't load an image */
1624 DEBUGF("ERR: Failed to load image %d - %s\n",n
,img_path
);
1630 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
1631 if (bmp_names
[BACKDROP_BMP
])
1633 get_image_filename(bmp_names
[BACKDROP_BMP
], bmpdir
,
1634 img_path
, sizeof(img_path
));
1636 #if defined(HAVE_REMOTE_LCD)
1637 /* We only need to check LCD type if there is a remote LCD */
1638 if (!wps_data
->remote_wps
)
1641 /* Load backdrop for the main LCD */
1642 if (!load_wps_backdrop(img_path
))
1645 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1648 /* Load backdrop for the remote LCD */
1649 if (!load_remote_wps_backdrop(img_path
))
1654 #endif /* has backdrop support */
1656 /* If we got here, everything was OK */
1660 #endif /* HAVE_LCD_BITMAP */
1662 /* to setup up the wps-data from a format-buffer (isfile = false)
1663 from a (wps-)file (isfile = true)*/
1664 bool wps_data_load(struct wps_data
*wps_data
,
1665 struct screen
*display
,
1669 #ifdef HAVE_ALBUMART
1670 struct mp3entry
*curtrack
;
1673 int wps_uses_albumart
= wps_data
->wps_uses_albumart
;
1674 int albumart_max_height
= wps_data
->albumart_max_height
;
1675 int albumart_max_width
= wps_data
->albumart_max_width
;
1677 if (!wps_data
|| !buf
)
1680 wps_reset(wps_data
);
1682 /* Initialise the first (default) viewport */
1683 wps_data
->viewports
[0].vp
.x
= 0;
1684 wps_data
->viewports
[0].vp
.width
= display
->getwidth();
1685 if (!global_settings
.statusbar
)
1687 wps_data
->viewports
[0].vp
.y
= 0;
1688 wps_data
->viewports
[0].vp
.height
= display
->getheight();
1692 wps_data
->viewports
[0].vp
.y
= STATUSBAR_HEIGHT
;
1693 wps_data
->viewports
[0].vp
.height
= display
->getheight() -
1696 #ifdef HAVE_LCD_BITMAP
1697 wps_data
->viewports
[0].vp
.font
= FONT_UI
;
1698 wps_data
->viewports
[0].vp
.drawmode
= DRMODE_SOLID
;
1701 if (display
->depth
> 1)
1703 wps_data
->viewports
[0].vp
.fg_pattern
= display
->get_foreground();
1704 wps_data
->viewports
[0].vp
.bg_pattern
= display
->get_background();
1709 return wps_parse(wps_data
, buf
);
1714 * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
1715 * wants to be a virtual file. Feel free to modify dirbrowse()
1716 * if you're feeling brave.
1719 if (! strcmp(buf
, WPS_DEFAULTCFG
) )
1721 global_settings
.wps_file
[0] = 0;
1725 #ifdef HAVE_REMOTE_LCD
1726 if (! strcmp(buf
, RWPS_DEFAULTCFG
) )
1728 global_settings
.rwps_file
[0] = 0;
1732 #endif /* __PCTOOL__ */
1734 int fd
= open_utf8(buf
, O_RDONLY
);
1739 /* get buffer space from the plugin buffer */
1740 size_t buffersize
= 0;
1741 char *wps_buffer
= (char *)plugin_get_buffer(&buffersize
);
1746 /* copy the file's content to the buffer for parsing,
1747 ensuring that every line ends with a newline char. */
1748 unsigned int start
= 0;
1749 while(read_line(fd
, wps_buffer
+ start
, buffersize
- start
) > 0)
1751 start
+= strlen(wps_buffer
+ start
);
1752 if (start
< buffersize
- 1)
1754 wps_buffer
[start
++] = '\n';
1755 wps_buffer
[start
] = 0;
1764 #ifdef HAVE_LCD_BITMAP
1765 /* Set all filename pointers to NULL */
1766 memset(bmp_names
, 0, sizeof(bmp_names
));
1769 /* parse the WPS source */
1770 if (!wps_parse(wps_data
, wps_buffer
)) {
1771 wps_reset(wps_data
);
1775 wps_data
->wps_loaded
= true;
1777 #ifdef HAVE_LCD_BITMAP
1778 /* get the bitmap dir */
1779 char bmpdir
[MAX_PATH
];
1781 char *dot
= strrchr(buf
, '.');
1782 bmpdirlen
= dot
- buf
;
1783 strncpy(bmpdir
, buf
, dot
- buf
);
1784 bmpdir
[bmpdirlen
] = 0;
1786 /* load the bitmaps that were found by the parsing */
1787 if (!load_wps_bitmaps(wps_data
, bmpdir
)) {
1788 wps_reset(wps_data
);
1792 #ifdef HAVE_ALBUMART
1793 status
= audio_status();
1794 if (((!wps_uses_albumart
&& wps_data
->wps_uses_albumart
) ||
1795 (wps_data
->wps_uses_albumart
&&
1796 (albumart_max_height
!= wps_data
->albumart_max_height
||
1797 albumart_max_width
!= wps_data
->albumart_max_width
))) &&
1798 status
& AUDIO_STATUS_PLAY
)
1800 curtrack
= audio_current_track();
1801 offset
= curtrack
->offset
;
1803 if (!(status
& AUDIO_STATUS_PAUSE
))
1811 int wps_subline_index(struct wps_data
*data
, int line
, int subline
)
1813 return data
->lines
[line
].first_subline_idx
+ subline
;
1816 int wps_first_token_index(struct wps_data
*data
, int line
, int subline
)
1818 int first_subline_idx
= data
->lines
[line
].first_subline_idx
;
1819 return data
->sublines
[first_subline_idx
+ subline
].first_token_idx
;
1822 int wps_last_token_index(struct wps_data
*data
, int line
, int subline
)
1824 int first_subline_idx
= data
->lines
[line
].first_subline_idx
;
1825 int idx
= first_subline_idx
+ subline
;
1826 if (idx
< data
->num_sublines
- 1)
1828 /* This subline ends where the next begins */
1829 return data
->sublines
[idx
+1].first_token_idx
- 1;
1833 /* The last subline goes to the end */
1834 return data
->num_tokens
- 1;