blob: 68dc8475b8f5afe27796e2a94576633d6265b582 [file] [log] [blame]
Patrick Georgi53ea1d42019-11-22 16:55:58 +01001/* SPDX-License-Identifier: GPL-2.0 */
Patrick Georgi0588d192009-08-12 15:00:51 +00002/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
Patrick Georgi0588d192009-08-12 15:00:51 +00004 */
5
6#ifndef LKC_H
7#define LKC_H
8
Patrick Georgi53ea1d42019-11-22 16:55:58 +01009#include <assert.h>
10#include <stdio.h>
11#include <stdlib.h>
Patrick Georgi0588d192009-08-12 15:00:51 +000012
Patrick Georgi53ea1d42019-11-22 16:55:58 +010013#include "expr.h"
Patrick Georgi0588d192009-08-12 15:00:51 +000014
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Patrick Georgi0588d192009-08-12 15:00:51 +000019#include "lkc_proto.h"
Patrick Georgi0588d192009-08-12 15:00:51 +000020
Patrick Georgid5208402014-04-11 20:24:06 +020021#define SRCTREE "srctree"
Patrick Georgi0588d192009-08-12 15:00:51 +000022
Patrick Georgid5208402014-04-11 20:24:06 +020023#ifndef CONFIG_
24#define CONFIG_ "CONFIG_"
25#endif
26static inline const char *CONFIG_prefix(void)
27{
28 return getenv( "CONFIG_" ) ?: CONFIG_;
29}
30#undef CONFIG_
31#define CONFIG_ CONFIG_prefix()
Patrick Georgi0588d192009-08-12 15:00:51 +000032
Patrick Georgi53ea1d42019-11-22 16:55:58 +010033extern int yylineno;
Patrick Georgi0588d192009-08-12 15:00:51 +000034void zconfdump(FILE *out);
Patrick Georgi0588d192009-08-12 15:00:51 +000035void zconf_starthelp(void);
36FILE *zconf_fopen(const char *name);
37void zconf_initscan(const char *name);
38void zconf_nextfile(const char *name);
Stefan Reinauerf78a09b2015-04-03 20:01:38 +020039void zconf_nextfiles(const char *name);
Patrick Georgi0588d192009-08-12 15:00:51 +000040int zconf_lineno(void);
Patrick Georgid5208402014-04-11 20:24:06 +020041const char *zconf_curname(void);
Patrick Georgi0588d192009-08-12 15:00:51 +000042
Stefan Reinauer57a31312015-08-20 11:19:34 -070043/* conf.c */
44extern int kconfig_warnings;
45
Patrick Georgi0588d192009-08-12 15:00:51 +000046/* confdata.c */
47const char *conf_get_configname(void);
Patrick Georgid5208402014-04-11 20:24:06 +020048void set_all_choice_values(struct symbol *csym);
Patrick Georgi0588d192009-08-12 15:00:51 +000049
Patrick Georgid5208402014-04-11 20:24:06 +020050/* confdata.c and expr.c */
51static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
52{
53 assert(len != 0);
54
55 if (fwrite(str, len, count, out) != count)
56 fprintf(stderr, "Error in writing or end of file.\n");
57}
Patrick Georgi0588d192009-08-12 15:00:51 +000058
Patrick Georgi0588d192009-08-12 15:00:51 +000059/* util.c */
60struct file *file_lookup(const char *name);
Patrick Georgid5208402014-04-11 20:24:06 +020061void *xmalloc(size_t size);
62void *xcalloc(size_t nmemb, size_t size);
Patrick Georgi53ea1d42019-11-22 16:55:58 +010063void *xrealloc(void *p, size_t size);
64char *xstrdup(const char *s);
65char *xstrndup(const char *s, size_t n);
66
67/* lexer.l */
68int yylex(void);
Patrick Georgi0588d192009-08-12 15:00:51 +000069
70struct gstr {
71 size_t len;
72 char *s;
Patrick Georgid5208402014-04-11 20:24:06 +020073 /*
74 * when max_width is not zero long lines in string s (if any) get
75 * wrapped not to exceed the max_width value
76 */
77 int max_width;
Patrick Georgi0588d192009-08-12 15:00:51 +000078};
79struct gstr str_new(void);
Patrick Georgi0588d192009-08-12 15:00:51 +000080void str_free(struct gstr *gs);
81void str_append(struct gstr *gs, const char *s);
82void str_printf(struct gstr *gs, const char *fmt, ...);
83const char *str_get(struct gstr *gs);
84
Patrick Georgi53ea1d42019-11-22 16:55:58 +010085/* menu.c */
86void _menu_init(void);
87void menu_warn(struct menu *menu, const char *fmt, ...);
88struct menu *menu_add_menu(void);
89void menu_end_menu(void);
90void menu_add_entry(struct symbol *sym);
91void menu_add_dep(struct expr *dep);
92void menu_add_visibility(struct expr *dep);
93struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
94void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
95void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
96void menu_finalize(struct menu *parent);
97void menu_set_type(int type);
Patrick Georgi0588d192009-08-12 15:00:51 +000098
Patrick Georgi53ea1d42019-11-22 16:55:58 +010099extern struct menu rootmenu;
100
101bool menu_is_empty(struct menu *menu);
102bool menu_is_visible(struct menu *menu);
103bool menu_has_prompt(struct menu *menu);
104const char *menu_get_prompt(struct menu *menu);
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100105struct menu *menu_get_parent_menu(struct menu *menu);
106bool menu_has_help(struct menu *menu);
107const char *menu_get_help(struct menu *menu);
108struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
109void menu_get_ext_help(struct menu *menu, struct gstr *help);
110
111/* symbol.c */
Patrick Georgi0588d192009-08-12 15:00:51 +0000112void sym_clear_all_valid(void);
Patrick Georgid5208402014-04-11 20:24:06 +0200113struct symbol *sym_choice_default(struct symbol *sym);
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100114struct property *sym_get_range_prop(struct symbol *sym);
Patrick Georgid5208402014-04-11 20:24:06 +0200115const char *sym_get_string_default(struct symbol *sym);
Patrick Georgi0588d192009-08-12 15:00:51 +0000116struct symbol *sym_check_deps(struct symbol *sym);
Patrick Georgi0588d192009-08-12 15:00:51 +0000117struct symbol *prop_get_symbol(struct property *prop);
Patrick Georgi0588d192009-08-12 15:00:51 +0000118
119static inline tristate sym_get_tristate_value(struct symbol *sym)
120{
121 return sym->curr.tri;
122}
123
124
125static inline struct symbol *sym_get_choice_value(struct symbol *sym)
126{
127 return (struct symbol *)sym->curr.val;
128}
129
130static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
131{
132 return sym_set_tristate_value(chval, yes);
133}
134
135static inline bool sym_is_choice(struct symbol *sym)
136{
137 return sym->flags & SYMBOL_CHOICE ? true : false;
138}
139
140static inline bool sym_is_choice_value(struct symbol *sym)
141{
142 return sym->flags & SYMBOL_CHOICEVAL ? true : false;
143}
144
145static inline bool sym_is_optional(struct symbol *sym)
146{
147 return sym->flags & SYMBOL_OPTIONAL ? true : false;
148}
149
150static inline bool sym_has_value(struct symbol *sym)
151{
152 return sym->flags & SYMBOL_DEF_USER ? true : false;
153}
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif /* LKC_H */