18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef LKC_H 78c2ecf20Sopenharmony_ci#define LKC_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "expr.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifdef __cplusplus 128c2ecf20Sopenharmony_ciextern "C" { 138c2ecf20Sopenharmony_ci#endif 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "lkc_proto.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define SRCTREE "srctree" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#ifndef PACKAGE 208c2ecf20Sopenharmony_ci#define PACKAGE "linux" 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#ifndef CONFIG_ 248c2ecf20Sopenharmony_ci#define CONFIG_ "CONFIG_" 258c2ecf20Sopenharmony_ci#endif 268c2ecf20Sopenharmony_cistatic inline const char *CONFIG_prefix(void) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci return getenv( "CONFIG_" ) ?: CONFIG_; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci#undef CONFIG_ 318c2ecf20Sopenharmony_ci#define CONFIG_ CONFIG_prefix() 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cienum conf_def_mode { 348c2ecf20Sopenharmony_ci def_default, 358c2ecf20Sopenharmony_ci def_yes, 368c2ecf20Sopenharmony_ci def_mod, 378c2ecf20Sopenharmony_ci def_y2m, 388c2ecf20Sopenharmony_ci def_m2y, 398c2ecf20Sopenharmony_ci def_no, 408c2ecf20Sopenharmony_ci def_random 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciextern int yylineno; 448c2ecf20Sopenharmony_civoid zconfdump(FILE *out); 458c2ecf20Sopenharmony_civoid zconf_starthelp(void); 468c2ecf20Sopenharmony_ciFILE *zconf_fopen(const char *name); 478c2ecf20Sopenharmony_civoid zconf_initscan(const char *name); 488c2ecf20Sopenharmony_civoid zconf_nextfile(const char *name); 498c2ecf20Sopenharmony_ciint zconf_lineno(void); 508c2ecf20Sopenharmony_ciconst char *zconf_curname(void); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* confdata.c */ 538c2ecf20Sopenharmony_ciconst char *conf_get_configname(void); 548c2ecf20Sopenharmony_civoid sym_set_change_count(int count); 558c2ecf20Sopenharmony_civoid sym_add_change_count(int count); 568c2ecf20Sopenharmony_cibool conf_set_all_new_symbols(enum conf_def_mode mode); 578c2ecf20Sopenharmony_civoid conf_rewrite_mod_or_yes(enum conf_def_mode mode); 588c2ecf20Sopenharmony_civoid set_all_choice_values(struct symbol *csym); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* confdata.c and expr.c */ 618c2ecf20Sopenharmony_cistatic inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci assert(len != 0); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci if (fwrite(str, len, count, out) != count) 668c2ecf20Sopenharmony_ci fprintf(stderr, "Error in writing or end of file.\n"); 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* util.c */ 708c2ecf20Sopenharmony_cistruct file *file_lookup(const char *name); 718c2ecf20Sopenharmony_civoid *xmalloc(size_t size); 728c2ecf20Sopenharmony_civoid *xcalloc(size_t nmemb, size_t size); 738c2ecf20Sopenharmony_civoid *xrealloc(void *p, size_t size); 748c2ecf20Sopenharmony_cichar *xstrdup(const char *s); 758c2ecf20Sopenharmony_cichar *xstrndup(const char *s, size_t n); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* lexer.l */ 788c2ecf20Sopenharmony_ciint yylex(void); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistruct gstr { 818c2ecf20Sopenharmony_ci size_t len; 828c2ecf20Sopenharmony_ci char *s; 838c2ecf20Sopenharmony_ci /* 848c2ecf20Sopenharmony_ci * when max_width is not zero long lines in string s (if any) get 858c2ecf20Sopenharmony_ci * wrapped not to exceed the max_width value 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ci int max_width; 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_cistruct gstr str_new(void); 908c2ecf20Sopenharmony_civoid str_free(struct gstr *gs); 918c2ecf20Sopenharmony_civoid str_append(struct gstr *gs, const char *s); 928c2ecf20Sopenharmony_civoid str_printf(struct gstr *gs, const char *fmt, ...); 938c2ecf20Sopenharmony_ciconst char *str_get(struct gstr *gs); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* menu.c */ 968c2ecf20Sopenharmony_civoid _menu_init(void); 978c2ecf20Sopenharmony_civoid menu_warn(struct menu *menu, const char *fmt, ...); 988c2ecf20Sopenharmony_cistruct menu *menu_add_menu(void); 998c2ecf20Sopenharmony_civoid menu_end_menu(void); 1008c2ecf20Sopenharmony_civoid menu_add_entry(struct symbol *sym); 1018c2ecf20Sopenharmony_civoid menu_add_dep(struct expr *dep); 1028c2ecf20Sopenharmony_civoid menu_add_visibility(struct expr *dep); 1038c2ecf20Sopenharmony_cistruct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); 1048c2ecf20Sopenharmony_civoid menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); 1058c2ecf20Sopenharmony_civoid menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); 1068c2ecf20Sopenharmony_civoid menu_add_option_modules(void); 1078c2ecf20Sopenharmony_civoid menu_add_option_defconfig_list(void); 1088c2ecf20Sopenharmony_civoid menu_add_option_allnoconfig_y(void); 1098c2ecf20Sopenharmony_civoid menu_finalize(struct menu *parent); 1108c2ecf20Sopenharmony_civoid menu_set_type(int type); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciextern struct menu rootmenu; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cibool menu_is_empty(struct menu *menu); 1158c2ecf20Sopenharmony_cibool menu_is_visible(struct menu *menu); 1168c2ecf20Sopenharmony_cibool menu_has_prompt(struct menu *menu); 1178c2ecf20Sopenharmony_ciconst char *menu_get_prompt(struct menu *menu); 1188c2ecf20Sopenharmony_cistruct menu *menu_get_root_menu(struct menu *menu); 1198c2ecf20Sopenharmony_cistruct menu *menu_get_parent_menu(struct menu *menu); 1208c2ecf20Sopenharmony_cibool menu_has_help(struct menu *menu); 1218c2ecf20Sopenharmony_ciconst char *menu_get_help(struct menu *menu); 1228c2ecf20Sopenharmony_cistruct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head); 1238c2ecf20Sopenharmony_civoid menu_get_ext_help(struct menu *menu, struct gstr *help); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* symbol.c */ 1268c2ecf20Sopenharmony_civoid sym_clear_all_valid(void); 1278c2ecf20Sopenharmony_cistruct symbol *sym_choice_default(struct symbol *sym); 1288c2ecf20Sopenharmony_cistruct property *sym_get_range_prop(struct symbol *sym); 1298c2ecf20Sopenharmony_ciconst char *sym_get_string_default(struct symbol *sym); 1308c2ecf20Sopenharmony_cistruct symbol *sym_check_deps(struct symbol *sym); 1318c2ecf20Sopenharmony_cistruct symbol *prop_get_symbol(struct property *prop); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline tristate sym_get_tristate_value(struct symbol *sym) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci return sym->curr.tri; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic inline struct symbol *sym_get_choice_value(struct symbol *sym) 1408c2ecf20Sopenharmony_ci{ 1418c2ecf20Sopenharmony_ci return (struct symbol *)sym->curr.val; 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval) 1458c2ecf20Sopenharmony_ci{ 1468c2ecf20Sopenharmony_ci return sym_set_tristate_value(chval, yes); 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic inline bool sym_is_choice(struct symbol *sym) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci return sym->flags & SYMBOL_CHOICE ? true : false; 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline bool sym_is_choice_value(struct symbol *sym) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci return sym->flags & SYMBOL_CHOICEVAL ? true : false; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic inline bool sym_is_optional(struct symbol *sym) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci return sym->flags & SYMBOL_OPTIONAL ? true : false; 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic inline bool sym_has_value(struct symbol *sym) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci return sym->flags & SYMBOL_DEF_USER ? true : false; 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci#ifdef __cplusplus 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci#endif 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#endif /* LKC_H */ 174