diff options
author | Antoine Cellerier <dionoea@videolan.org> | 2008-12-07 16:19:25 +0000 |
---|---|---|
committer | Antoine Cellerier <dionoea@videolan.org> | 2008-12-07 16:19:25 +0000 |
commit | 3ad535031a84f0fa9c65a24e140c81b0a60c3026 (patch) | |
tree | 009295444ffb26c5e130d72d0258ea4786f196b7 | |
parent | 89da4328a07c8736c42843607a3f3bf91c17601d (diff) | |
download | rockbox-3ad535031a84f0fa9c65a24e140c81b0a60c3026.tar.gz rockbox-3ad535031a84f0fa9c65a24e140c81b0a60c3026.zip |
Add new cfg_to_string function (this just splits existing code).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19356 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/settings.c | 109 | ||||
-rw-r--r-- | apps/settings.h | 1 |
2 files changed, 60 insertions, 50 deletions
diff --git a/apps/settings.c b/apps/settings.c index f8c9acd151..4babe33cdb 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -416,6 +416,63 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) | |||
416 | return true; | 416 | return true; |
417 | } | 417 | } |
418 | 418 | ||
419 | bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) | ||
420 | { | ||
421 | switch (settings[i].flags&F_T_MASK) | ||
422 | { | ||
423 | case F_T_CUSTOM: | ||
424 | settings[i].custom_setting->write_to_cfg(settings[i].setting, | ||
425 | buf, buf_len); | ||
426 | break; | ||
427 | case F_T_INT: | ||
428 | case F_T_UINT: | ||
429 | #ifdef HAVE_LCD_COLOR | ||
430 | if (settings[i].flags&F_RGB) | ||
431 | { | ||
432 | int colour = *(int*)settings[i].setting; | ||
433 | snprintf(buf,buf_len,"%02x%02x%02x", | ||
434 | (int)RGB_UNPACK_RED(colour), | ||
435 | (int)RGB_UNPACK_GREEN(colour), | ||
436 | (int)RGB_UNPACK_BLUE(colour)); | ||
437 | } | ||
438 | else | ||
439 | #endif | ||
440 | if (settings[i].cfg_vals == NULL) | ||
441 | { | ||
442 | snprintf(buf,buf_len,"%d",*(int*)settings[i].setting); | ||
443 | } | ||
444 | else | ||
445 | { | ||
446 | if (cfg_int_to_string(i, *(int*)settings[i].setting, | ||
447 | buf, buf_len) == false) | ||
448 | { | ||
449 | snprintf(buf,buf_len,"%d",*(int*)settings[i].setting); | ||
450 | } | ||
451 | else | ||
452 | return false; | ||
453 | } | ||
454 | break; | ||
455 | case F_T_BOOL: | ||
456 | cfg_int_to_string(i, | ||
457 | *(bool*)settings[i].setting==false?0:1, buf, buf_len); | ||
458 | break; | ||
459 | case F_T_CHARPTR: | ||
460 | case F_T_UCHARPTR: | ||
461 | if (((char*)settings[i].setting)[0] | ||
462 | && settings[i].filename_setting->prefix) | ||
463 | { | ||
464 | snprintf(buf,buf_len,"%s%s%s", | ||
465 | settings[i].filename_setting->prefix, | ||
466 | (char*)settings[i].setting, | ||
467 | settings[i].filename_setting->suffix); | ||
468 | } | ||
469 | else strncpy(buf,(char*)settings[i].setting, | ||
470 | settings[i].filename_setting->max_len); | ||
471 | break; | ||
472 | } /* switch () */ | ||
473 | return true; | ||
474 | } | ||
475 | |||
419 | 476 | ||
420 | static bool is_changed(int setting_id) | 477 | static bool is_changed(int setting_id) |
421 | { | 478 | { |
@@ -503,56 +560,8 @@ static bool settings_write_config(const char* filename, int options) | |||
503 | break; | 560 | break; |
504 | #endif | 561 | #endif |
505 | } | 562 | } |
506 | switch (settings[i].flags&F_T_MASK) | 563 | |
507 | { | 564 | cfg_to_string(i, value, MAX_PATH); |
508 | case F_T_CUSTOM: | ||
509 | settings[i].custom_setting->write_to_cfg(settings[i].setting, | ||
510 | value, MAX_PATH); | ||
511 | break; | ||
512 | case F_T_INT: | ||
513 | case F_T_UINT: | ||
514 | #ifdef HAVE_LCD_COLOR | ||
515 | if (settings[i].flags&F_RGB) | ||
516 | { | ||
517 | int colour = *(int*)settings[i].setting; | ||
518 | snprintf(value,MAX_PATH,"%02x%02x%02x", | ||
519 | (int)RGB_UNPACK_RED(colour), | ||
520 | (int)RGB_UNPACK_GREEN(colour), | ||
521 | (int)RGB_UNPACK_BLUE(colour)); | ||
522 | } | ||
523 | else | ||
524 | #endif | ||
525 | if (settings[i].cfg_vals == NULL) | ||
526 | { | ||
527 | snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting); | ||
528 | } | ||
529 | else | ||
530 | { | ||
531 | if (cfg_int_to_string(i, *(int*)settings[i].setting, | ||
532 | value, MAX_PATH) == false) | ||
533 | { | ||
534 | snprintf(value,MAX_PATH,"%d",*(int*)settings[i].setting); | ||
535 | } | ||
536 | } | ||
537 | break; | ||
538 | case F_T_BOOL: | ||
539 | cfg_int_to_string(i, | ||
540 | *(bool*)settings[i].setting==false?0:1, value, MAX_PATH); | ||
541 | break; | ||
542 | case F_T_CHARPTR: | ||
543 | case F_T_UCHARPTR: | ||
544 | if (((char*)settings[i].setting)[0] | ||
545 | && settings[i].filename_setting->prefix) | ||
546 | { | ||
547 | snprintf(value,MAX_PATH,"%s%s%s", | ||
548 | settings[i].filename_setting->prefix, | ||
549 | (char*)settings[i].setting, | ||
550 | settings[i].filename_setting->suffix); | ||
551 | } | ||
552 | else strncpy(value,(char*)settings[i].setting, | ||
553 | settings[i].filename_setting->max_len); | ||
554 | break; | ||
555 | } /* switch () */ | ||
556 | fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value); | 565 | fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value); |
557 | } /* for(...) */ | 566 | } /* for(...) */ |
558 | close(fd); | 567 | close(fd); |
diff --git a/apps/settings.h b/apps/settings.h index f79fb9d09e..60d5245f1b 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -248,6 +248,7 @@ enum optiontype { INT, BOOL }; | |||
248 | 248 | ||
249 | const struct settings_list* find_setting(const void* variable, int *id); | 249 | const struct settings_list* find_setting(const void* variable, int *id); |
250 | bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len); | 250 | bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len); |
251 | bool cfg_to_string(int setting_id, char* buf, int buf_len); | ||
251 | bool set_bool_options(const char* string, const bool* variable, | 252 | bool set_bool_options(const char* string, const bool* variable, |
252 | const char* yes_str, int yes_voice, | 253 | const char* yes_str, int yes_voice, |
253 | const char* no_str, int no_voice, | 254 | const char* no_str, int no_voice, |