diff options
-rw-r--r-- | apps/filetypes.c | 6 | ||||
-rw-r--r-- | apps/gui/wps_parser.c | 55 | ||||
-rw-r--r-- | apps/misc.c | 108 | ||||
-rw-r--r-- | apps/misc.h | 5 | ||||
-rw-r--r-- | apps/plugins/text_editor.c | 9 | ||||
-rw-r--r-- | apps/settings.c | 2 |
6 files changed, 137 insertions, 48 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index 8427bc7450..1ef136d5ce 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -164,12 +164,12 @@ void read_color_theme_file(void) { | |||
164 | continue; | 164 | continue; |
165 | if (!strcasecmp(ext, "folder")) | 165 | if (!strcasecmp(ext, "folder")) |
166 | { | 166 | { |
167 | custom_colors[0] = hex_to_rgb(color); | 167 | hex_to_rgb(color, &custom_colors[0]); |
168 | continue; | 168 | continue; |
169 | } | 169 | } |
170 | if (!strcasecmp(ext, "???")) | 170 | if (!strcasecmp(ext, "???")) |
171 | { | 171 | { |
172 | custom_colors[MAX_FILETYPES] = hex_to_rgb(color); | 172 | hex_to_rgb(color, &custom_colors[MAX_FILETYPES]); |
173 | continue; | 173 | continue; |
174 | } | 174 | } |
175 | for (i=1; i<filetype_count; i++) | 175 | for (i=1; i<filetype_count; i++) |
@@ -177,7 +177,7 @@ void read_color_theme_file(void) { | |||
177 | if (filetypes[i].extension && | 177 | if (filetypes[i].extension && |
178 | !strcasecmp(ext, filetypes[i].extension)) | 178 | !strcasecmp(ext, filetypes[i].extension)) |
179 | { | 179 | { |
180 | custom_colors[i] = hex_to_rgb(color); | 180 | hex_to_rgb(color, &custom_colors[i]); |
181 | break; | 181 | break; |
182 | } | 182 | } |
183 | } | 183 | } |
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; |
diff --git a/apps/misc.c b/apps/misc.c index 6f34e50a54..632b12b9aa 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -1098,7 +1098,7 @@ static int hex2dec(int c) | |||
1098 | (toupper(c)) - 'A' + 10); | 1098 | (toupper(c)) - 'A' + 10); |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | int hex_to_rgb(const char* hex) | 1101 | int hex_to_rgb(const char* hex, int* color) |
1102 | { int ok = 1; | 1102 | { int ok = 1; |
1103 | int i; | 1103 | int i; |
1104 | int red, green, blue; | 1104 | int red, green, blue; |
@@ -1115,11 +1115,12 @@ int hex_to_rgb(const char* hex) | |||
1115 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); | 1115 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); |
1116 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); | 1116 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); |
1117 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); | 1117 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); |
1118 | return LCD_RGBPACK(red,green,blue); | 1118 | *color = LCD_RGBPACK(red,green,blue); |
1119 | return 0; | ||
1119 | } | 1120 | } |
1120 | } | 1121 | } |
1121 | 1122 | ||
1122 | return 0; | 1123 | return -1; |
1123 | } | 1124 | } |
1124 | #endif /* HAVE_LCD_COLOR */ | 1125 | #endif /* HAVE_LCD_COLOR */ |
1125 | 1126 | ||
@@ -1200,3 +1201,104 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename) | |||
1200 | 1201 | ||
1201 | return buffer; | 1202 | return buffer; |
1202 | } | 1203 | } |
1204 | |||
1205 | #ifdef HAVE_LCD_BITMAP | ||
1206 | /* A simplified scanf - used (at time of writing) by wps parsing functions. | ||
1207 | |||
1208 | fmt - char array specifying the format of each list option. Valid values | ||
1209 | are: d - int | ||
1210 | s - string (sets pointer to string, without copying) | ||
1211 | c - hex colour (RGB888 - e.g. ff00ff) | ||
1212 | g - greyscale "colour" (0-3) | ||
1213 | |||
1214 | sep - list separator (e.g. ',' or '|') | ||
1215 | str - string to parse, must be terminated by 0 or sep | ||
1216 | ... - pointers to store the parsed values | ||
1217 | |||
1218 | return value - pointer to char after parsed data, 0 if there was an error. | ||
1219 | |||
1220 | */ | ||
1221 | |||
1222 | /* '0'-'3' are ASCII 0x30 to 0x33 */ | ||
1223 | #define is0123(x) (((x) & 0xfc) == 0x30) | ||
1224 | |||
1225 | const char* parse_list(const char *fmt, const char sep, const char* str, ...) | ||
1226 | { | ||
1227 | va_list ap; | ||
1228 | const char* p = str; | ||
1229 | const char** s; | ||
1230 | int* d; | ||
1231 | |||
1232 | va_start(ap, str); | ||
1233 | |||
1234 | while (*fmt) | ||
1235 | { | ||
1236 | /* Check for separator, if we're not at the start */ | ||
1237 | if (p != str) | ||
1238 | { | ||
1239 | if (*p != sep) | ||
1240 | goto err; | ||
1241 | p++; | ||
1242 | } | ||
1243 | |||
1244 | switch (*fmt++) | ||
1245 | { | ||
1246 | case 's': /* string - return a pointer to it (not a copy) */ | ||
1247 | s = va_arg(ap, const char **); | ||
1248 | |||
1249 | *s = p; | ||
1250 | while (*p && *p != sep) | ||
1251 | p++; | ||
1252 | |||
1253 | break; | ||
1254 | |||
1255 | case 'd': /* int */ | ||
1256 | d = va_arg(ap, int*); | ||
1257 | if (!isdigit(*p)) | ||
1258 | goto err; | ||
1259 | |||
1260 | *d = *p++ - '0'; | ||
1261 | |||
1262 | while (isdigit(*p)) | ||
1263 | *d = (*d * 10) + (*p++ - '0'); | ||
1264 | |||
1265 | break; | ||
1266 | |||
1267 | #ifdef HAVE_LCD_COLOR | ||
1268 | case 'c': /* colour (rrggbb - e.g. f3c1a8) */ | ||
1269 | d = va_arg(ap, int*); | ||
1270 | |||
1271 | if (hex_to_rgb(p, d) < 0) | ||
1272 | goto err; | ||
1273 | |||
1274 | p += 6; | ||
1275 | |||
1276 | break; | ||
1277 | #endif | ||
1278 | |||
1279 | #if LCD_DEPTH == 2 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) | ||
1280 | case 'g': /* greyscale colour (0-3) */ | ||
1281 | d = va_arg(ap, int*); | ||
1282 | |||
1283 | if (is0123(*p)) | ||
1284 | *d = *p++ - '0'; | ||
1285 | else | ||
1286 | goto err; | ||
1287 | |||
1288 | break; | ||
1289 | #endif | ||
1290 | |||
1291 | default: /* Unknown format type */ | ||
1292 | goto err; | ||
1293 | break; | ||
1294 | } | ||
1295 | } | ||
1296 | |||
1297 | va_end(ap); | ||
1298 | return p; | ||
1299 | |||
1300 | err: | ||
1301 | va_end(ap); | ||
1302 | return 0; | ||
1303 | } | ||
1304 | #endif | ||
diff --git a/apps/misc.h b/apps/misc.h index 289d952afb..c6a91646b8 100644 --- a/apps/misc.h +++ b/apps/misc.h | |||
@@ -110,7 +110,7 @@ void check_bootfile(bool do_rolo); | |||
110 | void setvol(void); | 110 | void setvol(void); |
111 | 111 | ||
112 | #ifdef HAVE_LCD_COLOR | 112 | #ifdef HAVE_LCD_COLOR |
113 | int hex_to_rgb(const char* hex); | 113 | int hex_to_rgb(const char* hex, int* color); |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | char* strrsplt(char* str, int c); | 116 | char* strrsplt(char* str, int c); |
@@ -124,4 +124,7 @@ bool dir_exists(const char *path); | |||
124 | */ | 124 | */ |
125 | char *strip_extension(char* buffer, int buffer_size, const char *filename); | 125 | char *strip_extension(char* buffer, int buffer_size, const char *filename); |
126 | 126 | ||
127 | /* A simplified scanf */ | ||
128 | const char* parse_list(const char *fmt, const char sep, const char* str, ...); | ||
129 | |||
127 | #endif /* MISC_H */ | 130 | #endif /* MISC_H */ |
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index 6b6e449ae9..780516e896 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c | |||
@@ -273,7 +273,7 @@ int do_item_menu(int cur_sel, char* copy_buffer) | |||
273 | || (c>='0' && c<= '9')) | 273 | || (c>='0' && c<= '9')) |
274 | #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ | 274 | #define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ |
275 | (toupper(c)) - 'A' + 10) | 275 | (toupper(c)) - 'A' + 10) |
276 | int hex_to_rgb(const char* hex) | 276 | int hex_to_rgb(const char* hex, int* color) |
277 | { int ok = 1; | 277 | { int ok = 1; |
278 | int i; | 278 | int i; |
279 | int red, green, blue; | 279 | int red, green, blue; |
@@ -290,11 +290,12 @@ int hex_to_rgb(const char* hex) | |||
290 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); | 290 | red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); |
291 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); | 291 | green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); |
292 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); | 292 | blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); |
293 | return LCD_RGBPACK(red,green,blue); | 293 | *color = LCD_RGBPACK(red,green,blue); |
294 | return 0; | ||
294 | } | 295 | } |
295 | } | 296 | } |
296 | 297 | ||
297 | return 0; | 298 | return -1; |
298 | } | 299 | } |
299 | #endif /* HAVE_LCD_COLOR */ | 300 | #endif /* HAVE_LCD_COLOR */ |
300 | 301 | ||
@@ -407,7 +408,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
407 | case 1: | 408 | case 1: |
408 | edit_text = false; | 409 | edit_text = false; |
409 | if (value) | 410 | if (value) |
410 | color = hex_to_rgb(value); | 411 | hex_to_rgb(value, &color); |
411 | else color = 0; | 412 | else color = 0; |
412 | rb->strcpy(extension, name); | 413 | rb->strcpy(extension, name); |
413 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); | 414 | rb->set_color(rb->screens[SCREEN_MAIN], name, &color, -1); |
diff --git a/apps/settings.c b/apps/settings.c index 7eec15baf3..6fb5e3ee47 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -290,7 +290,7 @@ bool settings_load_config(const char* file, bool apply) | |||
290 | case F_T_UINT: | 290 | case F_T_UINT: |
291 | #ifdef HAVE_LCD_COLOR | 291 | #ifdef HAVE_LCD_COLOR |
292 | if (settings[i].flags&F_RGB) | 292 | if (settings[i].flags&F_RGB) |
293 | *(int*)settings[i].setting = hex_to_rgb(value); | 293 | hex_to_rgb(value, (int*)settings[i].setting); |
294 | else | 294 | else |
295 | #endif | 295 | #endif |
296 | if (settings[i].cfg_vals == NULL) | 296 | if (settings[i].cfg_vals == NULL) |