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