提交 0c1822e6 编写于 作者: R Roman Zippel 提交者: Sam Ravnborg

kconfig: allow multiple default values per symbol

Extend struct symbol to allow storing multiple default values, which can be
used to hold multiple configurations.
Signed-off-by: NRoman Zippel <zippel@linux-m68k.org>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
上级 c0e150ac
...@@ -134,11 +134,11 @@ int conf_read_simple(const char *name) ...@@ -134,11 +134,11 @@ int conf_read_simple(const char *name)
case S_INT: case S_INT:
case S_HEX: case S_HEX:
case S_STRING: case S_STRING:
if (sym->user.val) if (sym->def[S_DEF_USER].val)
free(sym->user.val); free(sym->def[S_DEF_USER].val);
default: default:
sym->user.val = NULL; sym->def[S_DEF_USER].val = NULL;
sym->user.tri = no; sym->def[S_DEF_USER].tri = no;
} }
} }
...@@ -166,7 +166,7 @@ int conf_read_simple(const char *name) ...@@ -166,7 +166,7 @@ int conf_read_simple(const char *name)
switch (sym->type) { switch (sym->type) {
case S_BOOLEAN: case S_BOOLEAN:
case S_TRISTATE: case S_TRISTATE:
sym->user.tri = no; sym->def[S_DEF_USER].tri = no;
sym->flags &= ~SYMBOL_NEW; sym->flags &= ~SYMBOL_NEW;
break; break;
default: default:
...@@ -196,18 +196,18 @@ int conf_read_simple(const char *name) ...@@ -196,18 +196,18 @@ int conf_read_simple(const char *name)
switch (sym->type) { switch (sym->type) {
case S_TRISTATE: case S_TRISTATE:
if (p[0] == 'm') { if (p[0] == 'm') {
sym->user.tri = mod; sym->def[S_DEF_USER].tri = mod;
sym->flags &= ~SYMBOL_NEW; sym->flags &= ~SYMBOL_NEW;
break; break;
} }
case S_BOOLEAN: case S_BOOLEAN:
if (p[0] == 'y') { if (p[0] == 'y') {
sym->user.tri = yes; sym->def[S_DEF_USER].tri = yes;
sym->flags &= ~SYMBOL_NEW; sym->flags &= ~SYMBOL_NEW;
break; break;
} }
if (p[0] == 'n') { if (p[0] == 'n') {
sym->user.tri = no; sym->def[S_DEF_USER].tri = no;
sym->flags &= ~SYMBOL_NEW; sym->flags &= ~SYMBOL_NEW;
break; break;
} }
...@@ -230,7 +230,7 @@ int conf_read_simple(const char *name) ...@@ -230,7 +230,7 @@ int conf_read_simple(const char *name)
case S_INT: case S_INT:
case S_HEX: case S_HEX:
if (sym_string_valid(sym, p)) { if (sym_string_valid(sym, p)) {
sym->user.val = strdup(p); sym->def[S_DEF_USER].val = strdup(p);
sym->flags &= ~SYMBOL_NEW; sym->flags &= ~SYMBOL_NEW;
} else { } else {
conf_warning("symbol value '%s' invalid for %s", p, sym->name); conf_warning("symbol value '%s' invalid for %s", p, sym->name);
...@@ -249,24 +249,24 @@ int conf_read_simple(const char *name) ...@@ -249,24 +249,24 @@ int conf_read_simple(const char *name)
} }
if (sym && sym_is_choice_value(sym)) { if (sym && sym_is_choice_value(sym)) {
struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
switch (sym->user.tri) { switch (sym->def[S_DEF_USER].tri) {
case no: case no:
break; break;
case mod: case mod:
if (cs->user.tri == yes) { if (cs->def[S_DEF_USER].tri == yes) {
conf_warning("%s creates inconsistent choice state", sym->name); conf_warning("%s creates inconsistent choice state", sym->name);
cs->flags |= SYMBOL_NEW; cs->flags |= SYMBOL_NEW;
} }
break; break;
case yes: case yes:
if (cs->user.tri != no) { if (cs->def[S_DEF_USER].tri != no) {
conf_warning("%s creates inconsistent choice state", sym->name); conf_warning("%s creates inconsistent choice state", sym->name);
cs->flags |= SYMBOL_NEW; cs->flags |= SYMBOL_NEW;
} else } else
cs->user.val = sym; cs->def[S_DEF_USER].val = sym;
break; break;
} }
cs->user.tri = E_OR(cs->user.tri, sym->user.tri); cs->def[S_DEF_USER].tri = E_OR(cs->def[S_DEF_USER].tri, sym->def[S_DEF_USER].tri);
} }
} }
fclose(in); fclose(in);
...@@ -297,12 +297,12 @@ int conf_read(const char *name) ...@@ -297,12 +297,12 @@ int conf_read(const char *name)
switch (sym->type) { switch (sym->type) {
case S_BOOLEAN: case S_BOOLEAN:
case S_TRISTATE: case S_TRISTATE:
if (sym->user.tri != sym_get_tristate_value(sym)) if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))
break; break;
if (!sym_is_choice(sym)) if (!sym_is_choice(sym))
goto sym_ok; goto sym_ok;
default: default:
if (!strcmp(sym->curr.val, sym->user.val)) if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
goto sym_ok; goto sym_ok;
break; break;
} }
...@@ -319,7 +319,7 @@ int conf_read(const char *name) ...@@ -319,7 +319,7 @@ int conf_read(const char *name)
case S_STRING: case S_STRING:
case S_INT: case S_INT:
case S_HEX: case S_HEX:
if (!sym_string_within_range(sym, sym->user.val)) { if (!sym_string_within_range(sym, sym->def[S_DEF_USER].val)) {
sym->flags |= SYMBOL_NEW; sym->flags |= SYMBOL_NEW;
sym->flags &= ~SYMBOL_VALID; sym->flags &= ~SYMBOL_VALID;
} }
......
...@@ -63,12 +63,17 @@ enum symbol_type { ...@@ -63,12 +63,17 @@ enum symbol_type {
S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
}; };
enum {
S_DEF_USER, /* main user value */
};
struct symbol { struct symbol {
struct symbol *next; struct symbol *next;
char *name; char *name;
char *help; char *help;
enum symbol_type type; enum symbol_type type;
struct symbol_value curr, user; struct symbol_value curr;
struct symbol_value def[4];
tristate visible; tristate visible;
int flags; int flags;
struct property *prop; struct property *prop;
......
...@@ -227,7 +227,7 @@ static struct symbol *sym_calc_choice(struct symbol *sym) ...@@ -227,7 +227,7 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
struct expr *e; struct expr *e;
/* is the user choice visible? */ /* is the user choice visible? */
def_sym = sym->user.val; def_sym = sym->def[S_DEF_USER].val;
if (def_sym) { if (def_sym) {
sym_calc_visibility(def_sym); sym_calc_visibility(def_sym);
if (def_sym->visible != no) if (def_sym->visible != no)
...@@ -306,7 +306,7 @@ void sym_calc_value(struct symbol *sym) ...@@ -306,7 +306,7 @@ void sym_calc_value(struct symbol *sym)
} else if (E_OR(sym->visible, sym->rev_dep.tri) != no) { } else if (E_OR(sym->visible, sym->rev_dep.tri) != no) {
sym->flags |= SYMBOL_WRITE; sym->flags |= SYMBOL_WRITE;
if (sym_has_value(sym)) if (sym_has_value(sym))
newval.tri = sym->user.tri; newval.tri = sym->def[S_DEF_USER].tri;
else if (!sym_is_choice(sym)) { else if (!sym_is_choice(sym)) {
prop = sym_get_default_prop(sym); prop = sym_get_default_prop(sym);
if (prop) if (prop)
...@@ -329,7 +329,7 @@ void sym_calc_value(struct symbol *sym) ...@@ -329,7 +329,7 @@ void sym_calc_value(struct symbol *sym)
if (sym->visible != no) { if (sym->visible != no) {
sym->flags |= SYMBOL_WRITE; sym->flags |= SYMBOL_WRITE;
if (sym_has_value(sym)) { if (sym_has_value(sym)) {
newval.val = sym->user.val; newval.val = sym->def[S_DEF_USER].val;
break; break;
} }
} }
...@@ -439,7 +439,7 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val) ...@@ -439,7 +439,7 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
struct property *prop; struct property *prop;
struct expr *e; struct expr *e;
cs->user.val = sym; cs->def[S_DEF_USER].val = sym;
cs->flags &= ~SYMBOL_NEW; cs->flags &= ~SYMBOL_NEW;
prop = sym_get_choice_prop(cs); prop = sym_get_choice_prop(cs);
for (e = prop->expr; e; e = e->left.expr) { for (e = prop->expr; e; e = e->left.expr) {
...@@ -448,7 +448,7 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val) ...@@ -448,7 +448,7 @@ bool sym_set_tristate_value(struct symbol *sym, tristate val)
} }
} }
sym->user.tri = val; sym->def[S_DEF_USER].tri = val;
if (oldval != val) { if (oldval != val) {
sym_clear_all_valid(); sym_clear_all_valid();
if (sym == modules_sym) if (sym == modules_sym)
...@@ -596,15 +596,15 @@ bool sym_set_string_value(struct symbol *sym, const char *newval) ...@@ -596,15 +596,15 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
sym_set_changed(sym); sym_set_changed(sym);
} }
oldval = sym->user.val; oldval = sym->def[S_DEF_USER].val;
size = strlen(newval) + 1; size = strlen(newval) + 1;
if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) { if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
size += 2; size += 2;
sym->user.val = val = malloc(size); sym->def[S_DEF_USER].val = val = malloc(size);
*val++ = '0'; *val++ = '0';
*val++ = 'x'; *val++ = 'x';
} else if (!oldval || strcmp(oldval, newval)) } else if (!oldval || strcmp(oldval, newval))
sym->user.val = val = malloc(size); sym->def[S_DEF_USER].val = val = malloc(size);
else else
return true; return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册