summaryrefslogtreecommitdiff
path: root/apps/gui/wps_parser.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2008-03-21 13:41:35 +0000
committerDave Chapman <dave@dchapman.com>2008-03-21 13:41:35 +0000
commite92d2c51ed455cc0a889fb6d38b4802eee252a6a (patch)
tree028860f37ad61406d82ad036694186dbc9d45360 /apps/gui/wps_parser.c
parentbb026334c020bb04839186e7a45bac1dc7cb1724 (diff)
downloadrockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.zip
rockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.tar.gz
rockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.tar.bz2
rockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.tar.xz
Add a general-purpose parse_list function to parse a string containing a delimited list of items and adapt the parse_image_load() function in the WPS parser to use it. This function will also be used to parse the upcoming WPS %V viewport tag, but I'm committing it separately as these changes are unrelated to the viewport implementation itself.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16728 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/wps_parser.c')
-rw-r--r--apps/gui/wps_parser.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 960eab4..307fa2a 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -447,21 +447,27 @@ static int parse_image_load(const char *wps_bufptr,
{
int n;
const char *ptr = wps_bufptr;
- const char *pos = NULL;
- const char *newline;
-
+ const char* filename;
+ const char* id;
+ int x,y;
+
/* format: %x|n|filename.bmp|x|y|
or %xl|n|filename.bmp|x|y| */
- ptr = strchr(ptr, '|') + 1;
- pos = strchr(ptr, '|');
- newline = strchr(ptr, '\n');
+ if (*ptr != '|')
+ return WPS_ERROR_INVALID_PARAM;
- if (!pos || pos > newline)
- return 0;
+ ptr++;
+
+ if (!(ptr = parse_list("ssdd", '|', ptr, &id, &filename, &x, &y)))
+ return WPS_ERROR_INVALID_PARAM;
+
+ /* Check there is a terminating | */
+ if (*ptr != '|')
+ return WPS_ERROR_INVALID_PARAM;
/* get the image ID */
- n = get_image_id(*ptr);
+ n = get_image_id(*id);
/* check the image number and load state */
if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded)
@@ -470,34 +476,11 @@ static int parse_image_load(const char *wps_bufptr,
return WPS_ERROR_INVALID_PARAM;
}
- ptr = pos + 1;
-
- /* get image name */
- bmp_names[n] = ptr;
+ /* save a pointer to the filename */
+ bmp_names[n] = filename;
- pos = strchr(ptr, '|');
- ptr = pos + 1;
-
- /* get x-position */
- pos = strchr(ptr, '|');
- if (pos && pos < newline)
- wps_data->img[n].x = atoi(ptr);
- else
- {
- /* weird syntax, bail out */
- return WPS_ERROR_INVALID_PARAM;
- }
-
- /* get y-position */
- ptr = pos + 1;
- pos = strchr(ptr, '|');
- if (pos && pos < newline)
- wps_data->img[n].y = atoi(ptr);
- else
- {
- /* weird syntax, bail out */
- return WPS_ERROR_INVALID_PARAM;
- }
+ wps_data->img[n].x = x;
+ wps_data->img[n].y = y;
if (token->type == WPS_TOKEN_IMAGE_DISPLAY)
wps_data->img[n].always_display = true;