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