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> |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 8 | #include <limits.h> |
Randy Dunlap | 9dfb563 | 2006-04-18 22:21:53 -0700 | [diff] [blame] | 9 | #include <stdio.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 10 | #include <stdlib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <time.h> |
Ladislav Michl | 75ff430 | 2008-01-09 16:36:19 +0100 | [diff] [blame] | 13 | #include <unistd.h> |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 14 | #include <getopt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <sys/stat.h> |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 16 | #include <sys/time.h> |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 17 | #include <errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "lkc.h" |
| 20 | |
| 21 | static void conf(struct menu *menu); |
| 22 | static void check_conf(struct menu *menu); |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 23 | static void xfgets(char *str, int size, FILE *in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 25 | enum input_mode { |
| 26 | oldaskconfig, |
| 27 | silentoldconfig, |
| 28 | oldconfig, |
| 29 | allnoconfig, |
| 30 | allyesconfig, |
| 31 | allmodconfig, |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 32 | alldefconfig, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 33 | randconfig, |
| 34 | defconfig, |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 35 | savedefconfig, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 36 | listnewconfig, |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 37 | olddefconfig, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 38 | } input_mode = oldaskconfig; |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static int indent = 1; |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 41 | static int tty_stdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static int valid_stdin = 1; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 43 | static int sync_kconfig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static int conf_cnt; |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 45 | static char line[PATH_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static struct menu *rootEntry; |
| 47 | |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 48 | static void print_help(struct menu *menu) |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 49 | { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 50 | struct gstr help = str_new(); |
| 51 | |
| 52 | menu_get_ext_help(menu, &help); |
| 53 | |
| 54 | printf("\n%s\n", str_get(&help)); |
| 55 | str_free(&help); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 56 | } |
| 57 | |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 58 | static void strip(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 60 | char *p = str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int l; |
| 62 | |
| 63 | while ((isspace(*p))) |
| 64 | p++; |
| 65 | l = strlen(p); |
| 66 | if (p != str) |
| 67 | memmove(str, p, l + 1); |
| 68 | if (!l) |
| 69 | return; |
| 70 | p = str + l - 1; |
| 71 | while ((isspace(*p))) |
| 72 | *p-- = 0; |
| 73 | } |
| 74 | |
| 75 | static void check_stdin(void) |
| 76 | { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 77 | if (!valid_stdin) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 78 | printf(_("aborted!\n\n")); |
| 79 | printf(_("Console input/output is redirected. ")); |
| 80 | printf(_("Run 'make oldconfig' to update configuration.\n\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | exit(1); |
| 82 | } |
| 83 | } |
| 84 | |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 85 | static int conf_askvalue(struct symbol *sym, const char *def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | enum symbol_type type = sym_get_type(sym); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | if (!sym_has_value(sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 90 | printf(_("(NEW) ")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | line[0] = '\n'; |
| 93 | line[1] = 0; |
| 94 | |
| 95 | if (!sym_is_changable(sym)) { |
| 96 | printf("%s\n", def); |
| 97 | line[0] = '\n'; |
| 98 | line[1] = 0; |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 99 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 103 | case oldconfig: |
| 104 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | if (sym_has_value(sym)) { |
| 106 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 107 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | check_stdin(); |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 110 | /* fall through */ |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 111 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 113 | xfgets(line, sizeof(line), stdin); |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 114 | if (!tty_stdio) |
| 115 | printf("\n"); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 116 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | default: |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | switch (type) { |
| 122 | case S_INT: |
| 123 | case S_HEX: |
| 124 | case S_STRING: |
| 125 | printf("%s\n", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 126 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | default: |
| 128 | ; |
| 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | printf("%s", line); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 131 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 134 | static int conf_string(struct menu *menu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | struct symbol *sym = menu->sym; |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 137 | const char *def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 140 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | printf("(%s) ", sym->name); |
| 142 | def = sym_get_string_value(sym); |
| 143 | if (sym_get_string_value(sym)) |
| 144 | printf("[%s] ", def); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 145 | if (!conf_askvalue(sym, def)) |
| 146 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | switch (line[0]) { |
| 148 | case '\n': |
| 149 | break; |
| 150 | case '?': |
| 151 | /* print help */ |
| 152 | if (line[1] == '\n') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 153 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | def = NULL; |
| 155 | break; |
| 156 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 157 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | default: |
| 159 | line[strlen(line)-1] = 0; |
| 160 | def = line; |
| 161 | } |
| 162 | if (def && sym_set_string_value(sym, def)) |
| 163 | return 0; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | static int conf_sym(struct menu *menu) |
| 168 | { |
| 169 | struct symbol *sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | tristate oldval, newval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | while (1) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 173 | printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (sym->name) |
| 175 | printf("(%s) ", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | putchar('['); |
| 177 | oldval = sym_get_tristate_value(sym); |
| 178 | switch (oldval) { |
| 179 | case no: |
| 180 | putchar('N'); |
| 181 | break; |
| 182 | case mod: |
| 183 | putchar('M'); |
| 184 | break; |
| 185 | case yes: |
| 186 | putchar('Y'); |
| 187 | break; |
| 188 | } |
| 189 | if (oldval != no && sym_tristate_within_range(sym, no)) |
| 190 | printf("/n"); |
| 191 | if (oldval != mod && sym_tristate_within_range(sym, mod)) |
| 192 | printf("/m"); |
| 193 | if (oldval != yes && sym_tristate_within_range(sym, yes)) |
| 194 | printf("/y"); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 195 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | printf("/?"); |
| 197 | printf("] "); |
Roman Zippel | f82f3f9 | 2007-08-30 05:06:17 +0200 | [diff] [blame] | 198 | if (!conf_askvalue(sym, sym_get_string_value(sym))) |
| 199 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | strip(line); |
| 201 | |
| 202 | switch (line[0]) { |
| 203 | case 'n': |
| 204 | case 'N': |
| 205 | newval = no; |
| 206 | if (!line[1] || !strcmp(&line[1], "o")) |
| 207 | break; |
| 208 | continue; |
| 209 | case 'm': |
| 210 | case 'M': |
| 211 | newval = mod; |
| 212 | if (!line[1]) |
| 213 | break; |
| 214 | continue; |
| 215 | case 'y': |
| 216 | case 'Y': |
| 217 | newval = yes; |
| 218 | if (!line[1] || !strcmp(&line[1], "es")) |
| 219 | break; |
| 220 | continue; |
| 221 | case 0: |
| 222 | newval = oldval; |
| 223 | break; |
| 224 | case '?': |
| 225 | goto help; |
| 226 | default: |
| 227 | continue; |
| 228 | } |
| 229 | if (sym_set_tristate_value(sym, newval)) |
| 230 | return 0; |
| 231 | help: |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 232 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | static int conf_choice(struct menu *menu) |
| 237 | { |
| 238 | struct symbol *sym, *def_sym; |
| 239 | struct menu *child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | bool is_new; |
| 241 | |
| 242 | sym = menu->sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | is_new = !sym_has_value(sym); |
| 244 | if (sym_is_changable(sym)) { |
| 245 | conf_sym(menu); |
| 246 | sym_calc_value(sym); |
| 247 | switch (sym_get_tristate_value(sym)) { |
| 248 | case no: |
| 249 | return 1; |
| 250 | case mod: |
| 251 | return 0; |
| 252 | case yes: |
| 253 | break; |
| 254 | } |
| 255 | } else { |
| 256 | switch (sym_get_tristate_value(sym)) { |
| 257 | case no: |
| 258 | return 1; |
| 259 | case mod: |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 260 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return 0; |
| 262 | case yes: |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | while (1) { |
| 268 | int cnt, def; |
| 269 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 270 | printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | def_sym = sym_get_choice_value(sym); |
| 272 | cnt = def = 0; |
Roman Zippel | 40aee72 | 2006-04-09 17:26:39 +0200 | [diff] [blame] | 273 | line[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | for (child = menu->list; child; child = child->next) { |
| 275 | if (!menu_is_visible(child)) |
| 276 | continue; |
| 277 | if (!child->sym) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 278 | printf("%*c %s\n", indent, '*', _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | continue; |
| 280 | } |
| 281 | cnt++; |
| 282 | if (child->sym == def_sym) { |
| 283 | def = cnt; |
| 284 | printf("%*c", indent, '>'); |
| 285 | } else |
| 286 | printf("%*c", indent, ' '); |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 287 | printf(" %d. %s", cnt, _(menu_get_prompt(child))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (child->sym->name) |
| 289 | printf(" (%s)", child->sym->name); |
| 290 | if (!sym_has_value(child->sym)) |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 291 | printf(_(" (NEW)")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | printf("\n"); |
| 293 | } |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 294 | printf(_("%*schoice"), indent - 1, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if (cnt == 1) { |
| 296 | printf("[1]: 1\n"); |
| 297 | goto conf_childs; |
| 298 | } |
| 299 | printf("[1-%d", cnt); |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 300 | if (menu_has_help(menu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | printf("?"); |
| 302 | printf("]: "); |
| 303 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 304 | case oldconfig: |
| 305 | case silentoldconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | if (!is_new) { |
| 307 | cnt = def; |
| 308 | printf("%d\n", cnt); |
| 309 | break; |
| 310 | } |
| 311 | check_stdin(); |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 312 | /* fall through */ |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 313 | case oldaskconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | fflush(stdout); |
Markus Mayer | 74dba80 | 2015-12-09 14:56:12 -0800 | [diff] [blame] | 315 | xfgets(line, sizeof(line), stdin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | strip(line); |
| 317 | if (line[0] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 318 | print_help(menu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | continue; |
| 320 | } |
| 321 | if (!line[0]) |
| 322 | cnt = def; |
| 323 | else if (isdigit(line[0])) |
| 324 | cnt = atoi(line); |
| 325 | else |
| 326 | continue; |
| 327 | break; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 328 | default: |
| 329 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | conf_childs: |
| 333 | for (child = menu->list; child; child = child->next) { |
| 334 | if (!child->sym || !menu_is_visible(child)) |
| 335 | continue; |
| 336 | if (!--cnt) |
| 337 | break; |
| 338 | } |
| 339 | if (!child) |
| 340 | continue; |
Ben Hutchings | 3ba4162 | 2011-04-23 18:42:56 +0100 | [diff] [blame] | 341 | if (line[0] && line[strlen(line) - 1] == '?') { |
Cheng Renquan | 66c4bd8 | 2009-07-12 16:11:48 +0800 | [diff] [blame] | 342 | print_help(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | continue; |
| 344 | } |
| 345 | sym_set_choice_value(sym, child->sym); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 346 | for (child = child->list; child; child = child->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | indent += 2; |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 348 | conf(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | indent -= 2; |
| 350 | } |
| 351 | return 1; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | static void conf(struct menu *menu) |
| 356 | { |
| 357 | struct symbol *sym; |
| 358 | struct property *prop; |
| 359 | struct menu *child; |
| 360 | |
| 361 | if (!menu_is_visible(menu)) |
| 362 | return; |
| 363 | |
| 364 | sym = menu->sym; |
| 365 | prop = menu->prompt; |
| 366 | if (prop) { |
| 367 | const char *prompt; |
| 368 | |
| 369 | switch (prop->type) { |
| 370 | case P_MENU: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 371 | if ((input_mode == silentoldconfig || |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 372 | input_mode == listnewconfig || |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 373 | input_mode == olddefconfig) && |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 374 | rootEntry != menu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | check_conf(menu); |
| 376 | return; |
| 377 | } |
Arnaud Lacombe | d8fc320 | 2011-05-31 12:30:26 -0400 | [diff] [blame] | 378 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | case P_COMMENT: |
| 380 | prompt = menu_get_prompt(menu); |
| 381 | if (prompt) |
| 382 | printf("%*c\n%*c %s\n%*c\n", |
| 383 | indent, '*', |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 384 | indent, '*', _(prompt), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | indent, '*'); |
| 386 | default: |
| 387 | ; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | if (!sym) |
| 392 | goto conf_childs; |
| 393 | |
| 394 | if (sym_is_choice(sym)) { |
| 395 | conf_choice(menu); |
| 396 | if (sym->curr.tri != mod) |
| 397 | return; |
| 398 | goto conf_childs; |
| 399 | } |
| 400 | |
| 401 | switch (sym->type) { |
| 402 | case S_INT: |
| 403 | case S_HEX: |
| 404 | case S_STRING: |
| 405 | conf_string(menu); |
| 406 | break; |
| 407 | default: |
| 408 | conf_sym(menu); |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | conf_childs: |
| 413 | if (sym) |
| 414 | indent += 2; |
| 415 | for (child = menu->list; child; child = child->next) |
| 416 | conf(child); |
| 417 | if (sym) |
| 418 | indent -= 2; |
| 419 | } |
| 420 | |
| 421 | static void check_conf(struct menu *menu) |
| 422 | { |
| 423 | struct symbol *sym; |
| 424 | struct menu *child; |
| 425 | |
| 426 | if (!menu_is_visible(menu)) |
| 427 | return; |
| 428 | |
| 429 | sym = menu->sym; |
Roman Zippel | 3f23ca2 | 2005-11-08 21:34:48 -0800 | [diff] [blame] | 430 | if (sym && !sym_has_value(sym)) { |
| 431 | if (sym_is_changable(sym) || |
| 432 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 433 | if (input_mode == listnewconfig) { |
| 434 | if (sym->name && !sym_is_choice_value(sym)) { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame] | 435 | printf("%s%s\n", CONFIG_, sym->name); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 436 | } |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 437 | } else if (input_mode != olddefconfig) { |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 438 | if (!conf_cnt++) |
| 439 | printf(_("*\n* Restart config...\n*\n")); |
| 440 | rootEntry = menu_get_parent_menu(menu); |
| 441 | conf(rootEntry); |
| 442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | for (child = menu->list; child; child = child->next) |
| 447 | check_conf(child); |
| 448 | } |
| 449 | |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 450 | static struct option long_opts[] = { |
| 451 | {"oldaskconfig", no_argument, NULL, oldaskconfig}, |
| 452 | {"oldconfig", no_argument, NULL, oldconfig}, |
| 453 | {"silentoldconfig", no_argument, NULL, silentoldconfig}, |
| 454 | {"defconfig", optional_argument, NULL, defconfig}, |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 455 | {"savedefconfig", required_argument, NULL, savedefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 456 | {"allnoconfig", no_argument, NULL, allnoconfig}, |
| 457 | {"allyesconfig", no_argument, NULL, allyesconfig}, |
| 458 | {"allmodconfig", no_argument, NULL, allmodconfig}, |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 459 | {"alldefconfig", no_argument, NULL, alldefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 460 | {"randconfig", no_argument, NULL, randconfig}, |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 461 | {"listnewconfig", no_argument, NULL, listnewconfig}, |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 462 | {"olddefconfig", no_argument, NULL, olddefconfig}, |
| 463 | /* |
| 464 | * oldnoconfig is an alias of olddefconfig, because people already |
| 465 | * are dependent on its behavior(sets new symbols to their default |
| 466 | * value but not 'n') with the counter-intuitive name. |
| 467 | */ |
| 468 | {"oldnoconfig", no_argument, NULL, olddefconfig}, |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 469 | {NULL, 0, NULL, 0} |
| 470 | }; |
| 471 | |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 472 | static void conf_usage(const char *progname) |
| 473 | { |
| 474 | |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 475 | printf("Usage: %s [-s] [option] <kconfig-file>\n", progname); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 476 | printf("[option] is _one_ of the following:\n"); |
| 477 | printf(" --listnewconfig List new options\n"); |
| 478 | printf(" --oldaskconfig Start a new configuration using a line-oriented program\n"); |
| 479 | printf(" --oldconfig Update a configuration using a provided .config as base\n"); |
| 480 | printf(" --silentoldconfig Same as oldconfig, but quietly, additionally update deps\n"); |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 481 | printf(" --olddefconfig Same as silentoldconfig but sets new symbols to their default value\n"); |
| 482 | printf(" --oldnoconfig An alias of olddefconfig\n"); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 483 | printf(" --defconfig <file> New config with default defined in <file>\n"); |
| 484 | printf(" --savedefconfig <file> Save the minimal current configuration to <file>\n"); |
| 485 | printf(" --allnoconfig New config where all options are answered with no\n"); |
| 486 | printf(" --allyesconfig New config where all options are answered with yes\n"); |
| 487 | printf(" --allmodconfig New config where all options are answered with mod\n"); |
| 488 | printf(" --alldefconfig New config with all symbols set to default\n"); |
| 489 | printf(" --randconfig New config with random answer to all options\n"); |
| 490 | } |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | int main(int ac, char **av) |
| 493 | { |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 494 | const char *progname = av[0]; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 495 | int opt; |
Arnaud Lacombe | 275744c | 2010-10-13 20:43:28 -0400 | [diff] [blame] | 496 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | struct stat tmpstat; |
| 498 | |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 499 | setlocale(LC_ALL, ""); |
| 500 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 501 | textdomain(PACKAGE); |
| 502 | |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 503 | tty_stdio = isatty(0) && isatty(1) && isatty(2); |
| 504 | |
Michal Marek | 0a1f00a | 2015-04-08 13:30:42 +0200 | [diff] [blame] | 505 | while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { |
| 506 | if (opt == 's') { |
| 507 | conf_set_message_callback(NULL); |
| 508 | continue; |
| 509 | } |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 510 | input_mode = (enum input_mode)opt; |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 511 | switch (opt) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 512 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 513 | sync_kconfig = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 515 | case defconfig: |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 516 | case savedefconfig: |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 517 | defconfig_file = optarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 519 | case randconfig: |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 520 | { |
| 521 | struct timeval now; |
| 522 | unsigned int seed; |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 523 | char *seed_env; |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 524 | |
| 525 | /* |
| 526 | * Use microseconds derived seed, |
| 527 | * compensate for systems where it may be zero |
| 528 | */ |
| 529 | gettimeofday(&now, NULL); |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 530 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 531 | |
| 532 | seed_env = getenv("KCONFIG_SEED"); |
| 533 | if( seed_env && *seed_env ) { |
| 534 | char *endp; |
Yann E. MORIN | e85ac12 | 2013-05-20 23:17:34 +0200 | [diff] [blame] | 535 | int tmp = (int)strtol(seed_env, &endp, 0); |
Yann E. MORIN | 0d8024c | 2013-04-13 22:49:13 +0200 | [diff] [blame] | 536 | if (*endp == '\0') { |
| 537 | seed = tmp; |
| 538 | } |
| 539 | } |
Yann E. MORIN | a5f6d79 | 2013-05-20 23:09:03 +0200 | [diff] [blame] | 540 | fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed ); |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 541 | srand(seed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | break; |
Ingo Molnar | b0fe551 | 2009-03-12 15:15:31 +0100 | [diff] [blame] | 543 | } |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 544 | case oldaskconfig: |
| 545 | case oldconfig: |
| 546 | case allnoconfig: |
| 547 | case allyesconfig: |
| 548 | case allmodconfig: |
| 549 | case alldefconfig: |
| 550 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 551 | case olddefconfig: |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 552 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 553 | case '?': |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 554 | conf_usage(progname); |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 555 | exit(1); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 556 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 559 | if (ac == optind) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 560 | printf(_("%s: Kconfig file missing\n"), av[0]); |
Arnaud Lacombe | 3254399 | 2010-11-02 00:26:33 -0400 | [diff] [blame] | 561 | conf_usage(progname); |
Randy Dunlap | 250725a | 2006-06-08 22:12:50 -0700 | [diff] [blame] | 562 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
Andres Salomon | 2f4b489 | 2007-12-17 01:34:58 -0500 | [diff] [blame] | 564 | name = av[optind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | conf_parse(name); |
| 566 | //zconfdump(stdout); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 567 | if (sync_kconfig) { |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 568 | name = conf_get_configname(); |
| 569 | if (stat(name, &tmpstat)) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 570 | fprintf(stderr, _("***\n" |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 571 | "*** Configuration file \"%s\" not found!\n" |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 572 | "***\n" |
| 573 | "*** Please run some configurator (e.g. \"make oldconfig\" or\n" |
| 574 | "*** \"make menuconfig\" or \"make xconfig\").\n" |
Markus Heidelberg | 284026c | 2009-05-18 01:36:53 +0200 | [diff] [blame] | 575 | "***\n"), name); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 576 | exit(1); |
| 577 | } |
| 578 | } |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 581 | case defconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | if (!defconfig_file) |
| 583 | defconfig_file = conf_get_default_confname(); |
| 584 | if (conf_read(defconfig_file)) { |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 585 | printf(_("***\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | "*** Can't find default configuration \"%s\"!\n" |
EGRY Gabor | 534a450 | 2008-01-11 23:44:39 +0100 | [diff] [blame] | 587 | "***\n"), defconfig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | exit(1); |
| 589 | } |
| 590 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 591 | case savedefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 592 | case silentoldconfig: |
| 593 | case oldaskconfig: |
| 594 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 595 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 596 | case olddefconfig: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | conf_read(NULL); |
| 598 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 599 | case allnoconfig: |
| 600 | case allyesconfig: |
| 601 | case allmodconfig: |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 602 | case alldefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 603 | case randconfig: |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 604 | name = getenv("KCONFIG_ALLCONFIG"); |
Eric W. Biederman | 9f420bf | 2012-05-07 05:37:45 -0700 | [diff] [blame] | 605 | if (!name) |
| 606 | break; |
| 607 | if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) { |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 608 | if (conf_read_simple(name, S_DEF_USER)) { |
| 609 | fprintf(stderr, |
| 610 | _("*** Can't read seed configuration \"%s\"!\n"), |
| 611 | name); |
| 612 | exit(1); |
| 613 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 614 | break; |
| 615 | } |
| 616 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 617 | case allnoconfig: name = "allno.config"; break; |
| 618 | case allyesconfig: name = "allyes.config"; break; |
| 619 | case allmodconfig: name = "allmod.config"; break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 620 | case alldefconfig: name = "alldef.config"; break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 621 | case randconfig: name = "allrandom.config"; break; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 622 | default: break; |
| 623 | } |
Eric W. Biederman | 5efe241 | 2012-04-26 01:51:32 -0700 | [diff] [blame] | 624 | if (conf_read_simple(name, S_DEF_USER) && |
| 625 | conf_read_simple("all.config", S_DEF_USER)) { |
| 626 | fprintf(stderr, |
| 627 | _("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"), |
| 628 | name); |
| 629 | exit(1); |
| 630 | } |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 631 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | default: |
| 633 | break; |
| 634 | } |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 635 | |
| 636 | if (sync_kconfig) { |
| 637 | if (conf_get_changed()) { |
| 638 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 639 | if (name && *name) { |
| 640 | fprintf(stderr, |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 641 | _("\n*** The configuration requires explicit update.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | } |
Ben Hutchings | 62dc989 | 2013-02-19 02:24:26 +0200 | [diff] [blame] | 645 | valid_stdin = tty_stdio; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 646 | } |
| 647 | |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 648 | switch (input_mode) { |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 649 | case allnoconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 650 | conf_set_all_new_symbols(def_no); |
| 651 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 652 | case allyesconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 653 | conf_set_all_new_symbols(def_yes); |
| 654 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 655 | case allmodconfig: |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 656 | conf_set_all_new_symbols(def_mod); |
| 657 | break; |
Sam Ravnborg | 0748cb3 | 2010-07-31 23:35:31 +0200 | [diff] [blame] | 658 | case alldefconfig: |
| 659 | conf_set_all_new_symbols(def_default); |
| 660 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 661 | case randconfig: |
Yann E. MORIN | 3b9a19e | 2013-04-28 22:36:38 +0200 | [diff] [blame] | 662 | /* Really nothing to do in this loop */ |
| 663 | while (conf_set_all_new_symbols(def_random)) ; |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 664 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 665 | case defconfig: |
Sam Ravnborg | 09748e1 | 2008-06-30 23:02:59 +0200 | [diff] [blame] | 666 | conf_set_all_new_symbols(def_default); |
| 667 | break; |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 668 | case savedefconfig: |
| 669 | break; |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 670 | case oldaskconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 671 | rootEntry = &rootmenu; |
| 672 | conf(&rootmenu); |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 673 | input_mode = silentoldconfig; |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 674 | /* fall through */ |
Sam Ravnborg | 1482834 | 2010-08-06 07:13:54 +0200 | [diff] [blame] | 675 | case oldconfig: |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 676 | case listnewconfig: |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 677 | case olddefconfig: |
Sam Ravnborg | 4062f1a | 2010-07-31 23:35:26 +0200 | [diff] [blame] | 678 | case silentoldconfig: |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 679 | /* Update until a loop caused no more changes */ |
| 680 | do { |
| 681 | conf_cnt = 0; |
| 682 | check_conf(&rootmenu); |
Aristeu Rozanski | f0778c8 | 2010-05-06 12:48:34 -0400 | [diff] [blame] | 683 | } while (conf_cnt && |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 684 | (input_mode != listnewconfig && |
Adam Lee | fb16d89 | 2012-09-01 01:05:17 +0800 | [diff] [blame] | 685 | input_mode != olddefconfig)); |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 686 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
Sam Ravnborg | f443d2e | 2008-06-30 22:45:38 +0200 | [diff] [blame] | 688 | |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 689 | if (sync_kconfig) { |
| 690 | /* silentoldconfig is used during the build so we shall update autoconf. |
| 691 | * All other commands are only used to generate a config. |
| 692 | */ |
| 693 | if (conf_get_changed() && conf_write(NULL)) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 694 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 695 | exit(1); |
| 696 | } |
| 697 | if (conf_write_autoconf()) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 698 | fprintf(stderr, _("\n*** Error during update of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 699 | return 1; |
| 700 | } |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 701 | } else if (input_mode == savedefconfig) { |
| 702 | if (conf_write_defconfig(defconfig_file)) { |
| 703 | fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"), |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 704 | defconfig_file); |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 705 | return 1; |
| 706 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 707 | } else if (input_mode != listnewconfig) { |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 708 | if (conf_write(NULL)) { |
Arnaud Lacombe | 652cf98 | 2010-08-14 23:51:40 -0400 | [diff] [blame] | 709 | fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n")); |
zippel@linux-m68k.org | 204c96f | 2008-09-29 05:27:10 +0200 | [diff] [blame] | 710 | exit(1); |
| 711 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 712 | } |
Sam Ravnborg | 861b4ea | 2010-07-31 23:35:28 +0200 | [diff] [blame] | 713 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 715 | |
Jean Sacren | 4418a2b | 2010-08-04 16:03:16 -0600 | [diff] [blame] | 716 | /* |
| 717 | * Helper function to facilitate fgets() by Jean Sacren. |
| 718 | */ |
Arnaud Lacombe | ab63f58 | 2011-07-02 00:59:41 -0400 | [diff] [blame] | 719 | void xfgets(char *str, int size, FILE *in) |
Jean Sacren | 4418a2b | 2010-08-04 16:03:16 -0600 | [diff] [blame] | 720 | { |
| 721 | if (fgets(str, size, in) == NULL) |
| 722 | fprintf(stderr, "\nError in reading or end of file.\n"); |
| 723 | } |