lkc.h 3.9 KB

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