1.1 --- a/kconfig/confdata.c Sat Feb 24 11:00:05 2007 +0000
1.2 +++ b/kconfig/confdata.c Tue May 01 16:32:52 2007 +0000
1.3 @@ -5,9 +5,7 @@
1.4
1.5 #include <sys/stat.h>
1.6 #include <ctype.h>
1.7 -#include <errno.h>
1.8 #include <fcntl.h>
1.9 -#include <limits.h>
1.10 #include <stdio.h>
1.11 #include <stdlib.h>
1.12 #include <string.h>
1.13 @@ -23,9 +21,7 @@
1.14 static const char *conf_filename;
1.15 static int conf_lineno, conf_warnings, conf_unsaved;
1.16
1.17 -#ifndef conf_defname
1.18 const char conf_defname[] = "arch/$ARCH/defconfig";
1.19 -#endif
1.20
1.21 static void conf_warning(const char *fmt, ...)
1.22 {
1.23 @@ -104,7 +100,7 @@
1.24 in = zconf_fopen(name);
1.25 if (in)
1.26 goto load;
1.27 - sym_change_count++;
1.28 + sym_add_change_count(1);
1.29 if (!sym_defconfig_list)
1.30 return 1;
1.31
1.32 @@ -316,7 +312,7 @@
1.33 struct expr *e;
1.34 int i, flags;
1.35
1.36 - sym_change_count = 0;
1.37 + sym_set_change_count(0);
1.38
1.39 if (conf_read_simple(name, S_DEF_USER))
1.40 return 1;
1.41 @@ -368,26 +364,11 @@
1.42 sym->flags &= flags | ~SYMBOL_DEF_USER;
1.43 }
1.44
1.45 - sym_change_count += conf_warnings || conf_unsaved;
1.46 + sym_add_change_count(conf_warnings || conf_unsaved);
1.47
1.48 return 0;
1.49 }
1.50
1.51 -struct menu *next_menu(struct menu *menu)
1.52 -{
1.53 - if (menu->list) return menu->list;
1.54 - do {
1.55 - if (menu->next) {
1.56 - menu = menu->next;
1.57 - break;
1.58 - }
1.59 - } while ((menu = menu->parent));
1.60 -
1.61 - return menu;
1.62 -}
1.63 -
1.64 -#define SYMBOL_FORCEWRITE (1<<31)
1.65 -
1.66 int conf_write(const char *name)
1.67 {
1.68 FILE *out;
1.69 @@ -395,7 +376,7 @@
1.70 struct menu *menu;
1.71 const char *basename;
1.72 char dirname[128], tmpname[128], newname[128];
1.73 - int type, l, writetype;
1.74 + int type, l;
1.75 const char *str;
1.76 time_t now;
1.77 int use_timestamp = 1;
1.78 @@ -451,20 +432,9 @@
1.79 use_timestamp ? "# " : "",
1.80 use_timestamp ? ctime(&now) : "");
1.81
1.82 - if (!sym_change_count)
1.83 + if (!conf_get_changed())
1.84 sym_clear_all_valid();
1.85
1.86 - // Write out all symbols (even in closed sub-menus).
1.87 - if (1) {
1.88 - for (menu = rootmenu.list; menu; menu = next_menu(menu))
1.89 - if (menu->sym) menu->sym->flags |= SYMBOL_FORCEWRITE;
1.90 - writetype = SYMBOL_FORCEWRITE;
1.91 -
1.92 - // Don't write out symbols in closed menus.
1.93 -
1.94 - } else writetype = SYMBOL_WRITE;
1.95 -
1.96 -
1.97 menu = rootmenu.list;
1.98 while (menu) {
1.99 sym = menu->sym;
1.100 @@ -478,9 +448,9 @@
1.101 "#\n", str);
1.102 } else if (!(sym->flags & SYMBOL_CHOICE)) {
1.103 sym_calc_value(sym);
1.104 - if (!(sym->flags & writetype))
1.105 + if (!(sym->flags & SYMBOL_WRITE))
1.106 goto next;
1.107 - sym->flags &= ~writetype;
1.108 + sym->flags &= ~SYMBOL_WRITE;
1.109 type = sym->type;
1.110 if (type == S_TRISTATE) {
1.111 sym_calc_value(modules_sym);
1.112 @@ -520,32 +490,29 @@
1.113 case S_HEX:
1.114 str = sym_get_string_value(sym);
1.115 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
1.116 - fprintf(out, "CT_%s=%s\n", sym->name, *str ? str : "0");
1.117 + fprintf(out, "CT_%s=%s\n", sym->name, str);
1.118 break;
1.119 }
1.120 case S_INT:
1.121 str = sym_get_string_value(sym);
1.122 - fprintf(out, "CT_%s=%s\n", sym->name, *str ? str : "0");
1.123 + fprintf(out, "CT_%s=%s\n", sym->name, str);
1.124 break;
1.125 }
1.126 }
1.127
1.128 next:
1.129 - if (writetype == SYMBOL_WRITE) {
1.130 - if (menu->list) {
1.131 - menu = menu->list;
1.132 - continue;
1.133 + if (menu->list) {
1.134 + menu = menu->list;
1.135 + continue;
1.136 + }
1.137 + if (menu->next)
1.138 + menu = menu->next;
1.139 + else while ((menu = menu->parent)) {
1.140 + if (menu->next) {
1.141 + menu = menu->next;
1.142 + break;
1.143 }
1.144 - if (menu->next)
1.145 - menu = menu->next;
1.146 - else while ((menu = menu->parent)) {
1.147 - if (menu->next) {
1.148 - menu = menu->next;
1.149 - break;
1.150 - }
1.151 - }
1.152 - } else
1.153 - menu = next_menu(menu);
1.154 + }
1.155 }
1.156 fclose(out);
1.157
1.158 @@ -561,7 +528,7 @@
1.159 "# configuration written to %s\n"
1.160 "#\n"), newname);
1.161
1.162 - sym_change_count = 0;
1.163 + sym_set_change_count(0);
1.164
1.165 return 0;
1.166 }
1.167 @@ -798,3 +765,30 @@
1.168
1.169 return 0;
1.170 }
1.171 +
1.172 +static int sym_change_count;
1.173 +static void (*conf_changed_callback)(void);
1.174 +
1.175 +void sym_set_change_count(int count)
1.176 +{
1.177 + int _sym_change_count = sym_change_count;
1.178 + sym_change_count = count;
1.179 + if (conf_changed_callback &&
1.180 + (bool)_sym_change_count != (bool)count)
1.181 + conf_changed_callback();
1.182 +}
1.183 +
1.184 +void sym_add_change_count(int count)
1.185 +{
1.186 + sym_set_change_count(count + sym_change_count);
1.187 +}
1.188 +
1.189 +bool conf_get_changed(void)
1.190 +{
1.191 + return sym_change_count;
1.192 +}
1.193 +
1.194 +void conf_set_changed_callback(void (*fn)(void))
1.195 +{
1.196 + conf_changed_callback = fn;
1.197 +}