Masahiro Yamada | 0c87410 | 2018-12-18 21:13:35 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
Masahiro Yamada | 0c87410 | 2018-12-18 21:13:35 +0900 | [diff] [blame] | 5 | %{ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
| 7 | #include <ctype.h> |
| 8 | #include <stdarg.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <stdbool.h> |
| 13 | |
Roman Zippel | 7a88488 | 2005-11-08 21:34:51 -0800 | [diff] [blame] | 14 | #include "lkc.h" |
Masahiro Yamada | a77a05d | 2021-04-14 00:08:17 +0900 | [diff] [blame] | 15 | #include "internal.h" |
Roman Zippel | 7a88488 | 2005-11-08 21:34:51 -0800 | [diff] [blame] | 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) |
| 18 | |
| 19 | #define PRINTD 0x0001 |
| 20 | #define DEBUG_PARSE 0x0002 |
| 21 | |
| 22 | int cdebug = PRINTD; |
| 23 | |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 24 | static void yyerror(const char *err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static void zconfprint(const char *err, ...); |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 26 | static void zconf_error(const char *err, ...); |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 27 | static bool zconf_endtoken(const char *tokenname, |
| 28 | const char *expected_tokenname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Andi Kleen | e66f25d | 2010-01-13 17:02:44 +0100 | [diff] [blame] | 30 | struct symbol *symbol_hash[SYMBOL_HASHSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Masahiro Yamada | a77a05d | 2021-04-14 00:08:17 +0900 | [diff] [blame] | 32 | struct menu *current_menu, *current_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | %} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | %union |
| 37 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | char *string; |
| 39 | struct symbol *symbol; |
| 40 | struct expr *expr; |
| 41 | struct menu *menu; |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 42 | enum symbol_type type; |
Masahiro Yamada | 1175c02 | 2018-05-28 18:21:50 +0900 | [diff] [blame] | 43 | enum variable_flavor flavor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | %token <string> T_HELPTEXT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | %token <string> T_WORD |
| 48 | %token <string> T_WORD_QUOTE |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 49 | %token T_BOOL |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 50 | %token T_CHOICE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | %token T_CLOSE_PAREN |
Masahiro Yamada | c3d2287 | 2018-12-11 20:01:01 +0900 | [diff] [blame] | 52 | %token T_COLON_EQUAL |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 53 | %token T_COMMENT |
| 54 | %token T_CONFIG |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 55 | %token T_DEFAULT |
| 56 | %token T_DEF_BOOL |
| 57 | %token T_DEF_TRISTATE |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 58 | %token T_DEPENDS |
| 59 | %token T_ENDCHOICE |
| 60 | %token T_ENDIF |
| 61 | %token T_ENDMENU |
| 62 | %token T_HELP |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 63 | %token T_HEX |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 64 | %token T_IF |
| 65 | %token T_IMPLY |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 66 | %token T_INT |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 67 | %token T_MAINMENU |
| 68 | %token T_MENU |
| 69 | %token T_MENUCONFIG |
Masahiro Yamada | ce2164a | 2018-12-11 20:01:00 +0900 | [diff] [blame] | 70 | %token T_MODULES |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 71 | %token T_ON |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | %token T_OPEN_PAREN |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 73 | %token T_OPTIONAL |
Masahiro Yamada | c3d2287 | 2018-12-11 20:01:01 +0900 | [diff] [blame] | 74 | %token T_PLUS_EQUAL |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 75 | %token T_PROMPT |
| 76 | %token T_RANGE |
| 77 | %token T_SELECT |
| 78 | %token T_SOURCE |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 79 | %token T_STRING |
| 80 | %token T_TRISTATE |
Masahiro Yamada | b3d1d9d | 2018-12-11 20:01:07 +0900 | [diff] [blame] | 81 | %token T_VISIBLE |
Roman Zippel | 3370f9f | 2005-11-08 21:34:52 -0800 | [diff] [blame] | 82 | %token T_EOL |
Masahiro Yamada | 9ced3bd | 2018-05-28 18:21:49 +0900 | [diff] [blame] | 83 | %token <string> T_ASSIGN_VAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | %left T_OR |
| 86 | %left T_AND |
| 87 | %left T_EQUAL T_UNEQUAL |
Jan Beulich | 31847b6 | 2015-06-15 13:00:21 +0100 | [diff] [blame] | 88 | %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | %nonassoc T_NOT |
| 90 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 91 | %type <symbol> nonconst_symbol |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | %type <symbol> symbol |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 93 | %type <type> type logic_type default |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | %type <expr> expr |
| 95 | %type <expr> if_expr |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 96 | %type <string> end |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 97 | %type <menu> if_entry menu_entry choice_entry |
Masahiro Yamada | ce2164a | 2018-12-11 20:01:00 +0900 | [diff] [blame] | 98 | %type <string> word_opt assign_val |
Masahiro Yamada | c3d2287 | 2018-12-11 20:01:01 +0900 | [diff] [blame] | 99 | %type <flavor> assign_op |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 100 | |
| 101 | %destructor { |
| 102 | fprintf(stderr, "%s:%d: missing end statement for this entry\n", |
| 103 | $$->file->name, $$->lineno); |
| 104 | if (current_menu == $$) |
| 105 | menu_end_menu(); |
| 106 | } if_entry menu_entry choice_entry |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | %% |
Masahiro Yamada | cc66bca | 2018-12-11 20:00:49 +0900 | [diff] [blame] | 109 | input: mainmenu_stmt stmt_list | stmt_list; |
Ulf Magnusson | 0724a7c | 2017-10-08 19:11:21 +0200 | [diff] [blame] | 110 | |
| 111 | /* mainmenu entry */ |
| 112 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 113 | mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL |
Ulf Magnusson | 0724a7c | 2017-10-08 19:11:21 +0200 | [diff] [blame] | 114 | { |
| 115 | menu_add_prompt(P_MENU, $2, NULL); |
| 116 | }; |
| 117 | |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 118 | stmt_list: |
| 119 | /* empty */ |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 120 | | stmt_list assignment_stmt |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 121 | | stmt_list choice_stmt |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 122 | | stmt_list comment_stmt |
| 123 | | stmt_list config_stmt |
| 124 | | stmt_list if_stmt |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 125 | | stmt_list menu_stmt |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 126 | | stmt_list menuconfig_stmt |
| 127 | | stmt_list source_stmt |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 128 | | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); } |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 129 | | stmt_list error T_EOL { zconf_error("invalid statement"); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | ; |
| 131 | |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 132 | stmt_list_in_choice: |
| 133 | /* empty */ |
| 134 | | stmt_list_in_choice comment_stmt |
| 135 | | stmt_list_in_choice config_stmt |
| 136 | | stmt_list_in_choice if_stmt_in_choice |
| 137 | | stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); } |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 138 | ; |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* config/menuconfig entry */ |
| 141 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 142 | config_entry_start: T_CONFIG nonconst_symbol T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 144 | $2->flags |= SYMBOL_OPTIONAL; |
| 145 | menu_add_entry($2); |
| 146 | printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | config_stmt: config_entry_start config_option_list |
| 150 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); |
| 152 | }; |
| 153 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 154 | menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 156 | $2->flags |= SYMBOL_OPTIONAL; |
| 157 | menu_add_entry($2); |
| 158 | printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | menuconfig_stmt: menuconfig_entry_start config_option_list |
| 162 | { |
| 163 | if (current_entry->prompt) |
| 164 | current_entry->prompt->type = P_MENU; |
| 165 | else |
| 166 | zconfprint("warning: menuconfig statement without prompt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); |
| 168 | }; |
| 169 | |
| 170 | config_option_list: |
| 171 | /* empty */ |
| 172 | | config_option_list config_option |
| 173 | | config_option_list depends |
| 174 | | config_option_list help |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | ; |
| 176 | |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 177 | config_option: type prompt_stmt_opt T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 179 | menu_set_type($1); |
Roman Zippel | 3370f9f | 2005-11-08 21:34:52 -0800 | [diff] [blame] | 180 | printd(DEBUG_PARSE, "%s:%d:type(%u)\n", |
| 181 | zconf_curname(), zconf_lineno(), |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 182 | $1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 185 | config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
| 187 | menu_add_prompt(P_PROMPT, $2, $3); |
| 188 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); |
| 189 | }; |
| 190 | |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 191 | config_option: default expr if_expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | menu_add_expr(P_DEFAULT, $2, $3); |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 194 | if ($1 != S_UNKNOWN) |
| 195 | menu_set_type($1); |
Roman Zippel | 3370f9f | 2005-11-08 21:34:52 -0800 | [diff] [blame] | 196 | printd(DEBUG_PARSE, "%s:%d:default(%u)\n", |
| 197 | zconf_curname(), zconf_lineno(), |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 198 | $1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 201 | config_option: T_SELECT nonconst_symbol if_expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 203 | menu_add_symbol(P_SELECT, $2, $3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno()); |
| 205 | }; |
| 206 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 207 | config_option: T_IMPLY nonconst_symbol if_expr T_EOL |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 208 | { |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 209 | menu_add_symbol(P_IMPLY, $2, $3); |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 210 | printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno()); |
| 211 | }; |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | config_option: T_RANGE symbol symbol if_expr T_EOL |
| 214 | { |
| 215 | menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); |
| 216 | printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); |
| 217 | }; |
| 218 | |
Masahiro Yamada | 6dd85ff | 2021-03-14 04:48:36 +0900 | [diff] [blame] | 219 | config_option: T_MODULES T_EOL |
Roman Zippel | f6a88aa | 2006-06-08 22:12:44 -0700 | [diff] [blame] | 220 | { |
Masahiro Yamada | 6dd85ff | 2021-03-14 04:48:36 +0900 | [diff] [blame] | 221 | if (modules_sym) |
| 222 | zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'", |
| 223 | current_entry->sym->name, modules_sym->name); |
| 224 | modules_sym = current_entry->sym; |
Roman Zippel | f6a88aa | 2006-06-08 22:12:44 -0700 | [diff] [blame] | 225 | }; |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* choice entry */ |
| 228 | |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 229 | choice: T_CHOICE word_opt T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 231 | struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE); |
Dirk Gouders | 693359f | 2018-07-03 14:43:31 +0200 | [diff] [blame] | 232 | sym->flags |= SYMBOL_NO_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | menu_add_entry(sym); |
| 234 | menu_add_expr(P_CHOICE, NULL, NULL); |
Masahiro Yamada | bf0bbdc | 2018-02-20 20:40:29 +0900 | [diff] [blame] | 235 | free($2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); |
| 237 | }; |
| 238 | |
| 239 | choice_entry: choice choice_option_list |
| 240 | { |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 241 | $$ = menu_add_menu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | choice_end: end |
| 245 | { |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 246 | if (zconf_endtoken($1, "choice")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | menu_end_menu(); |
| 248 | printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); |
| 249 | } |
| 250 | }; |
| 251 | |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 252 | choice_stmt: choice_entry stmt_list_in_choice choice_end |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 253 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | choice_option_list: |
| 256 | /* empty */ |
| 257 | | choice_option_list choice_option |
| 258 | | choice_option_list depends |
| 259 | | choice_option_list help |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | ; |
| 261 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 262 | choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | menu_add_prompt(P_PROMPT, $2, $3); |
| 265 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); |
| 266 | }; |
| 267 | |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 268 | choice_option: logic_type prompt_stmt_opt T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 270 | menu_set_type($1); |
| 271 | printd(DEBUG_PARSE, "%s:%d:type(%u)\n", |
| 272 | zconf_curname(), zconf_lineno(), $1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | choice_option: T_OPTIONAL T_EOL |
| 276 | { |
| 277 | current_entry->sym->flags |= SYMBOL_OPTIONAL; |
| 278 | printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno()); |
| 279 | }; |
| 280 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 281 | choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 283 | menu_add_symbol(P_DEFAULT, $2, $3); |
| 284 | printd(DEBUG_PARSE, "%s:%d:default\n", |
| 285 | zconf_curname(), zconf_lineno()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Masahiro Yamada | 3c8f317 | 2018-12-11 20:00:59 +0900 | [diff] [blame] | 288 | type: |
| 289 | logic_type |
| 290 | | T_INT { $$ = S_INT; } |
| 291 | | T_HEX { $$ = S_HEX; } |
| 292 | | T_STRING { $$ = S_STRING; } |
| 293 | |
| 294 | logic_type: |
| 295 | T_BOOL { $$ = S_BOOLEAN; } |
| 296 | | T_TRISTATE { $$ = S_TRISTATE; } |
| 297 | |
| 298 | default: |
| 299 | T_DEFAULT { $$ = S_UNKNOWN; } |
| 300 | | T_DEF_BOOL { $$ = S_BOOLEAN; } |
| 301 | | T_DEF_TRISTATE { $$ = S_TRISTATE; } |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* if entry */ |
| 304 | |
Dirk Gouders | b2d00d7 | 2018-06-21 15:30:54 +0200 | [diff] [blame] | 305 | if_entry: T_IF expr T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); |
| 308 | menu_add_entry(NULL); |
| 309 | menu_add_dep($2); |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 310 | $$ = menu_add_menu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | if_end: end |
| 314 | { |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 315 | if (zconf_endtoken($1, "if")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | menu_end_menu(); |
| 317 | printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); |
| 318 | } |
| 319 | }; |
| 320 | |
Masahiro Yamada | 4891796 | 2018-12-11 20:00:54 +0900 | [diff] [blame] | 321 | if_stmt: if_entry stmt_list if_end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | ; |
| 323 | |
Masahiro Yamada | 09d5873 | 2020-04-24 14:49:29 +0900 | [diff] [blame] | 324 | if_stmt_in_choice: if_entry stmt_list_in_choice if_end |
| 325 | ; |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | /* menu entry */ |
| 328 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 329 | menu: T_MENU T_WORD_QUOTE T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
| 331 | menu_add_entry(NULL); |
blaisorblade@yahoo.it | fb7f6ff | 2005-07-28 17:56:25 +0200 | [diff] [blame] | 332 | menu_add_prompt(P_MENU, $2, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); |
| 334 | }; |
| 335 | |
Masahiro Yamada | 1f31be9 | 2018-12-11 20:00:56 +0900 | [diff] [blame] | 336 | menu_entry: menu menu_option_list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 338 | $$ = menu_add_menu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | menu_end: end |
| 342 | { |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 343 | if (zconf_endtoken($1, "menu")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | menu_end_menu(); |
| 345 | printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); |
| 346 | } |
| 347 | }; |
| 348 | |
Masahiro Yamada | 94d4e1b | 2018-12-11 20:00:55 +0900 | [diff] [blame] | 349 | menu_stmt: menu_entry stmt_list menu_end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | ; |
| 351 | |
Masahiro Yamada | 1f31be9 | 2018-12-11 20:00:56 +0900 | [diff] [blame] | 352 | menu_option_list: |
| 353 | /* empty */ |
| 354 | | menu_option_list visible |
| 355 | | menu_option_list depends |
| 356 | ; |
| 357 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 358 | source_stmt: T_SOURCE T_WORD_QUOTE T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 361 | zconf_nextfile($2); |
Ulf Magnusson | 24161a6 | 2017-10-08 19:11:19 +0200 | [diff] [blame] | 362 | free($2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | /* comment entry */ |
| 366 | |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 367 | comment: T_COMMENT T_WORD_QUOTE T_EOL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
| 369 | menu_add_entry(NULL); |
blaisorblade@yahoo.it | fb7f6ff | 2005-07-28 17:56:25 +0200 | [diff] [blame] | 370 | menu_add_prompt(P_COMMENT, $2, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); |
| 372 | }; |
| 373 | |
Masahiro Yamada | 4b5ec81 | 2018-12-11 20:00:57 +0900 | [diff] [blame] | 374 | comment_stmt: comment comment_option_list |
| 375 | ; |
| 376 | |
| 377 | comment_option_list: |
| 378 | /* empty */ |
| 379 | | comment_option_list depends |
Ulf Magnusson | df60f4b | 2017-10-09 00:14:48 +0200 | [diff] [blame] | 380 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | /* help option */ |
| 383 | |
| 384 | help_start: T_HELP T_EOL |
| 385 | { |
| 386 | printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); |
| 387 | zconf_starthelp(); |
| 388 | }; |
| 389 | |
| 390 | help: help_start T_HELPTEXT |
| 391 | { |
Ulf Magnusson | 6479f32 | 2018-01-12 07:47:47 +0100 | [diff] [blame] | 392 | if (current_entry->help) { |
| 393 | free(current_entry->help); |
| 394 | zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used", |
| 395 | current_entry->sym->name ?: "<choice>"); |
| 396 | } |
Ulf Magnusson | 1b9eda2 | 2018-01-31 10:34:30 +0100 | [diff] [blame] | 397 | |
| 398 | /* Is the help text empty or all whitespace? */ |
| 399 | if ($2[strspn($2, " \f\n\r\t\v")] == '\0') |
| 400 | zconfprint("warning: '%s' defined with blank help text", |
| 401 | current_entry->sym->name ?: "<choice>"); |
| 402 | |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 403 | current_entry->help = $2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | /* depends option */ |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | depends: T_DEPENDS T_ON expr T_EOL |
| 409 | { |
| 410 | menu_add_dep($3); |
| 411 | printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
Arnaud Lacombe | 86e187f | 2010-11-06 18:30:23 -0300 | [diff] [blame] | 414 | /* visibility option */ |
Masahiro Yamada | 413cd19 | 2018-12-11 20:00:46 +0900 | [diff] [blame] | 415 | visible: T_VISIBLE if_expr T_EOL |
Arnaud Lacombe | 86e187f | 2010-11-06 18:30:23 -0300 | [diff] [blame] | 416 | { |
| 417 | menu_add_visibility($2); |
| 418 | }; |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* prompt statement */ |
| 421 | |
| 422 | prompt_stmt_opt: |
| 423 | /* empty */ |
Masahiro Yamada | 1be6e79 | 2019-12-17 13:14:19 +0900 | [diff] [blame] | 424 | | T_WORD_QUOTE if_expr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
blaisorblade@yahoo.it | fb7f6ff | 2005-07-28 17:56:25 +0200 | [diff] [blame] | 426 | menu_add_prompt(P_PROMPT, $1, $2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | }; |
| 428 | |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 429 | end: T_ENDMENU T_EOL { $$ = "menu"; } |
| 430 | | T_ENDCHOICE T_EOL { $$ = "choice"; } |
| 431 | | T_ENDIF T_EOL { $$ = "if"; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | ; |
| 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if_expr: /* empty */ { $$ = NULL; } |
| 435 | | T_IF expr { $$ = $2; } |
| 436 | ; |
| 437 | |
| 438 | expr: symbol { $$ = expr_alloc_symbol($1); } |
Jan Beulich | 31847b6 | 2015-06-15 13:00:21 +0100 | [diff] [blame] | 439 | | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); } |
| 440 | | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); } |
| 441 | | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); } |
| 442 | | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); } |
| 444 | | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); } |
| 445 | | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; } |
| 446 | | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); } |
| 447 | | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); } |
| 448 | | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); } |
| 449 | ; |
| 450 | |
Ulf Magnusson | 26e47a3 | 2017-10-08 19:11:18 +0200 | [diff] [blame] | 451 | /* For symbol definitions, selects, etc., where quotes are not accepted */ |
| 452 | nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }; |
| 453 | |
| 454 | symbol: nonconst_symbol |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 455 | | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | ; |
| 457 | |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 458 | word_opt: /* empty */ { $$ = NULL; } |
| 459 | | T_WORD |
| 460 | |
Masahiro Yamada | 9ced3bd | 2018-05-28 18:21:49 +0900 | [diff] [blame] | 461 | /* assignment statement */ |
| 462 | |
Masahiro Yamada | 171a515 | 2018-12-11 20:01:02 +0900 | [diff] [blame] | 463 | assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); } |
Masahiro Yamada | c3d2287 | 2018-12-11 20:01:01 +0900 | [diff] [blame] | 464 | |
| 465 | assign_op: |
| 466 | T_EQUAL { $$ = VAR_RECURSIVE; } |
| 467 | | T_COLON_EQUAL { $$ = VAR_SIMPLE; } |
| 468 | | T_PLUS_EQUAL { $$ = VAR_APPEND; } |
| 469 | ; |
Masahiro Yamada | 9ced3bd | 2018-05-28 18:21:49 +0900 | [diff] [blame] | 470 | |
| 471 | assign_val: |
| 472 | /* empty */ { $$ = xstrdup(""); }; |
| 473 | | T_ASSIGN_VAL |
| 474 | ; |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | %% |
| 477 | |
| 478 | void conf_parse(const char *name) |
| 479 | { |
| 480 | struct symbol *sym; |
| 481 | int i; |
| 482 | |
| 483 | zconf_initscan(name); |
| 484 | |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 485 | _menu_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 487 | if (getenv("ZCONF_DEBUG")) |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 488 | yydebug = 1; |
| 489 | yyparse(); |
Masahiro Yamada | 9ced3bd | 2018-05-28 18:21:49 +0900 | [diff] [blame] | 490 | |
| 491 | /* Variables are expanded in the parse phase. We can free them here. */ |
| 492 | variable_all_del(); |
| 493 | |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 494 | if (yynerrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | exit(1); |
Yann E. MORIN | 6902dcc | 2013-09-03 17:07:18 +0200 | [diff] [blame] | 496 | if (!modules_sym) |
| 497 | modules_sym = sym_find( "n" ); |
Arnaud Lacombe | f6ce00b | 2010-09-09 21:17:26 -0400 | [diff] [blame] | 498 | |
Masahiro Yamada | 96d8e48 | 2018-05-28 18:21:42 +0900 | [diff] [blame] | 499 | if (!menu_has_prompt(&rootmenu)) { |
| 500 | current_entry = &rootmenu; |
Masahiro Yamada | 137c011 | 2018-05-28 18:21:44 +0900 | [diff] [blame] | 501 | menu_add_prompt(P_MENU, "Main menu", NULL); |
Masahiro Yamada | 96d8e48 | 2018-05-28 18:21:42 +0900 | [diff] [blame] | 502 | } |
Arnaud Lacombe | f6ce00b | 2010-09-09 21:17:26 -0400 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | menu_finalize(&rootmenu); |
| 505 | for_all_symbols(i, sym) { |
Sam Ravnborg | 5447d34 | 2007-05-06 09:20:10 +0200 | [diff] [blame] | 506 | if (sym_check_deps(sym)) |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 507 | yynerrs++; |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 508 | } |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 509 | if (yynerrs) |
Sam Ravnborg | 5447d34 | 2007-05-06 09:20:10 +0200 | [diff] [blame] | 510 | exit(1); |
Masahiro Yamada | 5ee5465 | 2021-04-10 15:57:22 +0900 | [diff] [blame] | 511 | conf_set_changed(true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 514 | static bool zconf_endtoken(const char *tokenname, |
| 515 | const char *expected_tokenname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 517 | if (strcmp(tokenname, expected_tokenname)) { |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 518 | zconf_error("unexpected '%s' within %s block", |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 519 | tokenname, expected_tokenname); |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 520 | yynerrs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return false; |
| 522 | } |
| 523 | if (current_menu->file != current_file) { |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 524 | zconf_error("'%s' in different file than '%s'", |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 525 | tokenname, expected_tokenname); |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 526 | fprintf(stderr, "%s:%d: location of the '%s'\n", |
| 527 | current_menu->file->name, current_menu->lineno, |
Masahiro Yamada | caaebb3 | 2018-12-11 20:01:06 +0900 | [diff] [blame] | 528 | expected_tokenname); |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 529 | yynerrs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return false; |
| 531 | } |
| 532 | return true; |
| 533 | } |
| 534 | |
| 535 | static void zconfprint(const char *err, ...) |
| 536 | { |
| 537 | va_list ap; |
| 538 | |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 539 | fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); |
| 540 | va_start(ap, err); |
| 541 | vfprintf(stderr, err, ap); |
| 542 | va_end(ap); |
| 543 | fprintf(stderr, "\n"); |
| 544 | } |
| 545 | |
| 546 | static void zconf_error(const char *err, ...) |
| 547 | { |
| 548 | va_list ap; |
| 549 | |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 550 | yynerrs++; |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 551 | fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | va_start(ap, err); |
| 553 | vfprintf(stderr, err, ap); |
| 554 | va_end(ap); |
| 555 | fprintf(stderr, "\n"); |
| 556 | } |
| 557 | |
Masahiro Yamada | 765f4cd | 2018-01-12 00:50:50 +0900 | [diff] [blame] | 558 | static void yyerror(const char *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
| 560 | fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Josh Triplett | 6516657 | 2009-10-15 12:13:36 -0700 | [diff] [blame] | 563 | static void print_quoted_string(FILE *out, const char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
| 565 | const char *p; |
| 566 | int len; |
| 567 | |
| 568 | putc('"', out); |
| 569 | while ((p = strchr(str, '"'))) { |
| 570 | len = p - str; |
| 571 | if (len) |
| 572 | fprintf(out, "%.*s", len, str); |
| 573 | fputs("\\\"", out); |
| 574 | str = p + 1; |
| 575 | } |
| 576 | fputs(str, out); |
| 577 | putc('"', out); |
| 578 | } |
| 579 | |
Josh Triplett | 6516657 | 2009-10-15 12:13:36 -0700 | [diff] [blame] | 580 | static void print_symbol(FILE *out, struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | struct symbol *sym = menu->sym; |
| 583 | struct property *prop; |
| 584 | |
| 585 | if (sym_is_choice(sym)) |
Li Zefan | c6ccc30 | 2010-04-14 11:44:20 +0800 | [diff] [blame] | 586 | fprintf(out, "\nchoice\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | else |
Li Zefan | c6ccc30 | 2010-04-14 11:44:20 +0800 | [diff] [blame] | 588 | fprintf(out, "\nconfig %s\n", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | switch (sym->type) { |
| 590 | case S_BOOLEAN: |
Masahiro Yamada | b92d804 | 2017-12-16 00:38:02 +0900 | [diff] [blame] | 591 | fputs(" bool\n", out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
| 593 | case S_TRISTATE: |
| 594 | fputs(" tristate\n", out); |
| 595 | break; |
| 596 | case S_STRING: |
| 597 | fputs(" string\n", out); |
| 598 | break; |
| 599 | case S_INT: |
| 600 | fputs(" integer\n", out); |
| 601 | break; |
| 602 | case S_HEX: |
| 603 | fputs(" hex\n", out); |
| 604 | break; |
| 605 | default: |
| 606 | fputs(" ???\n", out); |
| 607 | break; |
| 608 | } |
| 609 | for (prop = sym->prop; prop; prop = prop->next) { |
| 610 | if (prop->menu != menu) |
| 611 | continue; |
| 612 | switch (prop->type) { |
| 613 | case P_PROMPT: |
| 614 | fputs(" prompt ", out); |
| 615 | print_quoted_string(out, prop->text); |
| 616 | if (!expr_is_yes(prop->visible.expr)) { |
| 617 | fputs(" if ", out); |
| 618 | expr_fprint(prop->visible.expr, out); |
| 619 | } |
| 620 | fputc('\n', out); |
| 621 | break; |
| 622 | case P_DEFAULT: |
| 623 | fputs( " default ", out); |
| 624 | expr_fprint(prop->expr, out); |
| 625 | if (!expr_is_yes(prop->visible.expr)) { |
| 626 | fputs(" if ", out); |
| 627 | expr_fprint(prop->visible.expr, out); |
| 628 | } |
| 629 | fputc('\n', out); |
| 630 | break; |
| 631 | case P_CHOICE: |
| 632 | fputs(" #choice value\n", out); |
| 633 | break; |
Li Zefan | c6ccc30 | 2010-04-14 11:44:20 +0800 | [diff] [blame] | 634 | case P_SELECT: |
| 635 | fputs( " select ", out); |
| 636 | expr_fprint(prop->expr, out); |
| 637 | fputc('\n', out); |
| 638 | break; |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 639 | case P_IMPLY: |
| 640 | fputs( " imply ", out); |
| 641 | expr_fprint(prop->expr, out); |
| 642 | fputc('\n', out); |
| 643 | break; |
Li Zefan | c6ccc30 | 2010-04-14 11:44:20 +0800 | [diff] [blame] | 644 | case P_RANGE: |
| 645 | fputs( " range ", out); |
| 646 | expr_fprint(prop->expr, out); |
| 647 | fputc('\n', out); |
| 648 | break; |
| 649 | case P_MENU: |
| 650 | fputs( " menu ", out); |
| 651 | print_quoted_string(out, prop->text); |
| 652 | fputc('\n', out); |
| 653 | break; |
Dirk Gouders | ecd53ac | 2018-06-22 21:27:38 +0200 | [diff] [blame] | 654 | case P_SYMBOL: |
| 655 | fputs( " symbol ", out); |
Masahiro Yamada | 6397d96 | 2019-12-17 13:14:22 +0900 | [diff] [blame] | 656 | fprintf(out, "%s\n", prop->menu->sym->name); |
Dirk Gouders | ecd53ac | 2018-06-22 21:27:38 +0200 | [diff] [blame] | 657 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | default: |
| 659 | fprintf(out, " unknown prop %d!\n", prop->type); |
| 660 | break; |
| 661 | } |
| 662 | } |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 663 | if (menu->help) { |
| 664 | int len = strlen(menu->help); |
| 665 | while (menu->help[--len] == '\n') |
| 666 | menu->help[len] = 0; |
| 667 | fprintf(out, " help\n%s\n", menu->help); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | void zconfdump(FILE *out) |
| 672 | { |
| 673 | struct property *prop; |
| 674 | struct symbol *sym; |
| 675 | struct menu *menu; |
| 676 | |
| 677 | menu = rootmenu.list; |
| 678 | while (menu) { |
| 679 | if ((sym = menu->sym)) |
| 680 | print_symbol(out, menu); |
| 681 | else if ((prop = menu->prompt)) { |
| 682 | switch (prop->type) { |
| 683 | case P_COMMENT: |
| 684 | fputs("\ncomment ", out); |
| 685 | print_quoted_string(out, prop->text); |
| 686 | fputs("\n", out); |
| 687 | break; |
| 688 | case P_MENU: |
| 689 | fputs("\nmenu ", out); |
| 690 | print_quoted_string(out, prop->text); |
| 691 | fputs("\n", out); |
| 692 | break; |
| 693 | default: |
| 694 | ; |
| 695 | } |
| 696 | if (!expr_is_yes(prop->visible.expr)) { |
| 697 | fputs(" depends ", out); |
| 698 | expr_fprint(prop->visible.expr, out); |
| 699 | fputc('\n', out); |
| 700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | if (menu->list) |
| 704 | menu = menu->list; |
| 705 | else if (menu->next) |
| 706 | menu = menu->next; |
| 707 | else while ((menu = menu->parent)) { |
| 708 | if (menu->prompt && menu->prompt->type == P_MENU) |
| 709 | fputs("\nendmenu\n", out); |
| 710 | if (menu->next) { |
| 711 | menu = menu->next; |
| 712 | break; |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |