forked from luck/tmp_suning_uos_patched
[PATCH] kconfig: allow variable argumnts for range
This allows variable arguments in the range option for int and hex config symbols. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
90389160ef
commit
4cf3cbe2a9
|
@ -151,6 +151,12 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
|
||||||
menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
|
menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int menu_range_valid_sym(struct symbol *sym, struct symbol *sym2)
|
||||||
|
{
|
||||||
|
return sym2->type == S_INT || sym2->type == S_HEX ||
|
||||||
|
(sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
|
||||||
|
}
|
||||||
|
|
||||||
void sym_check_prop(struct symbol *sym)
|
void sym_check_prop(struct symbol *sym)
|
||||||
{
|
{
|
||||||
struct property *prop;
|
struct property *prop;
|
||||||
|
@ -185,8 +191,8 @@ void sym_check_prop(struct symbol *sym)
|
||||||
if (sym->type != S_INT && sym->type != S_HEX)
|
if (sym->type != S_INT && sym->type != S_HEX)
|
||||||
prop_warn(prop, "range is only allowed "
|
prop_warn(prop, "range is only allowed "
|
||||||
"for int or hex symbols");
|
"for int or hex symbols");
|
||||||
if (!sym_string_valid(sym, prop->expr->left.sym->name) ||
|
if (!menu_range_valid_sym(sym, prop->expr->left.sym) ||
|
||||||
!sym_string_valid(sym, prop->expr->right.sym->name))
|
!menu_range_valid_sym(sym, prop->expr->right.sym))
|
||||||
prop_warn(prop, "range is invalid");
|
prop_warn(prop, "range is invalid");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -141,6 +141,55 @@ struct property *sym_get_range_prop(struct symbol *sym)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sym_get_range_val(struct symbol *sym, int base)
|
||||||
|
{
|
||||||
|
sym_calc_value(sym);
|
||||||
|
switch (sym->type) {
|
||||||
|
case S_INT:
|
||||||
|
base = 10;
|
||||||
|
break;
|
||||||
|
case S_HEX:
|
||||||
|
base = 16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return strtol(sym->curr.val, NULL, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sym_validate_range(struct symbol *sym)
|
||||||
|
{
|
||||||
|
struct property *prop;
|
||||||
|
int base, val, val2;
|
||||||
|
char str[64];
|
||||||
|
|
||||||
|
switch (sym->type) {
|
||||||
|
case S_INT:
|
||||||
|
base = 10;
|
||||||
|
break;
|
||||||
|
case S_HEX:
|
||||||
|
base = 16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prop = sym_get_range_prop(sym);
|
||||||
|
if (!prop)
|
||||||
|
return;
|
||||||
|
val = strtol(sym->curr.val, NULL, base);
|
||||||
|
val2 = sym_get_range_val(prop->expr->left.sym, base);
|
||||||
|
if (val >= val2) {
|
||||||
|
val2 = sym_get_range_val(prop->expr->right.sym, base);
|
||||||
|
if (val <= val2)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sym->type == S_INT)
|
||||||
|
sprintf(str, "%d", val2);
|
||||||
|
else
|
||||||
|
sprintf(str, "0x%x", val2);
|
||||||
|
sym->curr.val = strdup(str);
|
||||||
|
}
|
||||||
|
|
||||||
static void sym_calc_visibility(struct symbol *sym)
|
static void sym_calc_visibility(struct symbol *sym)
|
||||||
{
|
{
|
||||||
struct property *prop;
|
struct property *prop;
|
||||||
|
@ -301,6 +350,7 @@ void sym_calc_value(struct symbol *sym)
|
||||||
sym->curr = newval;
|
sym->curr = newval;
|
||||||
if (sym_is_choice(sym) && newval.tri == yes)
|
if (sym_is_choice(sym) && newval.tri == yes)
|
||||||
sym->curr.val = sym_calc_choice(sym);
|
sym->curr.val = sym_calc_choice(sym);
|
||||||
|
sym_validate_range(sym);
|
||||||
|
|
||||||
if (memcmp(&oldval, &sym->curr, sizeof(oldval)))
|
if (memcmp(&oldval, &sym->curr, sizeof(oldval)))
|
||||||
sym_set_changed(sym);
|
sym_set_changed(sym);
|
||||||
|
@ -489,8 +539,8 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
|
||||||
if (!prop)
|
if (!prop)
|
||||||
return true;
|
return true;
|
||||||
val = strtol(str, NULL, 10);
|
val = strtol(str, NULL, 10);
|
||||||
return val >= strtol(prop->expr->left.sym->name, NULL, 10) &&
|
return val >= sym_get_range_val(prop->expr->left.sym, 10) &&
|
||||||
val <= strtol(prop->expr->right.sym->name, NULL, 10);
|
val <= sym_get_range_val(prop->expr->right.sym, 10);
|
||||||
case S_HEX:
|
case S_HEX:
|
||||||
if (!sym_string_valid(sym, str))
|
if (!sym_string_valid(sym, str))
|
||||||
return false;
|
return false;
|
||||||
|
@ -498,8 +548,8 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
|
||||||
if (!prop)
|
if (!prop)
|
||||||
return true;
|
return true;
|
||||||
val = strtol(str, NULL, 16);
|
val = strtol(str, NULL, 16);
|
||||||
return val >= strtol(prop->expr->left.sym->name, NULL, 16) &&
|
return val >= sym_get_range_val(prop->expr->left.sym, 16) &&
|
||||||
val <= strtol(prop->expr->right.sym->name, NULL, 16);
|
val <= sym_get_range_val(prop->expr->right.sym, 16);
|
||||||
case S_BOOLEAN:
|
case S_BOOLEAN:
|
||||||
case S_TRISTATE:
|
case S_TRISTATE:
|
||||||
switch (str[0]) {
|
switch (str[0]) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user