lkc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2002 Roman Zippel <[email protected]>
  4. */
  5. #ifndef LKC_H
  6. #define LKC_H
  7. #include <assert.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "expr.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include "lkc_proto.h"
  15. #define SRCTREE "srctree"
  16. #ifndef CONFIG_
  17. #define CONFIG_ "CONFIG_"
  18. #endif
  19. static inline const char *CONFIG_prefix(void)
  20. {
  21. return getenv( "CONFIG_" ) ?: CONFIG_;
  22. }
  23. #undef CONFIG_
  24. #define CONFIG_ CONFIG_prefix()
  25. extern int yylineno;
  26. void zconfdump(FILE *out);
  27. void zconf_starthelp(void);
  28. FILE *zconf_fopen(const char *name);
  29. void zconf_initscan(const char *name);
  30. void zconf_nextfile(const char *name);
  31. int zconf_lineno(void);
  32. const char *zconf_curname(void);
  33. /* confdata.c */
  34. const char *conf_get_configname(void);
  35. void set_all_choice_values(struct symbol *csym);
  36. /* confdata.c and expr.c */
  37. static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
  38. {
  39. assert(len != 0);
  40. if (fwrite(str, len, count, out) != count)
  41. fprintf(stderr, "Error in writing or end of file.\n");
  42. }
  43. /* util.c */
  44. struct file *file_lookup(const char *name);
  45. void *xmalloc(size_t size);
  46. void *xcalloc(size_t nmemb, size_t size);
  47. void *xrealloc(void *p, size_t size);
  48. char *xstrdup(const char *s);
  49. char *xstrndup(const char *s, size_t n);
  50. /* lexer.l */
  51. int yylex(void);
  52. struct gstr {
  53. size_t len;
  54. char *s;
  55. /*
  56. * when max_width is not zero long lines in string s (if any) get
  57. * wrapped not to exceed the max_width value
  58. */
  59. int max_width;
  60. };
  61. struct gstr str_new(void);
  62. void str_free(struct gstr *gs);
  63. void str_append(struct gstr *gs, const char *s);
  64. void str_printf(struct gstr *gs, const char *fmt, ...);
  65. const char *str_get(struct gstr *gs);
  66. /* menu.c */
  67. void _menu_init(void);
  68. void menu_warn(struct menu *menu, const char *fmt, ...);
  69. struct menu *menu_add_menu(void);
  70. void menu_end_menu(void);
  71. void menu_add_entry(struct symbol *sym);
  72. void menu_add_dep(struct expr *dep);
  73. void menu_add_visibility(struct expr *dep);
  74. struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
  75. void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
  76. void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
  77. void menu_finalize(struct menu *parent);
  78. void menu_set_type(int type);
  79. extern struct menu rootmenu;
  80. bool menu_is_empty(struct menu *menu);
  81. bool menu_is_visible(struct menu *menu);
  82. bool menu_has_prompt(struct menu *menu);
  83. const char *menu_get_prompt(struct menu *menu);
  84. struct menu *menu_get_parent_menu(struct menu *menu);
  85. bool menu_has_help(struct menu *menu);
  86. const char *menu_get_help(struct menu *menu);
  87. struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
  88. void menu_get_ext_help(struct menu *menu, struct gstr *help);
  89. /* symbol.c */
  90. void sym_clear_all_valid(void);
  91. struct symbol *sym_choice_default(struct symbol *sym);
  92. struct property *sym_get_range_prop(struct symbol *sym);
  93. const char *sym_get_string_default(struct symbol *sym);
  94. struct symbol *sym_check_deps(struct symbol *sym);
  95. struct symbol *prop_get_symbol(struct property *prop);
  96. static inline tristate sym_get_tristate_value(struct symbol *sym)
  97. {
  98. return sym->curr.tri;
  99. }
  100. static inline struct symbol *sym_get_choice_value(struct symbol *sym)
  101. {
  102. return (struct symbol *)sym->curr.val;
  103. }
  104. static inline bool sym_is_choice(struct symbol *sym)
  105. {
  106. return sym->flags & SYMBOL_CHOICE ? true : false;
  107. }
  108. static inline bool sym_is_choice_value(struct symbol *sym)
  109. {
  110. return sym->flags & SYMBOL_CHOICEVAL ? true : false;
  111. }
  112. static inline bool sym_is_optional(struct symbol *sym)
  113. {
  114. return sym->flags & SYMBOL_OPTIONAL ? true : false;
  115. }
  116. static inline bool sym_has_value(struct symbol *sym)
  117. {
  118. return sym->flags & SYMBOL_DEF_USER ? true : false;
  119. }
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif /* LKC_H */