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; |
| 208 | tri = no; |
| 209 | if (sym->rev_dep.expr) |
| 210 | tri = expr_calc_value(sym->rev_dep.expr); |
| 211 | if (tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 212 | tri = yes; |
| 213 | if (sym->rev_dep.tri != tri) { |
| 214 | sym->rev_dep.tri = tri; |
| 215 | sym_set_changed(sym); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | static struct symbol *sym_calc_choice(struct symbol *sym) |
| 220 | { |
| 221 | struct symbol *def_sym; |
| 222 | struct property *prop; |
| 223 | struct expr *e; |
| 224 | |
| 225 | /* is the user choice visible? */ |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 226 | def_sym = sym->def[S_DEF_USER].val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if (def_sym) { |
| 228 | sym_calc_visibility(def_sym); |
| 229 | if (def_sym->visible != no) |
| 230 | return def_sym; |
| 231 | } |
| 232 | |
| 233 | /* any of the defaults visible? */ |
| 234 | for_all_defaults(sym, prop) { |
| 235 | prop->visible.tri = expr_calc_value(prop->visible.expr); |
| 236 | if (prop->visible.tri == no) |
| 237 | continue; |
| 238 | def_sym = prop_get_symbol(prop); |
| 239 | sym_calc_visibility(def_sym); |
| 240 | if (def_sym->visible != no) |
| 241 | return def_sym; |
| 242 | } |
| 243 | |
| 244 | /* just get the first visible value */ |
| 245 | prop = sym_get_choice_prop(sym); |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 246 | expr_list_for_each_sym(prop->expr, e, def_sym) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | sym_calc_visibility(def_sym); |
| 248 | if (def_sym->visible != no) |
| 249 | return def_sym; |
| 250 | } |
| 251 | |
| 252 | /* no choice? reset tristate value */ |
| 253 | sym->curr.tri = no; |
| 254 | return NULL; |
| 255 | } |
| 256 | |
| 257 | void sym_calc_value(struct symbol *sym) |
| 258 | { |
| 259 | struct symbol_value newval, oldval; |
| 260 | struct property *prop; |
| 261 | struct expr *e; |
| 262 | |
| 263 | if (!sym) |
| 264 | return; |
| 265 | |
| 266 | if (sym->flags & SYMBOL_VALID) |
| 267 | return; |
| 268 | sym->flags |= SYMBOL_VALID; |
| 269 | |
| 270 | oldval = sym->curr; |
| 271 | |
| 272 | switch (sym->type) { |
| 273 | case S_INT: |
| 274 | case S_HEX: |
| 275 | case S_STRING: |
| 276 | newval = symbol_empty.curr; |
| 277 | break; |
| 278 | case S_BOOLEAN: |
| 279 | case S_TRISTATE: |
| 280 | newval = symbol_no.curr; |
| 281 | break; |
| 282 | default: |
| 283 | sym->curr.val = sym->name; |
| 284 | sym->curr.tri = no; |
| 285 | return; |
| 286 | } |
| 287 | if (!sym_is_choice_value(sym)) |
| 288 | sym->flags &= ~SYMBOL_WRITE; |
| 289 | |
| 290 | sym_calc_visibility(sym); |
| 291 | |
| 292 | /* set default if recursively called */ |
| 293 | sym->curr = newval; |
| 294 | |
| 295 | switch (sym_get_type(sym)) { |
| 296 | case S_BOOLEAN: |
| 297 | case S_TRISTATE: |
| 298 | if (sym_is_choice_value(sym) && sym->visible == yes) { |
| 299 | prop = sym_get_choice_prop(sym); |
| 300 | newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no; |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 301 | } else { |
| 302 | if (sym->visible != no) { |
| 303 | /* if the symbol is visible use the user value |
| 304 | * if available, otherwise try the default value |
| 305 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | sym->flags |= SYMBOL_WRITE; |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 307 | if (sym_has_value(sym)) { |
| 308 | newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri, |
| 309 | sym->visible); |
| 310 | goto calc_newval; |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
Roman Zippel | 587c906 | 2008-02-11 21:13:47 +0100 | [diff] [blame] | 313 | if (sym->rev_dep.tri != no) |
| 314 | sym->flags |= SYMBOL_WRITE; |
| 315 | if (!sym_is_choice(sym)) { |
| 316 | prop = sym_get_default_prop(sym); |
| 317 | if (prop) { |
| 318 | sym->flags |= SYMBOL_WRITE; |
| 319 | newval.tri = EXPR_AND(expr_calc_value(prop->expr), |
| 320 | prop->visible.tri); |
| 321 | } |
| 322 | } |
| 323 | calc_newval: |
| 324 | newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) |
| 327 | newval.tri = yes; |
| 328 | break; |
| 329 | case S_STRING: |
| 330 | case S_HEX: |
| 331 | case S_INT: |
| 332 | if (sym->visible != no) { |
| 333 | sym->flags |= SYMBOL_WRITE; |
| 334 | if (sym_has_value(sym)) { |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 335 | newval.val = sym->def[S_DEF_USER].val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | } |
| 339 | prop = sym_get_default_prop(sym); |
| 340 | if (prop) { |
| 341 | struct symbol *ds = prop_get_symbol(prop); |
| 342 | if (ds) { |
| 343 | sym->flags |= SYMBOL_WRITE; |
| 344 | sym_calc_value(ds); |
| 345 | newval.val = ds->curr.val; |
| 346 | } |
| 347 | } |
| 348 | break; |
| 349 | default: |
| 350 | ; |
| 351 | } |
| 352 | |
| 353 | sym->curr = newval; |
| 354 | if (sym_is_choice(sym) && newval.tri == yes) |
| 355 | sym->curr.val = sym_calc_choice(sym); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 356 | sym_validate_range(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 358 | if (memcmp(&oldval, &sym->curr, sizeof(oldval))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | sym_set_changed(sym); |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 360 | if (modules_sym == sym) { |
| 361 | sym_set_all_changed(); |
| 362 | modules_val = modules_sym->curr.tri; |
| 363 | } |
| 364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | if (sym_is_choice(sym)) { |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 367 | struct symbol *choice_sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE); |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | prop = sym_get_choice_prop(sym); |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 371 | expr_list_for_each_sym(prop->expr, e, choice_sym) { |
| 372 | choice_sym->flags |= flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | if (flags & SYMBOL_CHANGED) |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 374 | sym_set_changed(choice_sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 377 | |
| 378 | if (sym->flags & SYMBOL_AUTO) |
| 379 | sym->flags &= ~SYMBOL_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void sym_clear_all_valid(void) |
| 383 | { |
| 384 | struct symbol *sym; |
| 385 | int i; |
| 386 | |
| 387 | for_all_symbols(i, sym) |
| 388 | sym->flags &= ~SYMBOL_VALID; |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 389 | sym_add_change_count(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | if (modules_sym) |
| 391 | sym_calc_value(modules_sym); |
| 392 | } |
| 393 | |
| 394 | void sym_set_changed(struct symbol *sym) |
| 395 | { |
| 396 | struct property *prop; |
| 397 | |
| 398 | sym->flags |= SYMBOL_CHANGED; |
| 399 | for (prop = sym->prop; prop; prop = prop->next) { |
| 400 | if (prop->menu) |
| 401 | prop->menu->flags |= MENU_CHANGED; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | void sym_set_all_changed(void) |
| 406 | { |
| 407 | struct symbol *sym; |
| 408 | int i; |
| 409 | |
| 410 | for_all_symbols(i, sym) |
| 411 | sym_set_changed(sym); |
| 412 | } |
| 413 | |
| 414 | bool sym_tristate_within_range(struct symbol *sym, tristate val) |
| 415 | { |
| 416 | int type = sym_get_type(sym); |
| 417 | |
| 418 | if (sym->visible == no) |
| 419 | return false; |
| 420 | |
| 421 | if (type != S_BOOLEAN && type != S_TRISTATE) |
| 422 | return false; |
| 423 | |
| 424 | if (type == S_BOOLEAN && val == mod) |
| 425 | return false; |
| 426 | if (sym->visible <= sym->rev_dep.tri) |
| 427 | return false; |
| 428 | if (sym_is_choice_value(sym) && sym->visible == yes) |
| 429 | return val == yes; |
| 430 | return val >= sym->rev_dep.tri && val <= sym->visible; |
| 431 | } |
| 432 | |
| 433 | bool sym_set_tristate_value(struct symbol *sym, tristate val) |
| 434 | { |
| 435 | tristate oldval = sym_get_tristate_value(sym); |
| 436 | |
| 437 | if (oldval != val && !sym_tristate_within_range(sym, val)) |
| 438 | return false; |
| 439 | |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 440 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 441 | sym->flags |= SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | sym_set_changed(sym); |
| 443 | } |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 444 | /* |
| 445 | * setting a choice value also resets the new flag of the choice |
| 446 | * symbol and all other choice values. |
| 447 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (sym_is_choice_value(sym) && val == yes) { |
| 449 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 450 | struct property *prop; |
| 451 | struct expr *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 453 | cs->def[S_DEF_USER].val = sym; |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 454 | cs->flags |= SYMBOL_DEF_USER; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 455 | prop = sym_get_choice_prop(cs); |
| 456 | for (e = prop->expr; e; e = e->left.expr) { |
| 457 | if (e->right.sym->visible != no) |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 458 | e->right.sym->flags |= SYMBOL_DEF_USER; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 462 | sym->def[S_DEF_USER].tri = val; |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 463 | if (oldval != val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | sym_clear_all_valid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | return true; |
| 467 | } |
| 468 | |
| 469 | tristate sym_toggle_tristate_value(struct symbol *sym) |
| 470 | { |
| 471 | tristate oldval, newval; |
| 472 | |
| 473 | oldval = newval = sym_get_tristate_value(sym); |
| 474 | do { |
| 475 | switch (newval) { |
| 476 | case no: |
| 477 | newval = mod; |
| 478 | break; |
| 479 | case mod: |
| 480 | newval = yes; |
| 481 | break; |
| 482 | case yes: |
| 483 | newval = no; |
| 484 | break; |
| 485 | } |
| 486 | if (sym_set_tristate_value(sym, newval)) |
| 487 | break; |
| 488 | } while (oldval != newval); |
| 489 | return newval; |
| 490 | } |
| 491 | |
| 492 | bool sym_string_valid(struct symbol *sym, const char *str) |
| 493 | { |
| 494 | signed char ch; |
| 495 | |
| 496 | switch (sym->type) { |
| 497 | case S_STRING: |
| 498 | return true; |
| 499 | case S_INT: |
| 500 | ch = *str++; |
| 501 | if (ch == '-') |
| 502 | ch = *str++; |
| 503 | if (!isdigit(ch)) |
| 504 | return false; |
| 505 | if (ch == '0' && *str != 0) |
| 506 | return false; |
| 507 | while ((ch = *str++)) { |
| 508 | if (!isdigit(ch)) |
| 509 | return false; |
| 510 | } |
| 511 | return true; |
| 512 | case S_HEX: |
| 513 | if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) |
| 514 | str += 2; |
| 515 | ch = *str++; |
| 516 | do { |
| 517 | if (!isxdigit(ch)) |
| 518 | return false; |
| 519 | } while ((ch = *str++)); |
| 520 | return true; |
| 521 | case S_BOOLEAN: |
| 522 | case S_TRISTATE: |
| 523 | switch (str[0]) { |
| 524 | case 'y': case 'Y': |
| 525 | case 'm': case 'M': |
| 526 | case 'n': case 'N': |
| 527 | return true; |
| 528 | } |
| 529 | return false; |
| 530 | default: |
| 531 | return false; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | bool sym_string_within_range(struct symbol *sym, const char *str) |
| 536 | { |
| 537 | struct property *prop; |
| 538 | int val; |
| 539 | |
| 540 | switch (sym->type) { |
| 541 | case S_STRING: |
| 542 | return sym_string_valid(sym, str); |
| 543 | case S_INT: |
| 544 | if (!sym_string_valid(sym, str)) |
| 545 | return false; |
| 546 | prop = sym_get_range_prop(sym); |
| 547 | if (!prop) |
| 548 | return true; |
| 549 | val = strtol(str, NULL, 10); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 550 | return val >= sym_get_range_val(prop->expr->left.sym, 10) && |
| 551 | val <= sym_get_range_val(prop->expr->right.sym, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | case S_HEX: |
| 553 | if (!sym_string_valid(sym, str)) |
| 554 | return false; |
| 555 | prop = sym_get_range_prop(sym); |
| 556 | if (!prop) |
| 557 | return true; |
| 558 | val = strtol(str, NULL, 16); |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 559 | return val >= sym_get_range_val(prop->expr->left.sym, 16) && |
| 560 | val <= sym_get_range_val(prop->expr->right.sym, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | case S_BOOLEAN: |
| 562 | case S_TRISTATE: |
| 563 | switch (str[0]) { |
| 564 | case 'y': case 'Y': |
| 565 | return sym_tristate_within_range(sym, yes); |
| 566 | case 'm': case 'M': |
| 567 | return sym_tristate_within_range(sym, mod); |
| 568 | case 'n': case 'N': |
| 569 | return sym_tristate_within_range(sym, no); |
| 570 | } |
| 571 | return false; |
| 572 | default: |
| 573 | return false; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | bool sym_set_string_value(struct symbol *sym, const char *newval) |
| 578 | { |
| 579 | const char *oldval; |
| 580 | char *val; |
| 581 | int size; |
| 582 | |
| 583 | switch (sym->type) { |
| 584 | case S_BOOLEAN: |
| 585 | case S_TRISTATE: |
| 586 | switch (newval[0]) { |
| 587 | case 'y': case 'Y': |
| 588 | return sym_set_tristate_value(sym, yes); |
| 589 | case 'm': case 'M': |
| 590 | return sym_set_tristate_value(sym, mod); |
| 591 | case 'n': case 'N': |
| 592 | return sym_set_tristate_value(sym, no); |
| 593 | } |
| 594 | return false; |
| 595 | default: |
| 596 | ; |
| 597 | } |
| 598 | |
| 599 | if (!sym_string_within_range(sym, newval)) |
| 600 | return false; |
| 601 | |
Roman Zippel | 669bfad | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 602 | if (!(sym->flags & SYMBOL_DEF_USER)) { |
| 603 | sym->flags |= SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | sym_set_changed(sym); |
| 605 | } |
| 606 | |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 607 | oldval = sym->def[S_DEF_USER].val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | size = strlen(newval) + 1; |
| 609 | if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) { |
| 610 | size += 2; |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 611 | sym->def[S_DEF_USER].val = val = malloc(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | *val++ = '0'; |
| 613 | *val++ = 'x'; |
| 614 | } else if (!oldval || strcmp(oldval, newval)) |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 615 | sym->def[S_DEF_USER].val = val = malloc(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | else |
| 617 | return true; |
| 618 | |
| 619 | strcpy(val, newval); |
| 620 | free((void *)oldval); |
| 621 | sym_clear_all_valid(); |
| 622 | |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | const char *sym_get_string_value(struct symbol *sym) |
| 627 | { |
| 628 | tristate val; |
| 629 | |
| 630 | switch (sym->type) { |
| 631 | case S_BOOLEAN: |
| 632 | case S_TRISTATE: |
| 633 | val = sym_get_tristate_value(sym); |
| 634 | switch (val) { |
| 635 | case no: |
| 636 | return "n"; |
| 637 | case mod: |
| 638 | return "m"; |
| 639 | case yes: |
| 640 | return "y"; |
| 641 | } |
| 642 | break; |
| 643 | default: |
| 644 | ; |
| 645 | } |
| 646 | return (const char *)sym->curr.val; |
| 647 | } |
| 648 | |
| 649 | bool sym_is_changable(struct symbol *sym) |
| 650 | { |
| 651 | return sym->visible > sym->rev_dep.tri; |
| 652 | } |
| 653 | |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 654 | static unsigned strhash(const char *s) |
| 655 | { |
| 656 | /* fnv32 hash */ |
| 657 | unsigned hash = 2166136261U; |
| 658 | for (; *s; s++) |
| 659 | hash = (hash ^ *s) * 0x01000193; |
| 660 | return hash; |
| 661 | } |
| 662 | |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 663 | struct symbol *sym_lookup(const char *name, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
| 665 | struct symbol *symbol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | char *new_name; |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 667 | int hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | if (name) { |
| 670 | if (name[0] && !name[1]) { |
| 671 | switch (name[0]) { |
| 672 | case 'y': return &symbol_yes; |
| 673 | case 'm': return &symbol_mod; |
| 674 | case 'n': return &symbol_no; |
| 675 | } |
| 676 | } |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 677 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
| 679 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 680 | if (symbol->name && |
| 681 | !strcmp(symbol->name, name) && |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 682 | (flags ? symbol->flags & flags |
| 683 | : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) |
| 684 | return symbol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | new_name = strdup(name); |
| 687 | } else { |
| 688 | new_name = NULL; |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 689 | hash = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | symbol = malloc(sizeof(*symbol)); |
| 693 | memset(symbol, 0, sizeof(*symbol)); |
| 694 | symbol->name = new_name; |
| 695 | symbol->type = S_UNKNOWN; |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 696 | symbol->flags |= flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
| 698 | symbol->next = symbol_hash[hash]; |
| 699 | symbol_hash[hash] = symbol; |
| 700 | |
| 701 | return symbol; |
| 702 | } |
| 703 | |
| 704 | struct symbol *sym_find(const char *name) |
| 705 | { |
| 706 | struct symbol *symbol = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | int hash = 0; |
| 708 | |
| 709 | if (!name) |
| 710 | return NULL; |
| 711 | |
| 712 | if (name[0] && !name[1]) { |
| 713 | switch (name[0]) { |
| 714 | case 'y': return &symbol_yes; |
| 715 | case 'm': return &symbol_mod; |
| 716 | case 'n': return &symbol_no; |
| 717 | } |
| 718 | } |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 719 | hash = strhash(name) % SYMBOL_HASHSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame^] | 722 | if (symbol->name && |
| 723 | !strcmp(symbol->name, name) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | !(symbol->flags & SYMBOL_CONST)) |
| 725 | break; |
| 726 | } |
| 727 | |
| 728 | return symbol; |
| 729 | } |
| 730 | |
| 731 | struct symbol **sym_re_search(const char *pattern) |
| 732 | { |
| 733 | struct symbol *sym, **sym_arr = NULL; |
| 734 | int i, cnt, size; |
| 735 | regex_t re; |
| 736 | |
| 737 | cnt = size = 0; |
| 738 | /* Skip if empty */ |
| 739 | if (strlen(pattern) == 0) |
| 740 | return NULL; |
| 741 | if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) |
| 742 | return NULL; |
| 743 | |
| 744 | for_all_symbols(i, sym) { |
| 745 | if (sym->flags & SYMBOL_CONST || !sym->name) |
| 746 | continue; |
| 747 | if (regexec(&re, sym->name, 0, NULL, 0)) |
| 748 | continue; |
| 749 | if (cnt + 1 >= size) { |
| 750 | void *tmp = sym_arr; |
| 751 | size += 16; |
| 752 | sym_arr = realloc(sym_arr, size * sizeof(struct symbol *)); |
| 753 | if (!sym_arr) { |
| 754 | free(tmp); |
| 755 | return NULL; |
| 756 | } |
| 757 | } |
| 758 | sym_arr[cnt++] = sym; |
| 759 | } |
| 760 | if (sym_arr) |
| 761 | sym_arr[cnt] = NULL; |
| 762 | regfree(&re); |
| 763 | |
| 764 | return sym_arr; |
| 765 | } |
| 766 | |
| 767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | static struct symbol *sym_check_expr_deps(struct expr *e) |
| 769 | { |
| 770 | struct symbol *sym; |
| 771 | |
| 772 | if (!e) |
| 773 | return NULL; |
| 774 | switch (e->type) { |
| 775 | case E_OR: |
| 776 | case E_AND: |
| 777 | sym = sym_check_expr_deps(e->left.expr); |
| 778 | if (sym) |
| 779 | return sym; |
| 780 | return sym_check_expr_deps(e->right.expr); |
| 781 | case E_NOT: |
| 782 | return sym_check_expr_deps(e->left.expr); |
| 783 | case E_EQUAL: |
| 784 | case E_UNEQUAL: |
| 785 | sym = sym_check_deps(e->left.sym); |
| 786 | if (sym) |
| 787 | return sym; |
| 788 | return sym_check_deps(e->right.sym); |
| 789 | case E_SYMBOL: |
| 790 | return sym_check_deps(e->left.sym); |
| 791 | default: |
| 792 | break; |
| 793 | } |
| 794 | printf("Oops! How to check %d?\n", e->type); |
| 795 | return NULL; |
| 796 | } |
| 797 | |
Sam Ravnborg | 5447d34 | 2007-05-06 09:20:10 +0200 | [diff] [blame] | 798 | /* return NULL when dependencies are OK */ |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 799 | static struct symbol *sym_check_sym_deps(struct symbol *sym) |
| 800 | { |
| 801 | struct symbol *sym2; |
| 802 | struct property *prop; |
| 803 | |
| 804 | sym2 = sym_check_expr_deps(sym->rev_dep.expr); |
| 805 | if (sym2) |
| 806 | return sym2; |
| 807 | |
| 808 | for (prop = sym->prop; prop; prop = prop->next) { |
| 809 | if (prop->type == P_CHOICE || prop->type == P_SELECT) |
| 810 | continue; |
| 811 | sym2 = sym_check_expr_deps(prop->visible.expr); |
| 812 | if (sym2) |
| 813 | break; |
| 814 | if (prop->type != P_DEFAULT || sym_is_choice(sym)) |
| 815 | continue; |
| 816 | sym2 = sym_check_expr_deps(prop->expr); |
| 817 | if (sym2) |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | return sym2; |
| 822 | } |
| 823 | |
| 824 | static struct symbol *sym_check_choice_deps(struct symbol *choice) |
| 825 | { |
| 826 | struct symbol *sym, *sym2; |
| 827 | struct property *prop; |
| 828 | struct expr *e; |
| 829 | |
| 830 | prop = sym_get_choice_prop(choice); |
| 831 | expr_list_for_each_sym(prop->expr, e, sym) |
| 832 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 833 | |
| 834 | choice->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 835 | sym2 = sym_check_sym_deps(choice); |
| 836 | choice->flags &= ~SYMBOL_CHECK; |
| 837 | if (sym2) |
| 838 | goto out; |
| 839 | |
| 840 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 841 | sym2 = sym_check_sym_deps(sym); |
| 842 | if (sym2) { |
| 843 | fprintf(stderr, " -> %s", sym->name); |
| 844 | break; |
| 845 | } |
| 846 | } |
| 847 | out: |
| 848 | expr_list_for_each_sym(prop->expr, e, sym) |
| 849 | sym->flags &= ~SYMBOL_CHECK; |
| 850 | |
| 851 | if (sym2 && sym_is_choice_value(sym2) && |
| 852 | prop_get_symbol(sym_get_choice_prop(sym2)) == choice) |
| 853 | sym2 = choice; |
| 854 | |
| 855 | return sym2; |
| 856 | } |
| 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | struct symbol *sym_check_deps(struct symbol *sym) |
| 859 | { |
| 860 | struct symbol *sym2; |
| 861 | struct property *prop; |
| 862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (sym->flags & SYMBOL_CHECK) { |
Sam Ravnborg | 5447d34 | 2007-05-06 09:20:10 +0200 | [diff] [blame] | 864 | fprintf(stderr, "%s:%d:error: found recursive dependency: %s", |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 865 | sym->prop->file->name, sym->prop->lineno, |
| 866 | sym->name ? sym->name : "<choice>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | return sym; |
| 868 | } |
David Gibson | 3f04e7d | 2005-11-08 21:34:46 -0800 | [diff] [blame] | 869 | if (sym->flags & SYMBOL_CHECKED) |
| 870 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 872 | if (sym_is_choice_value(sym)) { |
| 873 | /* for choice groups start the check with main choice symbol */ |
| 874 | prop = sym_get_choice_prop(sym); |
| 875 | sym2 = sym_check_deps(prop_get_symbol(prop)); |
| 876 | } else if (sym_is_choice(sym)) { |
| 877 | sym2 = sym_check_choice_deps(sym); |
| 878 | } else { |
| 879 | sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED); |
| 880 | sym2 = sym_check_sym_deps(sym); |
| 881 | sym->flags &= ~SYMBOL_CHECK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
Roman Zippel | 4898117 | 2008-02-29 05:10:24 +0100 | [diff] [blame] | 883 | |
| 884 | if (sym2) { |
| 885 | fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>"); |
| 886 | if (sym2 == sym) { |
| 887 | fprintf(stderr, "\n"); |
| 888 | zconfnerrs++; |
| 889 | sym2 = NULL; |
| 890 | } |
| 891 | } |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return sym2; |
| 894 | } |
| 895 | |
| 896 | struct property *prop_alloc(enum prop_type type, struct symbol *sym) |
| 897 | { |
| 898 | struct property *prop; |
| 899 | struct property **propp; |
| 900 | |
| 901 | prop = malloc(sizeof(*prop)); |
| 902 | memset(prop, 0, sizeof(*prop)); |
| 903 | prop->type = type; |
| 904 | prop->sym = sym; |
| 905 | prop->file = current_file; |
| 906 | prop->lineno = zconf_lineno(); |
| 907 | |
| 908 | /* append property to the prop list of symbol */ |
| 909 | if (sym) { |
| 910 | for (propp = &sym->prop; *propp; propp = &(*propp)->next) |
| 911 | ; |
| 912 | *propp = prop; |
| 913 | } |
| 914 | |
| 915 | return prop; |
| 916 | } |
| 917 | |
| 918 | struct symbol *prop_get_symbol(struct property *prop) |
| 919 | { |
| 920 | if (prop->expr && (prop->expr->type == E_SYMBOL || |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 921 | prop->expr->type == E_LIST)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | return prop->expr->left.sym; |
| 923 | return NULL; |
| 924 | } |
| 925 | |
| 926 | const char *prop_get_type_name(enum prop_type type) |
| 927 | { |
| 928 | switch (type) { |
| 929 | case P_PROMPT: |
| 930 | return "prompt"; |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 931 | case P_ENV: |
| 932 | return "env"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | case P_COMMENT: |
| 934 | return "comment"; |
| 935 | case P_MENU: |
| 936 | return "menu"; |
| 937 | case P_DEFAULT: |
| 938 | return "default"; |
| 939 | case P_CHOICE: |
| 940 | return "choice"; |
| 941 | case P_SELECT: |
| 942 | return "select"; |
| 943 | case P_RANGE: |
| 944 | return "range"; |
| 945 | case P_UNKNOWN: |
| 946 | break; |
| 947 | } |
| 948 | return "unknown"; |
| 949 | } |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 950 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 951 | static void prop_add_env(const char *env) |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 952 | { |
| 953 | struct symbol *sym, *sym2; |
| 954 | struct property *prop; |
| 955 | char *p; |
| 956 | |
| 957 | sym = current_entry->sym; |
| 958 | sym->flags |= SYMBOL_AUTO; |
| 959 | for_all_properties(sym, prop, P_ENV) { |
| 960 | sym2 = prop_get_symbol(prop); |
| 961 | if (strcmp(sym2->name, env)) |
| 962 | menu_warn(current_entry, "redefining environment symbol from %s", |
| 963 | sym2->name); |
| 964 | return; |
| 965 | } |
| 966 | |
| 967 | prop = prop_alloc(P_ENV, sym); |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 968 | prop->expr = expr_alloc_symbol(sym_lookup(env, SYMBOL_CONST)); |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 969 | |
| 970 | sym_env_list = expr_alloc_one(E_LIST, sym_env_list); |
| 971 | sym_env_list->right.sym = sym; |
| 972 | |
| 973 | p = getenv(env); |
| 974 | if (p) |
| 975 | sym_add_default(sym, p); |
| 976 | else |
| 977 | menu_warn(current_entry, "environment variable %s undefined", env); |
| 978 | } |