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