summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings.c101
1 files changed, 42 insertions, 59 deletions
diff --git a/apps/settings.c b/apps/settings.c
index 38f083f595..a627cce65b 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -240,32 +240,34 @@ void settings_load(int which)
240 240
241bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str) 241bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str)
242{ 242{
243 const char* start = setting->cfg_vals; 243 const char* ptr = setting->cfg_vals;
244 char* end = NULL; 244 size_t len = strlen(str);
245 char temp[MAX_PATH]; 245 int index = 0;
246 int count = 0; 246
247 while (1) 247 while (true)
248 { 248 {
249 end = strchr(start, ','); 249 if (!strncmp(ptr, str, len))
250 if (!end)
251 { 250 {
252 if (!strcmp(str, start)) 251 ptr += len;
252 /* if the next character is not a comma or end of string,
253 * it means the comparison was only a partial match. */
254 if (*ptr == ',' || *ptr == '\0')
253 { 255 {
254 *out = count; 256 *out = index;
255 return true; 257 return true;
256 } 258 }
257 else return false;
258 } 259 }
259 strmemccpy(temp, start, end-start+1); 260
260 if (!strcmp(str, temp)) 261 while (*ptr != ',')
261 { 262 {
262 *out = count; 263 if (!*ptr)
263 return true; 264 return false;
265 ptr++;
264 } 266 }
265 start = end +1; 267
266 count++; 268 ptr++;
269 index++;
267 } 270 }
268 return false;
269} 271}
270 272
271/** 273/**
@@ -409,55 +411,36 @@ bool settings_load_config(const char* file, bool apply)
409 411
410bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len) 412bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len)
411{ 413{
412 const char* start = setting->cfg_vals; 414 const char* ptr = setting->cfg_vals;
413 char* end = NULL; 415 const int *values = NULL;
414 int count = 0; 416 int index = 0;
417
418 if (setting->flags & F_TABLE_SETTING)
419 values = setting->table_setting->values;
415 420
416 if ((setting->flags & F_T_MASK) == F_T_INT && 421 while (true)
417 (setting->flags & F_TABLE_SETTING))
418 { 422 {
419 const int *value = setting->table_setting->values; 423 if ((values && values[index] == val) ||
420 while (start) 424 (!values && index == val))
421 { 425 {
422 end = strchr(start,','); 426 char *buf_end = buf + buf_len - 1;
423 if (value[count] == val) 427 while (*ptr && *ptr != ',' && buf != buf_end)
424 { 428 *buf++ = *ptr++;
425 if (end == NULL)
426 strmemccpy(buf, start, buf_len);
427 else
428 {
429 int len = MIN(buf_len, (end-start) + 1);
430 strmemccpy(buf, start, len);
431 }
432 return true;
433 }
434 count++;
435 429
436 if (end) 430 *buf++ = '\0';
437 start = end+1; 431 return true;
438 else
439 break;
440 } 432 }
441 return false;
442 }
443 433
444 while (count < val) 434 while (*ptr != ',')
445 { 435 {
446 start = strchr(start,','); 436 if (!*ptr)
447 if (!start) 437 return false;
448 return false; 438 ptr++;
449 count++; 439 }
450 start++; 440
451 } 441 ptr++;
452 end = strchr(start,','); 442 index++;
453 if (end == NULL)
454 strmemccpy(buf, start, buf_len);
455 else
456 {
457 int len = MIN(buf_len, (end-start) + 1);
458 strmemccpy(buf, start, len);
459 } 443 }
460 return true;
461} 444}
462 445
463void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len) 446void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len)