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