summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-12-21 10:54:25 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2024-12-22 01:11:10 -0500
commit7c678f5e7a3f110f14683a01e757c44ab475ac26 (patch)
tree3925301055d28469a8903c7a8ba9d2d1dc63cce0
parent632e72273d87d0f02de6a31a864ccf6dde03e725 (diff)
downloadrockbox-7c678f5e7a.tar.gz
rockbox-7c678f5e7a.zip
[Feature] %ft file text tags add prefix search
%ft(filename,search_text) finds a line beginning with search_text strips search_text and returns the remainder of the line Change-Id: I06fe029b89aa60e4dbf34c039d180c75213519a4
-rw-r--r--apps/gui/skin_engine/skin_parser.c36
-rw-r--r--lib/skin_parser/tag_table.c2
-rw-r--r--manual/appendix/wps_tags.tex12
3 files changed, 41 insertions, 9 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 1397f0b41c..2b0cfb6bbc 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -1343,14 +1343,30 @@ static int parse_filetext(struct skin_element *element,
(void)wps_data;
const char* filename;
char buf[MAX_PATH];
+ char *buf_start = buf;
int fd;
int line = 0;
+ const char *search_text = NULL;
+ int search_len = 0;
- /* format: %ft(filename[,line]) */
+ /* format: %ft(filename[,line|search text]) */
filename = get_param_text(element, 0);
if (element->params_count == 2)
- line = get_param(element, 1)->data.number;
+ {
+ struct skin_tag_parameter *param1 = get_param(element, 1);
+ if (param1->type == INTEGER)
+ line = param1->data.number;
+ else if (param1->type == STRING)
+ {
+ search_text = get_param_text(element, 1);
+ line = 0x3FF; /* 1k lines is a pretty large file */
+ search_len = strlen(search_text);
+ DEBUGF("%s: found search text %s\n", __func__, search_text);
+ }
+ else
+ return WPS_ERROR_INVALID_PARAM;
+ }
else if (element->params_count != 1)
{
DEBUGF("%s(file, line): %s Error: param count %d\n",
@@ -1364,7 +1380,7 @@ static int parse_filetext(struct skin_element *element,
path_append(buf, ROCKBOX_DIR, filename, sizeof(buf));
DEBUGF("%s %s[%d]\n", __func__, buf, line);
- if ((fd = open_utf8(buf, O_RDONLY)) < 0)
+ if (line > 0x3FF || (fd = open_utf8(buf, O_RDONLY)) < 0)
{
DEBUGF("%s: Error Opening %s\n", __func__, buf);
goto failure;
@@ -1373,8 +1389,15 @@ static int parse_filetext(struct skin_element *element,
int rd = 0;
while (line >= 0)
{
- if ((rd = read_line(fd, buf, sizeof(buf))) < 0)
+ if ((rd = read_line(fd, buf, sizeof(buf))) <= 0)
break;
+ if (search_text && strncasecmp(buf, search_text, search_len) == 0)
+ {
+ buf_start += search_len;
+ rd -= search_len;
+ DEBUGF("%s: found '%s' Reading '%s'\n", __func__, search_text, buf);
+ break;
+ }
line--;
}
@@ -1386,10 +1409,11 @@ static int parse_filetext(struct skin_element *element,
if (element->is_conditional)
{
+ buf_start = buf;
rd = 1; /* just alloc enough for the conditional to work*/
}
- buf[rd] = '\0';
+ buf_start[rd] = '\0';
char * skinbuf = skin_buffer_alloc(rd+1);
@@ -1399,7 +1423,7 @@ static int parse_filetext(struct skin_element *element,
close(fd);
return WPS_ERROR_INVALID_PARAM;
}
- strcpy(skinbuf, buf);
+ strcpy(skinbuf, buf_start);
close(fd);
token->value.data = PTRTOSKINOFFSET(skin_buffer, skinbuf);
token->type = SKIN_TOKEN_STRING;
diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c
index a337d2af83..233276c7fa 100644
--- a/lib/skin_parser/tag_table.c
+++ b/lib/skin_parser/tag_table.c
@@ -50,7 +50,7 @@ static const struct tag_info legal_tags[] =
TAG(SKIN_TOKEN_FILE_SIZE, "fs", "", SKIN_REFRESH_STATIC),
TAG(SKIN_TOKEN_FILE_VBR, "fv", "", SKIN_REFRESH_STATIC),
TAG(SKIN_TOKEN_FILE_DIRECTORY, "d" , "I", SKIN_REFRESH_STATIC),
- TAG(SKIN_TOKEN_FILE_TEXT, "ft" , "F|i", SKIN_REFRESH_STATIC),
+ TAG(SKIN_TOKEN_FILE_TEXT, "ft" , "F|[is]", SKIN_REFRESH_STATIC),
TAG(SKIN_TOKEN_FILE_BITRATE, "Fb", "", SKIN_REFRESH_STATIC),
TAG(SKIN_TOKEN_FILE_CODEC, "Fc", "", SKIN_REFRESH_STATIC),
diff --git a/manual/appendix/wps_tags.tex b/manual/appendix/wps_tags.tex
index 86859837f0..52bfac1a2b 100644
--- a/manual/appendix/wps_tags.tex
+++ b/manual/appendix/wps_tags.tex
@@ -758,18 +758,26 @@ a horizontal progressbar which doesn't fill and draws the image
\end{description}
\begin{tagmap}
- \config{\%ft(filename [,line]} & Get a line of text from a file.\\
+ \config{\%ft(filename [,line|search_text]} & Get a line of text from a file.\\
\end{tagmap}
Use this tag to check for the existence of a file or read a line of text from a file.
Checking if a file exists can be done with \%?(ft(filename)<Found|NotFound>
similarly you can also check if a specific line exists with \%?(ft(filename, n)<Found|NotFound>
where n is the desired line.
+ or supply search text and do a search (ignoring case) of the beginning of each line.
+ If found this prefix will be removed and the rest of the string returned to the end of line.
+ \%?(ft(filename, search_text)<Found|NotFound>
+
Note: empty files or files that do not exist are ignored by the skin engine otherwise
\begin{description}
\item[filename] -- filename Note: files can only be found in \fname{/.rockbox} directory or one of its children.
eg. \%ft(wps/file.txt) would refer to \fname{/.rockbox/wps/file.txt}
\item[line] -- OPTIONAL, which line to grab, defaults to the first line.
- Note: lines must end with CR or LF but may not exceed 320 characters
+ Note: lines must end with CR or LF but may not exceed 320 characters, Max 1023 lines
+ \item[search_text] -- OPTIONAL, instead of a line number find a line that begins with search_text.
+ Note: search_text will be stripped from beginning of string quotes should not be included
+ unless you want to search for a string containing them
+ lines must end with CR or LF but may not exceed 320 characters including search text.
\end{description}
\begin{tagmap}