forked from len0rd/rockbox
Accept FS#9075 and rename valid_vals to set_vals
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17698 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
cbbbaac650
commit
ae49b387bf
3 changed files with 33 additions and 26 deletions
|
@ -544,7 +544,7 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
const char *ptr = wps_bufptr;
|
const char *ptr = wps_bufptr;
|
||||||
struct viewport* vp;
|
struct viewport* vp;
|
||||||
int depth;
|
int depth;
|
||||||
int valid = 0;
|
uint32_t set = 0;
|
||||||
enum {
|
enum {
|
||||||
PL_X = 0,
|
PL_X = 0,
|
||||||
PL_Y,
|
PL_Y,
|
||||||
|
@ -590,7 +590,7 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
if (depth == 16)
|
if (depth == 16)
|
||||||
{
|
{
|
||||||
if (!(ptr = parse_list("dddddcc", &valid, '|', ptr, &vp->x, &vp->y, &vp->width,
|
if (!(ptr = parse_list("dddddcc", &set, '|', ptr, &vp->x, &vp->y, &vp->width,
|
||||||
&vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern)))
|
&vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern)))
|
||||||
return WPS_ERROR_INVALID_PARAM;
|
return WPS_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
@ -601,7 +601,7 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
/* Default to black on white */
|
/* Default to black on white */
|
||||||
vp->fg_pattern = 0;
|
vp->fg_pattern = 0;
|
||||||
vp->bg_pattern = 3;
|
vp->bg_pattern = 3;
|
||||||
if (!(ptr = parse_list("dddddgg", &valid, '|', ptr, &vp->x, &vp->y, &vp->width,
|
if (!(ptr = parse_list("dddddgg", &set, '|', ptr, &vp->x, &vp->y, &vp->width,
|
||||||
&vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern)))
|
&vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern)))
|
||||||
return WPS_ERROR_INVALID_PARAM;
|
return WPS_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
@ -610,7 +610,7 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
|
#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
|
||||||
if (depth == 1)
|
if (depth == 1)
|
||||||
{
|
{
|
||||||
if (!(ptr = parse_list("ddddd", &valid, '|', ptr, &vp->x, &vp->y,
|
if (!(ptr = parse_list("ddddd", &set, '|', ptr, &vp->x, &vp->y,
|
||||||
&vp->width, &vp->height, &vp->font)))
|
&vp->width, &vp->height, &vp->font)))
|
||||||
return WPS_ERROR_INVALID_PARAM;
|
return WPS_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
@ -622,17 +622,17 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
if (*ptr != '|')
|
if (*ptr != '|')
|
||||||
return WPS_ERROR_INVALID_PARAM;
|
return WPS_ERROR_INVALID_PARAM;
|
||||||
|
|
||||||
if ((valid&(1<<PL_X)) == 0 || (valid&(1<<PL_Y)) == 0)
|
if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
|
||||||
return WPS_ERROR_INVALID_PARAM;
|
return WPS_ERROR_INVALID_PARAM;
|
||||||
|
|
||||||
/* fix defaults */
|
/* fix defaults */
|
||||||
if ((valid&(1<<PL_WIDTH)) == 0)
|
if (!LIST_VALUE_PARSED(set, PL_WIDTH))
|
||||||
vp->width = lcd_width - vp->x;
|
vp->width = lcd_width - vp->x;
|
||||||
if ((valid&(1<<PL_HEIGHT)) == 0)
|
if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
|
||||||
vp->height = lcd_height - vp->y;
|
vp->height = lcd_height - vp->y;
|
||||||
|
|
||||||
/* Default to using the user font if the font was an invalid number */
|
/* Default to using the user font if the font was an invalid number */
|
||||||
if (((valid&(1<<PL_FONT)) == 0) ||
|
if (!LIST_VALUE_PARSED(set, PL_FONT) ||
|
||||||
((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)))
|
((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)))
|
||||||
vp->font = FONT_UI;
|
vp->font = FONT_UI;
|
||||||
|
|
||||||
|
@ -649,9 +649,9 @@ static int parse_viewport(const char *wps_bufptr,
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
if (depth == 16)
|
if (depth == 16)
|
||||||
{
|
{
|
||||||
if ((valid&(1<<PL_FG)) == 0)
|
if (!LIST_VALUE_PARSED(set, PL_FG))
|
||||||
vp->fg_pattern = global_settings.fg_color;
|
vp->fg_pattern = global_settings.fg_color;
|
||||||
if ((valid&(1<<PL_BG)) == 0)
|
if (!LIST_VALUE_PARSED(set, PL_BG))
|
||||||
vp->bg_pattern = global_settings.bg_color;
|
vp->bg_pattern = global_settings.bg_color;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
30
apps/misc.c
30
apps/misc.c
|
@ -1217,7 +1217,7 @@ int hex_to_rgb(const char* hex, int* color)
|
||||||
s - string (sets pointer to string, without copying)
|
s - string (sets pointer to string, without copying)
|
||||||
c - hex colour (RGB888 - e.g. ff00ff)
|
c - hex colour (RGB888 - e.g. ff00ff)
|
||||||
g - greyscale "colour" (0-3)
|
g - greyscale "colour" (0-3)
|
||||||
valid_vals - if not NULL 1 is set in the bitplace if the item was read OK
|
set_vals - if not NULL 1 is set in the bitplace if the item was read OK
|
||||||
0 if not read.
|
0 if not read.
|
||||||
first item is LSB, (max 32 items! )
|
first item is LSB, (max 32 items! )
|
||||||
Stops parseing if an item is invalid unless the item == '-'
|
Stops parseing if an item is invalid unless the item == '-'
|
||||||
|
@ -1232,19 +1232,19 @@ int hex_to_rgb(const char* hex, int* color)
|
||||||
/* '0'-'3' are ASCII 0x30 to 0x33 */
|
/* '0'-'3' are ASCII 0x30 to 0x33 */
|
||||||
#define is0123(x) (((x) & 0xfc) == 0x30)
|
#define is0123(x) (((x) & 0xfc) == 0x30)
|
||||||
|
|
||||||
const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
const char* parse_list(const char *fmt, unsigned int *set_vals,
|
||||||
const char sep, const char* str, ...)
|
const char sep, const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
const char* p = str, *f = fmt;
|
const char* p = str, *f = fmt;
|
||||||
const char** s;
|
const char** s;
|
||||||
int* d;
|
int* d;
|
||||||
bool valid;
|
bool set;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
va_start(ap, str);
|
va_start(ap, str);
|
||||||
if (valid_vals)
|
if (set_vals)
|
||||||
*valid_vals = 0;
|
*set_vals = 0;
|
||||||
while (*fmt)
|
while (*fmt)
|
||||||
{
|
{
|
||||||
/* Check for separator, if we're not at the start */
|
/* Check for separator, if we're not at the start */
|
||||||
|
@ -1254,7 +1254,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
goto err;
|
goto err;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
valid = false;
|
set = false;
|
||||||
switch (*fmt++)
|
switch (*fmt++)
|
||||||
{
|
{
|
||||||
case 's': /* string - return a pointer to it (not a copy) */
|
case 's': /* string - return a pointer to it (not a copy) */
|
||||||
|
@ -1263,14 +1263,14 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
*s = p;
|
*s = p;
|
||||||
while (*p && *p != sep)
|
while (*p && *p != sep)
|
||||||
p++;
|
p++;
|
||||||
valid = (*s[0]!='-') && (*s[1]!=sep) ;
|
set = (*s[0]!='-') && (*s[1]!=sep) ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd': /* int */
|
case 'd': /* int */
|
||||||
d = va_arg(ap, int*);
|
d = va_arg(ap, int*);
|
||||||
if (!isdigit(*p))
|
if (!isdigit(*p))
|
||||||
{
|
{
|
||||||
if (!valid_vals || *p != '-')
|
if (!set_vals || *p != '-')
|
||||||
goto err;
|
goto err;
|
||||||
while (*p && *p != sep)
|
while (*p && *p != sep)
|
||||||
p++;
|
p++;
|
||||||
|
@ -1280,7 +1280,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
*d = *p++ - '0';
|
*d = *p++ - '0';
|
||||||
while (isdigit(*p))
|
while (isdigit(*p))
|
||||||
*d = (*d * 10) + (*p++ - '0');
|
*d = (*d * 10) + (*p++ - '0');
|
||||||
valid = true;
|
set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1291,7 +1291,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
|
|
||||||
if (hex_to_rgb(p, d) < 0)
|
if (hex_to_rgb(p, d) < 0)
|
||||||
{
|
{
|
||||||
if (!valid_vals || *p != '-')
|
if (!set_vals || *p != '-')
|
||||||
goto err;
|
goto err;
|
||||||
while (*p && *p != sep)
|
while (*p && *p != sep)
|
||||||
p++;
|
p++;
|
||||||
|
@ -1299,7 +1299,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p += 6;
|
p += 6;
|
||||||
valid = true;
|
set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1312,9 +1312,9 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
if (is0123(*p))
|
if (is0123(*p))
|
||||||
{
|
{
|
||||||
*d = *p++ - '0';
|
*d = *p++ - '0';
|
||||||
valid = true;
|
set = true;
|
||||||
}
|
}
|
||||||
else if (!valid_vals || *p != '-')
|
else if (!set_vals || *p != '-')
|
||||||
goto err;
|
goto err;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1329,8 +1329,8 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
||||||
goto err;
|
goto err;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (valid_vals && valid)
|
if (set_vals && set)
|
||||||
*valid_vals |= (1<<i);
|
*set_vals |= (1<<i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,14 @@ bool dir_exists(const char *path);
|
||||||
char *strip_extension(char* buffer, int buffer_size, const char *filename);
|
char *strip_extension(char* buffer, int buffer_size, const char *filename);
|
||||||
|
|
||||||
/* A simplified scanf */
|
/* A simplified scanf */
|
||||||
const char* parse_list(const char *fmt, unsigned int *valid_vals,
|
/*
|
||||||
|
* Checks whether the value at position 'position' was really read
|
||||||
|
* during a call to 'parse_list'
|
||||||
|
* - position: 0-based number of the value
|
||||||
|
* - valid_vals: value after the call to 'parse_list'
|
||||||
|
*/
|
||||||
|
#define LIST_VALUE_PARSED(setvals, position) ((setvals)&(1<<(position)))
|
||||||
|
const char* parse_list(const char *fmt, unsigned int *set_vals,
|
||||||
const char sep, const char* str, ...);
|
const char sep, const char* str, ...);
|
||||||
|
|
||||||
#endif /* MISC_H */
|
#endif /* MISC_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue