summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2008-06-05 08:20:39 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2008-06-05 08:20:39 +0000
commitf002b7d0552f7c4b5d8229fe07982748e9ade731 (patch)
tree143d256739a433b5980ae3f80fb7ca986d837db8 /apps
parentdd7103ae2e2a73c91a393aaa2ae62f17bbd93535 (diff)
downloadrockbox-f002b7d0552f7c4b5d8229fe07982748e9ade731.tar.gz
rockbox-f002b7d0552f7c4b5d8229fe07982748e9ade731.tar.bz2
rockbox-f002b7d0552f7c4b5d8229fe07982748e9ade731.zip
make %V a little simpler. only the x and y values have to be specified now (i.e %V|0|0|||||| )
default values are as follows: width - lcd width - the x value height - lcd height - y value font - user font fg colour - the themes fg colour on 16bit targets, black on greyscale targets bg colour - the themes bg colour on 16bit targets, white on greyscale targets git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17690 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/wps_parser.c79
-rw-r--r--apps/misc.c66
-rw-r--r--apps/misc.h3
3 files changed, 103 insertions, 45 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index fd4db2e9de..54f9f588bf 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -489,7 +489,7 @@ static int parse_image_load(const char *wps_bufptr,
ptr++;
- if (!(ptr = parse_list("ssdd", '|', ptr, &id, &filename, &x, &y)))
+ if (!(ptr = parse_list("ssdd", NULL, '|', ptr, &id, &filename, &x, &y)))
return WPS_ERROR_INVALID_PARAM;
/* Check there is a terminating | */
@@ -540,17 +540,34 @@ static int parse_viewport(const char *wps_bufptr,
struct wps_token *token,
struct wps_data *wps_data)
{
+ (void)token; /* Kill warnings */
const char *ptr = wps_bufptr;
struct viewport* vp;
int depth;
-
- (void)token; /* Kill warnings */
+ int valid = 0;
+ enum {
+ PL_X = 0,
+ PL_Y,
+ PL_WIDTH,
+ PL_HEIGHT,
+ PL_FONT,
+ PL_FG,
+ PL_BG,
+ };
+ int lcd_width = LCD_WIDTH, lcd_height = LCD_HEIGHT;
+#ifdef HAVE_REMOTE_LCD
+ if (wps_data->remote_wps)
+ {
+ lcd_width = LCD_REMOTE_WIDTH;
+ lcd_height = LCD_REMOTE_HEIGHT;
+ }
+#endif
if (*wps_bufptr != '|')
return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */
ptr = wps_bufptr + 1;
- /* format: %V|x|y|width|height|fg_pattern|bg_pattern| */
+ /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */
if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS)
return WPS_ERROR_INVALID_PARAM;
@@ -573,7 +590,7 @@ static int parse_viewport(const char *wps_bufptr,
#ifdef HAVE_LCD_COLOR
if (depth == 16)
{
- if (!(ptr = parse_list("dddddcc", '|', ptr, &vp->x, &vp->y, &vp->width,
+ if (!(ptr = parse_list("dddddcc", &valid, '|', ptr, &vp->x, &vp->y, &vp->width,
&vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern)))
return WPS_ERROR_INVALID_PARAM;
}
@@ -581,7 +598,10 @@ static int parse_viewport(const char *wps_bufptr,
#endif
#if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2)
if (depth == 2) {
- if (!(ptr = parse_list("dddddgg", '|', ptr, &vp->x, &vp->y, &vp->width,
+ /* Default to black on white */
+ vp->fg_pattern = 0;
+ vp->bg_pattern = 3;
+ if (!(ptr = parse_list("dddddgg", &valid, '|', ptr, &vp->x, &vp->y, &vp->width,
&vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern)))
return WPS_ERROR_INVALID_PARAM;
}
@@ -590,8 +610,8 @@ static int parse_viewport(const char *wps_bufptr,
#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
if (depth == 1)
{
- if (!(ptr = parse_list("ddddd", '|', ptr, &vp->x, &vp->y, &vp->width,
- &vp->height, &vp->font)))
+ if (!(ptr = parse_list("ddddd", &valid, '|', ptr, &vp->x, &vp->y,
+ &vp->width, &vp->height, &vp->font)))
return WPS_ERROR_INVALID_PARAM;
}
else
@@ -602,34 +622,39 @@ static int parse_viewport(const char *wps_bufptr,
if (*ptr != '|')
return WPS_ERROR_INVALID_PARAM;
+ if ((valid&(1<<PL_X)) == 0 || (valid&(1<<PL_Y)) == 0)
+ return WPS_ERROR_INVALID_PARAM;
+
+ /* fix defaults */
+ if ((valid&(1<<PL_WIDTH)) == 0)
+ vp->width = lcd_width - vp->x;
+ if ((valid&(1<<PL_HEIGHT)) == 0)
+ vp->height = lcd_height - vp->y;
+
/* Default to using the user font if the font was an invalid number */
- if ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))
+ if (((valid&(1<<PL_FONT)) == 0) ||
+ ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)))
vp->font = FONT_UI;
/* Validate the viewport dimensions - we know that the numbers are
non-negative integers */
-#ifdef HAVE_REMOTE_LCD
- if (wps_data->remote_wps)
+ if ((vp->x >= lcd_width) ||
+ ((vp->x + vp->width) > lcd_width) ||
+ (vp->y >= lcd_height) ||
+ ((vp->y + vp->height) > lcd_height))
{
- if ((vp->x >= LCD_REMOTE_WIDTH) ||
- ((vp->x + vp->width) > LCD_REMOTE_WIDTH) ||
- (vp->y >= LCD_REMOTE_HEIGHT) ||
- ((vp->y + vp->height) > LCD_REMOTE_HEIGHT))
- {
- return WPS_ERROR_INVALID_PARAM;
- }
+ return WPS_ERROR_INVALID_PARAM;
}
- else
-#endif
+
+#ifdef HAVE_LCD_COLOR
+ if (depth == 16)
{
- if ((vp->x >= LCD_WIDTH) ||
- ((vp->x + vp->width) > LCD_WIDTH) ||
- (vp->y >= LCD_HEIGHT) ||
- ((vp->y + vp->height) > LCD_HEIGHT))
- {
- return WPS_ERROR_INVALID_PARAM;
- }
+ if ((valid&(1<<PL_FG)) == 0)
+ vp->fg_pattern = global_settings.fg_color;
+ if ((valid&(1<<PL_BG)) == 0)
+ vp->fg_pattern = global_settings.bg_color;
}
+#endif
wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1;
diff --git a/apps/misc.c b/apps/misc.c
index e9f1724b1b..51e02f6a62 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1217,7 +1217,9 @@ int hex_to_rgb(const char* hex, int* color)
s - string (sets pointer to string, without copying)
c - hex colour (RGB888 - e.g. ff00ff)
g - greyscale "colour" (0-3)
-
+ valid_vals - if not NULL 1 is set in the bitplace if the item was read OK
+ 0 if not read.
+ first item is LSB, (max 32 items! )
sep - list separator (e.g. ',' or '|')
str - string to parse, must be terminated by 0 or sep
... - pointers to store the parsed values
@@ -1229,25 +1231,29 @@ int hex_to_rgb(const char* hex, int* color)
/* '0'-'3' are ASCII 0x30 to 0x33 */
#define is0123(x) (((x) & 0xfc) == 0x30)
-const char* parse_list(const char *fmt, const char sep, const char* str, ...)
+const char* parse_list(const char *fmt, unsigned int *valid_vals,
+ const char sep, const char* str, ...)
{
va_list ap;
- const char* p = str;
+ const char* p = str, *f = fmt;
const char** s;
int* d;
+ bool valid;
+ int i=0;
va_start(ap, str);
-
+ if (valid_vals)
+ *valid_vals = 0;
while (*fmt)
{
/* Check for separator, if we're not at the start */
- if (p != str)
+ if (f != fmt)
{
if (*p != sep)
goto err;
p++;
}
-
+ valid = false;
switch (*fmt++)
{
case 's': /* string - return a pointer to it (not a copy) */
@@ -1256,18 +1262,25 @@ const char* parse_list(const char *fmt, const char sep, const char* str, ...)
*s = p;
while (*p && *p != sep)
p++;
-
+ valid = (*s[0]!=sep);
break;
case 'd': /* int */
d = va_arg(ap, int*);
if (!isdigit(*p))
- goto err;
-
- *d = *p++ - '0';
-
- while (isdigit(*p))
- *d = (*d * 10) + (*p++ - '0');
+ {
+ if (!valid_vals)
+ goto err;
+ while (*p && *p != sep)
+ p++;
+ }
+ else
+ {
+ *d = *p++ - '0';
+ while (isdigit(*p))
+ *d = (*d * 10) + (*p++ - '0');
+ valid = true;
+ }
break;
@@ -1276,9 +1289,17 @@ const char* parse_list(const char *fmt, const char sep, const char* str, ...)
d = va_arg(ap, int*);
if (hex_to_rgb(p, d) < 0)
- goto err;
-
- p += 6;
+ {
+ if (!valid_vals)
+ goto err;
+ while (*p && *p != sep)
+ p++;
+ }
+ else
+ {
+ p += 6;
+ valid = true;
+ }
break;
#endif
@@ -1288,9 +1309,17 @@ const char* parse_list(const char *fmt, const char sep, const char* str, ...)
d = va_arg(ap, int*);
if (is0123(*p))
+ {
*d = *p++ - '0';
- else
+ valid = true;
+ }
+ else if (!valid_vals)
goto err;
+ else
+ {
+ while (*p && *p != sep)
+ p++;
+ }
break;
#endif
@@ -1299,6 +1328,9 @@ const char* parse_list(const char *fmt, const char sep, const char* str, ...)
goto err;
break;
}
+ if (valid_vals && valid)
+ *valid_vals |= (1<<i);
+ i++;
}
va_end(ap);
diff --git a/apps/misc.h b/apps/misc.h
index 4d0226ae51..8dc61920c8 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -129,6 +129,7 @@ bool dir_exists(const char *path);
char *strip_extension(char* buffer, int buffer_size, const char *filename);
/* A simplified scanf */
-const char* parse_list(const char *fmt, const char sep, const char* str, ...);
+const char* parse_list(const char *fmt, unsigned int *valid_vals,
+ const char sep, const char* str, ...);
#endif /* MISC_H */