lkc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 "expr.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include "lkc_proto.h"
  12. #define SRCTREE "srctree"
  13. #ifndef PACKAGE
  14. #define PACKAGE "linux"
  15. #endif
  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. enum conf_def_mode {
  26. def_default,
  27. def_yes,
  28. def_mod,
  29. def_y2m,
  30. def_m2y,
  31. def_no,
  32. def_random
  33. };
  34. extern int yylineno;
  35. void zconfdump(FILE *out);
  36. void zconf_starthelp(void);
  37. FILE *zconf_fopen(const char *name);
  38. void zconf_initscan(const char *name);
  39. void zconf_nextfile(const char *name);
  40. int zconf_lineno(void);
  41. const char *zconf_curname(void);
  42. /* confdata.c */
  43. const char *conf_get_configname(void);
  44. void sym_set_change_count(int count);
  45. void sym_add_change_count(int count);
  46. bool conf_set_all_new_symbols(enum conf_def_mode mode);
  47. void conf_rewrite_mod_or_yes(enum conf_def_mode mode);
  48. void set_all_choice_values(struct symbol *csym);
  49. /* confdata.c and expr.c */
  50. static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
  51. {
  52. assert(len != 0);
  53. if (fwrite(str, len, count, out) != count)
  54. fprintf(stderr, "Error in writing or end of file.\n");
  55. }
  56. /* menu.c */
  57. void _menu_init(void);
  58. void menu_warn(struct menu *menu, const char *fmt, ...);
  59. struct menu *menu_add_menu(void);
  60. void menu_end_menu(void);
  61. void menu_add_entry(struct symbol *sym);
  62. void menu_add_dep(struct expr *dep);
  63. void menu_add_visibility(struct expr *dep);
  64. struct property *menu_add_prop(enum prop_type type, struct expr *expr, struct expr *dep);
  65. struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
  66. void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
  67. void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
  68. void menu_add_option_modules(void);
  69. void menu_add_option_defconfig_list(void);
  70. void menu_add_option_allnoconfig_y(void);
  71. void menu_finalize(struct menu *parent);
  72. void menu_set_type(int type);
  73. /* util.c */
  74. struct file *file_lookup(const char *name);
  75. void *xmalloc(size_t size);
  76. void *xcalloc(size_t nmemb, size_t size);
  77. void *xrealloc(void *p, size_t size);
  78. char *xstrdup(const char *s);
  79. char *xstrndup(const char *s, size_t n);
  80. /* lexer.l */
  81. int yylex(void);
  82. struct gstr {
  83. size_t len;
  84. char *s;
  85. /*
  86. * when max_width is not zero long lines in string s (if any) get
  87. * wrapped not to exceed the max_width value
  88. */
  89. int max_width;
  90. };
  91. struct gstr str_new(void);
  92. void str_free(struct gstr *gs);
  93. void str_append(struct gstr *gs, const char *s);
  94. void str_printf(struct gstr *gs, const char *fmt, ...);
  95. const char *str_get(struct gstr *gs);
  96. /* symbol.c */
  97. void sym_clear_all_valid(void);
  98. struct symbol *sym_choice_default(struct symbol *sym);
  99. struct property *sym_get_range_prop(struct symbol *sym);
  100. const char *sym_get_string_default(struct symbol *sym);
  101. struct symbol *sym_check_deps(struct symbol *sym);
  102. struct symbol *prop_get_symbol(struct property *prop);
  103. static inline tristate sym_get_tristate_value(struct symbol *sym)
  104. {
  105. return sym->curr.tri;
  106. }
  107. static inline struct symbol *sym_get_choice_value(struct symbol *sym)
  108. {
  109. return (struct symbol *)sym->curr.val;
  110. }
  111. static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
  112. {
  113. return sym_set_tristate_value(chval, yes);
  114. }
  115. static inline bool sym_is_choice(struct symbol *sym)
  116. {
  117. return sym->flags & SYMBOL_CHOICE ? true : false;
  118. }
  119. static inline bool sym_is_choice_value(struct symbol *sym)
  120. {
  121. return sym->flags & SYMBOL_CHOICEVAL ? true : false;
  122. }
  123. static inline bool sym_is_optional(struct symbol *sym)
  124. {
  125. return sym->flags & SYMBOL_OPTIONAL ? true : false;
  126. }
  127. static inline bool sym_has_value(struct symbol *sym)
  128. {
  129. return sym->flags & SYMBOL_DEF_USER ? true : false;
  130. }
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif /* LKC_H */