mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
New tag %ss() which lets you get a substring of another tag.
%ss(start, length, tag) - i.e %ss(0,1,%TL) will get the first letter of the current lines text. use - for the length to get the rest of the tag (e.g %ss(1,-,%TL) will get everything after the first letter). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30500 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
86c543216f
commit
3b9ffd28da
5 changed files with 59 additions and 2 deletions
|
@ -720,6 +720,24 @@ static int parse_timeout_tag(struct skin_element *element,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int parse_substring_tag(struct skin_element* element,
|
||||||
|
struct wps_token *token,
|
||||||
|
struct wps_data *wps_data)
|
||||||
|
{
|
||||||
|
(void)wps_data;
|
||||||
|
struct substring *ss = (struct substring*)skin_buffer_alloc(sizeof(struct substring));
|
||||||
|
if (!ss)
|
||||||
|
return 1;
|
||||||
|
ss->start = element->params[0].data.number;
|
||||||
|
if (element->params[1].type == DEFAULT)
|
||||||
|
ss->length = -1;
|
||||||
|
else
|
||||||
|
ss->length = element->params[1].data.number;
|
||||||
|
ss->token = element->params[2].data.code->data;
|
||||||
|
token->value.data = ss;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_progressbar_tag(struct skin_element* element,
|
static int parse_progressbar_tag(struct skin_element* element,
|
||||||
struct wps_token *token,
|
struct wps_token *token,
|
||||||
struct wps_data *wps_data)
|
struct wps_data *wps_data)
|
||||||
|
@ -1788,6 +1806,9 @@ static int skin_element_callback(struct skin_element* element, void* data)
|
||||||
case SKIN_TOKEN_LOGICAL_IF:
|
case SKIN_TOKEN_LOGICAL_IF:
|
||||||
function = parse_logical_if;
|
function = parse_logical_if;
|
||||||
break;
|
break;
|
||||||
|
case SKIN_TOKEN_SUBSTRING:
|
||||||
|
function = parse_substring_tag;
|
||||||
|
break;
|
||||||
case SKIN_TOKEN_PROGRESSBAR:
|
case SKIN_TOKEN_PROGRESSBAR:
|
||||||
case SKIN_TOKEN_VOLUME:
|
case SKIN_TOKEN_VOLUME:
|
||||||
case SKIN_TOKEN_BATTERY_PERCENT:
|
case SKIN_TOKEN_BATTERY_PERCENT:
|
||||||
|
|
|
@ -868,7 +868,34 @@ const char *get_token_value(struct gui_wps *gwps,
|
||||||
struct logical_if *lif = token->value.data;
|
struct logical_if *lif = token->value.data;
|
||||||
return get_lif_token_value(gwps, lif, offset, buf, buf_size);
|
return get_lif_token_value(gwps, lif, offset, buf, buf_size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SKIN_TOKEN_SUBSTRING:
|
||||||
|
{
|
||||||
|
struct substring *ss = token->value.data;
|
||||||
|
const char *token_val = get_token_value(gwps, ss->token, offset,
|
||||||
|
buf, buf_size, intval);
|
||||||
|
int ret_len = ss->length;
|
||||||
|
if (token_val)
|
||||||
|
{
|
||||||
|
int len = strlen(token_val);
|
||||||
|
if (len < ss->start)
|
||||||
|
return NULL;
|
||||||
|
if (ret_len < 0)
|
||||||
|
ret_len = strlen(token_val) - ss->start;
|
||||||
|
if (token_val != buf)
|
||||||
|
{
|
||||||
|
memcpy(buf, &token_val[ss->start], ret_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buf = &buf[ss->start];
|
||||||
|
}
|
||||||
|
buf[ret_len] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case SKIN_TOKEN_CHARACTER:
|
case SKIN_TOKEN_CHARACTER:
|
||||||
if (token->value.c == '\n')
|
if (token->value.c == '\n')
|
||||||
|
|
|
@ -288,6 +288,12 @@ struct logical_if {
|
||||||
int num_options;
|
int num_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct substring {
|
||||||
|
int start;
|
||||||
|
int length;
|
||||||
|
struct wps_token *token;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HAVE_SKIN_VARIABLES
|
#ifdef HAVE_SKIN_VARIABLES
|
||||||
struct skin_var {
|
struct skin_var {
|
||||||
const char *label;
|
const char *label;
|
||||||
|
|
|
@ -236,7 +236,8 @@ static const struct tag_info legal_tags[] =
|
||||||
{ SKIN_TOKEN_VAR_SET, "vs", "SSI|I", SKIN_REFRESH_STATIC },
|
{ SKIN_TOKEN_VAR_SET, "vs", "SSI|I", SKIN_REFRESH_STATIC },
|
||||||
{ SKIN_TOKEN_VAR_GETVAL, "vg", "S", SKIN_REFRESH_DYNAMIC },
|
{ SKIN_TOKEN_VAR_GETVAL, "vg", "S", SKIN_REFRESH_DYNAMIC },
|
||||||
{ SKIN_TOKEN_VAR_TIMEOUT, "vl", "S|D", SKIN_REFRESH_DYNAMIC },
|
{ SKIN_TOKEN_VAR_TIMEOUT, "vl", "S|D", SKIN_REFRESH_DYNAMIC },
|
||||||
|
|
||||||
|
{ SKIN_TOKEN_SUBSTRING, "ss", "IiT", SKIN_REFRESH_DYNAMIC },
|
||||||
{ SKIN_TOKEN_UNKNOWN, "" , "", 0 }
|
{ SKIN_TOKEN_UNKNOWN, "" , "", 0 }
|
||||||
/* Keep this here to mark the end of the table */
|
/* Keep this here to mark the end of the table */
|
||||||
};
|
};
|
||||||
|
|
|
@ -279,6 +279,8 @@ enum skin_token_type {
|
||||||
SKIN_TOKEN_VAR_SET,
|
SKIN_TOKEN_VAR_SET,
|
||||||
SKIN_TOKEN_VAR_GETVAL,
|
SKIN_TOKEN_VAR_GETVAL,
|
||||||
SKIN_TOKEN_VAR_TIMEOUT,
|
SKIN_TOKEN_VAR_TIMEOUT,
|
||||||
|
|
||||||
|
SKIN_TOKEN_SUBSTRING,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue