summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/apps/settings.c b/apps/settings.c
index dcc3c8d9d2..302ea58aec 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -259,19 +259,11 @@ static int hex_to_rgb(const char* hex)
259 return 0; 259 return 0;
260} 260}
261#endif 261#endif
262#define MAX_PERSISTENT_VARS 8 262
263struct persistent_vars {
264 char setting[MAX_FILENAME];
265 char value[MAX_FILENAME];
266};
267static struct persistent_vars persistent_vars[MAX_PERSISTENT_VARS];
268static int persistent_vars_count = 0;
269bool settings_write_config(char* filename) 263bool settings_write_config(char* filename)
270{ 264{
271 int i; 265 int i;
272 int fd; 266 int fd;
273 bool check_persistent = !strcmp(filename, CONFIGFILE) &&
274 persistent_vars_count;
275 char value[MAX_PATH]; 267 char value[MAX_PATH];
276 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY); 268 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY);
277 if (fd < 0) 269 if (fd < 0)
@@ -282,23 +274,6 @@ bool settings_write_config(char* filename)
282 { 274 {
283 if (settings[i].cfg_name == NULL) 275 if (settings[i].cfg_name == NULL)
284 continue; 276 continue;
285 if (check_persistent)
286 {
287 int j;
288 bool found = false;
289 for(j=0; j<persistent_vars_count; j++)
290 {
291 if (!strcmp(persistent_vars[j].setting, settings[i].cfg_name))
292 {
293 fdprintf(fd,"~%s: %s\r\n", settings[i].cfg_name,
294 persistent_vars[j].value);
295 found = true;
296 break;
297 }
298 }
299 if (found)
300 continue;
301 }
302 switch (settings[i].flags&F_T_MASK) 277 switch (settings[i].flags&F_T_MASK)
303 { 278 {
304 case F_T_INT: 279 case F_T_INT:
@@ -706,7 +681,10 @@ void settings_load(int which)
706 if (which&SETTINGS_RTC) 681 if (which&SETTINGS_RTC)
707 read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); 682 read_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
708 if (which&SETTINGS_HD) 683 if (which&SETTINGS_HD)
684 {
709 settings_load_config(CONFIGFILE,false); 685 settings_load_config(CONFIGFILE,false);
686 settings_load_config(FIXEDSETTINGSFILE,false);
687 }
710} 688}
711 689
712void set_file(char* filename, char* setting, int maxlen) 690void set_file(char* filename, char* setting, int maxlen)
@@ -747,8 +725,6 @@ bool settings_load_config(const char* file, bool apply)
747 char* name; 725 char* name;
748 char* value; 726 char* value;
749 int i; 727 int i;
750 bool check_persistent = !strcmp(file, CONFIGFILE);
751 bool is_persistent = false;
752 fd = open(file, O_RDONLY); 728 fd = open(file, O_RDONLY);
753 if (fd < 0) 729 if (fd < 0)
754 return false; 730 return false;
@@ -757,52 +733,12 @@ bool settings_load_config(const char* file, bool apply)
757 { 733 {
758 if (!settings_parseline(line, &name, &value)) 734 if (!settings_parseline(line, &name, &value))
759 continue; 735 continue;
760 if (name[0] == '~')
761 {
762 name++;
763 if (check_persistent &&
764 (persistent_vars_count<MAX_PERSISTENT_VARS))
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 }
771 }
772 else is_persistent = false;
773 for(i=0; i<nb_settings; i++) 736 for(i=0; i<nb_settings; i++)
774 { 737 {
775 if (settings[i].cfg_name == NULL) 738 if (settings[i].cfg_name == NULL)
776 continue; 739 continue;
777 if (!strcasecmp(name,settings[i].cfg_name)) 740 if (!strcasecmp(name,settings[i].cfg_name))
778 { 741 {
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 }
806 switch (settings[i].flags&F_T_MASK) 742 switch (settings[i].flags&F_T_MASK)
807 { 743 {
808 case F_T_INT: 744 case F_T_INT: