symbol.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  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. #define LKC_DIRECT_LINK
  11. #include "lkc.h"
  12. struct symbol symbol_yes = {
  13. .name = "y",
  14. .curr = { "y", yes },
  15. .flags = SYMBOL_YES|SYMBOL_VALID,
  16. }, symbol_mod = {
  17. .name = "m",
  18. .curr = { "m", mod },
  19. .flags = SYMBOL_MOD|SYMBOL_VALID,
  20. }, symbol_no = {
  21. .name = "n",
  22. .curr = { "n", no },
  23. .flags = SYMBOL_NO|SYMBOL_VALID,
  24. }, symbol_empty = {
  25. .name = "",
  26. .curr = { "", no },
  27. .flags = SYMBOL_VALID,
  28. };
  29. int sym_change_count;
  30. struct symbol *modules_sym;
  31. tristate modules_val;
  32. 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, 1));
  36. }
  37. void sym_init(void)
  38. {
  39. struct symbol *sym;
  40. struct utsname uts;
  41. char *p;
  42. static bool inited = false;
  43. if (inited)
  44. return;
  45. inited = true;
  46. uname(&uts);
  47. sym = sym_lookup("ARCH", 0);
  48. sym->type = S_STRING;
  49. sym->flags |= SYMBOL_AUTO;
  50. p = getenv("ARCH");
  51. if (p)
  52. sym_add_default(sym, p);
  53. sym = sym_lookup("KERNELRELEASE", 0);
  54. sym->type = S_STRING;
  55. sym->flags |= SYMBOL_AUTO;
  56. p = getenv("KERNELRELEASE");
  57. if (p)
  58. sym_add_default(sym, p);
  59. sym = sym_lookup("UNAME_RELEASE", 0);
  60. sym->type = S_STRING;
  61. sym->flags |= SYMBOL_AUTO;
  62. sym_add_default(sym, uts.release);
  63. }
  64. enum symbol_type sym_get_type(struct symbol *sym)
  65. {
  66. enum symbol_type type = sym->type;
  67. if (type == S_TRISTATE) {
  68. if (sym_is_choice_value(sym) && sym->visible == yes)
  69. type = S_BOOLEAN;
  70. else if (modules_val == no)
  71. type = S_BOOLEAN;
  72. }
  73. return type;
  74. }
  75. const char *sym_type_name(enum symbol_type type)
  76. {
  77. switch (type) {
  78. case S_BOOLEAN:
  79. return "boolean";
  80. case S_TRISTATE:
  81. return "tristate";
  82. case S_INT:
  83. return "integer";
  84. case S_HEX:
  85. return "hex";
  86. case S_STRING:
  87. return "string";
  88. case S_UNKNOWN:
  89. return "unknown";
  90. case S_OTHER:
  91. break;
  92. }
  93. return "???";
  94. }
  95. struct property *sym_get_choice_prop(struct symbol *sym)
  96. {
  97. struct property *prop;
  98. for_all_choices(sym, prop)
  99. return prop;
  100. return NULL;
  101. }
  102. struct property *sym_get_default_prop(struct symbol *sym)
  103. {
  104. struct property *prop;
  105. for_all_defaults(sym, prop) {
  106. prop->visible.tri = expr_calc_value(prop->visible.expr);
  107. if (prop->visible.tri != no)
  108. return prop;
  109. }
  110. return NULL;
  111. }
  112. struct property *sym_get_range_prop(struct symbol *sym)
  113. {
  114. struct property *prop;
  115. for_all_properties(sym, prop, P_RANGE) {
  116. prop->visible.tri = expr_calc_value(prop->visible.expr);
  117. if (prop->visible.tri != no)
  118. return prop;
  119. }
  120. return NULL;
  121. }
  122. static void sym_calc_visibility(struct symbol *sym)
  123. {
  124. struct property *prop;
  125. tristate tri;
  126. /* any prompt visible? */
  127. tri = no;
  128. for_all_prompts(sym, prop) {
  129. prop->visible.tri = expr_calc_value(prop->visible.expr);
  130. tri = E_OR(tri, prop->visible.tri);
  131. }
  132. if (tri == mod && (sym->type != S_TRISTATE || modules_val == no))
  133. tri = yes;
  134. if (sym->visible != tri) {
  135. sym->visible = tri;
  136. sym_set_changed(sym);
  137. }
  138. if (sym_is_choice_value(sym))
  139. return;
  140. tri = no;
  141. if (sym->rev_dep.expr)
  142. tri = expr_calc_value(sym->rev_dep.expr);
  143. if (tri == mod && sym_get_type(sym) == S_BOOLEAN)
  144. tri = yes;
  145. if (sym->rev_dep.tri != tri) {
  146. sym->rev_dep.tri = tri;
  147. sym_set_changed(sym);
  148. }
  149. }
  150. static struct symbol *sym_calc_choice(struct symbol *sym)
  151. {
  152. struct symbol *def_sym;
  153. struct property *prop;
  154. struct expr *e;
  155. /* is the user choice visible? */
  156. def_sym = sym->user.val;
  157. if (def_sym) {
  158. sym_calc_visibility(def_sym);
  159. if (def_sym->visible != no)
  160. return def_sym;
  161. }
  162. /* any of the defaults visible? */
  163. for_all_defaults(sym, prop) {
  164. prop->visible.tri = expr_calc_value(prop->visible.expr);
  165. if (prop->visible.tri == no)
  166. continue;
  167. def_sym = prop_get_symbol(prop);
  168. sym_calc_visibility(def_sym);
  169. if (def_sym->visible != no)
  170. return def_sym;
  171. }
  172. /* just get the first visible value */
  173. prop = sym_get_choice_prop(sym);
  174. for (e = prop->expr; e; e = e->left.expr) {
  175. def_sym = e->right.sym;
  176. sym_calc_visibility(def_sym);
  177. if (def_sym->visible != no)
  178. return def_sym;
  179. }
  180. /* no choice? reset tristate value */
  181. sym->curr.tri = no;
  182. return NULL;
  183. }
  184. void sym_calc_value(struct symbol *sym)
  185. {
  186. struct symbol_value newval, oldval;
  187. struct property *prop;
  188. struct expr *e;
  189. if (!sym)
  190. return;
  191. if (sym->flags & SYMBOL_VALID)
  192. return;
  193. sym->flags |= SYMBOL_VALID;
  194. oldval = sym->curr;
  195. switch (sym->type) {
  196. case S_INT:
  197. case S_HEX:
  198. case S_STRING:
  199. newval = symbol_empty.curr;
  200. break;
  201. case S_BOOLEAN:
  202. case S_TRISTATE:
  203. newval = symbol_no.curr;
  204. break;
  205. default:
  206. sym->curr.val = sym->name;
  207. sym->curr.tri = no;
  208. return;
  209. }
  210. if (!sym_is_choice_value(sym))
  211. sym->flags &= ~SYMBOL_WRITE;
  212. sym_calc_visibility(sym);
  213. /* set default if recursively called */
  214. sym->curr = newval;
  215. switch (sym_get_type(sym)) {
  216. case S_BOOLEAN:
  217. case S_TRISTATE:
  218. if (sym_is_choice_value(sym) && sym->visible == yes) {
  219. prop = sym_get_choice_prop(sym);
  220. newval.tri = (prop_get_symbol(prop)->curr.val == sym) ? yes : no;
  221. } else if (E_OR(sym->visible, sym->rev_dep.tri) != no) {
  222. sym->flags |= SYMBOL_WRITE;
  223. if (sym_has_value(sym))
  224. newval.tri = sym->user.tri;
  225. else if (!sym_is_choice(sym)) {
  226. prop = sym_get_default_prop(sym);
  227. if (prop)
  228. newval.tri = expr_calc_value(prop->expr);
  229. }
  230. newval.tri = E_OR(E_AND(newval.tri, sym->visible), sym->rev_dep.tri);
  231. } else if (!sym_is_choice(sym)) {
  232. prop = sym_get_default_prop(sym);
  233. if (prop) {
  234. sym->flags |= SYMBOL_WRITE;
  235. newval.tri = expr_calc_value(prop->expr);
  236. }
  237. }
  238. if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
  239. newval.tri = yes;
  240. break;
  241. case S_STRING:
  242. case S_HEX:
  243. case S_INT:
  244. if (sym->visible != no) {
  245. sym->flags |= SYMBOL_WRITE;
  246. if (sym_has_value(sym)) {
  247. newval.val = sym->user.val;
  248. break;
  249. }
  250. }
  251. prop = sym_get_default_prop(sym);
  252. if (prop) {
  253. struct symbol *ds = prop_get_symbol(prop);
  254. if (ds) {
  255. sym->flags |= SYMBOL_WRITE;
  256. sym_calc_value(ds);
  257. newval.val = ds->curr.val;
  258. }
  259. }
  260. break;
  261. default:
  262. ;
  263. }
  264. sym->curr = newval;
  265. if (sym_is_choice(sym) && newval.tri == yes)
  266. sym->curr.val = sym_calc_choice(sym);
  267. if (memcmp(&oldval, &sym->curr, sizeof(oldval)))
  268. sym_set_changed(sym);
  269. if (modules_sym == sym)
  270. modules_val = modules_sym->curr.tri;
  271. if (sym_is_choice(sym)) {
  272. int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE);
  273. prop = sym_get_choice_prop(sym);
  274. for (e = prop->expr; e; e = e->left.expr) {
  275. e->right.sym->flags |= flags;
  276. if (flags & SYMBOL_CHANGED)
  277. sym_set_changed(e->right.sym);
  278. }
  279. }
  280. }
  281. void sym_clear_all_valid(void)
  282. {
  283. struct symbol *sym;
  284. int i;
  285. for_all_symbols(i, sym)
  286. sym->flags &= ~SYMBOL_VALID;
  287. sym_change_count++;
  288. if (modules_sym)
  289. sym_calc_value(modules_sym);
  290. }
  291. void sym_set_changed(struct symbol *sym)
  292. {
  293. struct property *prop;
  294. sym->flags |= SYMBOL_CHANGED;
  295. for (prop = sym->prop; prop; prop = prop->next) {
  296. if (prop->menu)
  297. prop->menu->flags |= MENU_CHANGED;
  298. }
  299. }
  300. void sym_set_all_changed(void)
  301. {
  302. struct symbol *sym;
  303. int i;
  304. for_all_symbols(i, sym)
  305. sym_set_changed(sym);
  306. }
  307. bool sym_tristate_within_range(struct symbol *sym, tristate val)
  308. {
  309. int type = sym_get_type(sym);
  310. if (sym->visible == no)
  311. return false;
  312. if (type != S_BOOLEAN && type != S_TRISTATE)
  313. return false;
  314. if (type == S_BOOLEAN && val == mod)
  315. return false;
  316. if (sym->visible <= sym->rev_dep.tri)
  317. return false;
  318. if (sym_is_choice_value(sym) && sym->visible == yes)
  319. return val == yes;
  320. return val >= sym->rev_dep.tri && val <= sym->visible;
  321. }
  322. bool sym_set_tristate_value(struct symbol *sym, tristate val)
  323. {
  324. tristate oldval = sym_get_tristate_value(sym);
  325. if (oldval != val && !sym_tristate_within_range(sym, val))
  326. return false;
  327. if (sym->flags & SYMBOL_NEW) {
  328. sym->flags &= ~SYMBOL_NEW;
  329. sym_set_changed(sym);
  330. }
  331. if (sym_is_choice_value(sym) && val == yes) {
  332. struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
  333. cs->user.val = sym;
  334. cs->flags &= ~SYMBOL_NEW;
  335. }
  336. sym->user.tri = val;
  337. if (oldval != val) {
  338. sym_clear_all_valid();
  339. if (sym == modules_sym)
  340. sym_set_all_changed();
  341. }
  342. return true;
  343. }
  344. tristate sym_toggle_tristate_value(struct symbol *sym)
  345. {
  346. tristate oldval, newval;
  347. oldval = newval = sym_get_tristate_value(sym);
  348. do {
  349. switch (newval) {
  350. case no:
  351. newval = mod;
  352. break;
  353. case mod:
  354. newval = yes;
  355. break;
  356. case yes:
  357. newval = no;
  358. break;
  359. }
  360. if (sym_set_tristate_value(sym, newval))
  361. break;
  362. } while (oldval != newval);
  363. return newval;
  364. }
  365. bool sym_string_valid(struct symbol *sym, const char *str)
  366. {
  367. signed char ch;
  368. switch (sym->type) {
  369. case S_STRING:
  370. return true;
  371. case S_INT:
  372. ch = *str++;
  373. if (ch == '-')
  374. ch = *str++;
  375. if (!isdigit(ch))
  376. return false;
  377. if (ch == '0' && *str != 0)
  378. return false;
  379. while ((ch = *str++)) {
  380. if (!isdigit(ch))
  381. return false;
  382. }
  383. return true;
  384. case S_HEX:
  385. if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
  386. str += 2;
  387. ch = *str++;
  388. do {
  389. if (!isxdigit(ch))
  390. return false;
  391. } while ((ch = *str++));
  392. return true;
  393. case S_BOOLEAN:
  394. case S_TRISTATE:
  395. switch (str[0]) {
  396. case 'y': case 'Y':
  397. case 'm': case 'M':
  398. case 'n': case 'N':
  399. return true;
  400. }
  401. return false;
  402. default:
  403. return false;
  404. }
  405. }
  406. bool sym_string_within_range(struct symbol *sym, const char *str)
  407. {
  408. struct property *prop;
  409. int val;
  410. switch (sym->type) {
  411. case S_STRING:
  412. return sym_string_valid(sym, str);
  413. case S_INT:
  414. if (!sym_string_valid(sym, str))
  415. return false;
  416. prop = sym_get_range_prop(sym);
  417. if (!prop)
  418. return true;
  419. val = strtol(str, NULL, 10);
  420. return val >= strtol(prop->expr->left.sym->name, NULL, 10) &&
  421. val <= strtol(prop->expr->right.sym->name, NULL, 10);
  422. case S_HEX:
  423. if (!sym_string_valid(sym, str))
  424. return false;
  425. prop = sym_get_range_prop(sym);
  426. if (!prop)
  427. return true;
  428. val = strtol(str, NULL, 16);
  429. return val >= strtol(prop->expr->left.sym->name, NULL, 16) &&
  430. val <= strtol(prop->expr->right.sym->name, NULL, 16);
  431. case S_BOOLEAN:
  432. case S_TRISTATE:
  433. switch (str[0]) {
  434. case 'y': case 'Y':
  435. return sym_tristate_within_range(sym, yes);
  436. case 'm': case 'M':
  437. return sym_tristate_within_range(sym, mod);
  438. case 'n': case 'N':
  439. return sym_tristate_within_range(sym, no);
  440. }
  441. return false;
  442. default:
  443. return false;
  444. }
  445. }
  446. bool sym_set_string_value(struct symbol *sym, const char *newval)
  447. {
  448. const char *oldval;
  449. char *val;
  450. int size;
  451. switch (sym->type) {
  452. case S_BOOLEAN:
  453. case S_TRISTATE:
  454. switch (newval[0]) {
  455. case 'y': case 'Y':
  456. return sym_set_tristate_value(sym, yes);
  457. case 'm': case 'M':
  458. return sym_set_tristate_value(sym, mod);
  459. case 'n': case 'N':
  460. return sym_set_tristate_value(sym, no);
  461. }
  462. return false;
  463. default:
  464. ;
  465. }
  466. if (!sym_string_within_range(sym, newval))
  467. return false;
  468. if (sym->flags & SYMBOL_NEW) {
  469. sym->flags &= ~SYMBOL_NEW;
  470. sym_set_changed(sym);
  471. }
  472. oldval = sym->user.val;
  473. size = strlen(newval) + 1;
  474. if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
  475. size += 2;
  476. sym->user.val = val = malloc(size);
  477. *val++ = '0';
  478. *val++ = 'x';
  479. } else if (!oldval || strcmp(oldval, newval))
  480. sym->user.val = val = malloc(size);
  481. else
  482. return true;
  483. strcpy(val, newval);
  484. free((void *)oldval);
  485. sym_clear_all_valid();
  486. return true;
  487. }
  488. const char *sym_get_string_value(struct symbol *sym)
  489. {
  490. tristate val;
  491. switch (sym->type) {
  492. case S_BOOLEAN:
  493. case S_TRISTATE:
  494. val = sym_get_tristate_value(sym);
  495. switch (val) {
  496. case no:
  497. return "n";
  498. case mod:
  499. return "m";
  500. case yes:
  501. return "y";
  502. }
  503. break;
  504. default:
  505. ;
  506. }
  507. return (const char *)sym->curr.val;
  508. }
  509. bool sym_is_changable(struct symbol *sym)
  510. {
  511. return sym->visible > sym->rev_dep.tri;
  512. }
  513. struct symbol *sym_lookup(const char *name, int isconst)
  514. {
  515. struct symbol *symbol;
  516. const char *ptr;
  517. char *new_name;
  518. int hash = 0;
  519. if (name) {
  520. if (name[0] && !name[1]) {
  521. switch (name[0]) {
  522. case 'y': return &symbol_yes;
  523. case 'm': return &symbol_mod;
  524. case 'n': return &symbol_no;
  525. }
  526. }
  527. for (ptr = name; *ptr; ptr++)
  528. hash += *ptr;
  529. hash &= 0xff;
  530. for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
  531. if (!strcmp(symbol->name, name)) {
  532. if ((isconst && symbol->flags & SYMBOL_CONST) ||
  533. (!isconst && !(symbol->flags & SYMBOL_CONST)))
  534. return symbol;
  535. }
  536. }
  537. new_name = strdup(name);
  538. } else {
  539. new_name = NULL;
  540. hash = 256;
  541. }
  542. symbol = malloc(sizeof(*symbol));
  543. memset(symbol, 0, sizeof(*symbol));
  544. symbol->name = new_name;
  545. symbol->type = S_UNKNOWN;
  546. symbol->flags = SYMBOL_NEW;
  547. if (isconst)
  548. symbol->flags |= SYMBOL_CONST;
  549. symbol->next = symbol_hash[hash];
  550. symbol_hash[hash] = symbol;
  551. return symbol;
  552. }
  553. struct symbol *sym_find(const char *name)
  554. {
  555. struct symbol *symbol = NULL;
  556. const char *ptr;
  557. int hash = 0;
  558. if (!name)
  559. return NULL;
  560. if (name[0] && !name[1]) {
  561. switch (name[0]) {
  562. case 'y': return &symbol_yes;
  563. case 'm': return &symbol_mod;
  564. case 'n': return &symbol_no;
  565. }
  566. }
  567. for (ptr = name; *ptr; ptr++)
  568. hash += *ptr;
  569. hash &= 0xff;
  570. for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
  571. if (!strcmp(symbol->name, name) &&
  572. !(symbol->flags & SYMBOL_CONST))
  573. break;
  574. }
  575. return symbol;
  576. }
  577. struct symbol **sym_re_search(const char *pattern)
  578. {
  579. struct symbol *sym, **sym_arr = NULL;
  580. int i, cnt, size;
  581. regex_t re;
  582. cnt = size = 0;
  583. /* Skip if empty */
  584. if (strlen(pattern) == 0)
  585. return NULL;
  586. if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE))
  587. return NULL;
  588. for_all_symbols(i, sym) {
  589. if (sym->flags & SYMBOL_CONST || !sym->name)
  590. continue;
  591. if (regexec(&re, sym->name, 0, NULL, 0))
  592. continue;
  593. if (cnt + 1 >= size) {
  594. void *tmp = sym_arr;
  595. size += 16;
  596. sym_arr = realloc(sym_arr, size * sizeof(struct symbol *));
  597. if (!sym_arr) {
  598. free(tmp);
  599. return NULL;
  600. }
  601. }
  602. sym_arr[cnt++] = sym;
  603. }
  604. if (sym_arr)
  605. sym_arr[cnt] = NULL;
  606. regfree(&re);
  607. return sym_arr;
  608. }
  609. struct symbol *sym_check_deps(struct symbol *sym);
  610. static struct symbol *sym_check_expr_deps(struct expr *e)
  611. {
  612. struct symbol *sym;
  613. if (!e)
  614. return NULL;
  615. switch (e->type) {
  616. case E_OR:
  617. case E_AND:
  618. sym = sym_check_expr_deps(e->left.expr);
  619. if (sym)
  620. return sym;
  621. return sym_check_expr_deps(e->right.expr);
  622. case E_NOT:
  623. return sym_check_expr_deps(e->left.expr);
  624. case E_EQUAL:
  625. case E_UNEQUAL:
  626. sym = sym_check_deps(e->left.sym);
  627. if (sym)
  628. return sym;
  629. return sym_check_deps(e->right.sym);
  630. case E_SYMBOL:
  631. return sym_check_deps(e->left.sym);
  632. default:
  633. break;
  634. }
  635. printf("Oops! How to check %d?\n", e->type);
  636. return NULL;
  637. }
  638. struct symbol *sym_check_deps(struct symbol *sym)
  639. {
  640. struct symbol *sym2;
  641. struct property *prop;
  642. if (sym->flags & SYMBOL_CHECK_DONE)
  643. return NULL;
  644. if (sym->flags & SYMBOL_CHECK) {
  645. printf("Warning! Found recursive dependency: %s", sym->name);
  646. return sym;
  647. }
  648. sym->flags |= (SYMBOL_CHECK | SYMBOL_CHECKED);
  649. sym2 = sym_check_expr_deps(sym->rev_dep.expr);
  650. if (sym2)
  651. goto out;
  652. for (prop = sym->prop; prop; prop = prop->next) {
  653. if (prop->type == P_CHOICE || prop->type == P_SELECT)
  654. continue;
  655. sym2 = sym_check_expr_deps(prop->visible.expr);
  656. if (sym2)
  657. goto out;
  658. if (prop->type != P_DEFAULT || sym_is_choice(sym))
  659. continue;
  660. sym2 = sym_check_expr_deps(prop->expr);
  661. if (sym2)
  662. goto out;
  663. }
  664. out:
  665. if (sym2)
  666. printf(" %s", sym->name);
  667. sym->flags &= ~SYMBOL_CHECK;
  668. return sym2;
  669. }
  670. struct property *prop_alloc(enum prop_type type, struct symbol *sym)
  671. {
  672. struct property *prop;
  673. struct property **propp;
  674. prop = malloc(sizeof(*prop));
  675. memset(prop, 0, sizeof(*prop));
  676. prop->type = type;
  677. prop->sym = sym;
  678. prop->file = current_file;
  679. prop->lineno = zconf_lineno();
  680. /* append property to the prop list of symbol */
  681. if (sym) {
  682. for (propp = &sym->prop; *propp; propp = &(*propp)->next)
  683. ;
  684. *propp = prop;
  685. }
  686. return prop;
  687. }
  688. struct symbol *prop_get_symbol(struct property *prop)
  689. {
  690. if (prop->expr && (prop->expr->type == E_SYMBOL ||
  691. prop->expr->type == E_CHOICE))
  692. return prop->expr->left.sym;
  693. return NULL;
  694. }
  695. const char *prop_get_type_name(enum prop_type type)
  696. {
  697. switch (type) {
  698. case P_PROMPT:
  699. return "prompt";
  700. case P_COMMENT:
  701. return "comment";
  702. case P_MENU:
  703. return "menu";
  704. case P_DEFAULT:
  705. return "default";
  706. case P_CHOICE:
  707. return "choice";
  708. case P_SELECT:
  709. return "select";
  710. case P_RANGE:
  711. return "range";
  712. case P_UNKNOWN:
  713. break;
  714. }
  715. return "unknown";
  716. }