Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 3 | * Released under the terms of the GNU GPL v2.0. |
| 4 | */ |
| 5 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 6 | #include <locale.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <ctype.h> |
Randy Dunlap | 9dfb563 | 2006-04-18 22:21:53 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 9 | #include <stdlib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <time.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 12 | #include <unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <sys/stat.h> |
| 14 | |
| 15 | #define LKC_DIRECT_LINK |
| 16 | #include "lkc.h" |
| 17 | |
| 18 | static void conf(struct menu *menu); |
| 19 | static void check_conf(struct menu *menu); |
| 20 | |
| 21 | enum { |
| 22 | ask_all, |
| 23 | ask_new, |
| 24 | ask_silent, |
| 25 | set_default, |
| 26 | set_yes, |
| 27 | set_mod, |
| 28 | set_no, |
| 29 | set_random |
| 30 | } input_mode = ask_all; |
| 31 | char *defconfig_file; |
| 32 | |
| 33 | static int indent = 1; |
| 34 | static int valid_stdin = 1; |
| 35 | static int conf_cnt; |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 36 | static char line[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static struct menu *rootEntry; |
| 38 | |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 39 | static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 41 | static const char *get_help(struct menu *menu) |
| 42 | { |
| 43 | if (menu_has_help(menu)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 44 | return _(menu_get_help(menu)); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 45 | else |
| 46 | return nohelp_text; |
| 47 | } |
| 48 | |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 49 | static void strip(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 51 | char *p = str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | int l; |
| 53 | |
| 54 | while ((isspace(*p))) |
| 55 | p++; |
| 56 | l = strlen(p); |
| 57 | if (p != str) |
| 58 | memmove(str, p, l + 1); |
| 59 | if (!l) |
| 60 | return; |
| 61 | p = str + l - 1; |
| 62 | while ((isspace(*p))) |
| 63 | *p-- = 0; |
| 64 | } |
| 65 | |
| 66 | static void check_stdin(void) |
| 67 | { |
| 68 | if (!valid_stdin && input_mode == ask_silent) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 69 | printf(_("aborted!\n\n")); |
| 70 | printf(_("Console input/output is redirected. ")); |
| 71 | printf(_("Run 'make oldconfig' to update configuration.\n\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | exit(1); |
| 73 | } |
| 74 | } |
| 75 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 76 | static int conf_askvalue(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | enum symbol_type type = sym_get_type(sym); |
| 79 | tristate val; |
| 80 | |
| 81 | if (!sym_has_value(sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 82 | printf(_("(NEW) ")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | line[0] = '\n'; |
| 85 | line[1] = 0; |
| 86 | |
| 87 | if (!sym_is_changable(sym)) { |
| 88 | printf("%s\n", def); |
| 89 | line[0] = '\n'; |
| 90 | line[1] = 0; |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 91 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | switch (input_mode) { |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 95 | case set_no: |
| 96 | case set_mod: |
| 97 | case set_yes: |
| 98 | case set_random: |
| 99 | if (sym_has_value(sym)) { |
| 100 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 101 | return 0; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 102 | } |
| 103 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | case ask_new: |
| 105 | case ask_silent: |
| 106 | if (sym_has_value(sym)) { |
| 107 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 108 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | check_stdin(); |
| 111 | case ask_all: |
| 112 | fflush(stdout); |
Roman Zippel | 59c6a3f | 2006-04-09 17:26:50 +0200 | [diff] [blame] | 113 | fgets(line, 128, stdin); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 114 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | case set_default: |
| 116 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 117 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | default: |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | switch (type) { |
| 123 | case S_INT: |
| 124 | case S_HEX: |
| 125 | case S_STRING: |
| 126 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 127 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | default: |
| 129 | ; |
| 130 | } |
| 131 | switch (input_mode) { |
| 132 | case set_yes: |
| 133 | if (sym_tristate_within_range(sym, yes)) { |
| 134 | line[0] = 'y'; |
| 135 | line[1] = '\n'; |
| 136 | line[2] = 0; |
| 137 | break; |
| 138 | } |
| 139 | case set_mod: |
| 140 | if (type == S_TRISTATE) { |
| 141 | if (sym_tristate_within_range(sym, mod)) { |
| 142 | line[0] = 'm'; |
| 143 | line[1] = '\n'; |
| 144 | line[2] = 0; |
| 145 | break; |
| 146 | } |
| 147 | } else { |
| 148 | if (sym_tristate_within_range(sym, yes)) { |
| 149 | line[0] = 'y'; |
| 150 | line[1] = '\n'; |
| 151 | line[2] = 0; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | case set_no: |
| 156 | if (sym_tristate_within_range(sym, no)) { |
| 157 | line[0] = 'n'; |
| 158 | line[1] = '\n'; |
| 159 | line[2] = 0; |
| 160 | break; |
| 161 | } |
| 162 | case set_random: |
| 163 | do { |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 164 | val = (tristate)(rand() % 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } while (!sym_tristate_within_range(sym, val)); |
| 166 | switch (val) { |
| 167 | case no: line[0] = 'n'; break; |
| 168 | case mod: line[0] = 'm'; break; |
| 169 | case yes: line[0] = 'y'; break; |
| 170 | } |
| 171 | line[1] = '\n'; |
| 172 | line[2] = 0; |
| 173 | break; |
| 174 | default: |
| 175 | break; |
| 176 | } |
| 177 | printf("%s", line); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 178 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | int conf_string(struct menu *menu) |
| 182 | { |
| 183 | struct symbol *sym = menu->sym; |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 184 | const char *def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 187 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | printf("(%s) ", sym->name); |
| 189 | def = sym_get_string_value(sym); |
| 190 | if (sym_get_string_value(sym)) |
| 191 | printf("[%s] ", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 192 | if (!conf_askvalue(sym, def)) |
| 193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | switch (line[0]) { |
| 195 | case '\n': |
| 196 | break; |
| 197 | case '?': |
| 198 | /* print help */ |
| 199 | if (line[1] == '\n') { |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 200 | printf("\n%s\n", get_help(menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | def = NULL; |
| 202 | break; |
| 203 | } |
| 204 | default: |
| 205 | line[strlen(line)-1] = 0; |
| 206 | def = line; |
| 207 | } |
| 208 | if (def && sym_set_string_value(sym, def)) |
| 209 | return 0; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | static int conf_sym(struct menu *menu) |
| 214 | { |
| 215 | struct symbol *sym = menu->sym; |
| 216 | int type; |
| 217 | tristate oldval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 220 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | if (sym->name) |
| 222 | printf("(%s) ", sym->name); |
| 223 | type = sym_get_type(sym); |
| 224 | putchar('['); |
| 225 | oldval = sym_get_tristate_value(sym); |
| 226 | switch (oldval) { |
| 227 | case no: |
| 228 | putchar('N'); |
| 229 | break; |
| 230 | case mod: |
| 231 | putchar('M'); |
| 232 | break; |
| 233 | case yes: |
| 234 | putchar('Y'); |
| 235 | break; |
| 236 | } |
| 237 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 238 | printf("/n"); |
| 239 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 240 | printf("/m"); |
| 241 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 242 | printf("/y"); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 243 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | printf("/?"); |
| 245 | printf("] "); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 246 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 247 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | strip(line); |
| 249 | |
| 250 | switch (line[0]) { |
| 251 | case 'n': |
| 252 | case 'N': |
| 253 | newval = no; |
| 254 | if (!line[1] || !strcmp(&line[1], "o")) |
| 255 | break; |
| 256 | continue; |
| 257 | case 'm': |
| 258 | case 'M': |
| 259 | newval = mod; |
| 260 | if (!line[1]) |
| 261 | break; |
| 262 | continue; |
| 263 | case 'y': |
| 264 | case 'Y': |
| 265 | newval = yes; |
| 266 | if (!line[1] || !strcmp(&line[1], "es")) |
| 267 | break; |
| 268 | continue; |
| 269 | case 0: |
| 270 | newval = oldval; |
| 271 | break; |
| 272 | case '?': |
| 273 | goto help; |
| 274 | default: |
| 275 | continue; |
| 276 | } |
| 277 | if (sym_set_tristate_value(sym, newval)) |
| 278 | return 0; |
| 279 | help: |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 280 | printf("\n%s\n", get_help(menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | static int conf_choice(struct menu *menu) |
| 285 | { |
| 286 | struct symbol *sym, *def_sym; |
| 287 | struct menu *child; |
| 288 | int type; |
| 289 | bool is_new; |
| 290 | |
| 291 | sym = menu->sym; |
| 292 | type = sym_get_type(sym); |
| 293 | is_new = !sym_has_value(sym); |
| 294 | if (sym_is_changable(sym)) { |
| 295 | conf_sym(menu); |
| 296 | sym_calc_value(sym); |
| 297 | switch (sym_get_tristate_value(sym)) { |
| 298 | case no: |
| 299 | return 1; |
| 300 | case mod: |
| 301 | return 0; |
| 302 | case yes: |
| 303 | break; |
| 304 | } |
| 305 | } else { |
| 306 | switch (sym_get_tristate_value(sym)) { |
| 307 | case no: |
| 308 | return 1; |
| 309 | case mod: |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 310 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return 0; |
| 312 | case yes: |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | while (1) { |
| 318 | int cnt, def; |
| 319 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 320 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | def_sym = sym_get_choice_value(sym); |
| 322 | cnt = def = 0; |
Roman Zippel | 40aee72 | 2006-04-09 17:26:39 +0200 | [diff] [blame] | 323 | line[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | for (child = menu->list; child; child = child->next) { |
| 325 | if (!menu_is_visible(child)) |
| 326 | continue; |
| 327 | if (!child->sym) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 328 | printf("%*c %s\n", indent, '*', _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | continue; |
| 330 | } |
| 331 | cnt++; |
| 332 | if (child->sym == def_sym) { |
| 333 | def = cnt; |
| 334 | printf("%*c", indent, '>'); |
| 335 | } else |
| 336 | printf("%*c", indent, ' '); |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 337 | printf(" %d. %s", cnt, _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (child->sym->name) |
| 339 | printf(" (%s)", child->sym->name); |
| 340 | if (!sym_has_value(child->sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 341 | printf(_(" (NEW)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | printf("\n"); |
| 343 | } |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 344 | printf(_("%*schoice"), indent - 1, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | if (cnt == 1) { |
| 346 | printf("[1]: 1\n"); |
| 347 | goto conf_childs; |
| 348 | } |
| 349 | printf("[1-%d", cnt); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 350 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | printf("?"); |
| 352 | printf("]: "); |
| 353 | switch (input_mode) { |
| 354 | case ask_new: |
| 355 | case ask_silent: |
| 356 | if (!is_new) { |
| 357 | cnt = def; |
| 358 | printf("%d\n", cnt); |
| 359 | break; |
| 360 | } |
| 361 | check_stdin(); |
| 362 | case ask_all: |
| 363 | fflush(stdout); |
Roman Zippel | 59c6a3f | 2006-04-09 17:26:50 +0200 | [diff] [blame] | 364 | fgets(line, 128, stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | strip(line); |
| 366 | if (line[0] == '?') { |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 367 | printf("\n%s\n", get_help(menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | continue; |
| 369 | } |
| 370 | if (!line[0]) |
| 371 | cnt = def; |
| 372 | else if (isdigit(line[0])) |
| 373 | cnt = atoi(line); |
| 374 | else |
| 375 | continue; |
| 376 | break; |
| 377 | case set_random: |
Paul Mundt | 870e6f7 | 2007-12-22 14:03:30 -0800 | [diff] [blame] | 378 | if (is_new) |
Ladislav Michl | 07f7668 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 379 | def = (rand() % cnt) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | case set_default: |
| 381 | case set_yes: |
| 382 | case set_mod: |
| 383 | case set_no: |
| 384 | cnt = def; |
| 385 | printf("%d\n", cnt); |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | conf_childs: |
| 390 | for (child = menu->list; child; child = child->next) { |
| 391 | if (!child->sym || !menu_is_visible(child)) |
| 392 | continue; |
| 393 | if (!--cnt) |
| 394 | break; |
| 395 | } |
| 396 | if (!child) |
| 397 | continue; |
| 398 | if (line[strlen(line) - 1] == '?') { |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 399 | printf("\n%s\n", get_help(child)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | continue; |
| 401 | } |
| 402 | sym_set_choice_value(sym, child->sym); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 403 | for (child = child->list; child; child = child->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | indent += 2; |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 405 | conf(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | indent -= 2; |
| 407 | } |
| 408 | return 1; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | static void conf(struct menu *menu) |
| 413 | { |
| 414 | struct symbol *sym; |
| 415 | struct property *prop; |
| 416 | struct menu *child; |
| 417 | |
| 418 | if (!menu_is_visible(menu)) |
| 419 | return; |
| 420 | |
| 421 | sym = menu->sym; |
| 422 | prop = menu->prompt; |
| 423 | if (prop) { |
| 424 | const char *prompt; |
| 425 | |
| 426 | switch (prop->type) { |
| 427 | case P_MENU: |
| 428 | if (input_mode == ask_silent && rootEntry != menu) { |
| 429 | check_conf(menu); |
| 430 | return; |
| 431 | } |
| 432 | case P_COMMENT: |
| 433 | prompt = menu_get_prompt(menu); |
| 434 | if (prompt) |
| 435 | printf("%*c\n%*c %s\n%*c\n", |
| 436 | indent, '*', |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 437 | indent, '*', _(prompt), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | indent, '*'); |
| 439 | default: |
| 440 | ; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (!sym) |
| 445 | goto conf_childs; |
| 446 | |
| 447 | if (sym_is_choice(sym)) { |
| 448 | conf_choice(menu); |
| 449 | if (sym->curr.tri != mod) |
| 450 | return; |
| 451 | goto conf_childs; |
| 452 | } |
| 453 | |
| 454 | switch (sym->type) { |
| 455 | case S_INT: |
| 456 | case S_HEX: |
| 457 | case S_STRING: |
| 458 | conf_string(menu); |
| 459 | break; |
| 460 | default: |
| 461 | conf_sym(menu); |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | conf_childs: |
| 466 | if (sym) |
| 467 | indent += 2; |
| 468 | for (child = menu->list; child; child = child->next) |
| 469 | conf(child); |
| 470 | if (sym) |
| 471 | indent -= 2; |
| 472 | } |
| 473 | |
| 474 | static void check_conf(struct menu *menu) |
| 475 | { |
| 476 | struct symbol *sym; |
| 477 | struct menu *child; |
| 478 | |
| 479 | if (!menu_is_visible(menu)) |
| 480 | return; |
| 481 | |
| 482 | sym = menu->sym; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 483 | if (sym && !sym_has_value(sym)) { |
| 484 | if (sym_is_changable(sym) || |
| 485 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | if (!conf_cnt++) |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 487 | printf(_("*\n* Restart config...\n*\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | rootEntry = menu_get_parent_menu(menu); |
| 489 | conf(rootEntry); |
| 490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | for (child = menu->list; child; child = child->next) |
| 494 | check_conf(child); |
| 495 | } |
| 496 | |
| 497 | int main(int ac, char **av) |
| 498 | { |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 499 | int opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | const char *name; |
| 501 | struct stat tmpstat; |
| 502 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 503 | setlocale(LC_ALL, ""); |
| 504 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 505 | textdomain(PACKAGE); |
| 506 | |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 507 | while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) { |
| 508 | switch (opt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | case 'o': |
| 510 | input_mode = ask_new; |
| 511 | break; |
| 512 | case 's': |
| 513 | input_mode = ask_silent; |
| 514 | valid_stdin = isatty(0) && isatty(1) && isatty(2); |
| 515 | break; |
| 516 | case 'd': |
| 517 | input_mode = set_default; |
| 518 | break; |
| 519 | case 'D': |
| 520 | input_mode = set_default; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 521 | defconfig_file = optarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | break; |
| 523 | case 'n': |
| 524 | input_mode = set_no; |
| 525 | break; |
| 526 | case 'm': |
| 527 | input_mode = set_mod; |
| 528 | break; |
| 529 | case 'y': |
| 530 | input_mode = set_yes; |
| 531 | break; |
| 532 | case 'r': |
| 533 | input_mode = set_random; |
Ladislav Michl | 07f7668 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 534 | srand(time(NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | break; |
| 536 | case 'h': |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 537 | printf(_("See README for usage info\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | exit(0); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 539 | break; |
| 540 | default: |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 541 | fprintf(stderr, _("See README for usage info\n")); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 542 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 545 | if (ac == optind) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 546 | printf(_("%s: Kconfig file missing\n"), av[0]); |
Randy Dunlap | 250725a | 2006-06-08 22:12:50 -0700 | [diff] [blame] | 547 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 549 | name = av[optind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | conf_parse(name); |
| 551 | //zconfdump(stdout); |
| 552 | switch (input_mode) { |
| 553 | case set_default: |
| 554 | if (!defconfig_file) |
| 555 | defconfig_file = conf_get_default_confname(); |
| 556 | if (conf_read(defconfig_file)) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 557 | printf(_("***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | "*** Can't find default configuration \"%s\"!\n" |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 559 | "***\n"), defconfig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | exit(1); |
| 561 | } |
| 562 | break; |
| 563 | case ask_silent: |
| 564 | if (stat(".config", &tmpstat)) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 565 | printf(_("***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | "*** You have not yet configured your kernel!\n" |
Randy Dunlap | 7ac1c14 | 2007-04-04 21:58:41 -0700 | [diff] [blame] | 567 | "*** (missing kernel .config file)\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | "***\n" |
| 569 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" |
| 570 | "*** \"make menuconfig\" or \"make xconfig\").\n" |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 571 | "***\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | exit(1); |
| 573 | } |
| 574 | case ask_all: |
| 575 | case ask_new: |
| 576 | conf_read(NULL); |
| 577 | break; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 578 | case set_no: |
| 579 | case set_mod: |
| 580 | case set_yes: |
| 581 | case set_random: |
| 582 | name = getenv("KCONFIG_ALLCONFIG"); |
| 583 | if (name && !stat(name, &tmpstat)) { |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 584 | conf_read_simple(name, S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 585 | break; |
| 586 | } |
| 587 | switch (input_mode) { |
| 588 | case set_no: name = "allno.config"; break; |
| 589 | case set_mod: name = "allmod.config"; break; |
| 590 | case set_yes: name = "allyes.config"; break; |
| 591 | case set_random: name = "allrandom.config"; break; |
| 592 | default: break; |
| 593 | } |
| 594 | if (!stat(name, &tmpstat)) |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 595 | conf_read_simple(name, S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 596 | else if (!stat("all.config", &tmpstat)) |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 597 | conf_read_simple("all.config", S_DEF_USER); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 598 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | default: |
| 600 | break; |
| 601 | } |
| 602 | |
| 603 | if (input_mode != ask_silent) { |
| 604 | rootEntry = &rootmenu; |
| 605 | conf(&rootmenu); |
| 606 | if (input_mode == ask_all) { |
| 607 | input_mode = ask_silent; |
| 608 | valid_stdin = 1; |
| 609 | } |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 610 | } else if (conf_get_changed()) { |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 611 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 612 | if (name && *name) { |
| 613 | fprintf(stderr, _("\n*** Kernel configuration requires explicit update.\n\n")); |
| 614 | return 1; |
| 615 | } |
| 616 | } else |
| 617 | goto skip_check; |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | do { |
| 620 | conf_cnt = 0; |
| 621 | check_conf(&rootmenu); |
| 622 | } while (conf_cnt); |
| 623 | if (conf_write(NULL)) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 624 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return 1; |
| 626 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 627 | skip_check: |
| 628 | if (input_mode == ask_silent && conf_write_autoconf()) { |
| 629 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); |
| 630 | return 1; |
| 631 | } |
| 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return 0; |
| 634 | } |