blob: 2bdee9cbaec7cbf5a023311eca30ed95f5bc4208 [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
43/* confdata.c */
44const char *conf_get_configname(void);
Patrick Georgid5208402014-04-11 20:24:06 +020045void set_all_choice_values(struct symbol *csym);
Patrick Georgi0588d192009-08-12 15:00:51 +000046
Patrick Georgid5208402014-04-11 20:24:06 +020047/* confdata.c and expr.c */
48static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
49{
50 assert(len != 0);
51
52 if (fwrite(str, len, count, out) != count)
53 fprintf(stderr, "Error in writing or end of file.\n");
54}
Patrick Georgi0588d192009-08-12 15:00:51 +000055
Patrick Georgi0588d192009-08-12 15:00:51 +000056/* util.c */
57struct file *file_lookup(const char *name);
Patrick Georgid5208402014-04-11 20:24:06 +020058void *xmalloc(size_t size);
59void *xcalloc(size_t nmemb, size_t size);
Patrick Georgi53ea1d42019-11-22 16:55:58 +010060void *xrealloc(void *p, size_t size);
61char *xstrdup(const char *s);
62char *xstrndup(const char *s, size_t n);
63
64/* lexer.l */
65int yylex(void);
Patrick Georgi0588d192009-08-12 15:00:51 +000066
67struct gstr {
68 size_t len;
69 char *s;
Patrick Georgid5208402014-04-11 20:24:06 +020070 /*
71 * when max_width is not zero long lines in string s (if any) get
72 * wrapped not to exceed the max_width value
73 */
74 int max_width;
Patrick Georgi0588d192009-08-12 15:00:51 +000075};
76struct gstr str_new(void);
Patrick Georgi0588d192009-08-12 15:00:51 +000077void str_free(struct gstr *gs);
78void str_append(struct gstr *gs, const char *s);
79void str_printf(struct gstr *gs, const char *fmt, ...);
Patrick Georgi7eab8ef2023-11-20 18:03:34 +010080char *str_get(struct gstr *gs);
Patrick Georgi0588d192009-08-12 15:00:51 +000081
Patrick Georgi53ea1d42019-11-22 16:55:58 +010082/* menu.c */
83void _menu_init(void);
84void menu_warn(struct menu *menu, const char *fmt, ...);
85struct menu *menu_add_menu(void);
86void menu_end_menu(void);
87void menu_add_entry(struct symbol *sym);
88void menu_add_dep(struct expr *dep);
89void menu_add_visibility(struct expr *dep);
90struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
91void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
92void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
93void menu_finalize(struct menu *parent);
94void menu_set_type(int type);
Patrick Georgi0588d192009-08-12 15:00:51 +000095
Patrick Georgi53ea1d42019-11-22 16:55:58 +010096extern struct menu rootmenu;
97
98bool menu_is_empty(struct menu *menu);
99bool menu_is_visible(struct menu *menu);
100bool menu_has_prompt(struct menu *menu);
101const char *menu_get_prompt(struct menu *menu);
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100102struct menu *menu_get_parent_menu(struct menu *menu);
103bool menu_has_help(struct menu *menu);
104const char *menu_get_help(struct menu *menu);
Patrick Georgi0eab62b2023-11-20 19:49:29 +0100105int get_jump_key_char(void);
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100106struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
107void menu_get_ext_help(struct menu *menu, struct gstr *help);
108
109/* symbol.c */
Patrick Georgi0588d192009-08-12 15:00:51 +0000110void sym_clear_all_valid(void);
Patrick Georgid5208402014-04-11 20:24:06 +0200111struct symbol *sym_choice_default(struct symbol *sym);
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100112struct property *sym_get_range_prop(struct symbol *sym);
Patrick Georgid5208402014-04-11 20:24:06 +0200113const char *sym_get_string_default(struct symbol *sym);
Patrick Georgi0588d192009-08-12 15:00:51 +0000114struct symbol *sym_check_deps(struct symbol *sym);
Patrick Georgi0588d192009-08-12 15:00:51 +0000115struct symbol *prop_get_symbol(struct property *prop);
Patrick Georgi0588d192009-08-12 15:00:51 +0000116
117static inline tristate sym_get_tristate_value(struct symbol *sym)
118{
119 return sym->curr.tri;
120}
121
122
123static inline struct symbol *sym_get_choice_value(struct symbol *sym)
124{
125 return (struct symbol *)sym->curr.val;
126}
127
Patrick Georgi0588d192009-08-12 15:00:51 +0000128static inline bool sym_is_choice(struct symbol *sym)
129{
130 return sym->flags & SYMBOL_CHOICE ? true : false;
131}
132
133static inline bool sym_is_choice_value(struct symbol *sym)
134{
135 return sym->flags & SYMBOL_CHOICEVAL ? true : false;
136}
137
138static inline bool sym_is_optional(struct symbol *sym)
139{
140 return sym->flags & SYMBOL_OPTIONAL ? true : false;
141}
142
143static inline bool sym_has_value(struct symbol *sym)
144{
145 return sym->flags & SYMBOL_DEF_USER ? true : false;
146}
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif /* LKC_H */