diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-01-25 06:49:22 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-01-25 06:49:22 +0000 |
commit | b77f1217fb6b1bf34baa0da40de3ebf83c3c67c5 (patch) | |
tree | b5c2dcc489988dc2958764de07ceb2b253f066c4 | |
parent | 7760743b495a521195b04650450e64e0a5389261 (diff) | |
download | rockbox-b77f1217fb6b1bf34baa0da40de3ebf83c3c67c5.tar.gz rockbox-b77f1217fb6b1bf34baa0da40de3ebf83c3c67c5.zip |
Correct the spelling of persistent so its correct (Yes, I failed english at school).
Loading a persistent setting again (from any config file, including config.cfg unless it has a ~) will remove it from the list of
persistent settings.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12107 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/settings.c | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/apps/settings.c b/apps/settings.c index 5dad1a4ff6..dcc3c8d9d2 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -259,19 +259,19 @@ static int hex_to_rgb(const char* hex) | |||
259 | return 0; | 259 | return 0; |
260 | } | 260 | } |
261 | #endif | 261 | #endif |
262 | #define MAX_PERSISTANT_VARS 8 | 262 | #define MAX_PERSISTENT_VARS 8 |
263 | struct persistant_vars { | 263 | struct persistent_vars { |
264 | char setting[MAX_FILENAME]; | 264 | char setting[MAX_FILENAME]; |
265 | char value[MAX_FILENAME]; | 265 | char value[MAX_FILENAME]; |
266 | }; | 266 | }; |
267 | static struct persistant_vars persistant_vars[MAX_PERSISTANT_VARS]; | 267 | static struct persistent_vars persistent_vars[MAX_PERSISTENT_VARS]; |
268 | static int persistant_vars_count = 0; | 268 | static int persistent_vars_count = 0; |
269 | bool settings_write_config(char* filename) | 269 | bool settings_write_config(char* filename) |
270 | { | 270 | { |
271 | int i; | 271 | int i; |
272 | int fd; | 272 | int fd; |
273 | bool check_persistant = !strcmp(filename, CONFIGFILE) && | 273 | bool check_persistent = !strcmp(filename, CONFIGFILE) && |
274 | persistant_vars_count; | 274 | persistent_vars_count; |
275 | char value[MAX_PATH]; | 275 | char value[MAX_PATH]; |
276 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); | 276 | fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); |
277 | if (fd < 0) | 277 | if (fd < 0) |
@@ -282,16 +282,16 @@ bool settings_write_config(char* filename) | |||
282 | { | 282 | { |
283 | if (settings[i].cfg_name == NULL) | 283 | if (settings[i].cfg_name == NULL) |
284 | continue; | 284 | continue; |
285 | if (check_persistant) | 285 | if (check_persistent) |
286 | { | 286 | { |
287 | int j; | 287 | int j; |
288 | bool found = false; | 288 | bool found = false; |
289 | for(j=0; j<persistant_vars_count; j++) | 289 | for(j=0; j<persistent_vars_count; j++) |
290 | { | 290 | { |
291 | if (!strcmp(persistant_vars[j].setting, settings[i].cfg_name)) | 291 | if (!strcmp(persistent_vars[j].setting, settings[i].cfg_name)) |
292 | { | 292 | { |
293 | fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name, | 293 | fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name, |
294 | persistant_vars[j].value); | 294 | persistent_vars[j].value); |
295 | found = true; | 295 | found = true; |
296 | break; | 296 | break; |
297 | } | 297 | } |
@@ -747,7 +747,8 @@ bool settings_load_config(const char* file, bool apply) | |||
747 | char* name; | 747 | char* name; |
748 | char* value; | 748 | char* value; |
749 | int i; | 749 | int i; |
750 | bool check_persistant = !strcmp(file, CONFIGFILE); | 750 | bool check_persistent = !strcmp(file, CONFIGFILE); |
751 | bool is_persistent = false; | ||
751 | fd = open(file, O_RDONLY); | 752 | fd = open(file, O_RDONLY); |
752 | if (fd < 0) | 753 | if (fd < 0) |
753 | return false; | 754 | return false; |
@@ -756,20 +757,52 @@ bool settings_load_config(const char* file, bool apply) | |||
756 | { | 757 | { |
757 | if (!settings_parseline(line, &name, &value)) | 758 | if (!settings_parseline(line, &name, &value)) |
758 | continue; | 759 | continue; |
759 | if (check_persistant && (name[0] == '~') | 760 | if (name[0] == '~') |
760 | && (persistant_vars_count<MAX_PERSISTANT_VARS)) | ||
761 | { | 761 | { |
762 | name++; | 762 | name++; |
763 | strcpy(persistant_vars[persistant_vars_count].setting, name); | 763 | if (check_persistent && |
764 | strcpy(persistant_vars[persistant_vars_count].value, value); | 764 | (persistent_vars_count<MAX_PERSISTENT_VARS)) |
765 | persistant_vars_count++; | 765 | { |
766 | strcpy(persistent_vars[persistent_vars_count].setting, name); | ||
767 | strcpy(persistent_vars[persistent_vars_count].value, value); | ||
768 | persistent_vars_count++; | ||
769 | is_persistent = true; | ||
770 | } | ||
766 | } | 771 | } |
772 | else is_persistent = false; | ||
767 | for(i=0; i<nb_settings; i++) | 773 | for(i=0; i<nb_settings; i++) |
768 | { | 774 | { |
769 | if (settings[i].cfg_name == NULL) | 775 | if (settings[i].cfg_name == NULL) |
770 | continue; | 776 | continue; |
771 | if (!strcasecmp(name,settings[i].cfg_name)) | 777 | if (!strcasecmp(name,settings[i].cfg_name)) |
772 | { | 778 | { |
779 | if (persistent_vars_count && !is_persistent) | ||
780 | { | ||
781 | int j; | ||
782 | struct persistent_vars *p_var, | ||
783 | *p_var_last = &persistent_vars[persistent_vars_count-1]; | ||
784 | for (j=0; j< persistent_vars_count; j++) | ||
785 | { | ||
786 | p_var = &persistent_vars[j]; | ||
787 | if (!strcmp(name,p_var->setting)) | ||
788 | { | ||
789 | if (j+1 == persistent_vars_count) | ||
790 | { | ||
791 | /* simple case, just decrement | ||
792 | persistent_vars_count */ | ||
793 | persistent_vars_count--; | ||
794 | } | ||
795 | /*else move the last persistent var to here */ | ||
796 | else | ||
797 | { | ||
798 | strcpy(p_var->setting, p_var_last->setting); | ||
799 | strcpy(p_var->value, p_var_last->value); | ||
800 | persistent_vars_count--; | ||
801 | } | ||
802 | break; | ||
803 | } | ||
804 | } | ||
805 | } | ||
773 | switch (settings[i].flags&F_T_MASK) | 806 | switch (settings[i].flags&F_T_MASK) |
774 | { | 807 | { |
775 | case F_T_INT: | 808 | case F_T_INT: |