summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2003-06-02 03:25:20 -0700
committerBen Collins <bcollins@debian.org>2003-06-02 03:25:20 -0700
commite4922a0baa760bdfedaf8760242b002f2fa36c71 (patch)
tree13346d157a8e1fcc67330f69184b5ba263a0f211 /scripts
parentf3b837df9e2bb0225b26cd295225fd133207654e (diff)
[PATCH] support for 'range'
The 'range' keyword allows to define a lower and upper limit for integer and hex symbols.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kconfig/confdata.c14
-rw-r--r--scripts/kconfig/expr.c9
-rw-r--r--scripts/kconfig/expr.h4
-rw-r--r--scripts/kconfig/lkc_proto.h1
-rw-r--r--scripts/kconfig/symbol.c56
-rw-r--r--scripts/kconfig/zconf.tab.c_shipped1
-rw-r--r--scripts/kconfig/zconf.y1
7 files changed, 83 insertions, 3 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 4d83a5533dd2..87c1081dfc81 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -224,6 +224,20 @@ int conf_read(const char *name)
fclose(in);
for_all_symbols(i, sym) {
+ sym_calc_value(sym);
+ if (sym_has_value(sym)) {
+ if (sym->visible == no)
+ sym->flags |= SYMBOL_NEW;
+ switch (sym->type) {
+ case S_STRING:
+ case S_INT:
+ case S_HEX:
+ if (!sym_string_within_range(sym, sym->user.val))
+ sym->flags |= SYMBOL_NEW;
+ default:
+ break;
+ }
+ }
if (!sym_is_choice(sym))
continue;
prop = sym_get_choice_prop(sym);
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 33a9e0819f87..3f15ae859a5b 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -215,6 +215,7 @@ int expr_eq(struct expr *e1, struct expr *e2)
trans_count = old_count;
return res;
case E_CHOICE:
+ case E_RANGE:
case E_NONE:
/* panic */;
}
@@ -917,6 +918,7 @@ struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symb
case E_SYMBOL:
return expr_alloc_comp(type, e->left.sym, sym);
case E_CHOICE:
+ case E_RANGE:
case E_NONE:
/* panic */;
}
@@ -1043,6 +1045,13 @@ void expr_print(struct expr *e, void (*fn)(void *, const char *), void *data, in
expr_print(e->left.expr, fn, data, E_CHOICE);
}
break;
+ case E_RANGE:
+ fn(data, "[");
+ fn(data, e->left.sym->name);
+ fn(data, " ");
+ fn(data, e->right.sym->name);
+ fn(data, "]");
+ break;
default:
{
char buf[32];
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index f1fa5d83956b..dca5a63faf5f 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -32,7 +32,7 @@ typedef enum tristate {
} tristate;
enum expr_type {
- E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_CHOICE, E_SYMBOL
+ E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_CHOICE, E_SYMBOL, E_RANGE
};
union expr_data {
@@ -98,7 +98,7 @@ struct symbol {
#define SYMBOL_HASHMASK 0xff
enum prop_type {
- P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_DEFAULT, P_CHOICE, P_SELECT
+ P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_DEFAULT, P_CHOICE, P_SELECT, P_RANGE
};
struct property {
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 2a1494e1deb8..97c79178ee3d 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -25,6 +25,7 @@ P(sym_tristate_within_range,bool,(struct symbol *sym,tristate tri));
P(sym_set_tristate_value,bool,(struct symbol *sym,tristate tri));
P(sym_toggle_tristate_value,tristate,(struct symbol *sym));
P(sym_string_valid,bool,(struct symbol *sym, const char *newval));
+P(sym_string_within_range,bool,(struct symbol *sym, const char *str));
P(sym_set_string_value,bool,(struct symbol *sym, const char *newval));
P(sym_is_changable,bool,(struct symbol *sym));
P(sym_get_choice_prop,struct property *,(struct symbol *sym));
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 59e8143759b2..fe665d4338db 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -130,6 +130,18 @@ struct property *sym_get_default_prop(struct symbol *sym)
return NULL;
}
+struct property *sym_get_range_prop(struct symbol *sym)
+{
+ struct property *prop;
+
+ for_all_properties(sym, prop, P_RANGE) {
+ prop->visible.tri = expr_calc_value(prop->visible.expr);
+ if (prop->visible.tri != no)
+ return prop;
+ }
+ return NULL;
+}
+
static void sym_calc_visibility(struct symbol *sym)
{
struct property *prop;
@@ -435,6 +447,46 @@ bool sym_string_valid(struct symbol *sym, const char *str)
case S_TRISTATE:
switch (str[0]) {
case 'y': case 'Y':
+ case 'm': case 'M':
+ case 'n': case 'N':
+ return true;
+ }
+ return false;
+ default:
+ return false;
+ }
+}
+
+bool sym_string_within_range(struct symbol *sym, const char *str)
+{
+ struct property *prop;
+ int val;
+
+ switch (sym->type) {
+ case S_STRING:
+ return sym_string_valid(sym, str);
+ case S_INT:
+ if (!sym_string_valid(sym, str))
+ return false;
+ prop = sym_get_range_prop(sym);
+ if (!prop)
+ return true;
+ val = strtol(str, NULL, 10);
+ return val >= strtol(prop->expr->left.sym->name, NULL, 10) &&
+ val <= strtol(prop->expr->right.sym->name, NULL, 10);
+ case S_HEX:
+ if (!sym_string_valid(sym, str))
+ return false;
+ prop = sym_get_range_prop(sym);
+ if (!prop)
+ return true;
+ val = strtol(str, NULL, 16);
+ return val >= strtol(prop->expr->left.sym->name, NULL, 16) &&
+ val <= strtol(prop->expr->right.sym->name, NULL, 16);
+ case S_BOOLEAN:
+ case S_TRISTATE:
+ switch (str[0]) {
+ case 'y': case 'Y':
return sym_tristate_within_range(sym, yes);
case 'm': case 'M':
return sym_tristate_within_range(sym, mod);
@@ -469,7 +521,7 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
;
}
- if (!sym_string_valid(sym, newval))
+ if (!sym_string_within_range(sym, newval))
return false;
if (sym->flags & SYMBOL_NEW) {
@@ -644,6 +696,8 @@ const char *prop_get_type_name(enum prop_type type)
return "choice";
case P_SELECT:
return "select";
+ case P_RANGE:
+ return "range";
case P_UNKNOWN:
break;
}
diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped
index 36ee30543d1e..e246ab0d20e1 100644
--- a/scripts/kconfig/zconf.tab.c_shipped
+++ b/scripts/kconfig/zconf.tab.c_shipped
@@ -1414,6 +1414,7 @@ yyreduce:
case 37:
{
+ menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,yyvsp[-3].symbol, yyvsp[-2].symbol), yyvsp[-1].expr);
printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
;}
break;
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 7b730cea92f3..025bf2c33c15 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -221,6 +221,7 @@ config_option: T_SELECT T_WORD if_expr T_EOL
config_option: T_RANGE symbol symbol if_expr T_EOL
{
+ menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
};