symbol.c 31 KB

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