Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 3 | * Released under the terms of the GNU GPL v2.0. |
| 4 | */ |
| 5 | |
| 6 | #include <ctype.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include <regex.h> |
| 10 | #include <sys/utsname.h> |
| 11 | |
| 12 | #define LKC_DIRECT_LINK |
| 13 | #include "lkc.h" |
| 14 | |
| 15 | struct symbol symbol_yes = { |
| 16 | .name = "y", |
| 17 | .curr = { "y", yes }, |
Roman Zippel | c0e150ac | 2006-06-08 22:12:40 -0700 | [diff] [blame] | 18 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | }, symbol_mod = { |
| 20 | .name = "m", |
| 21 | .curr = { "m", mod }, |
Roman Zippel | c0e150ac | 2006-06-08 22:12:40 -0700 | [diff] [blame] | 22 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | }, symbol_no = { |
| 24 | .name = "n", |
| 25 | .curr = { "n", no }, |
Roman Zippel | c0e150ac | 2006-06-08 22:12:40 -0700 | [diff] [blame] | 26 | .flags = SYMBOL_CONST|SYMBOL_VALID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | }, symbol_empty = { |
| 28 | .name = "", |
| 29 | .curr = { "", no }, |
| 30 | .flags = SYMBOL_VALID, |
| 31 | }; |
| 32 | |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 33 | struct symbol *sym_defconfig_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct symbol *modules_sym; |
| 35 | tristate modules_val; |
| 36 | |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 37 | struct expr *sym_env_list; |
| 38 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 39 | static void sym_add_default(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | struct property *prop = prop_alloc(P_DEFAULT, sym); |
| 42 | |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 43 | prop->expr = expr_alloc_symbol(sym_lookup(def, SYMBOL_CONST)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void sym_init(void) |
| 47 | { |
| 48 | struct symbol *sym; |
| 49 | struct utsname uts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static bool inited = false; |
| 51 | |
| 52 | if (inited) |
| 53 | return; |
| 54 | inited = true; |
| 55 | |
| 56 | uname(&uts); |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | sym = sym_lookup("UNAME_RELEASE", 0); |
| 59 | sym->type = S_STRING; |
| 60 | sym->flags |= SYMBOL_AUTO; |
| 61 | sym_add_default(sym, uts.release); |
| 62 | } |
| 63 | |
| 64 | enum symbol_type sym_get_type(struct symbol *sym) |
| 65 | { |
| 66 | enum symbol_type type = sym->type; |
| 67 | |
| 68 | if (type == S_TRISTATE) { |
| 69 | if (sym_is_choice_value(sym) && sym->visible == yes) |
| 70 | type = S_BOOLEAN; |
| 71 | else if (modules_val == no) |
| 72 | type = S_BOOLEAN; |
| 73 | } |
| 74 | return type; |
| 75 | } |
| 76 | |
| 77 | const char *sym_type_name(enum symbol_type type) |
| 78 | { |
| 79 | switch (type) { |
| 80 | case S_BOOLEAN: |
| 81 | return "boolean"; |
| 82 | case S_TRISTATE: |
| 83 | return "tristate"; |
| 84 | case S_INT: |
| 85 | return "integer"; |
| 86 | case S_HEX: |
| 87 | return "hex"; |
| 88 | case S_STRING: |
| 89 | return "string"; |
| 90 | case S_UNKNOWN: |
| 91 | return "unknown"; |
| 92 | case S_OTHER: |
| 93 | break; |
| 94 | } |
| 95 | return "???"; |
| 96 | } |
| 97 | |
| 98 | struct property *sym_get_choice_prop(struct symbol *sym) |
| 99 | { |
| 100 | struct property *prop; |
| 101 | |
| 102 | for_all_choices(sym, prop) |
| 103 | return prop; |
| 104 | return NULL; |
| 105 | } |
| 106 | |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 107 | struct property *sym_get_env_prop(struct symbol *sym) |
| 108 | { |
| 109 | struct property *prop; |
| 110 | |
| 111 | for_all_properties(sym, prop, P_ENV) |
| 112 | return prop; |
| 113 | return NULL; |
| 114 | } |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | struct property *sym_get_default_prop(struct symbol *sym) |
| 117 | { |
| 118 | struct property *prop; |
| 119 | |
| 120 | for_all_defaults(sym, prop) { |
| 121 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 122 | if (prop->visible.tri != no) |
| 123 | return prop; |
| 124 | } |
| 125 | return NULL; |
| 126 | } |
| 127 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 128 | static struct property *sym_get_range_prop(struct symbol *sym) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | struct property *prop; |
| 131 | |
| 132 | for_all_properties(sym, prop, P_RANGE) { |
| 133 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 134 | if (prop->visible.tri != no) |
| 135 | return prop; |
| 136 | } |
| 137 | return NULL; |
| 138 | } |
| 139 | |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 140 | static int sym_get_range_val(struct symbol *sym, int base) |
| 141 | { |
| 142 | sym_calc_value(sym); |
| 143 | switch (sym->type) { |
| 144 | case S_INT: |
| 145 | base = 10; |
| 146 | break; |
| 147 | case S_HEX: |
| 148 | base = 16; |
| 149 | break; |
| 150 | default: |
| 151 | break; |
| 152 | } |
| 153 | return strtol(sym->curr.val, NULL, base); |
| 154 | } |
| 155 | |
| 156 | static void sym_validate_range(struct symbol *sym) |
| 157 | { |
| 158 | struct property *prop; |
| 159 | int base, val, val2; |
| 160 | char str[64]; |
| 161 | |
| 162 | switch (sym->type) { |
| 163 | case S_INT: |
| 164 | base = 10; |
| 165 | break; |
| 166 | case S_HEX: |
| 167 | base = 16; |
| 168 | break; |
| 169 | default: |
| 170 | return; |
| 171 | } |
| 172 | prop = sym_get_range_prop(sym); |
| 173 | if (!prop) |
| 174 | return; |
| 175 | val = strtol(sym->curr.val, NULL, base); |
| 176 | val2 = sym_get_range_val(prop->expr->left.sym, base); |
| 177 | if (val >= val2) { |
| 178 | val2 = sym_get_range_val(prop->expr->right.sym, base); |
| 179 | if (val <= val2) |
| 180 | return; |
| 181 | } |
| 182 | if (sym->type == S_INT) |
| 183 | sprintf(str, "%d", val2); |
| 184 | else |
| 185 | sprintf(str, "0x%x", val2); |
| 186 | sym->curr.val = strdup(str); |
| 187 | } |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | static void sym_calc_visibility(struct symbol *sym) |
| 190 | { |
| 191 | struct property *prop; |
| 192 | tristate tri; |
| 193 | |
| 194 | /* any prompt visible? */ |
| 195 | tri = no; |
| 196 | for_all_prompts(sym, prop) { |
| 197 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
Sam Ravnborg | d6ee357 | 2008-01-07 21:09:55 +0100 | [diff] [blame] | 198 | tri = EXPR_OR(tri, prop->visible.tri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | if (tri == mod && (sym->type != S_TRISTATE || modules_val == no)) |
| 201 | tri = yes; |
| 202 | if (sym->visible != tri) { |
| 203 | sym->visible = tri; |
| 204 | sym_set_changed(sym); |
| 205 | } |
| 206 | if (sym_is_choice_value(sym)) |
| 207 | return; |
Catalin Marinas | 246cf9c | 2010-06-08 17:25:57 +0100 | [diff] [blame] | 208 | /* defaulting to "yes" if no explicit "depends on" are given */ |
| 209 | tri = yes; |
| 210 | if (sym->dir_dep.expr) |
| 211 | tri = expr_calc_value(sym->dir_dep.expr); |
| 212 | if (tri == mod) |
| 213 | tri = yes; |
| 214 | if (sym->dir_dep.tri != tri) { |
| 215 | sym->dir_dep.tri = tri; |
| 216 | sym_set_changed(sym); |
| 217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | tri = no; |
| 219 | if (sym->rev_dep.expr) |
| 220 | tri = expr_calc_value(sym->rev_dep.expr); |
| 221 | if (tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 222 | tri = yes; |
| 223 | if (sym->rev_dep.tri != tri) { |
| 224 | sym->rev_dep.tri = tri; |
| 225 | sym_set_changed(sym); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | static struct symbol *sym_calc_choice(struct symbol *sym) |
| 230 | { |
| 231 | struct symbol *def_sym; |
| 232 | struct property *prop; |
| 233 | struct expr *e; |
| 234 | |
Jan Beulich | 0a28c47 | 2010-06-30 13:11:01 +0100 | [diff] [blame] | 235 | /* first calculate all choice values' visibilities */ |
| 236 | prop = sym_get_choice_prop(sym); |
| 237 | expr_list_for_each_sym(prop->expr, e, def_sym) |
| 238 | sym_calc_visibility(def_sym); |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* is the user choice visible? */ |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 241 | def_sym = sym->def[S_DEF_USER].val; |
Jan Beulich | 0a28c47 | 2010-06-30 13:11:01 +0100 | [diff] [blame] | 242 | if (def_sym && def_sym->visible != no) |
| 243 | return def_sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | /* any of the defaults visible? */ |
| 246 | for_all_defaults(sym, prop) { |
| 247 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 248 | if (prop->visible.tri == no) |
| 249 | continue; |
| 250 | def_sym = prop_get_symbol(prop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if (def_sym->visible != no) |
| 252 | return def_sym; |
| 253 | } |
| 254 | |
| 255 | /* just get the first visible value */ |
| 256 | prop = sym_get_choice_prop(sym); |
Jan Beulich | 0a28c47 | 2010-06-30 13:11:01 +0100 | [diff] [blame] | 257 | expr_list_for_each_sym(prop->expr, e, def_sym) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (def_sym->visible != no) |
| 259 | return def_sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* no choice? reset tristate value */ |
| 262 | sym->curr.tri = no; |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | void sym_calc_value(struct symbol *sym) |
| 267 | { |
| 268 | struct symbol_value newval, oldval; |
| 269 | struct property *prop; |
| 270 | struct expr *e; |
| 271 | |
| 272 | if (!sym) |
| 273 | return; |
| 274 | |
| 275 | if (sym->flags & SYMBOL_VALID) |
| 276 | return; |
| 277 | sym->flags |= SYMBOL_VALID; |
| 278 | |
| 279 | oldval = sym->curr; |
| 280 | |
| 281 | switch (sym->type) { |
| 282 | case S_INT: |
| 283 | case S_HEX: |
| 284 | case S_STRING: |
| 285 | newval = symbol_empty.curr; |
| 286 | break; |
| 287 | case S_BOOLEAN: |
| 288 | case S_TRISTATE: |
| 289 | newval = symbol_no.curr; |
| 290 | break; |
| 291 | default: |
| 292 | sym->curr.val = sym->name; |
| 293 | sym->curr.tri = no; |
| 294 | return; |
| 295 | } |
| 296 | if (!sym_is_choice_value(sym)) |
| 297 | sym->flags &= ~SYMBOL_WRITE; |
| 298 | |
| 299 | sym_calc_visibility(sym); |
| 300 | |
| 301 | /* set default if recursively called */ |
| 302 | sym->curr = newval; |
| 303 | |
| 304 | switch (sym_get_type(sym)) { |
| 305 | case S_BOOLEAN: |
| 306 | case S_TRISTATE: |
| 307 | if (sym_is_choice_value(sym) && sym->visible == yes) { |
| 308 | prop = sym_get_choice_prop(sym); |
| 309 | newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no; |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 310 | } else { |
| 311 | if (sym->visible != no) { |
| 312 | /* if the symbol is visible use the user value |
| 313 | * if available, otherwise try the default value |
| 314 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | sym->flags |= SYMBOL_WRITE; |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 316 | if (sym_has_value(sym)) { |
| 317 | newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri, |
| 318 | sym->visible); |
| 319 | goto calc_newval; |
| 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 322 | if (sym->rev_dep.tri != no) |
| 323 | sym->flags |= SYMBOL_WRITE; |
| 324 | if (!sym_is_choice(sym)) { |
| 325 | prop = sym_get_default_prop(sym); |
| 326 | if (prop) { |
| 327 | sym->flags |= SYMBOL_WRITE; |
| 328 | newval.tri = EXPR_AND(expr_calc_value(prop->expr), |
| 329 | prop->visible.tri); |
| 330 | } |
| 331 | } |
| 332 | calc_newval: |
Catalin Marinas | 246cf9c | 2010-06-08 17:25:57 +0100 | [diff] [blame] | 333 | if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) { |
| 334 | fprintf(stderr, "warning: ("); |
| 335 | expr_fprint(sym->rev_dep.expr, stderr); |
| 336 | fprintf(stderr, ") selects %s which has unmet direct dependencies (", |
| 337 | sym->name); |
| 338 | expr_fprint(sym->dir_dep.expr, stderr); |
| 339 | fprintf(stderr, ")\n"); |
| 340 | } |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 341 | newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 344 | newval.tri = yes; |
| 345 | break; |
| 346 | case S_STRING: |
| 347 | case S_HEX: |
| 348 | case S_INT: |
| 349 | if (sym->visible != no) { |
| 350 | sym->flags |= SYMBOL_WRITE; |
| 351 | if (sym_has_value(sym)) { |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 352 | newval.val = sym->def[S_DEF_USER].val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | break; |
| 354 | } |
| 355 | } |
| 356 | prop = sym_get_default_prop(sym); |
| 357 | if (prop) { |
| 358 | struct symbol *ds = prop_get_symbol(prop); |
| 359 | if (ds) { |
| 360 | sym->flags |= SYMBOL_WRITE; |
| 361 | sym_calc_value(ds); |
| 362 | newval.val = ds->curr.val; |
| 363 | } |
| 364 | } |
| 365 | break; |
| 366 | default: |
| 367 | ; |
| 368 | } |
| 369 | |
| 370 | sym->curr = newval; |
| 371 | if (sym_is_choice(sym) && newval.tri == yes) |
| 372 | sym->curr.val = sym_calc_choice(sym); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 373 | sym_validate_range(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 375 | if (memcmp(&oldval, &sym->curr, sizeof(oldval))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | sym_set_changed(sym); |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 377 | if (modules_sym == sym) { |
| 378 | sym_set_all_changed(); |
| 379 | modules_val = modules_sym->curr.tri; |
| 380 | } |
| 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | if (sym_is_choice(sym)) { |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 384 | struct symbol *choice_sym; |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | prop = sym_get_choice_prop(sym); |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 387 | expr_list_for_each_sym(prop->expr, e, choice_sym) { |
Jan Beulich | 0a28c47 | 2010-06-30 13:11:01 +0100 | [diff] [blame] | 388 | if ((sym->flags & SYMBOL_WRITE) && |
| 389 | choice_sym->visible != no) |
| 390 | choice_sym->flags |= SYMBOL_WRITE; |
| 391 | if (sym->flags & SYMBOL_CHANGED) |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 392 | sym_set_changed(choice_sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 395 | |
| 396 | if (sym->flags & SYMBOL_AUTO) |
| 397 | sym->flags &= ~SYMBOL_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void sym_clear_all_valid(void) |
| 401 | { |
| 402 | struct symbol *sym; |
| 403 | int i; |
| 404 | |
| 405 | for_all_symbols(i, sym) |
| 406 | sym->flags &= ~SYMBOL_VALID; |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 407 | sym_add_change_count(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | if (modules_sym) |
| 409 | sym_calc_value(modules_sym); |
| 410 | } |
| 411 | |
| 412 | void sym_set_changed(struct symbol *sym) |
| 413 | { |
| 414 | struct property *prop; |
| 415 | |
| 416 | sym->flags |= SYMBOL_CHANGED; |
| 417 | for (prop = sym->prop; prop; prop = prop->next) { |
| 418 | if (prop->menu) |
| 419 | prop->menu->flags |= MENU_CHANGED; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | void sym_set_all_changed(void) |
| 424 | { |
| 425 | struct symbol *sym; |
| 426 | int i; |
| 427 | |
| 428 | for_all_symbols(i, sym) |
| 429 | sym_set_changed(sym); |
| 430 | } |
| 431 | |
| 432 | bool sym_tristate_within_range(struct symbol *sym, tristate val) |
| 433 | { |
| 434 | int type = sym_get_type(sym); |
| 435 | |
| 436 | if (sym->visible == no) |
| 437 | return false; |
| 438 | |
| 439 | if (type != S_BOOLEAN && type != S_TRISTATE) |
| 440 | return false; |
| 441 | |
| 442 | if (type == S_BOOLEAN && val == mod) |
| 443 | return false; |
| 444 | if (sym->visible <= sym->rev_dep.tri) |
| 445 | return false; |
| 446 | if (sym_is_choice_value(sym) && sym->visible == yes) |
| 447 | return val == yes; |
| 448 | return val >= sym->rev_dep.tri && val <= sym->visible; |
| 449 | } |
| 450 | |
| 451 | bool sym_set_tristate_value(struct symbol *sym, tristate val) |
| 452 | { |
| 453 | tristate oldval = sym_get_tristate_value(sym); |
| 454 | |
| 455 | if (oldval != val && !sym_tristate_within_range(sym, val)) |
| 456 | return false; |
| 457 | |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 458 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 459 | sym->flags |= SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | sym_set_changed(sym); |
| 461 | } |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 462 | /* |
| 463 | * setting a choice value also resets the new flag of the choice |
| 464 | * symbol and all other choice values. |
| 465 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (sym_is_choice_value(sym) && val == yes) { |
| 467 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 468 | struct property *prop; |
| 469 | struct expr *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 471 | cs->def[S_DEF_USER].val = sym; |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 472 | cs->flags |= SYMBOL_DEF_USER; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 473 | prop = sym_get_choice_prop(cs); |
| 474 | for (e = prop->expr; e; e = e->left.expr) { |
| 475 | if (e->right.sym->visible != no) |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 476 | e->right.sym->flags |= SYMBOL_DEF_USER; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 480 | sym->def[S_DEF_USER].tri = val; |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 481 | if (oldval != val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | sym_clear_all_valid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | return true; |
| 485 | } |
| 486 | |
| 487 | tristate sym_toggle_tristate_value(struct symbol *sym) |
| 488 | { |
| 489 | tristate oldval, newval; |
| 490 | |
| 491 | oldval = newval = sym_get_tristate_value(sym); |
| 492 | do { |
| 493 | switch (newval) { |
| 494 | case no: |
| 495 | newval = mod; |
| 496 | break; |
| 497 | case mod: |
| 498 | newval = yes; |
| 499 | break; |
| 500 | case yes: |
| 501 | newval = no; |
| 502 | break; |
| 503 | } |
| 504 | if (sym_set_tristate_value(sym, newval)) |
| 505 | break; |
| 506 | } while (oldval != newval); |
| 507 | return newval; |
| 508 | } |
| 509 | |
| 510 | bool sym_string_valid(struct symbol *sym, const char *str) |
| 511 | { |
| 512 | signed char ch; |
| 513 | |
| 514 | switch (sym->type) { |
| 515 | case S_STRING: |
| 516 | return true; |
| 517 | case S_INT: |
| 518 | ch = *str++; |
| 519 | if (ch == '-') |
| 520 | ch = *str++; |
| 521 | if (!isdigit(ch)) |
| 522 | return false; |
| 523 | if (ch == '0' && *str != 0) |
| 524 | return false; |
| 525 | while ((ch = *str++)) { |
| 526 | if (!isdigit(ch)) |
| 527 | return false; |
| 528 | } |
| 529 | return true; |
| 530 | case S_HEX: |
| 531 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) |
| 532 | str += 2; |
| 533 | ch = *str++; |
| 534 | do { |
| 535 | if (!isxdigit(ch)) |
| 536 | return false; |
| 537 | } while ((ch = *str++)); |
| 538 | return true; |
| 539 | case S_BOOLEAN: |
| 540 | case S_TRISTATE: |
| 541 | switch (str[0]) { |
| 542 | case 'y': case 'Y': |
| 543 | case 'm': case 'M': |
| 544 | case 'n': case 'N': |
| 545 | return true; |
| 546 | } |
| 547 | return false; |
| 548 | default: |
| 549 | return false; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | bool sym_string_within_range(struct symbol *sym, const char *str) |
| 554 | { |
| 555 | struct property *prop; |
| 556 | int val; |
| 557 | |
| 558 | switch (sym->type) { |
| 559 | case S_STRING: |
| 560 | return sym_string_valid(sym, str); |
| 561 | case S_INT: |
| 562 | if (!sym_string_valid(sym, str)) |
| 563 | return false; |
| 564 | prop = sym_get_range_prop(sym); |
| 565 | if (!prop) |
| 566 | return true; |
| 567 | val = strtol(str, NULL, 10); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 568 | return val >= sym_get_range_val(prop->expr->left.sym, 10) && |
| 569 | val <= sym_get_range_val(prop->expr->right.sym, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | case S_HEX: |
| 571 | if (!sym_string_valid(sym, str)) |
| 572 | return false; |
| 573 | prop = sym_get_range_prop(sym); |
| 574 | if (!prop) |
| 575 | return true; |
| 576 | val = strtol(str, NULL, 16); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 577 | return val >= sym_get_range_val(prop->expr->left.sym, 16) && |
| 578 | val <= sym_get_range_val(prop->expr->right.sym, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | case S_BOOLEAN: |
| 580 | case S_TRISTATE: |
| 581 | switch (str[0]) { |
| 582 | case 'y': case 'Y': |
| 583 | return sym_tristate_within_range(sym, yes); |
| 584 | case 'm': case 'M': |
| 585 | return sym_tristate_within_range(sym, mod); |
| 586 | case 'n': case 'N': |
| 587 | return sym_tristate_within_range(sym, no); |
| 588 | } |
| 589 | return false; |
| 590 | default: |
| 591 | return false; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | bool sym_set_string_value(struct symbol *sym, const char *newval) |
| 596 | { |
| 597 | const char *oldval; |
| 598 | char *val; |
| 599 | int size; |
| 600 | |
| 601 | switch (sym->type) { |
| 602 | case S_BOOLEAN: |
| 603 | case S_TRISTATE: |
| 604 | switch (newval[0]) { |
| 605 | case 'y': case 'Y': |
| 606 | return sym_set_tristate_value(sym, yes); |
| 607 | case 'm': case 'M': |
| 608 | return sym_set_tristate_value(sym, mod); |
| 609 | case 'n': case 'N': |
| 610 | return sym_set_tristate_value(sym, no); |
| 611 | } |
| 612 | return false; |
| 613 | default: |
| 614 | ; |
| 615 | } |
| 616 | |
| 617 | if (!sym_string_within_range(sym, newval)) |
| 618 | return false; |
| 619 | |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 620 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 621 | sym->flags |= SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | sym_set_changed(sym); |
| 623 | } |
| 624 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 625 | oldval = sym->def[S_DEF_USER].val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | size = strlen(newval) + 1; |
| 627 | if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) { |
| 628 | size += 2; |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 629 | sym->def[S_DEF_USER].val = val = malloc(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | *val++ = '0'; |
| 631 | *val++ = 'x'; |
| 632 | } else if (!oldval || strcmp(oldval, newval)) |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 633 | sym->def[S_DEF_USER].val = val = malloc(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | else |
| 635 | return true; |
| 636 | |
| 637 | strcpy(val, newval); |
| 638 | free((void *)oldval); |
| 639 | sym_clear_all_valid(); |
| 640 | |
| 641 | return true; |
| 642 | } |
| 643 | |
| 644 | const char *sym_get_string_value(struct symbol *sym) |
| 645 | { |
| 646 | tristate val; |
| 647 | |
| 648 | switch (sym->type) { |
| 649 | case S_BOOLEAN: |
| 650 | case S_TRISTATE: |
| 651 | val = sym_get_tristate_value(sym); |
| 652 | switch (val) { |
| 653 | case no: |
| 654 | return "n"; |
| 655 | case mod: |
| 656 | return "m"; |
| 657 | case yes: |
| 658 | return "y"; |
| 659 | } |
| 660 | break; |
| 661 | default: |
| 662 | ; |
| 663 | } |
| 664 | return (const char *)sym->curr.val; |
| 665 | } |
| 666 | |
| 667 | bool sym_is_changable(struct symbol *sym) |
| 668 | { |
| 669 | return sym->visible > sym->rev_dep.tri; |
| 670 | } |
| 671 | |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 672 | static unsigned strhash(const char *s) |
| 673 | { |
| 674 | /* fnv32 hash */ |
| 675 | unsigned hash = 2166136261U; |
| 676 | for (; *s; s++) |
| 677 | hash = (hash ^ *s) * 0x01000193; |
| 678 | return hash; |
| 679 | } |
| 680 | |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 681 | struct symbol *sym_lookup(const char *name, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
| 683 | struct symbol *symbol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | char *new_name; |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 685 | int hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | if (name) { |
| 688 | if (name[0] && !name[1]) { |
| 689 | switch (name[0]) { |
| 690 | case 'y': return &symbol_yes; |
| 691 | case 'm': return &symbol_mod; |
| 692 | case 'n': return &symbol_no; |
| 693 | } |
| 694 | } |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 695 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
| 697 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 698 | if (symbol->name && |
| 699 | !strcmp(symbol->name, name) && |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 700 | (flags ? symbol->flags & flags |
| 701 | : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) |
| 702 | return symbol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | new_name = strdup(name); |
| 705 | } else { |
| 706 | new_name = NULL; |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 707 | hash = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | symbol = malloc(sizeof(*symbol)); |
| 711 | memset(symbol, 0, sizeof(*symbol)); |
| 712 | symbol->name = new_name; |
| 713 | symbol->type = S_UNKNOWN; |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 714 | symbol->flags |= flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | symbol->next = symbol_hash[hash]; |
| 717 | symbol_hash[hash] = symbol; |
| 718 | |
| 719 | return symbol; |
| 720 | } |
| 721 | |
| 722 | struct symbol *sym_find(const char *name) |
| 723 | { |
| 724 | struct symbol *symbol = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | int hash = 0; |
| 726 | |
| 727 | if (!name) |
| 728 | return NULL; |
| 729 | |
| 730 | if (name[0] && !name[1]) { |
| 731 | switch (name[0]) { |
| 732 | case 'y': return &symbol_yes; |
| 733 | case 'm': return &symbol_mod; |
| 734 | case 'n': return &symbol_no; |
| 735 | } |
| 736 | } |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 737 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 740 | if (symbol->name && |
| 741 | !strcmp(symbol->name, name) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | !(symbol->flags & SYMBOL_CONST)) |
| 743 | break; |
| 744 | } |
| 745 | |
| 746 | return symbol; |
| 747 | } |
| 748 | |
| 749 | struct symbol **sym_re_search(const char *pattern) |
| 750 | { |
| 751 | struct symbol *sym, **sym_arr = NULL; |
| 752 | int i, cnt, size; |
| 753 | regex_t re; |
| 754 | |
| 755 | cnt = size = 0; |
| 756 | /* Skip if empty */ |
| 757 | if (strlen(pattern) == 0) |
| 758 | return NULL; |
| 759 | if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) |
| 760 | return NULL; |
| 761 | |
| 762 | for_all_symbols(i, sym) { |
| 763 | if (sym->flags & SYMBOL_CONST || !sym->name) |
| 764 | continue; |
| 765 | if (regexec(&re, sym->name, 0, NULL, 0)) |
| 766 | continue; |
| 767 | if (cnt + 1 >= size) { |
| 768 | void *tmp = sym_arr; |
| 769 | size += 16; |
| 770 | sym_arr = realloc(sym_arr, size * sizeof(struct symbol *)); |
| 771 | if (!sym_arr) { |
| 772 | free(tmp); |
| 773 | return NULL; |
| 774 | } |
| 775 | } |
Li Zefan | da6df87 | 2010-03-19 14:57:47 +0800 | [diff] [blame] | 776 | sym_calc_value(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | sym_arr[cnt++] = sym; |
| 778 | } |
| 779 | if (sym_arr) |
| 780 | sym_arr[cnt] = NULL; |
| 781 | regfree(&re); |
| 782 | |
| 783 | return sym_arr; |
| 784 | } |
| 785 | |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 786 | /* |
| 787 | * When we check for recursive dependencies we use a stack to save |
| 788 | * current state so we can print out relevant info to user. |
| 789 | * The entries are located on the call stack so no need to free memory. |
| 790 | * Note inser() remove() must always match to properly clear the stack. |
| 791 | */ |
| 792 | static struct dep_stack { |
| 793 | struct dep_stack *prev, *next; |
| 794 | struct symbol *sym; |
| 795 | struct property *prop; |
| 796 | struct expr *expr; |
| 797 | } *check_top; |
| 798 | |
| 799 | static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym) |
| 800 | { |
| 801 | memset(stack, 0, sizeof(*stack)); |
| 802 | if (check_top) |
| 803 | check_top->next = stack; |
| 804 | stack->prev = check_top; |
| 805 | stack->sym = sym; |
| 806 | check_top = stack; |
| 807 | } |
| 808 | |
| 809 | static void dep_stack_remove(void) |
| 810 | { |
| 811 | check_top = check_top->prev; |
| 812 | if (check_top) |
| 813 | check_top->next = NULL; |
| 814 | } |
| 815 | |
| 816 | /* |
| 817 | * Called when we have detected a recursive dependency. |
| 818 | * check_top point to the top of the stact so we use |
| 819 | * the ->prev pointer to locate the bottom of the stack. |
| 820 | */ |
| 821 | static void sym_check_print_recursive(struct symbol *last_sym) |
| 822 | { |
| 823 | struct dep_stack *stack; |
| 824 | struct symbol *sym, *next_sym; |
| 825 | struct menu *menu = NULL; |
| 826 | struct property *prop; |
| 827 | struct dep_stack cv_stack; |
| 828 | |
| 829 | if (sym_is_choice_value(last_sym)) { |
| 830 | dep_stack_insert(&cv_stack, last_sym); |
| 831 | last_sym = prop_get_symbol(sym_get_choice_prop(last_sym)); |
| 832 | } |
| 833 | |
| 834 | for (stack = check_top; stack != NULL; stack = stack->prev) |
| 835 | if (stack->sym == last_sym) |
| 836 | break; |
| 837 | if (!stack) { |
| 838 | fprintf(stderr, "unexpected recursive dependency error\n"); |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | for (; stack; stack = stack->next) { |
| 843 | sym = stack->sym; |
| 844 | next_sym = stack->next ? stack->next->sym : last_sym; |
| 845 | prop = stack->prop; |
| 846 | |
| 847 | /* for choice values find the menu entry (used below) */ |
| 848 | if (sym_is_choice(sym) || sym_is_choice_value(sym)) { |
| 849 | for (prop = sym->prop; prop; prop = prop->next) { |
| 850 | menu = prop->menu; |
| 851 | if (prop->menu) |
| 852 | break; |
| 853 | } |
| 854 | } |
| 855 | if (stack->sym == last_sym) |
| 856 | fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", |
| 857 | prop->file->name, prop->lineno); |
| 858 | if (stack->expr) { |
| 859 | fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", |
| 860 | prop->file->name, prop->lineno, |
| 861 | sym->name ? sym->name : "<choice>", |
| 862 | prop_get_type_name(prop->type), |
| 863 | next_sym->name ? next_sym->name : "<choice>"); |
| 864 | } else if (stack->prop) { |
| 865 | fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", |
| 866 | prop->file->name, prop->lineno, |
| 867 | sym->name ? sym->name : "<choice>", |
| 868 | next_sym->name ? next_sym->name : "<choice>"); |
| 869 | } else if (sym_is_choice(sym)) { |
| 870 | fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", |
| 871 | menu->file->name, menu->lineno, |
| 872 | sym->name ? sym->name : "<choice>", |
| 873 | next_sym->name ? next_sym->name : "<choice>"); |
| 874 | } else if (sym_is_choice_value(sym)) { |
| 875 | fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", |
| 876 | menu->file->name, menu->lineno, |
| 877 | sym->name ? sym->name : "<choice>", |
| 878 | next_sym->name ? next_sym->name : "<choice>"); |
| 879 | } else { |
| 880 | fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", |
| 881 | prop->file->name, prop->lineno, |
| 882 | sym->name ? sym->name : "<choice>", |
| 883 | next_sym->name ? next_sym->name : "<choice>"); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | if (check_top == &cv_stack) |
| 888 | dep_stack_remove(); |
| 889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | static struct symbol *sym_check_expr_deps(struct expr *e) |
| 892 | { |
| 893 | struct symbol *sym; |
| 894 | |
| 895 | if (!e) |
| 896 | return NULL; |
| 897 | switch (e->type) { |
| 898 | case E_OR: |
| 899 | case E_AND: |
| 900 | sym = sym_check_expr_deps(e->left.expr); |
| 901 | if (sym) |
| 902 | return sym; |
| 903 | return sym_check_expr_deps(e->right.expr); |
| 904 | case E_NOT: |
| 905 | return sym_check_expr_deps(e->left.expr); |
| 906 | case E_EQUAL: |
| 907 | case E_UNEQUAL: |
| 908 | sym = sym_check_deps(e->left.sym); |
| 909 | if (sym) |
| 910 | return sym; |
| 911 | return sym_check_deps(e->right.sym); |
| 912 | case E_SYMBOL: |
| 913 | return sym_check_deps(e->left.sym); |
| 914 | default: |
| 915 | break; |
| 916 | } |
| 917 | printf("Oops! How to check %d?\n", e->type); |
| 918 | return NULL; |
| 919 | } |
| 920 | |
Sam Ravnborg | 5447d34 | 2007-05-06 09:20:10 +0200 | [diff] [blame] | 921 | /* return NULL when dependencies are OK */ |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 922 | static struct symbol *sym_check_sym_deps(struct symbol *sym) |
| 923 | { |
| 924 | struct symbol *sym2; |
| 925 | struct property *prop; |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 926 | struct dep_stack stack; |
| 927 | |
| 928 | dep_stack_insert(&stack, sym); |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 929 | |
| 930 | sym2 = sym_check_expr_deps(sym->rev_dep.expr); |
| 931 | if (sym2) |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 932 | goto out; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 933 | |
| 934 | for (prop = sym->prop; prop; prop = prop->next) { |
| 935 | if (prop->type == P_CHOICE || prop->type == P_SELECT) |
| 936 | continue; |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 937 | stack.prop = prop; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 938 | sym2 = sym_check_expr_deps(prop->visible.expr); |
| 939 | if (sym2) |
| 940 | break; |
| 941 | if (prop->type != P_DEFAULT || sym_is_choice(sym)) |
| 942 | continue; |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 943 | stack.expr = prop->expr; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 944 | sym2 = sym_check_expr_deps(prop->expr); |
| 945 | if (sym2) |
| 946 | break; |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 947 | stack.expr = NULL; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 950 | out: |
| 951 | dep_stack_remove(); |
| 952 | |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 953 | return sym2; |
| 954 | } |
| 955 | |
| 956 | static struct symbol *sym_check_choice_deps(struct symbol *choice) |
| 957 | { |
| 958 | struct symbol *sym, *sym2; |
| 959 | struct property *prop; |
| 960 | struct expr *e; |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 961 | struct dep_stack stack; |
| 962 | |
| 963 | dep_stack_insert(&stack, choice); |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 964 | |
| 965 | prop = sym_get_choice_prop(choice); |
| 966 | expr_list_for_each_sym(prop->expr, e, sym) |
| 967 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 968 | |
| 969 | choice->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 970 | sym2 = sym_check_sym_deps(choice); |
| 971 | choice->flags &= ~SYMBOL_CHECK; |
| 972 | if (sym2) |
| 973 | goto out; |
| 974 | |
| 975 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 976 | sym2 = sym_check_sym_deps(sym); |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 977 | if (sym2) |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 978 | break; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 979 | } |
| 980 | out: |
| 981 | expr_list_for_each_sym(prop->expr, e, sym) |
| 982 | sym->flags &= ~SYMBOL_CHECK; |
| 983 | |
| 984 | if (sym2 && sym_is_choice_value(sym2) && |
| 985 | prop_get_symbol(sym_get_choice_prop(sym2)) == choice) |
| 986 | sym2 = choice; |
| 987 | |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 988 | dep_stack_remove(); |
| 989 | |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 990 | return sym2; |
| 991 | } |
| 992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | struct symbol *sym_check_deps(struct symbol *sym) |
| 994 | { |
| 995 | struct symbol *sym2; |
| 996 | struct property *prop; |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | if (sym->flags & SYMBOL_CHECK) { |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 999 | sym_check_print_recursive(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | return sym; |
| 1001 | } |
David Gibson | 3f04e7d | 2005-11-08 21:34:46 -0800 | [diff] [blame] | 1002 | if (sym->flags & SYMBOL_CHECKED) |
| 1003 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1005 | if (sym_is_choice_value(sym)) { |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 1006 | struct dep_stack stack; |
| 1007 | |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1008 | /* for choice groups start the check with main choice symbol */ |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 1009 | dep_stack_insert(&stack, sym); |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1010 | prop = sym_get_choice_prop(sym); |
| 1011 | sym2 = sym_check_deps(prop_get_symbol(prop)); |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 1012 | dep_stack_remove(); |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1013 | } else if (sym_is_choice(sym)) { |
| 1014 | sym2 = sym_check_choice_deps(sym); |
| 1015 | } else { |
| 1016 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 1017 | sym2 = sym_check_sym_deps(sym); |
| 1018 | sym->flags &= ~SYMBOL_CHECK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | } |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1020 | |
Roman Zippel | d595cea | 2010-07-31 23:35:30 +0200 | [diff] [blame^] | 1021 | if (sym2 && sym2 == sym) |
| 1022 | sym2 = NULL; |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | return sym2; |
| 1025 | } |
| 1026 | |
| 1027 | struct property *prop_alloc(enum prop_type type, struct symbol *sym) |
| 1028 | { |
| 1029 | struct property *prop; |
| 1030 | struct property **propp; |
| 1031 | |
| 1032 | prop = malloc(sizeof(*prop)); |
| 1033 | memset(prop, 0, sizeof(*prop)); |
| 1034 | prop->type = type; |
| 1035 | prop->sym = sym; |
| 1036 | prop->file = current_file; |
| 1037 | prop->lineno = zconf_lineno(); |
| 1038 | |
| 1039 | /* append property to the prop list of symbol */ |
| 1040 | if (sym) { |
| 1041 | for (propp = &sym->prop; *propp; propp = &(*propp)->next) |
| 1042 | ; |
| 1043 | *propp = prop; |
| 1044 | } |
| 1045 | |
| 1046 | return prop; |
| 1047 | } |
| 1048 | |
| 1049 | struct symbol *prop_get_symbol(struct property *prop) |
| 1050 | { |
| 1051 | if (prop->expr && (prop->expr->type == E_SYMBOL || |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 1052 | prop->expr->type == E_LIST)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | return prop->expr->left.sym; |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | |
| 1057 | const char *prop_get_type_name(enum prop_type type) |
| 1058 | { |
| 1059 | switch (type) { |
| 1060 | case P_PROMPT: |
| 1061 | return "prompt"; |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1062 | case P_ENV: |
| 1063 | return "env"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | case P_COMMENT: |
| 1065 | return "comment"; |
| 1066 | case P_MENU: |
| 1067 | return "menu"; |
| 1068 | case P_DEFAULT: |
| 1069 | return "default"; |
| 1070 | case P_CHOICE: |
| 1071 | return "choice"; |
| 1072 | case P_SELECT: |
| 1073 | return "select"; |
| 1074 | case P_RANGE: |
| 1075 | return "range"; |
Sam Ravnborg | 59e89e3 | 2010-07-31 23:35:29 +0200 | [diff] [blame] | 1076 | case P_SYMBOL: |
| 1077 | return "symbol"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | case P_UNKNOWN: |
| 1079 | break; |
| 1080 | } |
| 1081 | return "unknown"; |
| 1082 | } |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1083 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 1084 | static void prop_add_env(const char *env) |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1085 | { |
| 1086 | struct symbol *sym, *sym2; |
| 1087 | struct property *prop; |
| 1088 | char *p; |
| 1089 | |
| 1090 | sym = current_entry->sym; |
| 1091 | sym->flags |= SYMBOL_AUTO; |
| 1092 | for_all_properties(sym, prop, P_ENV) { |
| 1093 | sym2 = prop_get_symbol(prop); |
| 1094 | if (strcmp(sym2->name, env)) |
| 1095 | menu_warn(current_entry, "redefining environment symbol from %s", |
| 1096 | sym2->name); |
| 1097 | return; |
| 1098 | } |
| 1099 | |
| 1100 | prop = prop_alloc(P_ENV, sym); |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 1101 | prop->expr = expr_alloc_symbol(sym_lookup(env, SYMBOL_CONST)); |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 1102 | |
| 1103 | sym_env_list = expr_alloc_one(E_LIST, sym_env_list); |
| 1104 | sym_env_list->right.sym = sym; |
| 1105 | |
| 1106 | p = getenv(env); |
| 1107 | if (p) |
| 1108 | sym_add_default(sym, p); |
| 1109 | else |
| 1110 | menu_warn(current_entry, "environment variable %s undefined", env); |
| 1111 | } |