summaryrefslogtreecommitdiff
path: root/kconfig/symbol.c
diff options
context:
space:
mode:
authorYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2008-10-17 12:47:53 (GMT)
committerYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2008-10-17 12:47:53 (GMT)
commitf31bcd0026c2a3d5a38d3f16418876efcf7cd031 (patch)
treecd294553e433dde5ecceee767fcbf002f531aef1 /kconfig/symbol.c
parentc54f4302cdd3f4b5e5fde5ab63001f263e0664a3 (diff)
Update the kconfig stuff to match the one in the linux-2.6.27 version.
/trunk/kconfig/zconf.hash.c | 225 110 115 0 +++---- /trunk/kconfig/lkc_proto.h | 4 3 1 0 + /trunk/kconfig/mconf.c | 217 110 107 0 +++--- /trunk/kconfig/menu.c | 86 60 26 0 ++- /trunk/kconfig/symbol.c | 212 156 56 0 ++++-- /trunk/kconfig/kconfig.mk | 24 9 15 0 - /trunk/kconfig/lex.zconf.c | 97 80 17 0 ++- /trunk/kconfig/util.c | 38 30 8 0 + /trunk/kconfig/lkc.h | 22 18 4 0 + /trunk/kconfig/expr.c | 32 19 13 0 + /trunk/kconfig/confdata.c | 254 172 82 0 +++++--- /trunk/kconfig/lxdialog/dialog.h | 12 9 3 0 + /trunk/kconfig/lxdialog/inputbox.c | 6 3 3 0 /trunk/kconfig/lxdialog/checklist.c | 4 2 2 0 /trunk/kconfig/lxdialog/menubox.c | 6 3 3 0 /trunk/kconfig/lxdialog/textbox.c | 2 1 1 0 /trunk/kconfig/lxdialog/util.c | 47 30 17 0 + /trunk/kconfig/lxdialog/yesno.c | 4 2 2 0 /trunk/kconfig/expr.h | 20 10 10 0 /trunk/kconfig/zconf.tab.c | 1441 793 648 0 ++++++++++++++++++++++++------------------- /trunk/kconfig/conf.c | 276 124 152 0 ++++---- /trunk/kconfig/check-gettext.sh | 14 14 0 0 + /trunk/ct-ng.in | 2 1 1 0 23 files changed, 1759 insertions(+), 1286 deletions(-)
Diffstat (limited to 'kconfig/symbol.c')
-rw-r--r--kconfig/symbol.c212
1 files changed, 156 insertions, 56 deletions
diff --git a/kconfig/symbol.c b/kconfig/symbol.c
index d79865c..bf61f81 100644
--- a/kconfig/symbol.c
+++ b/kconfig/symbol.c
@@ -34,19 +34,21 @@ struct symbol *sym_defconfig_list;
struct symbol *modules_sym;
tristate modules_val;
+struct expr *sym_env_list;
+
void sym_add_default(struct symbol *sym, const char *def)
{
struct property *prop = prop_alloc(P_DEFAULT, sym);
- prop->expr = expr_alloc_symbol(sym_lookup(def, 1));
+ prop->expr = expr_alloc_symbol(sym_lookup(def, SYMBOL_CONST));
}
void sym_init(void)
{
struct symbol *sym;
struct utsname uts;
- char *p;
static bool inited = false;
+ char* p;
if (inited)
return;
@@ -54,12 +56,10 @@ void sym_init(void)
uname(&uts);
- sym = sym_lookup("ARCH", 0);
+ sym = sym_lookup("UNAME_RELEASE", 0);
sym->type = S_STRING;
sym->flags |= SYMBOL_AUTO;
- p = getenv("ARCH");
- if (p)
- sym_add_default(sym, p);
+ sym_add_default(sym, uts.release);
sym = sym_lookup("PROJECTVERSION", 0);
sym->type = S_STRING;
@@ -67,11 +67,6 @@ void sym_init(void)
p = getenv("PROJECTVERSION");
if (p)
sym_add_default(sym, p);
-
- sym = sym_lookup("UNAME_RELEASE", 0);
- sym->type = S_STRING;
- sym->flags |= SYMBOL_AUTO;
- sym_add_default(sym, uts.release);
}
enum symbol_type sym_get_type(struct symbol *sym)
@@ -117,6 +112,15 @@ struct property *sym_get_choice_prop(struct symbol *sym)
return NULL;
}
+struct property *sym_get_env_prop(struct symbol *sym)
+{
+ struct property *prop;
+
+ for_all_properties(sym, prop, P_ENV)
+ return prop;
+ return NULL;
+}
+
struct property *sym_get_default_prop(struct symbol *sym)
{
struct property *prop;
@@ -199,7 +203,7 @@ static void sym_calc_visibility(struct symbol *sym)
tri = no;
for_all_prompts(sym, prop) {
prop->visible.tri = expr_calc_value(prop->visible.expr);
- tri = E_OR(tri, prop->visible.tri);
+ tri = EXPR_OR(tri, prop->visible.tri);
}
if (tri == mod && (sym->type != S_TRISTATE || modules_val == no))
tri = yes;
@@ -247,8 +251,7 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
/* just get the first visible value */
prop = sym_get_choice_prop(sym);
- for (e = prop->expr; e; e = e->left.expr) {
- def_sym = e->right.sym;
+ expr_list_for_each_sym(prop->expr, e, def_sym) {
sym_calc_visibility(def_sym);
if (def_sym->visible != no)
return def_sym;
@@ -303,22 +306,30 @@ void sym_calc_value(struct symbol *sym)
if (sym_is_choice_value(sym) && sym->visible == yes) {
prop = sym_get_choice_prop(sym);
newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no;
- } else if (E_OR(sym->visible, sym->rev_dep.tri) != no) {
- sym->flags |= SYMBOL_WRITE;
- if (sym_has_value(sym))
- newval.tri = sym->def[S_DEF_USER].tri;
- else if (!sym_is_choice(sym)) {
- prop = sym_get_default_prop(sym);
- if (prop)
- newval.tri = expr_calc_value(prop->expr);
+ } else {
+ if (sym->visible != no) {
+ /* if the symbol is visible use the user value
+ * if available, otherwise try the default value
+ */
+ sym->flags |= SYMBOL_WRITE;
+ if (sym_has_value(sym)) {
+ newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri,
+ sym->visible);
+ goto calc_newval;
+ }
}
- newval.tri = E_OR(E_AND(newval.tri, sym->visible), sym->rev_dep.tri);
- } else if (!sym_is_choice(sym)) {
- prop = sym_get_default_prop(sym);
- if (prop) {
+ if (sym->rev_dep.tri != no)
sym->flags |= SYMBOL_WRITE;
- newval.tri = expr_calc_value(prop->expr);
+ if (!sym_is_choice(sym)) {
+ prop = sym_get_default_prop(sym);
+ if (prop) {
+ sym->flags |= SYMBOL_WRITE;
+ newval.tri = EXPR_AND(expr_calc_value(prop->expr),
+ prop->visible.tri);
+ }
}
+ calc_newval:
+ newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
}
if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
newval.tri = yes;
@@ -361,14 +372,19 @@ void sym_calc_value(struct symbol *sym)
}
if (sym_is_choice(sym)) {
+ struct symbol *choice_sym;
int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE);
+
prop = sym_get_choice_prop(sym);
- for (e = prop->expr; e; e = e->left.expr) {
- e->right.sym->flags |= flags;
+ expr_list_for_each_sym(prop->expr, e, choice_sym) {
+ choice_sym->flags |= flags;
if (flags & SYMBOL_CHANGED)
- sym_set_changed(e->right.sym);
+ sym_set_changed(choice_sym);
}
}
+
+ if (sym->flags & SYMBOL_AUTO)
+ sym->flags &= ~SYMBOL_WRITE;
}
void sym_clear_all_valid(void)
@@ -643,7 +659,7 @@ bool sym_is_changable(struct symbol *sym)
return sym->visible > sym->rev_dep.tri;
}
-struct symbol *sym_lookup(const char *name, int isconst)
+struct symbol *sym_lookup(const char *name, int flags)
{
struct symbol *symbol;
const char *ptr;
@@ -663,11 +679,10 @@ struct symbol *sym_lookup(const char *name, int isconst)
hash &= 0xff;
for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
- if (!strcmp(symbol->name, name)) {
- if ((isconst && symbol->flags & SYMBOL_CONST) ||
- (!isconst && !(symbol->flags & SYMBOL_CONST)))
- return symbol;
- }
+ if (!strcmp(symbol->name, name) &&
+ (flags ? symbol->flags & flags
+ : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE))))
+ return symbol;
}
new_name = strdup(name);
} else {
@@ -679,8 +694,7 @@ struct symbol *sym_lookup(const char *name, int isconst)
memset(symbol, 0, sizeof(*symbol));
symbol->name = new_name;
symbol->type = S_UNKNOWN;
- if (isconst)
- symbol->flags |= SYMBOL_CONST;
+ symbol->flags |= flags;
symbol->next = symbol_hash[hash];
symbol_hash[hash] = symbol;
@@ -754,8 +768,6 @@ struct symbol **sym_re_search(const char *pattern)
}
-struct symbol *sym_check_deps(struct symbol *sym);
-
static struct symbol *sym_check_expr_deps(struct expr *e)
{
struct symbol *sym;
@@ -786,44 +798,101 @@ static struct symbol *sym_check_expr_deps(struct expr *e)
return NULL;
}
-struct symbol *sym_check_deps(struct symbol *sym)
+/* return NULL when dependencies are OK */
+static struct symbol *sym_check_sym_deps(struct symbol *sym)
{
struct symbol *sym2;
struct property *prop;
- if (sym->flags & SYMBOL_CHECK) {
- printf("Warning! Found recursive dependency: %s", sym->name);
- return sym;
- }
- if (sym->flags & SYMBOL_CHECKED)
- return NULL;
-
- sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
sym2 = sym_check_expr_deps(sym->rev_dep.expr);
if (sym2)
- goto out;
+ return sym2;
for (prop = sym->prop; prop; prop = prop->next) {
if (prop->type == P_CHOICE || prop->type == P_SELECT)
continue;
sym2 = sym_check_expr_deps(prop->visible.expr);
if (sym2)
- goto out;
+ break;
if (prop->type != P_DEFAULT || sym_is_choice(sym))
continue;
sym2 = sym_check_expr_deps(prop->expr);
if (sym2)
- goto out;
+ break;
+ }
+
+ return sym2;
+}
+
+static struct symbol *sym_check_choice_deps(struct symbol *choice)
+{
+ struct symbol *sym, *sym2;
+ struct property *prop;
+ struct expr *e;
+
+ prop = sym_get_choice_prop(choice);
+ expr_list_for_each_sym(prop->expr, e, sym)
+ sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
+
+ choice->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
+ sym2 = sym_check_sym_deps(choice);
+ choice->flags &= ~SYMBOL_CHECK;
+ if (sym2)
+ goto out;
+
+ expr_list_for_each_sym(prop->expr, e, sym) {
+ sym2 = sym_check_sym_deps(sym);
+ if (sym2) {
+ fprintf(stderr, " -> %s", sym->name);
+ break;
+ }
}
out:
+ expr_list_for_each_sym(prop->expr, e, sym)
+ sym->flags &= ~SYMBOL_CHECK;
+
+ if (sym2 && sym_is_choice_value(sym2) &&
+ prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
+ sym2 = choice;
+
+ return sym2;
+}
+
+struct symbol *sym_check_deps(struct symbol *sym)
+{
+ struct symbol *sym2;
+ struct property *prop;
+
+ if (sym->flags & SYMBOL_CHECK) {
+ fprintf(stderr, "%s:%d:error: found recursive dependency: %s",
+ sym->prop->file->name, sym->prop->lineno,
+ sym->name ? sym->name : "<choice>");
+ return sym;
+ }
+ if (sym->flags & SYMBOL_CHECKED)
+ return NULL;
+
+ if (sym_is_choice_value(sym)) {
+ /* for choice groups start the check with main choice symbol */
+ prop = sym_get_choice_prop(sym);
+ sym2 = sym_check_deps(prop_get_symbol(prop));
+ } else if (sym_is_choice(sym)) {
+ sym2 = sym_check_choice_deps(sym);
+ } else {
+ sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
+ sym2 = sym_check_sym_deps(sym);
+ sym->flags &= ~SYMBOL_CHECK;
+ }
+
if (sym2) {
- printf(" %s", sym->name);
+ fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>");
if (sym2 == sym) {
- printf("\n");
+ fprintf(stderr, "\n");
+ zconfnerrs++;
sym2 = NULL;
}
}
- sym->flags &= ~SYMBOL_CHECK;
+
return sym2;
}
@@ -852,7 +921,7 @@ struct property *prop_alloc(enum prop_type type, struct symbol *sym)
struct symbol *prop_get_symbol(struct property *prop)
{
if (prop->expr && (prop->expr->type == E_SYMBOL ||
- prop->expr->type == E_CHOICE))
+ prop->expr->type == E_LIST))
return prop->expr->left.sym;
return NULL;
}
@@ -862,6 +931,8 @@ const char *prop_get_type_name(enum prop_type type)
switch (type) {
case P_PROMPT:
return "prompt";
+ case P_ENV:
+ return "env";
case P_COMMENT:
return "comment";
case P_MENU:
@@ -879,3 +950,32 @@ const char *prop_get_type_name(enum prop_type type)
}
return "unknown";
}
+
+void prop_add_env(const char *env)
+{
+ struct symbol *sym, *sym2;
+ struct property *prop;
+ char *p;
+
+ sym = current_entry->sym;
+ sym->flags |= SYMBOL_AUTO;
+ for_all_properties(sym, prop, P_ENV) {
+ sym2 = prop_get_symbol(prop);
+ if (strcmp(sym2->name, env))
+ menu_warn(current_entry, "redefining environment symbol from %s",
+ sym2->name);
+ return;
+ }
+
+ prop = prop_alloc(P_ENV, sym);
+ prop->expr = expr_alloc_symbol(sym_lookup(env, SYMBOL_CONST));
+
+ sym_env_list = expr_alloc_one(E_LIST, sym_env_list);
+ sym_env_list->right.sym = sym;
+
+ p = getenv(env);
+ if (p)
+ sym_add_default(sym, p);
+ else
+ menu_warn(current_entry, "environment variable %s undefined", env);
+}