Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [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 | |
| 14 | #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) |
| 15 | |
| 16 | #define PRINTD 0x0001 |
| 17 | #define DEBUG_PARSE 0x0002 |
| 18 | |
| 19 | int cdebug = PRINTD; |
| 20 | |
| 21 | extern int zconflex(void); |
| 22 | static void zconfprint(const char *err, ...); |
| 23 | static void zconferror(const char *err); |
| 24 | static bool zconf_endtoken(int token, int starttoken, int endtoken); |
| 25 | |
| 26 | struct symbol *symbol_hash[257]; |
| 27 | |
Peter Kjellerstedt | bae38db | 2005-04-19 09:55:06 +0000 | [diff] [blame] | 28 | static struct menu *current_menu, *current_entry; |
| 29 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 30 | #define YYERROR_VERBOSE |
| 31 | %} |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 32 | %expect 40 |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 33 | |
| 34 | %union |
| 35 | { |
| 36 | int token; |
| 37 | char *string; |
| 38 | struct symbol *symbol; |
| 39 | struct expr *expr; |
| 40 | struct menu *menu; |
| 41 | } |
| 42 | |
| 43 | %token T_MAINMENU |
| 44 | %token T_MENU |
| 45 | %token T_ENDMENU |
| 46 | %token T_SOURCE |
| 47 | %token T_CHOICE |
| 48 | %token T_ENDCHOICE |
| 49 | %token T_COMMENT |
| 50 | %token T_CONFIG |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 51 | %token T_MENUCONFIG |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 52 | %token T_HELP |
| 53 | %token <string> T_HELPTEXT |
| 54 | %token T_IF |
| 55 | %token T_ENDIF |
| 56 | %token T_DEPENDS |
| 57 | %token T_REQUIRES |
| 58 | %token T_OPTIONAL |
| 59 | %token T_PROMPT |
| 60 | %token T_DEFAULT |
| 61 | %token T_TRISTATE |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 62 | %token T_DEF_TRISTATE |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 63 | %token T_BOOLEAN |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 64 | %token T_DEF_BOOLEAN |
| 65 | %token T_STRING |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 66 | %token T_INT |
| 67 | %token T_HEX |
| 68 | %token <string> T_WORD |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 69 | %token <string> T_WORD_QUOTE |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 70 | %token T_UNEQUAL |
| 71 | %token T_EOF |
| 72 | %token T_EOL |
| 73 | %token T_CLOSE_PAREN |
| 74 | %token T_OPEN_PAREN |
| 75 | %token T_ON |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 76 | %token T_SELECT |
| 77 | %token T_RANGE |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 78 | |
| 79 | %left T_OR |
| 80 | %left T_AND |
| 81 | %left T_EQUAL T_UNEQUAL |
| 82 | %nonassoc T_NOT |
| 83 | |
| 84 | %type <string> prompt |
| 85 | %type <string> source |
| 86 | %type <symbol> symbol |
| 87 | %type <expr> expr |
| 88 | %type <expr> if_expr |
| 89 | %type <token> end |
| 90 | |
| 91 | %{ |
| 92 | #define LKC_DIRECT_LINK |
| 93 | #include "lkc.h" |
| 94 | %} |
| 95 | %% |
| 96 | input: /* empty */ |
| 97 | | input block |
| 98 | ; |
| 99 | |
| 100 | block: common_block |
| 101 | | choice_stmt |
| 102 | | menu_stmt |
| 103 | | T_MAINMENU prompt nl_or_eof |
| 104 | | T_ENDMENU { zconfprint("unexpected 'endmenu' statement"); } |
| 105 | | T_ENDIF { zconfprint("unexpected 'endif' statement"); } |
| 106 | | T_ENDCHOICE { zconfprint("unexpected 'endchoice' statement"); } |
| 107 | | error nl_or_eof { zconfprint("syntax error"); yyerrok; } |
| 108 | ; |
| 109 | |
| 110 | common_block: |
| 111 | if_stmt |
| 112 | | comment_stmt |
| 113 | | config_stmt |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 114 | | menuconfig_stmt |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 115 | | source_stmt |
| 116 | | nl_or_eof |
| 117 | ; |
| 118 | |
| 119 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 120 | /* config/menuconfig entry */ |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 121 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 122 | config_entry_start: T_CONFIG T_WORD T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 123 | { |
| 124 | struct symbol *sym = sym_lookup($2, 0); |
| 125 | sym->flags |= SYMBOL_OPTIONAL; |
| 126 | menu_add_entry(sym); |
| 127 | printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2); |
| 128 | }; |
| 129 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 130 | config_stmt: config_entry_start config_option_list |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 131 | { |
| 132 | menu_end_entry(); |
| 133 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); |
| 134 | }; |
| 135 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 136 | menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL |
| 137 | { |
| 138 | struct symbol *sym = sym_lookup($2, 0); |
| 139 | sym->flags |= SYMBOL_OPTIONAL; |
| 140 | menu_add_entry(sym); |
| 141 | printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2); |
| 142 | }; |
| 143 | |
| 144 | menuconfig_stmt: menuconfig_entry_start config_option_list |
| 145 | { |
| 146 | if (current_entry->prompt) |
| 147 | current_entry->prompt->type = P_MENU; |
| 148 | else |
| 149 | zconfprint("warning: menuconfig statement without prompt"); |
| 150 | menu_end_entry(); |
| 151 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); |
| 152 | }; |
| 153 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 154 | config_option_list: |
| 155 | /* empty */ |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 156 | | config_option_list config_option |
| 157 | | config_option_list depends |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 158 | | config_option_list help |
| 159 | | config_option_list T_EOL |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 160 | ; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 161 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 162 | config_option: T_TRISTATE prompt_stmt_opt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 163 | { |
| 164 | menu_set_type(S_TRISTATE); |
| 165 | printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno()); |
| 166 | }; |
| 167 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 168 | config_option: T_DEF_TRISTATE expr if_expr T_EOL |
| 169 | { |
| 170 | menu_add_expr(P_DEFAULT, $2, $3); |
| 171 | menu_set_type(S_TRISTATE); |
| 172 | printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno()); |
| 173 | }; |
| 174 | |
| 175 | config_option: T_BOOLEAN prompt_stmt_opt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 176 | { |
| 177 | menu_set_type(S_BOOLEAN); |
| 178 | printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno()); |
| 179 | }; |
| 180 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 181 | config_option: T_DEF_BOOLEAN expr if_expr T_EOL |
| 182 | { |
| 183 | menu_add_expr(P_DEFAULT, $2, $3); |
| 184 | menu_set_type(S_BOOLEAN); |
| 185 | printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno()); |
| 186 | }; |
| 187 | |
| 188 | config_option: T_INT prompt_stmt_opt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 189 | { |
| 190 | menu_set_type(S_INT); |
| 191 | printd(DEBUG_PARSE, "%s:%d:int\n", zconf_curname(), zconf_lineno()); |
| 192 | }; |
| 193 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 194 | config_option: T_HEX prompt_stmt_opt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 195 | { |
| 196 | menu_set_type(S_HEX); |
| 197 | printd(DEBUG_PARSE, "%s:%d:hex\n", zconf_curname(), zconf_lineno()); |
| 198 | }; |
| 199 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 200 | config_option: T_STRING prompt_stmt_opt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 201 | { |
| 202 | menu_set_type(S_STRING); |
| 203 | printd(DEBUG_PARSE, "%s:%d:string\n", zconf_curname(), zconf_lineno()); |
| 204 | }; |
| 205 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 206 | config_option: T_PROMPT prompt if_expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 207 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 208 | menu_add_prompt(P_PROMPT, $2, $3); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 209 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); |
| 210 | }; |
| 211 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 212 | config_option: T_DEFAULT expr if_expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 213 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 214 | menu_add_expr(P_DEFAULT, $2, $3); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 215 | printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno()); |
| 216 | }; |
| 217 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 218 | config_option: T_SELECT T_WORD if_expr T_EOL |
| 219 | { |
| 220 | menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3); |
| 221 | printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno()); |
| 222 | }; |
| 223 | |
| 224 | config_option: T_RANGE symbol symbol if_expr T_EOL |
| 225 | { |
| 226 | menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); |
| 227 | printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); |
| 228 | }; |
| 229 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 230 | /* choice entry */ |
| 231 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 232 | choice: T_CHOICE T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 233 | { |
| 234 | struct symbol *sym = sym_lookup(NULL, 0); |
| 235 | sym->flags |= SYMBOL_CHOICE; |
| 236 | menu_add_entry(sym); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 237 | menu_add_expr(P_CHOICE, NULL, NULL); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 238 | printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); |
| 239 | }; |
| 240 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 241 | choice_entry: choice choice_option_list |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 242 | { |
| 243 | menu_end_entry(); |
| 244 | menu_add_menu(); |
| 245 | }; |
| 246 | |
| 247 | choice_end: end |
| 248 | { |
| 249 | if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) { |
| 250 | menu_end_menu(); |
| 251 | printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | choice_stmt: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 256 | choice_entry choice_block choice_end |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 257 | | choice_entry choice_block |
| 258 | { |
| 259 | printf("%s:%d: missing 'endchoice' for this 'choice' statement\n", current_menu->file->name, current_menu->lineno); |
| 260 | zconfnerrs++; |
| 261 | }; |
| 262 | |
| 263 | choice_option_list: |
| 264 | /* empty */ |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 265 | | choice_option_list choice_option |
| 266 | | choice_option_list depends |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 267 | | choice_option_list help |
| 268 | | choice_option_list T_EOL |
| 269 | ; |
| 270 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 271 | choice_option: T_PROMPT prompt if_expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 272 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 273 | menu_add_prompt(P_PROMPT, $2, $3); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 274 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); |
| 275 | }; |
| 276 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 277 | choice_option: T_TRISTATE prompt_stmt_opt T_EOL |
| 278 | { |
| 279 | menu_set_type(S_TRISTATE); |
| 280 | printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno()); |
| 281 | }; |
| 282 | |
| 283 | choice_option: T_BOOLEAN prompt_stmt_opt T_EOL |
| 284 | { |
| 285 | menu_set_type(S_BOOLEAN); |
| 286 | printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno()); |
| 287 | }; |
| 288 | |
| 289 | choice_option: T_OPTIONAL T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 290 | { |
| 291 | current_entry->sym->flags |= SYMBOL_OPTIONAL; |
| 292 | printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno()); |
| 293 | }; |
| 294 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 295 | choice_option: T_DEFAULT T_WORD if_expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 296 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 297 | menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 298 | printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno()); |
| 299 | }; |
| 300 | |
| 301 | choice_block: |
| 302 | /* empty */ |
| 303 | | choice_block common_block |
| 304 | ; |
| 305 | |
| 306 | /* if entry */ |
| 307 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 308 | if: T_IF expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 309 | { |
| 310 | printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); |
| 311 | menu_add_entry(NULL); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 312 | menu_add_dep($2); |
| 313 | menu_end_entry(); |
| 314 | menu_add_menu(); |
| 315 | }; |
| 316 | |
| 317 | if_end: end |
| 318 | { |
| 319 | if (zconf_endtoken($1, T_IF, T_ENDIF)) { |
| 320 | menu_end_menu(); |
| 321 | printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); |
| 322 | } |
| 323 | }; |
| 324 | |
| 325 | if_stmt: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 326 | if if_block if_end |
| 327 | | if if_block |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 328 | { |
| 329 | printf("%s:%d: missing 'endif' for this 'if' statement\n", current_menu->file->name, current_menu->lineno); |
| 330 | zconfnerrs++; |
| 331 | }; |
| 332 | |
| 333 | if_block: |
| 334 | /* empty */ |
| 335 | | if_block common_block |
| 336 | | if_block menu_stmt |
| 337 | | if_block choice_stmt |
| 338 | ; |
| 339 | |
| 340 | /* menu entry */ |
| 341 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 342 | menu: T_MENU prompt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 343 | { |
| 344 | menu_add_entry(NULL); |
| 345 | menu_add_prop(P_MENU, $2, NULL, NULL); |
| 346 | printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); |
| 347 | }; |
| 348 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 349 | menu_entry: menu depends_list |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 350 | { |
| 351 | menu_end_entry(); |
| 352 | menu_add_menu(); |
| 353 | }; |
| 354 | |
| 355 | menu_end: end |
| 356 | { |
| 357 | if (zconf_endtoken($1, T_MENU, T_ENDMENU)) { |
| 358 | menu_end_menu(); |
| 359 | printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); |
| 360 | } |
| 361 | }; |
| 362 | |
| 363 | menu_stmt: |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 364 | menu_entry menu_block menu_end |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 365 | | menu_entry menu_block |
| 366 | { |
| 367 | printf("%s:%d: missing 'endmenu' for this 'menu' statement\n", current_menu->file->name, current_menu->lineno); |
| 368 | zconfnerrs++; |
| 369 | }; |
| 370 | |
| 371 | menu_block: |
| 372 | /* empty */ |
| 373 | | menu_block common_block |
| 374 | | menu_block menu_stmt |
| 375 | | menu_block choice_stmt |
| 376 | | menu_block error T_EOL { zconfprint("invalid menu option"); yyerrok; } |
| 377 | ; |
| 378 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 379 | source: T_SOURCE prompt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 380 | { |
| 381 | $$ = $2; |
| 382 | printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); |
| 383 | }; |
| 384 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 385 | source_stmt: source |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 386 | { |
| 387 | zconf_nextfile($1); |
| 388 | }; |
| 389 | |
| 390 | /* comment entry */ |
| 391 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 392 | comment: T_COMMENT prompt T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 393 | { |
| 394 | menu_add_entry(NULL); |
| 395 | menu_add_prop(P_COMMENT, $2, NULL, NULL); |
| 396 | printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); |
| 397 | }; |
| 398 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 399 | comment_stmt: comment depends_list |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 400 | { |
| 401 | menu_end_entry(); |
| 402 | }; |
| 403 | |
| 404 | /* help option */ |
| 405 | |
| 406 | help_start: T_HELP T_EOL |
| 407 | { |
| 408 | printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); |
| 409 | zconf_starthelp(); |
| 410 | }; |
| 411 | |
| 412 | help: help_start T_HELPTEXT |
| 413 | { |
| 414 | current_entry->sym->help = $2; |
| 415 | }; |
| 416 | |
| 417 | /* depends option */ |
| 418 | |
| 419 | depends_list: /* empty */ |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 420 | | depends_list depends |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 421 | | depends_list T_EOL |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 422 | ; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 423 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 424 | depends: T_DEPENDS T_ON expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 425 | { |
| 426 | menu_add_dep($3); |
| 427 | printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); |
| 428 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 429 | | T_DEPENDS expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 430 | { |
| 431 | menu_add_dep($2); |
| 432 | printd(DEBUG_PARSE, "%s:%d:depends\n", zconf_curname(), zconf_lineno()); |
| 433 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 434 | | T_REQUIRES expr T_EOL |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 435 | { |
| 436 | menu_add_dep($2); |
| 437 | printd(DEBUG_PARSE, "%s:%d:requires\n", zconf_curname(), zconf_lineno()); |
| 438 | }; |
| 439 | |
| 440 | /* prompt statement */ |
| 441 | |
| 442 | prompt_stmt_opt: |
| 443 | /* empty */ |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 444 | | prompt if_expr |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 445 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 446 | menu_add_prop(P_PROMPT, $1, NULL, $2); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 447 | }; |
| 448 | |
| 449 | prompt: T_WORD |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 450 | | T_WORD_QUOTE |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 451 | ; |
| 452 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 453 | end: T_ENDMENU nl_or_eof { $$ = T_ENDMENU; } |
| 454 | | T_ENDCHOICE nl_or_eof { $$ = T_ENDCHOICE; } |
| 455 | | T_ENDIF nl_or_eof { $$ = T_ENDIF; } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 456 | ; |
| 457 | |
| 458 | nl_or_eof: |
| 459 | T_EOL | T_EOF; |
| 460 | |
| 461 | if_expr: /* empty */ { $$ = NULL; } |
| 462 | | T_IF expr { $$ = $2; } |
| 463 | ; |
| 464 | |
| 465 | expr: symbol { $$ = expr_alloc_symbol($1); } |
| 466 | | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); } |
| 467 | | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); } |
| 468 | | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; } |
| 469 | | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); } |
| 470 | | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); } |
| 471 | | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); } |
| 472 | ; |
| 473 | |
| 474 | symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 475 | | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 476 | ; |
| 477 | |
| 478 | %% |
| 479 | |
| 480 | void conf_parse(const char *name) |
| 481 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 482 | struct symbol *sym; |
| 483 | int i; |
| 484 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 485 | zconf_initscan(name); |
| 486 | |
| 487 | sym_init(); |
| 488 | menu_init(); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 489 | modules_sym = sym_lookup("MODULES", 0); |
Eric Andersen | 7001480 | 2003-08-05 05:59:48 +0000 | [diff] [blame] | 490 | rootmenu.prompt = menu_add_prop(P_MENU, "BusyBox Configuration", NULL, NULL); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 491 | |
| 492 | //zconfdebug = 1; |
| 493 | zconfparse(); |
| 494 | if (zconfnerrs) |
| 495 | exit(1); |
| 496 | menu_finalize(&rootmenu); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 497 | for_all_symbols(i, sym) { |
| 498 | if (!(sym->flags & SYMBOL_CHECKED) && sym_check_deps(sym)) |
| 499 | printf("\n"); |
| 500 | else |
| 501 | sym->flags |= SYMBOL_CHECK_DONE; |
| 502 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 503 | |
| 504 | sym_change_count = 1; |
| 505 | } |
| 506 | |
| 507 | const char *zconf_tokenname(int token) |
| 508 | { |
| 509 | switch (token) { |
| 510 | case T_MENU: return "menu"; |
| 511 | case T_ENDMENU: return "endmenu"; |
| 512 | case T_CHOICE: return "choice"; |
| 513 | case T_ENDCHOICE: return "endchoice"; |
| 514 | case T_IF: return "if"; |
| 515 | case T_ENDIF: return "endif"; |
| 516 | } |
| 517 | return "<token>"; |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 518 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 519 | |
| 520 | static bool zconf_endtoken(int token, int starttoken, int endtoken) |
| 521 | { |
| 522 | if (token != endtoken) { |
| 523 | zconfprint("unexpected '%s' within %s block", zconf_tokenname(token), zconf_tokenname(starttoken)); |
| 524 | zconfnerrs++; |
| 525 | return false; |
| 526 | } |
| 527 | if (current_menu->file != current_file) { |
| 528 | zconfprint("'%s' in different file than '%s'", zconf_tokenname(token), zconf_tokenname(starttoken)); |
| 529 | zconfprint("location of the '%s'", zconf_tokenname(starttoken)); |
| 530 | zconfnerrs++; |
| 531 | return false; |
| 532 | } |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | static void zconfprint(const char *err, ...) |
| 537 | { |
| 538 | va_list ap; |
| 539 | |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 540 | fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno() + 1); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 541 | va_start(ap, err); |
| 542 | vfprintf(stderr, err, ap); |
| 543 | va_end(ap); |
| 544 | fprintf(stderr, "\n"); |
| 545 | } |
| 546 | |
| 547 | static void zconferror(const char *err) |
| 548 | { |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 549 | fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | void print_quoted_string(FILE *out, const char *str) |
| 553 | { |
| 554 | const char *p; |
| 555 | int len; |
| 556 | |
| 557 | putc('"', out); |
| 558 | while ((p = strchr(str, '"'))) { |
| 559 | len = p - str; |
| 560 | if (len) |
| 561 | fprintf(out, "%.*s", len, str); |
| 562 | fputs("\\\"", out); |
| 563 | str = p + 1; |
| 564 | } |
| 565 | fputs(str, out); |
| 566 | putc('"', out); |
| 567 | } |
| 568 | |
| 569 | void print_symbol(FILE *out, struct menu *menu) |
| 570 | { |
| 571 | struct symbol *sym = menu->sym; |
| 572 | struct property *prop; |
| 573 | |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 574 | if (sym_is_choice(sym)) |
| 575 | fprintf(out, "choice\n"); |
| 576 | else |
| 577 | fprintf(out, "config %s\n", sym->name); |
| 578 | switch (sym->type) { |
| 579 | case S_BOOLEAN: |
| 580 | fputs(" boolean\n", out); |
| 581 | break; |
| 582 | case S_TRISTATE: |
| 583 | fputs(" tristate\n", out); |
| 584 | break; |
| 585 | case S_STRING: |
| 586 | fputs(" string\n", out); |
| 587 | break; |
| 588 | case S_INT: |
| 589 | fputs(" integer\n", out); |
| 590 | break; |
| 591 | case S_HEX: |
| 592 | fputs(" hex\n", out); |
| 593 | break; |
| 594 | default: |
| 595 | fputs(" ???\n", out); |
| 596 | break; |
| 597 | } |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 598 | for (prop = sym->prop; prop; prop = prop->next) { |
| 599 | if (prop->menu != menu) |
| 600 | continue; |
| 601 | switch (prop->type) { |
| 602 | case P_PROMPT: |
| 603 | fputs(" prompt ", out); |
| 604 | print_quoted_string(out, prop->text); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 605 | if (!expr_is_yes(prop->visible.expr)) { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 606 | fputs(" if ", out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 607 | expr_fprint(prop->visible.expr, out); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 608 | } |
| 609 | fputc('\n', out); |
| 610 | break; |
| 611 | case P_DEFAULT: |
| 612 | fputs( " default ", out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 613 | expr_fprint(prop->expr, out); |
| 614 | if (!expr_is_yes(prop->visible.expr)) { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 615 | fputs(" if ", out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 616 | expr_fprint(prop->visible.expr, out); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 617 | } |
| 618 | fputc('\n', out); |
| 619 | break; |
| 620 | case P_CHOICE: |
| 621 | fputs(" #choice value\n", out); |
| 622 | break; |
| 623 | default: |
| 624 | fprintf(out, " unknown prop %d!\n", prop->type); |
| 625 | break; |
| 626 | } |
| 627 | } |
| 628 | if (sym->help) { |
| 629 | int len = strlen(sym->help); |
| 630 | while (sym->help[--len] == '\n') |
| 631 | sym->help[len] = 0; |
| 632 | fprintf(out, " help\n%s\n", sym->help); |
| 633 | } |
| 634 | fputc('\n', out); |
| 635 | } |
| 636 | |
| 637 | void zconfdump(FILE *out) |
| 638 | { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 639 | struct property *prop; |
| 640 | struct symbol *sym; |
| 641 | struct menu *menu; |
| 642 | |
| 643 | menu = rootmenu.list; |
| 644 | while (menu) { |
| 645 | if ((sym = menu->sym)) |
| 646 | print_symbol(out, menu); |
| 647 | else if ((prop = menu->prompt)) { |
| 648 | switch (prop->type) { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 649 | case P_COMMENT: |
| 650 | fputs("\ncomment ", out); |
| 651 | print_quoted_string(out, prop->text); |
| 652 | fputs("\n", out); |
| 653 | break; |
| 654 | case P_MENU: |
| 655 | fputs("\nmenu ", out); |
| 656 | print_quoted_string(out, prop->text); |
| 657 | fputs("\n", out); |
| 658 | break; |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 659 | default: |
| 660 | ; |
| 661 | } |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 662 | if (!expr_is_yes(prop->visible.expr)) { |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 663 | fputs(" depends ", out); |
Eric Andersen | 72d8e44 | 2003-08-05 02:18:25 +0000 | [diff] [blame] | 664 | expr_fprint(prop->visible.expr, out); |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 665 | fputc('\n', out); |
| 666 | } |
| 667 | fputs("\n", out); |
| 668 | } |
| 669 | |
| 670 | if (menu->list) |
| 671 | menu = menu->list; |
| 672 | else if (menu->next) |
| 673 | menu = menu->next; |
| 674 | else while ((menu = menu->parent)) { |
| 675 | if (menu->prompt && menu->prompt->type == P_MENU) |
| 676 | fputs("\nendmenu\n", out); |
| 677 | if (menu->next) { |
| 678 | menu = menu->next; |
| 679 | break; |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | #include "lex.zconf.c" |
Peter Kjellerstedt | bae38db | 2005-04-19 09:55:06 +0000 | [diff] [blame] | 686 | #include "util.c" |
Eric Andersen | c9f20d9 | 2002-12-05 08:41:41 +0000 | [diff] [blame] | 687 | #include "confdata.c" |
| 688 | #include "expr.c" |
| 689 | #include "symbol.c" |
| 690 | #include "menu.c" |