lkc.h 4.0 KB

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