summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/gui/wps_parser.c20
-rw-r--r--apps/misc.c30
-rw-r--r--apps/misc.h9
3 files changed, 33 insertions, 26 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 859e5eebe2..53605e27cc 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -544,7 +544,7 @@ static int parse_viewport(const char *wps_bufptr,
544 const char *ptr = wps_bufptr; 544 const char *ptr = wps_bufptr;
545 struct viewport* vp; 545 struct viewport* vp;
546 int depth; 546 int depth;
547 int valid = 0; 547 uint32_t set = 0;
548 enum { 548 enum {
549 PL_X = 0, 549 PL_X = 0,
550 PL_Y, 550 PL_Y,
@@ -590,7 +590,7 @@ static int parse_viewport(const char *wps_bufptr,
590#ifdef HAVE_LCD_COLOR 590#ifdef HAVE_LCD_COLOR
591 if (depth == 16) 591 if (depth == 16)
592 { 592 {
593 if (!(ptr = parse_list("dddddcc", &valid, '|', ptr, &vp->x, &vp->y, &vp->width, 593 if (!(ptr = parse_list("dddddcc", &set, '|', ptr, &vp->x, &vp->y, &vp->width,
594 &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) 594 &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern)))
595 return WPS_ERROR_INVALID_PARAM; 595 return WPS_ERROR_INVALID_PARAM;
596 } 596 }
@@ -601,7 +601,7 @@ static int parse_viewport(const char *wps_bufptr,
601 /* Default to black on white */ 601 /* Default to black on white */
602 vp->fg_pattern = 0; 602 vp->fg_pattern = 0;
603 vp->bg_pattern = 3; 603 vp->bg_pattern = 3;
604 if (!(ptr = parse_list("dddddgg", &valid, '|', ptr, &vp->x, &vp->y, &vp->width, 604 if (!(ptr = parse_list("dddddgg", &set, '|', ptr, &vp->x, &vp->y, &vp->width,
605 &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) 605 &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern)))
606 return WPS_ERROR_INVALID_PARAM; 606 return WPS_ERROR_INVALID_PARAM;
607 } 607 }
@@ -610,7 +610,7 @@ static int parse_viewport(const char *wps_bufptr,
610#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) 610#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
611 if (depth == 1) 611 if (depth == 1)
612 { 612 {
613 if (!(ptr = parse_list("ddddd", &valid, '|', ptr, &vp->x, &vp->y, 613 if (!(ptr = parse_list("ddddd", &set, '|', ptr, &vp->x, &vp->y,
614 &vp->width, &vp->height, &vp->font))) 614 &vp->width, &vp->height, &vp->font)))
615 return WPS_ERROR_INVALID_PARAM; 615 return WPS_ERROR_INVALID_PARAM;
616 } 616 }
@@ -622,17 +622,17 @@ static int parse_viewport(const char *wps_bufptr,
622 if (*ptr != '|') 622 if (*ptr != '|')
623 return WPS_ERROR_INVALID_PARAM; 623 return WPS_ERROR_INVALID_PARAM;
624 624
625 if ((valid&(1<<PL_X)) == 0 || (valid&(1<<PL_Y)) == 0) 625 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
626 return WPS_ERROR_INVALID_PARAM; 626 return WPS_ERROR_INVALID_PARAM;
627 627
628 /* fix defaults */ 628 /* fix defaults */
629 if ((valid&(1<<PL_WIDTH)) == 0) 629 if (!LIST_VALUE_PARSED(set, PL_WIDTH))
630 vp->width = lcd_width - vp->x; 630 vp->width = lcd_width - vp->x;
631 if ((valid&(1<<PL_HEIGHT)) == 0) 631 if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
632 vp->height = lcd_height - vp->y; 632 vp->height = lcd_height - vp->y;
633 633
634 /* Default to using the user font if the font was an invalid number */ 634 /* Default to using the user font if the font was an invalid number */
635 if (((valid&(1<<PL_FONT)) == 0) || 635 if (!LIST_VALUE_PARSED(set, PL_FONT) ||
636 ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))) 636 ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)))
637 vp->font = FONT_UI; 637 vp->font = FONT_UI;
638 638
@@ -649,9 +649,9 @@ static int parse_viewport(const char *wps_bufptr,
649#ifdef HAVE_LCD_COLOR 649#ifdef HAVE_LCD_COLOR
650 if (depth == 16) 650 if (depth == 16)
651 { 651 {
652 if ((valid&(1<<PL_FG)) == 0) 652 if (!LIST_VALUE_PARSED(set, PL_FG))
653 vp->fg_pattern = global_settings.fg_color; 653 vp->fg_pattern = global_settings.fg_color;
654 if ((valid&(1<<PL_BG)) == 0) 654 if (!LIST_VALUE_PARSED(set, PL_BG))
655 vp->bg_pattern = global_settings.bg_color; 655 vp->bg_pattern = global_settings.bg_color;
656 } 656 }
657#endif 657#endif
diff --git a/apps/misc.c b/apps/misc.c
index 4d7ddd57e6..65688024cc 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1217,7 +1217,7 @@ int hex_to_rgb(const char* hex, int* color)
1217 s - string (sets pointer to string, without copying) 1217 s - string (sets pointer to string, without copying)
1218 c - hex colour (RGB888 - e.g. ff00ff) 1218 c - hex colour (RGB888 - e.g. ff00ff)
1219 g - greyscale "colour" (0-3) 1219 g - greyscale "colour" (0-3)
1220 valid_vals - if not NULL 1 is set in the bitplace if the item was read OK 1220 set_vals - if not NULL 1 is set in the bitplace if the item was read OK
1221 0 if not read. 1221 0 if not read.
1222 first item is LSB, (max 32 items! ) 1222 first item is LSB, (max 32 items! )
1223 Stops parseing if an item is invalid unless the item == '-' 1223 Stops parseing if an item is invalid unless the item == '-'
@@ -1232,19 +1232,19 @@ int hex_to_rgb(const char* hex, int* color)
1232/* '0'-'3' are ASCII 0x30 to 0x33 */ 1232/* '0'-'3' are ASCII 0x30 to 0x33 */
1233#define is0123(x) (((x) & 0xfc) == 0x30) 1233#define is0123(x) (((x) & 0xfc) == 0x30)
1234 1234
1235const char* parse_list(const char *fmt, unsigned int *valid_vals, 1235const char* parse_list(const char *fmt, unsigned int *set_vals,
1236 const char sep, const char* str, ...) 1236 const char sep, const char* str, ...)
1237{ 1237{
1238 va_list ap; 1238 va_list ap;
1239 const char* p = str, *f = fmt; 1239 const char* p = str, *f = fmt;
1240 const char** s; 1240 const char** s;
1241 int* d; 1241 int* d;
1242 bool valid; 1242 bool set;
1243 int i=0; 1243 int i=0;
1244 1244
1245 va_start(ap, str); 1245 va_start(ap, str);
1246 if (valid_vals) 1246 if (set_vals)
1247 *valid_vals = 0; 1247 *set_vals = 0;
1248 while (*fmt) 1248 while (*fmt)
1249 { 1249 {
1250 /* Check for separator, if we're not at the start */ 1250 /* 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,
1254 goto err; 1254 goto err;
1255 p++; 1255 p++;
1256 } 1256 }
1257 valid = false; 1257 set = false;
1258 switch (*fmt++) 1258 switch (*fmt++)
1259 { 1259 {
1260 case 's': /* string - return a pointer to it (not a copy) */ 1260 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,
1263 *s = p; 1263 *s = p;
1264 while (*p && *p != sep) 1264 while (*p && *p != sep)
1265 p++; 1265 p++;
1266 valid = (*s[0]!='-') && (*s[1]!=sep) ; 1266 set = (*s[0]!='-') && (*s[1]!=sep) ;
1267 break; 1267 break;
1268 1268
1269 case 'd': /* int */ 1269 case 'd': /* int */
1270 d = va_arg(ap, int*); 1270 d = va_arg(ap, int*);
1271 if (!isdigit(*p)) 1271 if (!isdigit(*p))
1272 { 1272 {
1273 if (!valid_vals || *p != '-') 1273 if (!set_vals || *p != '-')
1274 goto err; 1274 goto err;
1275 while (*p && *p != sep) 1275 while (*p && *p != sep)
1276 p++; 1276 p++;
@@ -1280,7 +1280,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
1280 *d = *p++ - '0'; 1280 *d = *p++ - '0';
1281 while (isdigit(*p)) 1281 while (isdigit(*p))
1282 *d = (*d * 10) + (*p++ - '0'); 1282 *d = (*d * 10) + (*p++ - '0');
1283 valid = true; 1283 set = true;
1284 } 1284 }
1285 1285
1286 break; 1286 break;
@@ -1291,7 +1291,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
1291 1291
1292 if (hex_to_rgb(p, d) < 0) 1292 if (hex_to_rgb(p, d) < 0)
1293 { 1293 {
1294 if (!valid_vals || *p != '-') 1294 if (!set_vals || *p != '-')
1295 goto err; 1295 goto err;
1296 while (*p && *p != sep) 1296 while (*p && *p != sep)
1297 p++; 1297 p++;
@@ -1299,7 +1299,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
1299 else 1299 else
1300 { 1300 {
1301 p += 6; 1301 p += 6;
1302 valid = true; 1302 set = true;
1303 } 1303 }
1304 1304
1305 break; 1305 break;
@@ -1312,9 +1312,9 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
1312 if (is0123(*p)) 1312 if (is0123(*p))
1313 { 1313 {
1314 *d = *p++ - '0'; 1314 *d = *p++ - '0';
1315 valid = true; 1315 set = true;
1316 } 1316 }
1317 else if (!valid_vals || *p != '-') 1317 else if (!set_vals || *p != '-')
1318 goto err; 1318 goto err;
1319 else 1319 else
1320 { 1320 {
@@ -1329,8 +1329,8 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
1329 goto err; 1329 goto err;
1330 break; 1330 break;
1331 } 1331 }
1332 if (valid_vals && valid) 1332 if (set_vals && set)
1333 *valid_vals |= (1<<i); 1333 *set_vals |= (1<<i);
1334 i++; 1334 i++;
1335 } 1335 }
1336 1336
diff --git a/apps/misc.h b/apps/misc.h
index 8dc61920c8..d0edb3dcd1 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -129,7 +129,14 @@ bool dir_exists(const char *path);
129char *strip_extension(char* buffer, int buffer_size, const char *filename); 129char *strip_extension(char* buffer, int buffer_size, const char *filename);
130 130
131/* A simplified scanf */ 131/* A simplified scanf */
132const char* parse_list(const char *fmt, unsigned int *valid_vals, 132/*
133 * Checks whether the value at position 'position' was really read
134 * during a call to 'parse_list'
135 * - position: 0-based number of the value
136 * - valid_vals: value after the call to 'parse_list'
137 */
138#define LIST_VALUE_PARSED(setvals, position) ((setvals)&(1<<(position)))
139const char* parse_list(const char *fmt, unsigned int *set_vals,
133 const char sep, const char* str, ...); 140 const char sep, const char* str, ...);
134 141
135#endif /* MISC_H */ 142#endif /* MISC_H */