diff options
author | Dave Chapman <dave@dchapman.com> | 2008-03-21 13:41:35 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2008-03-21 13:41:35 +0000 |
commit | e92d2c51ed455cc0a889fb6d38b4802eee252a6a (patch) | |
tree | 028860f37ad61406d82ad036694186dbc9d45360 /apps/gui | |
parent | bb026334c020bb04839186e7a45bac1dc7cb1724 (diff) | |
download | rockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.tar.gz rockbox-e92d2c51ed455cc0a889fb6d38b4802eee252a6a.zip |
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')
-rw-r--r-- | apps/gui/wps_parser.c | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index 960eab43da..307fa2ad7f 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, | |||
447 | { | 447 | { |
448 | int n; | 448 | int n; |
449 | const char *ptr = wps_bufptr; | 449 | const char *ptr = wps_bufptr; |
450 | const char *pos = NULL; | 450 | const char* filename; |
451 | const char *newline; | 451 | const char* id; |
452 | 452 | int x,y; | |
453 | |||
453 | /* format: %x|n|filename.bmp|x|y| | 454 | /* format: %x|n|filename.bmp|x|y| |
454 | or %xl|n|filename.bmp|x|y| */ | 455 | or %xl|n|filename.bmp|x|y| */ |
455 | 456 | ||
456 | ptr = strchr(ptr, '|') + 1; | 457 | if (*ptr != '|') |
457 | pos = strchr(ptr, '|'); | 458 | return WPS_ERROR_INVALID_PARAM; |
458 | newline = strchr(ptr, '\n'); | ||
459 | 459 | ||
460 | if (!pos || pos > newline) | 460 | ptr++; |
461 | return 0; | 461 | |
462 | if (!(ptr = parse_list("ssdd", '|', ptr, &id, &filename, &x, &y))) | ||
463 | return WPS_ERROR_INVALID_PARAM; | ||
464 | |||
465 | /* Check there is a terminating | */ | ||
466 | if (*ptr != '|') | ||
467 | return WPS_ERROR_INVALID_PARAM; | ||
462 | 468 | ||
463 | /* get the image ID */ | 469 | /* get the image ID */ |
464 | n = get_image_id(*ptr); | 470 | n = get_image_id(*id); |
465 | 471 | ||
466 | /* check the image number and load state */ | 472 | /* check the image number and load state */ |
467 | if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded) | 473 | if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded) |
@@ -470,34 +476,11 @@ static int parse_image_load(const char *wps_bufptr, | |||
470 | return WPS_ERROR_INVALID_PARAM; | 476 | return WPS_ERROR_INVALID_PARAM; |
471 | } | 477 | } |
472 | 478 | ||
473 | ptr = pos + 1; | 479 | /* save a pointer to the filename */ |
474 | 480 | bmp_names[n] = filename; | |
475 | /* get image name */ | ||
476 | bmp_names[n] = ptr; | ||
477 | 481 | ||
478 | pos = strchr(ptr, '|'); | 482 | wps_data->img[n].x = x; |
479 | ptr = pos + 1; | 483 | wps_data->img[n].y = y; |
480 | |||
481 | /* get x-position */ | ||
482 | pos = strchr(ptr, '|'); | ||
483 | if (pos && pos < newline) | ||
484 | wps_data->img[n].x = atoi(ptr); | ||
485 | else | ||
486 | { | ||
487 | /* weird syntax, bail out */ | ||
488 | return WPS_ERROR_INVALID_PARAM; | ||
489 | } | ||
490 | |||
491 | /* get y-position */ | ||
492 | ptr = pos + 1; | ||
493 | pos = strchr(ptr, '|'); | ||
494 | if (pos && pos < newline) | ||
495 | wps_data->img[n].y = atoi(ptr); | ||
496 | else | ||
497 | { | ||
498 | /* weird syntax, bail out */ | ||
499 | return WPS_ERROR_INVALID_PARAM; | ||
500 | } | ||
501 | 484 | ||
502 | if (token->type == WPS_TOKEN_IMAGE_DISPLAY) | 485 | if (token->type == WPS_TOKEN_IMAGE_DISPLAY) |
503 | wps_data->img[n].always_display = true; | 486 | wps_data->img[n].always_display = true; |