2007-04-04 14:41:40 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "atoi.h"
|
|
|
|
#include "gwps.h"
|
2007-05-29 19:00:36 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-04-04 14:41:40 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "bmp.h"
|
|
|
|
#endif
|
2007-04-25 22:08:00 +00:00
|
|
|
|
|
|
|
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
|
|
|
|
#include "backdrop.h"
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-05-29 19:00:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
|
|
|
|
#define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
|
|
|
|
|
2007-11-14 22:02:41 +00:00
|
|
|
#define WPS_ERROR_INVALID_PARAM -1
|
|
|
|
|
|
|
|
#define PARSE_FAIL_UNCLOSED_COND 1
|
|
|
|
#define PARSE_FAIL_INVALID_CHAR 2
|
|
|
|
#define PARSE_FAIL_COND_SYNTAX_ERROR 3
|
|
|
|
#define PARSE_FAIL_COND_INVALID_PARAM 4
|
2007-04-24 00:57:04 +00:00
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* level of current conditional.
|
|
|
|
-1 means we're not in a conditional. */
|
2007-04-04 15:47:51 +00:00
|
|
|
static int level = -1;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* index of the last WPS_TOKEN_CONDITIONAL_OPTION
|
|
|
|
or WPS_TOKEN_CONDITIONAL_START in current level */
|
2007-04-04 15:47:51 +00:00
|
|
|
static int lastcond[WPS_MAX_COND_LEVEL];
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* index of the WPS_TOKEN_CONDITIONAL in current level */
|
2007-04-04 15:47:51 +00:00
|
|
|
static int condindex[WPS_MAX_COND_LEVEL];
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* number of condtional options in current level */
|
2007-04-04 15:47:51 +00:00
|
|
|
static int numoptions[WPS_MAX_COND_LEVEL];
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-24 00:57:04 +00:00
|
|
|
/* the current line in the file */
|
|
|
|
static int line;
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-06-05 14:57:07 +00:00
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
#define MAX_BITMAPS MAX_IMAGES+2 /* WPS images + pbar bitmap + backdrop */
|
|
|
|
#else
|
|
|
|
#define MAX_BITMAPS MAX_IMAGES+1 /* WPS images + pbar bitmap */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PROGRESSBAR_BMP MAX_IMAGES
|
|
|
|
#define BACKDROP_BMP MAX_IMAGES+1
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* pointers to the bitmap filenames in the WPS source */
|
2007-06-05 10:42:41 +00:00
|
|
|
static const char *bmp_names[MAX_BITMAPS];
|
2007-06-05 14:57:07 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-04-24 23:58:57 +00:00
|
|
|
/* debugging function */
|
|
|
|
extern void print_debug_info(struct wps_data *data, int fail, int line);
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-24 00:57:04 +00:00
|
|
|
static void wps_reset(struct wps_data *data);
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
/* Function for parsing of details for a token. At the moment the
|
|
|
|
function is called, the token type has already been set. The
|
|
|
|
function must fill in the details and possibly add more tokens
|
|
|
|
to the token array. It should return the number of chars that
|
|
|
|
has been consumed.
|
|
|
|
|
|
|
|
wps_bufptr points to the char following the tag (i.e. where
|
|
|
|
details begin).
|
|
|
|
token is the pointer to the 'main' token being parsed
|
|
|
|
*/
|
|
|
|
typedef int (*wps_tag_parse_func)(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
struct wps_tag {
|
|
|
|
enum wps_token_type type;
|
2007-04-05 10:21:49 +00:00
|
|
|
const char name[3];
|
2007-04-04 14:41:40 +00:00
|
|
|
unsigned char refresh_type;
|
2007-04-05 10:21:49 +00:00
|
|
|
const wps_tag_parse_func parse_func;
|
2007-04-04 14:41:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* prototypes of all special parse functions : */
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_subline_timeout(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_progressbar(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_dir_level(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
2007-11-11 12:29:37 +00:00
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-11-14 22:02:41 +00:00
|
|
|
static int parse_leftmargin(const char *wps_bufptr,
|
2007-11-12 21:34:01 +00:00
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_image_special(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_statusbar_enable(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_statusbar_disable(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_image_display(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_image_load(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif /*HAVE_LCD_BITMAP */
|
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
static int parse_albumart_load(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
static int parse_albumart_conditional(const char *wps_bufptr,
|
|
|
|
struct wps_token *token, struct wps_data *wps_data);
|
|
|
|
#endif /* HAVE_ALBUMART */
|
|
|
|
|
2007-06-16 20:33:30 +00:00
|
|
|
#ifdef CONFIG_RTC
|
|
|
|
#define WPS_RTC_REFRESH WPS_REFRESH_DYNAMIC
|
|
|
|
#else
|
|
|
|
#define WPS_RTC_REFRESH WPS_REFRESH_STATIC
|
|
|
|
#endif
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* array of available tags - those with more characters have to go first
|
|
|
|
(e.g. "xl" and "xd" before "x"). It needs to end with the unknown token. */
|
|
|
|
static const struct wps_tag all_tags[] = {
|
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_ALIGN_CENTER, "ac", 0, NULL },
|
|
|
|
{ WPS_TOKEN_ALIGN_LEFT, "al", 0, NULL },
|
|
|
|
{ WPS_TOKEN_ALIGN_RIGHT, "ar", 0, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_BATTERY_PERCENT, "bl", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_BATTERY_VOLTS, "bv", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_BATTERY_TIME, "bt", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_BATTERY_SLEEPTIME, "bs", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_BATTERY_CHARGING, "bc", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
#if CONFIG_CHARGING
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_BATTERY_CHARGER_CONNECTED,"bp", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-16 20:33:30 +00:00
|
|
|
{ WPS_TOKEN_RTC_DAY_OF_MONTH, "cd", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED,"ce", WPS_RTC_REFRESH, NULL },
|
2007-11-27 01:41:59 +00:00
|
|
|
{ WPS_TOKEN_RTC_12HOUR_CFG, "cf", WPS_RTC_REFRESH, NULL },
|
2007-06-16 20:33:30 +00:00
|
|
|
{ WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED, "cH", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_HOUR_24, "ck", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED, "cI", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_HOUR_12, "cl", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_MONTH, "cm", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_MINUTE, "cM", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_SECOND, "cS", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_YEAR_2_DIGITS, "cy", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_YEAR_4_DIGITS, "cY", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_AM_PM_UPPER, "cP", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_AM_PM_LOWER, "cp", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_WEEKDAY_NAME, "ca", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_MONTH_NAME, "cb", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON, "cu", WPS_RTC_REFRESH, NULL },
|
|
|
|
{ WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN, "cw", WPS_RTC_REFRESH, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* current file */
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_FILE_BITRATE, "fb", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_CODEC, "fc", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_FREQUENCY, "ff", WPS_REFRESH_STATIC, NULL },
|
2007-05-21 13:41:43 +00:00
|
|
|
{ WPS_TOKEN_FILE_FREQUENCY_KHZ, "fk", WPS_REFRESH_STATIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_FILE_NAME_WITH_EXTENSION, "fm", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_NAME, "fn", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_PATH, "fp", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_SIZE, "fs", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_VBR, "fv", WPS_REFRESH_STATIC, NULL },
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_FILE_DIRECTORY, "d", WPS_REFRESH_STATIC,
|
|
|
|
parse_dir_level },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* next file */
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_FILE_BITRATE, "Fb", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_CODEC, "Fc", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_FREQUENCY, "Ff", WPS_REFRESH_DYNAMIC, NULL },
|
2007-05-21 14:04:38 +00:00
|
|
|
{ WPS_TOKEN_FILE_FREQUENCY_KHZ, "Fk", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_FILE_NAME_WITH_EXTENSION, "Fm", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_NAME, "Fn", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_PATH, "Fp", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_SIZE, "Fs", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_FILE_VBR, "Fv", WPS_REFRESH_DYNAMIC, NULL },
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_FILE_DIRECTORY, "D", WPS_REFRESH_DYNAMIC,
|
|
|
|
parse_dir_level },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* current metadata */
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_ARTIST, "ia", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_COMPOSER, "ic", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_ALBUM, "id", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_ALBUM_ARTIST, "iA", WPS_REFRESH_STATIC, NULL },
|
2007-08-08 10:19:56 +00:00
|
|
|
{ WPS_TOKEN_METADATA_GROUPING, "iG", WPS_REFRESH_STATIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_GENRE, "ig", WPS_REFRESH_STATIC, NULL },
|
2007-08-03 10:00:42 +00:00
|
|
|
{ WPS_TOKEN_METADATA_DISC_NUMBER, "ik", WPS_REFRESH_STATIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_TRACK_NUMBER, "in", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_TRACK_TITLE, "it", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_VERSION, "iv", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_YEAR, "iy", WPS_REFRESH_STATIC, NULL },
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_METADATA_COMMENT, "iC", WPS_REFRESH_STATIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* next metadata */
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_ARTIST, "Ia", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_COMPOSER, "Ic", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_ALBUM, "Id", WPS_REFRESH_DYNAMIC, NULL },
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_METADATA_ALBUM_ARTIST, "IA", WPS_REFRESH_DYNAMIC, NULL },
|
2007-08-08 10:19:56 +00:00
|
|
|
{ WPS_TOKEN_METADATA_GROUPING, "IG", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_GENRE, "Ig", WPS_REFRESH_DYNAMIC, NULL },
|
2007-08-03 10:00:42 +00:00
|
|
|
{ WPS_TOKEN_METADATA_DISC_NUMBER, "Ik", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_METADATA_TRACK_NUMBER, "In", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_TRACK_TITLE, "It", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_VERSION, "Iv", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_YEAR, "Iy", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_METADATA_COMMENT, "IC", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-04 15:47:51 +00:00
|
|
|
#if (CONFIG_CODEC != MAS3507D)
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_SOUND_PITCH, "Sp", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_VLED_HDD, "lh", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_MAIN_HOLD, "mh", WPS_REFRESH_DYNAMIC, NULL },
|
2007-06-25 20:54:11 +00:00
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAS_REMOTE_BUTTON_HOLD
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_REMOTE_HOLD, "mr", WPS_REFRESH_DYNAMIC, NULL },
|
2007-11-14 00:45:04 +00:00
|
|
|
#else
|
|
|
|
{ WPS_TOKEN_UNKNOWN, "mr", 0, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_REPEAT_MODE, "mm", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_PLAYBACK_STATUS, "mp", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-11-14 00:45:04 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-11-14 22:02:41 +00:00
|
|
|
{ WPS_TOKEN_LEFTMARGIN, "m", 0, parse_leftmargin },
|
2007-11-14 00:45:04 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_PEAKMETER, "pm", WPS_REFRESH_PEAK_METER, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#else
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_PLAYER_PROGRESSBAR, "pf",
|
|
|
|
WPS_REFRESH_DYNAMIC | WPS_REFRESH_PLAYER_PROGRESS, parse_progressbar },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_PROGRESSBAR, "pb", WPS_REFRESH_PLAYER_PROGRESS,
|
|
|
|
parse_progressbar },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_VOLUME, "pv", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-07-25 14:14:47 +00:00
|
|
|
{ WPS_TOKEN_TRACK_ELAPSED_PERCENT, "px", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_TRACK_TIME_ELAPSED, "pc", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_TRACK_TIME_REMAINING, "pr", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_TRACK_LENGTH, "pt", WPS_REFRESH_STATIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_PLAYLIST_POSITION, "pp", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_PLAYLIST_ENTRIES, "pe", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_PLAYLIST_NAME, "pn", WPS_REFRESH_STATIC, NULL },
|
|
|
|
{ WPS_TOKEN_PLAYLIST_SHUFFLE, "ps", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-11-14 22:02:41 +00:00
|
|
|
#ifdef HAVE_TAGCACHE
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_DATABASE_PLAYCOUNT, "rp", WPS_REFRESH_DYNAMIC, NULL },
|
|
|
|
{ WPS_TOKEN_DATABASE_RATING, "rr", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-15 15:46:46 +00:00
|
|
|
{ WPS_TOKEN_DATABASE_AUTOSCORE, "ra", WPS_REFRESH_DYNAMIC, NULL },
|
2007-11-14 22:02:41 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_REPLAYGAIN, "rg", WPS_REFRESH_STATIC, NULL },
|
2007-04-12 16:15:34 +00:00
|
|
|
{ WPS_TOKEN_CROSSFADE, "xf", WPS_REFRESH_DYNAMIC, NULL },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
{ WPS_NO_TOKEN, "s", WPS_REFRESH_SCROLL, NULL },
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_TOKEN_SUBLINE_TIMEOUT, "t", 0, parse_subline_timeout },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-08 04:01:06 +00:00
|
|
|
{ WPS_NO_TOKEN, "we", 0, parse_statusbar_enable },
|
|
|
|
{ WPS_NO_TOKEN, "wd", 0, parse_statusbar_disable },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-05 10:21:49 +00:00
|
|
|
{ WPS_NO_TOKEN, "xl", 0, parse_image_load },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-05-02 17:51:01 +00:00
|
|
|
{ WPS_TOKEN_IMAGE_PRELOAD_DISPLAY, "xd", WPS_REFRESH_STATIC,
|
|
|
|
parse_image_display },
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
{ WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load },
|
|
|
|
{ WPS_TOKEN_IMAGE_PROGRESS_BAR, "P", 0, parse_image_special },
|
2007-11-11 12:29:37 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
{ WPS_NO_TOKEN, "Cl", 0, parse_albumart_load },
|
2007-11-12 01:31:42 +00:00
|
|
|
{ WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC,
|
2007-11-11 12:29:37 +00:00
|
|
|
parse_albumart_conditional },
|
|
|
|
#endif
|
2007-04-25 21:44:56 +00:00
|
|
|
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
|
2007-04-08 04:01:06 +00:00
|
|
|
{ WPS_TOKEN_IMAGE_BACKDROP, "X", 0, parse_image_special },
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
{ WPS_TOKEN_UNKNOWN, "", 0, NULL }
|
|
|
|
/* the array MUST end with an empty string (first char is \0) */
|
2007-04-04 14:41:40 +00:00
|
|
|
};
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
/* Returns the number of chars that should be skipped to jump
|
|
|
|
immediately after the first eol, i.e. to the start of the next line */
|
2007-04-05 14:09:59 +00:00
|
|
|
static int skip_end_of_line(const char *wps_bufptr)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-24 00:57:04 +00:00
|
|
|
line++;
|
2007-04-04 14:41:40 +00:00
|
|
|
int skip = 0;
|
2007-04-05 14:09:59 +00:00
|
|
|
while(*(wps_bufptr + skip) != '\n')
|
2007-04-04 14:41:40 +00:00
|
|
|
skip++;
|
|
|
|
return ++skip;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
/* Starts a new subline in the current line during parsing */
|
2007-04-15 02:59:34 +00:00
|
|
|
static void wps_start_new_subline(struct wps_data *data)
|
|
|
|
{
|
2007-04-08 04:01:06 +00:00
|
|
|
data->num_sublines++;
|
|
|
|
data->sublines[data->num_sublines].first_token_idx = data->num_tokens;
|
|
|
|
data->lines[data->num_lines].num_sublines++;
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_statusbar_enable(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-08 04:01:06 +00:00
|
|
|
(void)token; /* Kill warnings */
|
2007-04-04 14:41:40 +00:00
|
|
|
wps_data->wps_sb_tag = true;
|
2007-04-08 04:01:06 +00:00
|
|
|
wps_data->show_sb_on_wps = true;
|
|
|
|
return skip_end_of_line(wps_bufptr);
|
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_statusbar_disable(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
|
|
|
{
|
|
|
|
(void)token; /* Kill warnings */
|
|
|
|
wps_data->wps_sb_tag = true;
|
|
|
|
wps_data->show_sb_on_wps = false;
|
2007-04-05 14:09:59 +00:00
|
|
|
return skip_end_of_line(wps_bufptr);
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool load_bitmap(struct wps_data *wps_data,
|
|
|
|
char* filename,
|
|
|
|
struct bitmap *bm)
|
|
|
|
{
|
2007-04-25 13:09:56 +00:00
|
|
|
int format;
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
if (wps_data->remote_wps)
|
|
|
|
format = FORMAT_ANY|FORMAT_REMOTE;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
format = FORMAT_ANY|FORMAT_TRANSPARENT;
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
int ret = read_bmp_file(filename, bm,
|
|
|
|
wps_data->img_buf_free,
|
2007-04-25 13:09:56 +00:00
|
|
|
format);
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
#if LCD_DEPTH == 16
|
|
|
|
if (ret % 2) ret++;
|
|
|
|
/* Always consume an even number of bytes */
|
|
|
|
#endif
|
|
|
|
wps_data->img_buf_ptr += ret;
|
|
|
|
wps_data->img_buf_free -= ret;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_image_id(int c)
|
|
|
|
{
|
|
|
|
if(c >= 'a' && c <= 'z')
|
|
|
|
return c - 'a';
|
|
|
|
else if(c >= 'A' && c <= 'Z')
|
|
|
|
return c - 'A' + 26;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *get_image_filename(const char *start, const char* bmpdir,
|
|
|
|
char *buf, int buf_size)
|
|
|
|
{
|
|
|
|
const char *end = strchr(start, '|');
|
|
|
|
|
|
|
|
if ( !end || (end - start) >= (buf_size - ROCKBOX_DIR_LEN - 2) )
|
|
|
|
{
|
|
|
|
buf = "\0";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bmpdirlen = strlen(bmpdir);
|
|
|
|
|
|
|
|
strcpy(buf, bmpdir);
|
|
|
|
buf[bmpdirlen] = '/';
|
|
|
|
memcpy( &buf[bmpdirlen + 1], start, end - start);
|
|
|
|
buf[bmpdirlen + 1 + end - start] = 0;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_image_display(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-11-18 15:32:45 +00:00
|
|
|
(void)wps_data;
|
2007-04-05 14:09:59 +00:00
|
|
|
int n = get_image_id(*wps_bufptr);
|
2007-04-14 16:20:33 +00:00
|
|
|
|
|
|
|
if (n == -1)
|
|
|
|
{
|
|
|
|
/* invalid picture display tag */
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
2007-04-14 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
token->value.i = n;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_image_load(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
int n;
|
2007-04-05 14:09:59 +00:00
|
|
|
const char *ptr = wps_bufptr;
|
2007-11-14 22:02:41 +00:00
|
|
|
const char *pos = NULL;
|
|
|
|
const char *newline;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* format: %x|n|filename.bmp|x|y|
|
|
|
|
or %xl|n|filename.bmp|x|y| */
|
|
|
|
|
|
|
|
ptr = strchr(ptr, '|') + 1;
|
|
|
|
pos = strchr(ptr, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
newline = strchr(ptr, '\n');
|
2007-04-12 16:15:34 +00:00
|
|
|
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!pos || pos > newline)
|
2007-04-12 16:15:34 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* get the image ID */
|
|
|
|
n = get_image_id(*ptr);
|
|
|
|
|
|
|
|
/* check the image number and load state */
|
|
|
|
if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded)
|
|
|
|
{
|
2007-11-14 22:02:41 +00:00
|
|
|
/* Invalid image ID */
|
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
2007-04-12 16:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = pos + 1;
|
|
|
|
|
|
|
|
/* get image name */
|
|
|
|
bmp_names[n] = ptr;
|
|
|
|
|
|
|
|
pos = strchr(ptr, '|');
|
|
|
|
ptr = pos + 1;
|
|
|
|
|
|
|
|
/* get x-position */
|
|
|
|
pos = strchr(ptr, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (pos && pos < newline)
|
2007-04-12 16:15:34 +00:00
|
|
|
wps_data->img[n].x = atoi(ptr);
|
|
|
|
else
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-12 16:15:34 +00:00
|
|
|
/* weird syntax, bail out */
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 16:15:34 +00:00
|
|
|
/* get y-position */
|
|
|
|
ptr = pos + 1;
|
|
|
|
pos = strchr(ptr, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (pos && pos < newline)
|
2007-04-12 16:15:34 +00:00
|
|
|
wps_data->img[n].y = atoi(ptr);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* weird syntax, bail out */
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
2007-04-12 16:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (token->type == WPS_TOKEN_IMAGE_DISPLAY)
|
|
|
|
wps_data->img[n].always_display = true;
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* Skip the rest of the line */
|
2007-04-05 14:09:59 +00:00
|
|
|
return skip_end_of_line(wps_bufptr);
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_image_special(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-11-14 22:02:41 +00:00
|
|
|
(void)wps_data; /* kill warning */
|
|
|
|
const char *pos = NULL;
|
|
|
|
const char *newline;
|
|
|
|
|
|
|
|
pos = strchr(wps_bufptr + 1, '|');
|
|
|
|
newline = strchr(wps_bufptr, '\n');
|
|
|
|
|
|
|
|
if (pos > newline)
|
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
if (token->type == WPS_TOKEN_IMAGE_PROGRESS_BAR)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
/* format: %P|filename.bmp| */
|
2007-06-05 14:57:07 +00:00
|
|
|
bmp_names[PROGRESSBAR_BMP] = wps_bufptr + 1;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
#if LCD_DEPTH > 1
|
2007-04-08 04:01:06 +00:00
|
|
|
else if (token->type == WPS_TOKEN_IMAGE_BACKDROP)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
/* format: %X|filename.bmp| */
|
2007-06-05 14:57:07 +00:00
|
|
|
bmp_names[BACKDROP_BMP] = wps_bufptr + 1;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Skip the rest of the line */
|
2007-04-05 14:09:59 +00:00
|
|
|
return skip_end_of_line(wps_bufptr);
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_dir_level(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-05 14:09:59 +00:00
|
|
|
char val[] = { *wps_bufptr, '\0' };
|
2007-04-08 04:01:06 +00:00
|
|
|
token->value.i = atoi(val);
|
|
|
|
(void)wps_data; /* Kill warnings */
|
2007-04-04 14:41:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_subline_timeout(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
int skip = 0;
|
|
|
|
int val = 0;
|
|
|
|
bool have_point = false;
|
|
|
|
bool have_tenth = false;
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
(void)wps_data; /* Kill the warning */
|
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
while ( isdigit(*wps_bufptr) || *wps_bufptr == '.' )
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-05 14:09:59 +00:00
|
|
|
if (*wps_bufptr != '.')
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
val *= 10;
|
2007-04-05 14:09:59 +00:00
|
|
|
val += *wps_bufptr - '0';
|
2007-04-04 14:41:40 +00:00
|
|
|
if (have_point)
|
|
|
|
{
|
|
|
|
have_tenth = true;
|
2007-04-05 14:09:59 +00:00
|
|
|
wps_bufptr++;
|
2007-04-04 14:41:40 +00:00
|
|
|
skip++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
have_point = true;
|
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
wps_bufptr++;
|
2007-04-04 14:41:40 +00:00
|
|
|
skip++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_tenth == false)
|
|
|
|
val *= 10;
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
token->value.i = val;
|
2007-04-06 14:18:07 +00:00
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
static int parse_progressbar(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-08 04:01:06 +00:00
|
|
|
(void)token; /* Kill warnings */
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
|
|
|
short *vals[] = {
|
|
|
|
&wps_data->progress_height,
|
|
|
|
&wps_data->progress_start,
|
|
|
|
&wps_data->progress_end,
|
|
|
|
&wps_data->progress_top };
|
|
|
|
|
|
|
|
/* default values : */
|
|
|
|
wps_data->progress_height = 6;
|
|
|
|
wps_data->progress_start = 0;
|
|
|
|
wps_data->progress_end = 0;
|
|
|
|
wps_data->progress_top = -1;
|
|
|
|
|
|
|
|
int i = 0;
|
2007-04-05 14:09:59 +00:00
|
|
|
char *newline = strchr(wps_bufptr, '\n');
|
|
|
|
char *prev = strchr(wps_bufptr, '|');
|
2007-04-04 14:41:40 +00:00
|
|
|
if (prev && prev < newline) {
|
|
|
|
char *next = strchr(prev+1, '|');
|
|
|
|
while (i < 4 && next && next < newline)
|
|
|
|
{
|
|
|
|
*(vals[i++]) = atoi(++prev);
|
|
|
|
prev = strchr(prev, '|');
|
|
|
|
next = strchr(++next, '|');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wps_data->progress_height < 3)
|
|
|
|
wps_data->progress_height = 3;
|
|
|
|
if (wps_data->progress_end < wps_data->progress_start + 3)
|
|
|
|
wps_data->progress_end = 0;
|
|
|
|
}
|
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
return newline - wps_bufptr;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
if (*(wps_bufptr-1) == 'f')
|
2007-04-04 14:41:40 +00:00
|
|
|
wps_data->full_line_progressbar = true;
|
|
|
|
else
|
|
|
|
wps_data->full_line_progressbar = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
static int parse_albumart_load(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
|
|
|
{
|
2007-11-14 22:02:41 +00:00
|
|
|
const char *_pos, *newline;
|
2007-11-11 12:29:37 +00:00
|
|
|
bool parsing;
|
|
|
|
const short xalign_mask = WPS_ALBUMART_ALIGN_LEFT |
|
|
|
|
WPS_ALBUMART_ALIGN_CENTER |
|
|
|
|
WPS_ALBUMART_ALIGN_RIGHT;
|
|
|
|
const short yalign_mask = WPS_ALBUMART_ALIGN_TOP |
|
|
|
|
WPS_ALBUMART_ALIGN_CENTER |
|
|
|
|
WPS_ALBUMART_ALIGN_BOTTOM;
|
|
|
|
|
|
|
|
(void)token; /* silence warning */
|
|
|
|
|
|
|
|
/* reset albumart info in wps */
|
|
|
|
wps_data->wps_uses_albumart = WPS_ALBUMART_NONE;
|
|
|
|
wps_data->albumart_max_width = -1;
|
|
|
|
wps_data->albumart_max_height = -1;
|
|
|
|
wps_data->albumart_xalign = WPS_ALBUMART_ALIGN_CENTER; /* default */
|
|
|
|
wps_data->albumart_yalign = WPS_ALBUMART_ALIGN_CENTER; /* default */
|
|
|
|
|
|
|
|
/* format: %Cl|x|y|[[l|c|r][d|i|s]mwidth]|[[t|c|b][d|i|s]mheight]| */
|
|
|
|
|
2007-11-14 22:02:41 +00:00
|
|
|
newline = strchr(wps_bufptr, '\n');
|
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
/* initial validation and parsing of x and y components */
|
|
|
|
if (*wps_bufptr != '|')
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */
|
2007-11-11 12:29:37 +00:00
|
|
|
|
|
|
|
_pos = wps_bufptr + 1;
|
|
|
|
if (!isdigit(*_pos))
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl|@ */
|
2007-11-11 12:29:37 +00:00
|
|
|
wps_data->albumart_x = atoi(_pos);
|
|
|
|
|
|
|
|
_pos = strchr(_pos, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!_pos || _pos > newline || !isdigit(*(++_pos)))
|
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl|7\n or %Cl|7|@ */
|
2007-11-11 12:29:37 +00:00
|
|
|
|
|
|
|
wps_data->albumart_y = atoi(_pos);
|
|
|
|
|
|
|
|
_pos = strchr(_pos, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!_pos || _pos > newline)
|
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: no | after y coordinate
|
|
|
|
e.g. %Cl|7|59\n */
|
2007-11-11 12:29:37 +00:00
|
|
|
|
|
|
|
/* parsing width field */
|
|
|
|
parsing = true;
|
|
|
|
while (parsing)
|
|
|
|
{
|
|
|
|
/* apply each modifier in turn */
|
|
|
|
++_pos;
|
|
|
|
switch (*_pos)
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
case 'L':
|
|
|
|
case '+':
|
|
|
|
wps_data->albumart_xalign =
|
|
|
|
(wps_data->albumart_xalign & xalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
wps_data->albumart_xalign =
|
|
|
|
(wps_data->albumart_xalign & xalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
case '-':
|
|
|
|
wps_data->albumart_xalign =
|
|
|
|
(wps_data->albumart_xalign & xalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
wps_data->albumart_xalign |= WPS_ALBUMART_DECREASE;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
|
|
|
wps_data->albumart_xalign |= WPS_ALBUMART_INCREASE;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
wps_data->albumart_xalign |=
|
|
|
|
(WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
parsing = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* extract max width data */
|
|
|
|
if (*_pos != '|')
|
|
|
|
{
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!isdigit(*_pos)) /* malformed token: e.g. %Cl|7|59|# */
|
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
wps_data->albumart_max_width = atoi(_pos);
|
2007-11-14 22:02:41 +00:00
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
_pos = strchr(_pos, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!_pos || _pos > newline)
|
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: no | after width field
|
|
|
|
e.g. %Cl|7|59|200\n */
|
2007-11-11 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* parsing height field */
|
|
|
|
parsing = true;
|
|
|
|
while (parsing)
|
|
|
|
{
|
|
|
|
/* apply each modifier in turn */
|
|
|
|
++_pos;
|
|
|
|
switch (*_pos)
|
|
|
|
{
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
|
|
|
case '-':
|
|
|
|
wps_data->albumart_yalign =
|
|
|
|
(wps_data->albumart_yalign & yalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_TOP;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
|
|
|
wps_data->albumart_yalign =
|
|
|
|
(wps_data->albumart_yalign & yalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
case '+':
|
|
|
|
wps_data->albumart_yalign =
|
|
|
|
(wps_data->albumart_yalign & yalign_mask) |
|
|
|
|
WPS_ALBUMART_ALIGN_BOTTOM;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
wps_data->albumart_yalign |= WPS_ALBUMART_DECREASE;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
|
|
|
wps_data->albumart_yalign |= WPS_ALBUMART_INCREASE;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
wps_data->albumart_yalign |=
|
|
|
|
(WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
parsing = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* extract max height data */
|
|
|
|
if (*_pos != '|')
|
|
|
|
{
|
|
|
|
if (!isdigit(*_pos))
|
2007-11-14 22:02:41 +00:00
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token e.g. %Cl|7|59|200|@ */
|
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
wps_data->albumart_max_height = atoi(_pos);
|
2007-11-14 22:02:41 +00:00
|
|
|
|
2007-11-11 12:29:37 +00:00
|
|
|
_pos = strchr(_pos, '|');
|
2007-11-14 22:02:41 +00:00
|
|
|
if (!_pos || _pos > newline)
|
|
|
|
return WPS_ERROR_INVALID_PARAM; /* malformed token: no closing |
|
|
|
|
e.g. %Cl|7|59|200|200\n */
|
2007-11-11 12:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we got here, we parsed everything ok .. ! */
|
|
|
|
if (wps_data->albumart_max_width < 0)
|
|
|
|
wps_data->albumart_max_width = 0;
|
|
|
|
else if (wps_data->albumart_max_width > LCD_WIDTH)
|
|
|
|
wps_data->albumart_max_width = LCD_WIDTH;
|
|
|
|
|
|
|
|
if (wps_data->albumart_max_height < 0)
|
|
|
|
wps_data->albumart_max_height = 0;
|
|
|
|
else if (wps_data->albumart_max_height > LCD_HEIGHT)
|
|
|
|
wps_data->albumart_max_height = LCD_HEIGHT;
|
|
|
|
|
|
|
|
wps_data->wps_uses_albumart = WPS_ALBUMART_LOAD;
|
|
|
|
|
|
|
|
/* Skip the rest of the line */
|
|
|
|
return skip_end_of_line(wps_bufptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_albumart_conditional(const char *wps_bufptr,
|
|
|
|
struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
|
|
|
{
|
|
|
|
struct wps_token *prevtoken = token;
|
|
|
|
--prevtoken;
|
|
|
|
if (wps_data->num_tokens >= 1 && prevtoken->type == WPS_TOKEN_CONDITIONAL)
|
|
|
|
{
|
|
|
|
/* This %C is part of a %?C construct.
|
|
|
|
It's either %?C<blah> or %?Cn<blah> */
|
|
|
|
token->type = WPS_TOKEN_ALBUMART_FOUND;
|
|
|
|
if (*wps_bufptr == 'n' && *(wps_bufptr + 1) == '<')
|
|
|
|
{
|
|
|
|
token->next = true;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (*wps_bufptr == '<')
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
token->type = WPS_NO_TOKEN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-11-12 01:31:42 +00:00
|
|
|
{
|
|
|
|
/* This %C tag is in a conditional construct. */
|
|
|
|
wps_data->albumart_cond_index = condindex[level];
|
2007-11-11 12:29:37 +00:00
|
|
|
return 0;
|
2007-11-12 01:31:42 +00:00
|
|
|
}
|
2007-11-11 12:29:37 +00:00
|
|
|
};
|
|
|
|
#endif /* HAVE_ALBUMART */
|
|
|
|
|
2007-11-12 21:34:01 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-11-14 22:02:41 +00:00
|
|
|
static int parse_leftmargin(const char *wps_bufptr, struct wps_token *token,
|
|
|
|
struct wps_data *wps_data)
|
2007-11-12 21:34:01 +00:00
|
|
|
{
|
|
|
|
const char* p;
|
|
|
|
const char* pend;
|
2007-11-14 22:02:41 +00:00
|
|
|
const char *newline;
|
2007-11-12 21:34:01 +00:00
|
|
|
|
|
|
|
(void)wps_data; /* Kill the warning */
|
|
|
|
|
2007-11-14 22:02:41 +00:00
|
|
|
/* valid tag looks like %m|12| */
|
2007-11-12 21:34:01 +00:00
|
|
|
if(*wps_bufptr == '|')
|
|
|
|
{
|
|
|
|
p = wps_bufptr + 1;
|
2007-11-14 22:02:41 +00:00
|
|
|
newline = strchr(wps_bufptr, '\n');
|
|
|
|
if(isdigit(*p) && (pend = strchr(p, '|')) && pend < newline)
|
2007-11-12 21:34:01 +00:00
|
|
|
{
|
|
|
|
token->value.i = atoi(p);
|
2007-11-14 22:02:41 +00:00
|
|
|
return pend - wps_bufptr + 1;
|
2007-11-12 21:34:01 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:02:41 +00:00
|
|
|
|
|
|
|
/* invalid tag syntax */
|
|
|
|
return WPS_ERROR_INVALID_PARAM;
|
2007-11-12 21:34:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* Parse a generic token from the given string. Return the length read */
|
2007-04-05 14:09:59 +00:00
|
|
|
static int parse_token(const char *wps_bufptr, struct wps_data *wps_data)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-11-14 22:02:41 +00:00
|
|
|
int skip = 0, taglen = 0, ret;
|
2007-04-08 04:01:06 +00:00
|
|
|
struct wps_token *token = wps_data->tokens + wps_data->num_tokens;
|
|
|
|
const struct wps_tag *tag;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
switch(*wps_bufptr)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
case '<':
|
|
|
|
case '|':
|
|
|
|
case '>':
|
|
|
|
case ';':
|
2007-04-13 11:43:10 +00:00
|
|
|
case '#':
|
2007-04-04 14:41:40 +00:00
|
|
|
/* escaped characters */
|
2007-04-08 04:01:06 +00:00
|
|
|
token->type = WPS_TOKEN_CHARACTER;
|
|
|
|
token->value.c = *wps_bufptr;
|
2007-04-21 19:31:46 +00:00
|
|
|
taglen = 1;
|
2007-04-04 14:41:40 +00:00
|
|
|
wps_data->num_tokens++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
/* conditional tag */
|
2007-04-08 04:01:06 +00:00
|
|
|
token->type = WPS_TOKEN_CONDITIONAL;
|
2007-04-04 14:41:40 +00:00
|
|
|
level++;
|
|
|
|
condindex[level] = wps_data->num_tokens;
|
|
|
|
numoptions[level] = 1;
|
|
|
|
wps_data->num_tokens++;
|
2007-11-14 22:02:41 +00:00
|
|
|
ret = parse_token(wps_bufptr + 1, wps_data);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
taglen = 1 + ret;
|
2007-04-21 19:31:46 +00:00
|
|
|
break;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* find what tag we have */
|
2007-04-08 04:01:06 +00:00
|
|
|
for (tag = all_tags;
|
|
|
|
strncmp(wps_bufptr, tag->name, strlen(tag->name)) != 0;
|
|
|
|
tag++) ;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-21 19:31:46 +00:00
|
|
|
taglen = (tag->type != WPS_TOKEN_UNKNOWN) ? strlen(tag->name) : 2;
|
2007-04-08 04:01:06 +00:00
|
|
|
token->type = tag->type;
|
2007-05-02 17:51:01 +00:00
|
|
|
wps_data->sublines[wps_data->num_sublines].line_type |=
|
|
|
|
tag->refresh_type;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* if the tag has a special parsing function, we call it */
|
2007-04-08 04:01:06 +00:00
|
|
|
if (tag->parse_func)
|
2007-11-14 22:02:41 +00:00
|
|
|
{
|
|
|
|
ret = tag->parse_func(wps_bufptr + taglen, token, wps_data);
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
skip += ret;
|
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
/* Some tags we don't want to save as tokens */
|
2007-04-08 04:01:06 +00:00
|
|
|
if (tag->type == WPS_NO_TOKEN)
|
2007-04-04 14:41:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* tags that start with 'F', 'I' or 'D' are for the next file */
|
2007-05-02 17:51:01 +00:00
|
|
|
if ( *(tag->name) == 'I' || *(tag->name) == 'F' ||
|
|
|
|
*(tag->name) == 'D')
|
2007-04-08 04:01:06 +00:00
|
|
|
token->next = true;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
wps_data->num_tokens++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-21 19:31:46 +00:00
|
|
|
skip += taglen;
|
2007-04-04 14:41:40 +00:00
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
/* Parses the WPS.
|
|
|
|
data is the pointer to the structure where the parsed WPS should be stored.
|
|
|
|
It is initialised.
|
|
|
|
wps_bufptr points to the string containing the WPS tags */
|
2007-04-05 14:09:59 +00:00
|
|
|
static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-05 14:09:59 +00:00
|
|
|
if (!data || !wps_bufptr || !*wps_bufptr)
|
2007-04-04 14:41:40 +00:00
|
|
|
return false;
|
|
|
|
|
2007-04-30 14:08:58 +00:00
|
|
|
char *stringbuf = data->string_buffer;
|
2007-04-15 02:59:34 +00:00
|
|
|
int stringbuf_used = 0;
|
2007-04-24 00:57:04 +00:00
|
|
|
int fail = 0;
|
2007-11-14 22:02:41 +00:00
|
|
|
int ret;
|
2007-04-24 00:57:04 +00:00
|
|
|
line = 1;
|
2007-04-21 19:31:46 +00:00
|
|
|
level = -1;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-24 00:57:04 +00:00
|
|
|
while(*wps_bufptr && !fail && data->num_tokens < WPS_MAX_TOKENS - 1
|
2007-04-08 15:02:26 +00:00
|
|
|
&& data->num_lines < WPS_MAX_LINES)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-05 14:09:59 +00:00
|
|
|
switch(*wps_bufptr++)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Regular tag */
|
|
|
|
case '%':
|
2007-11-14 22:02:41 +00:00
|
|
|
if ((ret = parse_token(wps_bufptr, data)) < 0)
|
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_COND_INVALID_PARAM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wps_bufptr += ret;
|
2007-04-04 14:41:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Alternating sublines separator */
|
|
|
|
case ';':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (level >= 0) /* there are unclosed conditionals */
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_UNCLOSED_COND;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-15 02:59:34 +00:00
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
if (data->num_sublines+1 < WPS_MAX_SUBLINES)
|
|
|
|
wps_start_new_subline(data);
|
2007-04-04 14:41:40 +00:00
|
|
|
else
|
2007-04-05 14:09:59 +00:00
|
|
|
wps_bufptr += skip_end_of_line(wps_bufptr);
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Conditional list start */
|
|
|
|
case '<':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (data->tokens[data->num_tokens-2].type != WPS_TOKEN_CONDITIONAL)
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_COND_SYNTAX_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-21 19:31:46 +00:00
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
data->tokens[data->num_tokens].type = WPS_TOKEN_CONDITIONAL_START;
|
|
|
|
lastcond[level] = data->num_tokens++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Conditional list end */
|
|
|
|
case '>':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (level < 0) /* not in a conditional, invalid char */
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_INVALID_CHAR;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-21 19:31:46 +00:00
|
|
|
|
|
|
|
data->tokens[data->num_tokens].type = WPS_TOKEN_CONDITIONAL_END;
|
|
|
|
if (lastcond[level])
|
|
|
|
data->tokens[lastcond[level]].value.i = data->num_tokens;
|
2007-11-12 18:43:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_COND_SYNTAX_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-21 19:31:46 +00:00
|
|
|
lastcond[level] = 0;
|
|
|
|
data->num_tokens++;
|
|
|
|
data->tokens[condindex[level]].value.i = numoptions[level];
|
|
|
|
level--;
|
2007-04-04 14:41:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Conditional list option */
|
|
|
|
case '|':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (level < 0) /* not in a conditional, invalid char */
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_INVALID_CHAR;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
data->tokens[data->num_tokens].type = WPS_TOKEN_CONDITIONAL_OPTION;
|
|
|
|
if (lastcond[level])
|
|
|
|
data->tokens[lastcond[level]].value.i = data->num_tokens;
|
2007-11-12 18:43:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_COND_SYNTAX_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
lastcond[level] = data->num_tokens;
|
|
|
|
numoptions[level]++;
|
|
|
|
data->num_tokens++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Comment */
|
|
|
|
case '#':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (level >= 0) /* there are unclosed conditionals */
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_UNCLOSED_COND;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-15 02:59:34 +00:00
|
|
|
|
2007-04-05 14:09:59 +00:00
|
|
|
wps_bufptr += skip_end_of_line(wps_bufptr);
|
2007-04-04 14:41:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* End of this line */
|
|
|
|
case '\n':
|
2007-04-21 19:31:46 +00:00
|
|
|
if (level >= 0) /* there are unclosed conditionals */
|
2007-04-24 00:57:04 +00:00
|
|
|
{
|
|
|
|
fail = PARSE_FAIL_UNCLOSED_COND;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-15 02:59:34 +00:00
|
|
|
|
2007-04-24 00:57:04 +00:00
|
|
|
line++;
|
2007-04-08 04:01:06 +00:00
|
|
|
wps_start_new_subline(data);
|
|
|
|
data->num_lines++; /* Start a new line */
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-04-08 04:01:06 +00:00
|
|
|
if ((data->num_lines < WPS_MAX_LINES) &&
|
|
|
|
(data->num_sublines < WPS_MAX_SUBLINES))
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-05-02 17:51:01 +00:00
|
|
|
data->lines[data->num_lines].first_subline_idx =
|
|
|
|
data->num_sublines;
|
|
|
|
|
|
|
|
data->sublines[data->num_sublines].first_token_idx =
|
|
|
|
data->num_tokens;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* String */
|
|
|
|
default:
|
|
|
|
{
|
2007-04-30 14:08:58 +00:00
|
|
|
unsigned int len = 1;
|
|
|
|
const char *string_start = wps_bufptr - 1;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
2007-05-02 11:39:46 +00:00
|
|
|
/* find the length of the string */
|
2007-05-02 17:51:01 +00:00
|
|
|
while (*wps_bufptr && *wps_bufptr != '#' &&
|
2007-05-02 11:39:46 +00:00
|
|
|
*wps_bufptr != '%' && *wps_bufptr != ';' &&
|
|
|
|
*wps_bufptr != '<' && *wps_bufptr != '>' &&
|
|
|
|
*wps_bufptr != '|' && *wps_bufptr != '\n')
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-04-30 14:08:58 +00:00
|
|
|
wps_bufptr++;
|
|
|
|
len++;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 14:08:58 +00:00
|
|
|
/* look if we already have that string */
|
|
|
|
char **str;
|
|
|
|
int i;
|
|
|
|
bool found;
|
|
|
|
for (i = 0, str = data->strings, found = false;
|
2007-05-01 23:36:15 +00:00
|
|
|
i < data->num_strings &&
|
|
|
|
!(found = (strlen(*str) == len &&
|
2007-05-02 11:39:46 +00:00
|
|
|
strncmp(string_start, *str, len) == 0));
|
2007-05-01 23:36:15 +00:00
|
|
|
i++, str++);
|
|
|
|
/* If a matching string is found, found is true and i is
|
|
|
|
the index of the string. If not, found is false */
|
|
|
|
|
|
|
|
/* If it's NOT a duplicate, do nothing if we already have
|
|
|
|
too many unique strings */
|
|
|
|
if (found ||
|
2007-05-02 11:39:46 +00:00
|
|
|
(stringbuf_used < STRING_BUFFER_SIZE - 1 &&
|
|
|
|
data->num_strings < WPS_MAX_STRINGS))
|
2007-04-30 14:08:58 +00:00
|
|
|
{
|
2007-05-01 23:36:15 +00:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* new string */
|
2007-05-02 11:39:46 +00:00
|
|
|
|
|
|
|
/* truncate? */
|
2007-05-01 23:36:15 +00:00
|
|
|
if (stringbuf_used + len > STRING_BUFFER_SIZE - 1)
|
|
|
|
len = STRING_BUFFER_SIZE - stringbuf_used - 1;
|
2007-05-02 11:39:46 +00:00
|
|
|
|
2007-05-01 23:36:15 +00:00
|
|
|
strncpy(stringbuf, string_start, len);
|
2007-05-02 11:39:46 +00:00
|
|
|
*(stringbuf + len) = '\0';
|
|
|
|
|
2007-05-01 23:36:15 +00:00
|
|
|
data->strings[data->num_strings] = stringbuf;
|
|
|
|
stringbuf += len + 1;
|
|
|
|
stringbuf_used += len + 1;
|
2007-05-02 17:51:01 +00:00
|
|
|
data->tokens[data->num_tokens].value.i =
|
|
|
|
data->num_strings;
|
2007-05-01 23:36:15 +00:00
|
|
|
data->num_strings++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* another ocurrence of an existing string */
|
|
|
|
data->tokens[data->num_tokens].value.i = i;
|
|
|
|
}
|
|
|
|
data->tokens[data->num_tokens].type = WPS_TOKEN_STRING;
|
|
|
|
data->num_tokens++;
|
2007-04-30 14:08:58 +00:00
|
|
|
}
|
2007-04-15 02:59:34 +00:00
|
|
|
}
|
2007-04-04 14:41:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 18:43:38 +00:00
|
|
|
if (!fail && level >= 0) /* there are unclosed conditionals */
|
2007-05-02 11:39:46 +00:00
|
|
|
fail = PARSE_FAIL_UNCLOSED_COND;
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
#ifdef DEBUG
|
2007-04-24 23:58:57 +00:00
|
|
|
print_debug_info(data, fail, line);
|
2007-04-04 14:41:40 +00:00
|
|
|
#endif
|
2007-04-24 00:57:04 +00:00
|
|
|
|
|
|
|
if (fail)
|
|
|
|
wps_reset(data);
|
|
|
|
|
|
|
|
return (fail == 0);
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* Clear the WPS image cache */
|
|
|
|
static void wps_images_clear(struct wps_data *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* set images to unloaded and not displayed */
|
|
|
|
for (i = 0; i < MAX_IMAGES; i++)
|
|
|
|
{
|
|
|
|
data->img[i].loaded = false;
|
|
|
|
data->img[i].display = false;
|
|
|
|
data->img[i].always_display = false;
|
|
|
|
}
|
|
|
|
data->progressbar.have_bitmap_pb = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* initial setup of wps_data */
|
|
|
|
void wps_data_init(struct wps_data *wps_data)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
wps_images_clear(wps_data);
|
|
|
|
wps_data->wps_sb_tag = false;
|
|
|
|
wps_data->show_sb_on_wps = false;
|
|
|
|
wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */
|
|
|
|
wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */
|
|
|
|
wps_data->peak_meter_enabled = false;
|
|
|
|
#else /* HAVE_LCD_CHARCELLS */
|
2007-04-08 04:12:55 +00:00
|
|
|
int i;
|
2007-04-08 04:01:06 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
wps_data->wps_progress_pat[i] = 0;
|
|
|
|
}
|
|
|
|
wps_data->full_line_progressbar = false;
|
|
|
|
#endif
|
|
|
|
wps_data->wps_loaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wps_reset(struct wps_data *data)
|
|
|
|
{
|
2007-04-25 13:09:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
bool rwps = data->remote_wps; /* remember whether the data is for a RWPS */
|
|
|
|
#endif
|
2007-04-04 14:41:40 +00:00
|
|
|
memset(data, 0, sizeof(*data));
|
2007-11-11 12:29:37 +00:00
|
|
|
#ifdef HAVE_ALBUMART
|
|
|
|
data->wps_uses_albumart = WPS_ALBUMART_NONE;
|
|
|
|
#endif
|
2007-04-04 14:41:40 +00:00
|
|
|
wps_data_init(data);
|
2007-04-25 13:09:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
data->remote_wps = rwps;
|
|
|
|
#endif
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
|
|
|
|
|
|
|
static void clear_bmp_names(void)
|
|
|
|
{
|
|
|
|
int n;
|
2007-06-05 10:42:41 +00:00
|
|
|
for (n = 0; n < MAX_BITMAPS; n++)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
bmp_names[n] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void load_wps_bitmaps(struct wps_data *wps_data, char *bmpdir)
|
|
|
|
{
|
|
|
|
char img_path[MAX_PATH];
|
2007-06-05 10:42:41 +00:00
|
|
|
struct bitmap *bitmap;
|
|
|
|
bool *loaded;
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
int n;
|
2007-06-05 14:57:07 +00:00
|
|
|
for (n = 0; n < BACKDROP_BMP; n++)
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
|
|
|
if (bmp_names[n])
|
|
|
|
{
|
|
|
|
get_image_filename(bmp_names[n], bmpdir,
|
|
|
|
img_path, sizeof(img_path));
|
|
|
|
|
2007-06-05 14:57:07 +00:00
|
|
|
if (n == PROGRESSBAR_BMP) {
|
2007-06-05 10:42:41 +00:00
|
|
|
/* progressbar bitmap */
|
|
|
|
bitmap = &wps_data->progressbar.bm;
|
|
|
|
loaded = &wps_data->progressbar.have_bitmap_pb;
|
|
|
|
} else {
|
|
|
|
/* regular bitmap */
|
|
|
|
bitmap = &wps_data->img[n].bm;
|
|
|
|
loaded = &wps_data->img[n].loaded;
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* load the image */
|
2007-06-05 10:42:41 +00:00
|
|
|
bitmap->data = wps_data->img_buf_ptr;
|
|
|
|
if (load_bitmap(wps_data, img_path, bitmap))
|
2007-04-04 14:41:40 +00:00
|
|
|
{
|
2007-06-05 10:42:41 +00:00
|
|
|
*loaded = true;
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-25 21:44:56 +00:00
|
|
|
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
|
2007-06-05 14:57:07 +00:00
|
|
|
if (bmp_names[BACKDROP_BMP])
|
2007-04-25 21:44:56 +00:00
|
|
|
{
|
2007-06-05 14:57:07 +00:00
|
|
|
get_image_filename(bmp_names[BACKDROP_BMP], bmpdir,
|
2007-04-25 21:44:56 +00:00
|
|
|
img_path, sizeof(img_path));
|
2007-04-25 13:09:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-04-25 21:44:56 +00:00
|
|
|
if (wps_data->remote_wps)
|
|
|
|
#if LCD_REMOTE_DEPTH > 1
|
|
|
|
load_remote_wps_backdrop(img_path)
|
2007-04-25 13:09:56 +00:00
|
|
|
#endif
|
2007-04-25 21:44:56 +00:00
|
|
|
;
|
|
|
|
else
|
|
|
|
#endif /* HAVE_REMOTE_LCD */
|
2007-04-25 13:09:56 +00:00
|
|
|
load_wps_backdrop(img_path);
|
2007-04-25 21:44:56 +00:00
|
|
|
}
|
|
|
|
#endif /* has backdrop support */
|
2007-04-04 14:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
|
|
|
|
2007-04-08 15:02:26 +00:00
|
|
|
/* Skip leading UTF-8 BOM, if present. */
|
|
|
|
static char *skip_utf8_bom(char *buf)
|
|
|
|
{
|
|
|
|
unsigned char *s = (unsigned char *)buf;
|
|
|
|
|
|
|
|
if(s[0] == 0xef && s[1] == 0xbb && s[2] == 0xbf)
|
|
|
|
{
|
|
|
|
buf += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* to setup up the wps-data from a format-buffer (isfile = false)
|
|
|
|
from a (wps-)file (isfile = true)*/
|
|
|
|
bool wps_data_load(struct wps_data *wps_data,
|
|
|
|
const char *buf,
|
|
|
|
bool isfile)
|
|
|
|
{
|
|
|
|
if (!wps_data || !buf)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wps_reset(wps_data);
|
|
|
|
|
|
|
|
if (!isfile)
|
|
|
|
{
|
|
|
|
return wps_parse(wps_data, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this
|
|
|
|
* wants to be a virtual file. Feel free to modify dirbrowse()
|
|
|
|
* if you're feeling brave.
|
|
|
|
*/
|
2007-05-29 19:00:36 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-04-04 14:41:40 +00:00
|
|
|
if (! strcmp(buf, WPS_DEFAULTCFG) )
|
|
|
|
{
|
|
|
|
global_settings.wps_file[0] = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
if (! strcmp(buf, RWPS_DEFAULTCFG) )
|
|
|
|
{
|
|
|
|
global_settings.rwps_file[0] = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2007-05-29 19:00:36 +00:00
|
|
|
#endif /* __PCTOOL__ */
|
2007-04-04 14:41:40 +00:00
|
|
|
|
|
|
|
int fd = open(buf, O_RDONLY);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* get buffer space from the plugin buffer */
|
2007-04-21 18:38:25 +00:00
|
|
|
size_t buffersize = 0;
|
2007-04-04 14:41:40 +00:00
|
|
|
char *wps_buffer = (char *)plugin_get_buffer(&buffersize);
|
|
|
|
|
|
|
|
if (!wps_buffer)
|
|
|
|
return false;
|
|
|
|
|
2007-05-02 17:51:01 +00:00
|
|
|
/* copy the file's content to the buffer for parsing,
|
|
|
|
ensuring that every line ends with a newline char. */
|
2007-04-04 14:41:40 +00:00
|
|
|
unsigned int start = 0;
|
|
|
|
while(read_line(fd, wps_buffer + start, buffersize - start) > 0)
|
|
|
|
{
|
|
|
|
start += strlen(wps_buffer + start);
|
|
|
|
if (start < buffersize - 1)
|
|
|
|
{
|
|
|
|
wps_buffer[start++] = '\n';
|
|
|
|
wps_buffer[start] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (start <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
clear_bmp_names();
|
|
|
|
#endif
|
|
|
|
|
2007-04-08 15:02:26 +00:00
|
|
|
/* Skip leading UTF-8 BOM, if present. */
|
|
|
|
wps_buffer = skip_utf8_bom(wps_buffer);
|
|
|
|
|
2007-04-04 14:41:40 +00:00
|
|
|
/* parse the WPS source */
|
|
|
|
if (!wps_parse(wps_data, wps_buffer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wps_data->wps_loaded = true;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* get the bitmap dir */
|
|
|
|
char bmpdir[MAX_PATH];
|
|
|
|
size_t bmpdirlen;
|
|
|
|
char *dot = strrchr(buf, '.');
|
|
|
|
bmpdirlen = dot - buf;
|
|
|
|
strncpy(bmpdir, buf, dot - buf);
|
|
|
|
bmpdir[bmpdirlen] = 0;
|
|
|
|
|
|
|
|
/* load the bitmaps that were found by the parsing */
|
|
|
|
load_wps_bitmaps(wps_data, bmpdir);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2007-05-29 19:00:36 +00:00
|
|
|
|
|
|
|
int wps_subline_index(struct wps_data *data, int line, int subline)
|
|
|
|
{
|
|
|
|
return data->lines[line].first_subline_idx + subline;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wps_first_token_index(struct wps_data *data, int line, int subline)
|
|
|
|
{
|
|
|
|
int first_subline_idx = data->lines[line].first_subline_idx;
|
|
|
|
return data->sublines[first_subline_idx + subline].first_token_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wps_last_token_index(struct wps_data *data, int line, int subline)
|
|
|
|
{
|
|
|
|
int first_subline_idx = data->lines[line].first_subline_idx;
|
|
|
|
int idx = first_subline_idx + subline;
|
|
|
|
if (idx < data->num_sublines - 1)
|
|
|
|
{
|
|
|
|
/* This subline ends where the next begins */
|
|
|
|
return data->sublines[idx+1].first_token_idx - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The last subline goes to the end */
|
|
|
|
return data->num_tokens - 1;
|
|
|
|
}
|
|
|
|
}
|