kconfig/conf.c
branchgcc-4.4
changeset 1368 ec1cffe6d30b
parent 860 3ff8038f904c
child 1524 1031ea5af395
     1.1 --- a/kconfig/conf.c	Tue Sep 16 14:32:07 2008 +0000
     1.2 +++ b/kconfig/conf.c	Thu May 21 19:00:55 2009 +0000
     1.3 @@ -3,12 +3,13 @@
     1.4   * Released under the terms of the GNU GPL v2.0.
     1.5   */
     1.6  
     1.7 +#include <locale.h>
     1.8  #include <ctype.h>
     1.9 +#include <stdio.h>
    1.10  #include <stdlib.h>
    1.11 -#include <stdio.h>
    1.12  #include <string.h>
    1.13 +#include <time.h>
    1.14  #include <unistd.h>
    1.15 -#include <time.h>
    1.16  #include <sys/stat.h>
    1.17  
    1.18  #define LKC_DIRECT_LINK
    1.19 @@ -31,12 +32,21 @@
    1.20  
    1.21  static int indent = 1;
    1.22  static int valid_stdin = 1;
    1.23 +static int sync_kconfig;
    1.24  static int conf_cnt;
    1.25  static char line[128];
    1.26  static struct menu *rootEntry;
    1.27  
    1.28  static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
    1.29  
    1.30 +static const char *get_help(struct menu *menu)
    1.31 +{
    1.32 +	if (menu_has_help(menu))
    1.33 +		return _(menu_get_help(menu));
    1.34 +	else
    1.35 +		return nohelp_text;
    1.36 +}
    1.37 +
    1.38  static void strip(char *str)
    1.39  {
    1.40  	char *p = str;
    1.41 @@ -56,7 +66,7 @@
    1.42  
    1.43  static void check_stdin(void)
    1.44  {
    1.45 -	if (!valid_stdin && input_mode == ask_silent) {
    1.46 +	if (!valid_stdin) {
    1.47  		printf(_("aborted!\n\n"));
    1.48  		printf(_("Console input/output is redirected. "));
    1.49  		printf(_("Run 'make oldconfig' to update configuration.\n\n"));
    1.50 @@ -64,13 +74,12 @@
    1.51  	}
    1.52  }
    1.53  
    1.54 -static void conf_askvalue(struct symbol *sym, const char *def)
    1.55 +static int conf_askvalue(struct symbol *sym, const char *def)
    1.56  {
    1.57  	enum symbol_type type = sym_get_type(sym);
    1.58 -	tristate val;
    1.59  
    1.60  	if (!sym_has_value(sym))
    1.61 -		printf("(NEW) ");
    1.62 +		printf(_("(NEW) "));
    1.63  
    1.64  	line[0] = '\n';
    1.65  	line[1] = 0;
    1.66 @@ -79,33 +88,21 @@
    1.67  		printf("%s\n", def);
    1.68  		line[0] = '\n';
    1.69  		line[1] = 0;
    1.70 -		return;
    1.71 +		return 0;
    1.72  	}
    1.73  
    1.74  	switch (input_mode) {
    1.75 -	case set_no:
    1.76 -	case set_mod:
    1.77 -	case set_yes:
    1.78 -	case set_random:
    1.79 -		if (sym_has_value(sym)) {
    1.80 -			printf("%s\n", def);
    1.81 -			return;
    1.82 -		}
    1.83 -		break;
    1.84  	case ask_new:
    1.85  	case ask_silent:
    1.86  		if (sym_has_value(sym)) {
    1.87  			printf("%s\n", def);
    1.88 -			return;
    1.89 +			return 0;
    1.90  		}
    1.91  		check_stdin();
    1.92  	case ask_all:
    1.93  		fflush(stdout);
    1.94  		fgets(line, 128, stdin);
    1.95 -		return;
    1.96 -	case set_default:
    1.97 -		printf("%s\n", def);
    1.98 -		return;
    1.99 +		return 1;
   1.100  	default:
   1.101  		break;
   1.102  	}
   1.103 @@ -115,81 +112,34 @@
   1.104  	case S_HEX:
   1.105  	case S_STRING:
   1.106  		printf("%s\n", def);
   1.107 -		return;
   1.108 +		return 1;
   1.109  	default:
   1.110  		;
   1.111  	}
   1.112 -	switch (input_mode) {
   1.113 -	case set_yes:
   1.114 -		if (sym_tristate_within_range(sym, yes)) {
   1.115 -			line[0] = 'y';
   1.116 -			line[1] = '\n';
   1.117 -			line[2] = 0;
   1.118 -			break;
   1.119 -		}
   1.120 -	case set_mod:
   1.121 -		if (type == S_TRISTATE) {
   1.122 -			if (sym_tristate_within_range(sym, mod)) {
   1.123 -				line[0] = 'm';
   1.124 -				line[1] = '\n';
   1.125 -				line[2] = 0;
   1.126 -				break;
   1.127 -			}
   1.128 -		} else {
   1.129 -			if (sym_tristate_within_range(sym, yes)) {
   1.130 -				line[0] = 'y';
   1.131 -				line[1] = '\n';
   1.132 -				line[2] = 0;
   1.133 -				break;
   1.134 -			}
   1.135 -		}
   1.136 -	case set_no:
   1.137 -		if (sym_tristate_within_range(sym, no)) {
   1.138 -			line[0] = 'n';
   1.139 -			line[1] = '\n';
   1.140 -			line[2] = 0;
   1.141 -			break;
   1.142 -		}
   1.143 -	case set_random:
   1.144 -		do {
   1.145 -			val = (tristate)(random() % 3);
   1.146 -		} while (!sym_tristate_within_range(sym, val));
   1.147 -		switch (val) {
   1.148 -		case no: line[0] = 'n'; break;
   1.149 -		case mod: line[0] = 'm'; break;
   1.150 -		case yes: line[0] = 'y'; break;
   1.151 -		}
   1.152 -		line[1] = '\n';
   1.153 -		line[2] = 0;
   1.154 -		break;
   1.155 -	default:
   1.156 -		break;
   1.157 -	}
   1.158  	printf("%s", line);
   1.159 +	return 1;
   1.160  }
   1.161  
   1.162  int conf_string(struct menu *menu)
   1.163  {
   1.164  	struct symbol *sym = menu->sym;
   1.165 -	const char *def, *help;
   1.166 +	const char *def;
   1.167  
   1.168  	while (1) {
   1.169 -		printf("%*s%s ", indent - 1, "", menu->prompt->text);
   1.170 +		printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
   1.171  		printf("(%s) ", sym->name);
   1.172  		def = sym_get_string_value(sym);
   1.173  		if (sym_get_string_value(sym))
   1.174  			printf("[%s] ", def);
   1.175 -		conf_askvalue(sym, def);
   1.176 +		if (!conf_askvalue(sym, def))
   1.177 +			return 0;
   1.178  		switch (line[0]) {
   1.179  		case '\n':
   1.180  			break;
   1.181  		case '?':
   1.182  			/* print help */
   1.183  			if (line[1] == '\n') {
   1.184 -				help = nohelp_text;
   1.185 -				if (menu->sym->help)
   1.186 -					help = menu->sym->help;
   1.187 -				printf("\n%s\n", menu->sym->help);
   1.188 +				printf("\n%s\n", get_help(menu));
   1.189  				def = NULL;
   1.190  				break;
   1.191  			}
   1.192 @@ -207,10 +157,9 @@
   1.193  	struct symbol *sym = menu->sym;
   1.194  	int type;
   1.195  	tristate oldval, newval;
   1.196 -	const char *help;
   1.197  
   1.198  	while (1) {
   1.199 -		printf("%*s%s ", indent - 1, "", menu->prompt->text);
   1.200 +		printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
   1.201  		if (sym->name)
   1.202  			printf("(%s) ", sym->name);
   1.203  		type = sym_get_type(sym);
   1.204 @@ -233,10 +182,11 @@
   1.205  			printf("/m");
   1.206  		if (oldval != yes && sym_tristate_within_range(sym, yes))
   1.207  			printf("/y");
   1.208 -		if (sym->help)
   1.209 +		if (menu_has_help(menu))
   1.210  			printf("/?");
   1.211  		printf("] ");
   1.212 -		conf_askvalue(sym, sym_get_string_value(sym));
   1.213 +		if (!conf_askvalue(sym, sym_get_string_value(sym)))
   1.214 +			return 0;
   1.215  		strip(line);
   1.216  
   1.217  		switch (line[0]) {
   1.218 @@ -269,10 +219,7 @@
   1.219  		if (sym_set_tristate_value(sym, newval))
   1.220  			return 0;
   1.221  help:
   1.222 -		help = nohelp_text;
   1.223 -		if (sym->help)
   1.224 -			help = sym->help;
   1.225 -		printf("\n%s\n", help);
   1.226 +		printf("\n%s\n", get_help(menu));
   1.227  	}
   1.228  }
   1.229  
   1.230 @@ -302,7 +249,7 @@
   1.231  		case no:
   1.232  			return 1;
   1.233  		case mod:
   1.234 -			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
   1.235 +			printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
   1.236  			return 0;
   1.237  		case yes:
   1.238  			break;
   1.239 @@ -312,7 +259,7 @@
   1.240  	while (1) {
   1.241  		int cnt, def;
   1.242  
   1.243 -		printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
   1.244 +		printf("%*s%s\n", indent - 1, "", _(menu_get_prompt(menu)));
   1.245  		def_sym = sym_get_choice_value(sym);
   1.246  		cnt = def = 0;
   1.247  		line[0] = 0;
   1.248 @@ -320,7 +267,7 @@
   1.249  			if (!menu_is_visible(child))
   1.250  				continue;
   1.251  			if (!child->sym) {
   1.252 -				printf("%*c %s\n", indent, '*', menu_get_prompt(child));
   1.253 +				printf("%*c %s\n", indent, '*', _(menu_get_prompt(child)));
   1.254  				continue;
   1.255  			}
   1.256  			cnt++;
   1.257 @@ -329,20 +276,20 @@
   1.258  				printf("%*c", indent, '>');
   1.259  			} else
   1.260  				printf("%*c", indent, ' ');
   1.261 -			printf(" %d. %s", cnt, menu_get_prompt(child));
   1.262 +			printf(" %d. %s", cnt, _(menu_get_prompt(child)));
   1.263  			if (child->sym->name)
   1.264  				printf(" (%s)", child->sym->name);
   1.265  			if (!sym_has_value(child->sym))
   1.266 -				printf(" (NEW)");
   1.267 +				printf(_(" (NEW)"));
   1.268  			printf("\n");
   1.269  		}
   1.270 -		printf("%*schoice", indent - 1, "");
   1.271 +		printf(_("%*schoice"), indent - 1, "");
   1.272  		if (cnt == 1) {
   1.273  			printf("[1]: 1\n");
   1.274  			goto conf_childs;
   1.275  		}
   1.276  		printf("[1-%d", cnt);
   1.277 -		if (sym->help)
   1.278 +		if (menu_has_help(menu))
   1.279  			printf("?");
   1.280  		printf("]: ");
   1.281  		switch (input_mode) {
   1.282 @@ -359,8 +306,7 @@
   1.283  			fgets(line, 128, stdin);
   1.284  			strip(line);
   1.285  			if (line[0] == '?') {
   1.286 -				printf("\n%s\n", menu->sym->help ?
   1.287 -					menu->sym->help : nohelp_text);
   1.288 +				printf("\n%s\n", get_help(menu));
   1.289  				continue;
   1.290  			}
   1.291  			if (!line[0])
   1.292 @@ -370,14 +316,7 @@
   1.293  			else
   1.294  				continue;
   1.295  			break;
   1.296 -		case set_random:
   1.297 -			def = (random() % cnt) + 1;
   1.298 -		case set_default:
   1.299 -		case set_yes:
   1.300 -		case set_mod:
   1.301 -		case set_no:
   1.302 -			cnt = def;
   1.303 -			printf("%d\n", cnt);
   1.304 +		default:
   1.305  			break;
   1.306  		}
   1.307  
   1.308 @@ -391,14 +330,13 @@
   1.309  		if (!child)
   1.310  			continue;
   1.311  		if (line[strlen(line) - 1] == '?') {
   1.312 -			printf("\n%s\n", child->sym->help ?
   1.313 -				child->sym->help : nohelp_text);
   1.314 +			printf("\n%s\n", get_help(child));
   1.315  			continue;
   1.316  		}
   1.317  		sym_set_choice_value(sym, child->sym);
   1.318 -		if (child->list) {
   1.319 +		for (child = child->list; child; child = child->next) {
   1.320  			indent += 2;
   1.321 -			conf(child->list);
   1.322 +			conf(child);
   1.323  			indent -= 2;
   1.324  		}
   1.325  		return 1;
   1.326 @@ -430,7 +368,7 @@
   1.327  			if (prompt)
   1.328  				printf("%*c\n%*c %s\n%*c\n",
   1.329  					indent, '*',
   1.330 -					indent, '*', prompt,
   1.331 +					indent, '*', _(prompt),
   1.332  					indent, '*');
   1.333  		default:
   1.334  			;
   1.335 @@ -492,29 +430,29 @@
   1.336  
   1.337  int main(int ac, char **av)
   1.338  {
   1.339 -	int i = 1;
   1.340 +	int opt;
   1.341  	const char *name;
   1.342  	struct stat tmpstat;
   1.343  
   1.344 -	if (ac > i && av[i][0] == '-') {
   1.345 -		switch (av[i++][1]) {
   1.346 +	setlocale(LC_ALL, "");
   1.347 +	bindtextdomain(PACKAGE, LOCALEDIR);
   1.348 +	textdomain(PACKAGE);
   1.349 +
   1.350 +	while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
   1.351 +		switch (opt) {
   1.352  		case 'o':
   1.353 -			input_mode = ask_new;
   1.354 +			input_mode = ask_silent;
   1.355  			break;
   1.356  		case 's':
   1.357  			input_mode = ask_silent;
   1.358 +			sync_kconfig = 1;
   1.359  			break;
   1.360  		case 'd':
   1.361  			input_mode = set_default;
   1.362  			break;
   1.363  		case 'D':
   1.364  			input_mode = set_default;
   1.365 -			defconfig_file = av[i++];
   1.366 -			if (!defconfig_file) {
   1.367 -				printf(_("%s: No default config file specified\n"),
   1.368 -					av[0]);
   1.369 -				exit(1);
   1.370 -			}
   1.371 +			defconfig_file = optarg;
   1.372  			break;
   1.373  		case 'n':
   1.374  			input_mode = set_no;
   1.375 @@ -527,42 +465,45 @@
   1.376  			break;
   1.377  		case 'r':
   1.378  			input_mode = set_random;
   1.379 -			srandom(time(NULL));
   1.380 +			srand(time(NULL));
   1.381  			break;
   1.382  		case 'h':
   1.383 -		case '?':
   1.384 -			fprintf(stderr, "See README for usage info\n");
   1.385 +			printf(_("See README for usage info\n"));
   1.386  			exit(0);
   1.387 +			break;
   1.388 +		default:
   1.389 +			fprintf(stderr, _("See README for usage info\n"));
   1.390 +			exit(1);
   1.391  		}
   1.392  	}
   1.393 -  	name = av[i];
   1.394 -	if (!name) {
   1.395 +	if (ac == optind) {
   1.396  		printf(_("%s: Kconfig file missing\n"), av[0]);
   1.397  		exit(1);
   1.398  	}
   1.399 +	name = av[optind];
   1.400  	conf_parse(name);
   1.401  	//zconfdump(stdout);
   1.402 +	if (sync_kconfig) {
   1.403 +		if (stat(".config", &tmpstat)) {
   1.404 +			fprintf(stderr, _("***\n"
   1.405 +				"*** Please run some configurator (e.g. \"make menuconfig\").\n"
   1.406 +				"***\n"));
   1.407 +			exit(1);
   1.408 +		}
   1.409 +	}
   1.410 +
   1.411  	switch (input_mode) {
   1.412  	case set_default:
   1.413  		if (!defconfig_file)
   1.414  			defconfig_file = conf_get_default_confname();
   1.415  		if (conf_read(defconfig_file)) {
   1.416 -			printf("***\n"
   1.417 +			printf(_("***\n"
   1.418  				"*** Can't find default configuration \"%s\"!\n"
   1.419 -				"***\n", defconfig_file);
   1.420 +				"***\n"), defconfig_file);
   1.421  			exit(1);
   1.422  		}
   1.423  		break;
   1.424  	case ask_silent:
   1.425 -		if (stat(".config", &tmpstat)) {
   1.426 -			printf(_("***\n"
   1.427 -				"*** You have not yet configured "PROJECT_NAME"!\n"
   1.428 -				"***\n"
   1.429 -				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
   1.430 -				"*** \"make menuconfig\" or \"make config\").\n"
   1.431 -				"***\n"));
   1.432 -			exit(1);
   1.433 -		}
   1.434  	case ask_all:
   1.435  	case ask_new:
   1.436  		conf_read(NULL);
   1.437 @@ -592,31 +533,62 @@
   1.438  		break;
   1.439  	}
   1.440  
   1.441 -	if (input_mode != ask_silent) {
   1.442 +	if (sync_kconfig) {
   1.443 +		if (conf_get_changed()) {
   1.444 +			name = getenv("KCONFIG_NOSILENTUPDATE");
   1.445 +			if (name && *name) {
   1.446 +				fprintf(stderr,
   1.447 +					_("\n*** Configuration requires explicit update.\n\n"));
   1.448 +				return 1;
   1.449 +			}
   1.450 +		}
   1.451 +		valid_stdin = isatty(0) && isatty(1) && isatty(2);
   1.452 +	}
   1.453 +
   1.454 +	switch (input_mode) {
   1.455 +	case set_no:
   1.456 +		conf_set_all_new_symbols(def_no);
   1.457 +		break;
   1.458 +	case set_yes:
   1.459 +		conf_set_all_new_symbols(def_yes);
   1.460 +		break;
   1.461 +	case set_mod:
   1.462 +		conf_set_all_new_symbols(def_mod);
   1.463 +		break;
   1.464 +	case set_random:
   1.465 +		conf_set_all_new_symbols(def_random);
   1.466 +		break;
   1.467 +	case set_default:
   1.468 +		conf_set_all_new_symbols(def_default);
   1.469 +		break;
   1.470 +	case ask_new:
   1.471 +	case ask_all:
   1.472  		rootEntry = &rootmenu;
   1.473  		conf(&rootmenu);
   1.474 -		if (input_mode == ask_all) {
   1.475 -			input_mode = ask_silent;
   1.476 -			valid_stdin = 1;
   1.477 +		input_mode = ask_silent;
   1.478 +		/* fall through */
   1.479 +	case ask_silent:
   1.480 +		/* Update until a loop caused no more changes */
   1.481 +		do {
   1.482 +			conf_cnt = 0;
   1.483 +			check_conf(&rootmenu);
   1.484 +		} while (conf_cnt);
   1.485 +		break;
   1.486 +	}
   1.487 +
   1.488 +	if (sync_kconfig) {
   1.489 +		/* silentoldconfig is used during the build so we shall update autoconf.
   1.490 +		 * All other commands are only used to generate a config.
   1.491 +		 */
   1.492 +		if (conf_get_changed() && conf_write(NULL)) {
   1.493 +			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
   1.494 +			exit(1);
   1.495  		}
   1.496 -	} else if (conf_get_changed()) {
   1.497 -		name = getenv("KCONFIG_NOSILENTUPDATE");
   1.498 -		if (name && *name) {
   1.499 -			fprintf(stderr, _("\n*** "PROJECT_NAME" configuration requires explicit update.\n\n"));
   1.500 -			return 1;
   1.501 +	} else {
   1.502 +		if (conf_write(NULL)) {
   1.503 +			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
   1.504 +			exit(1);
   1.505  		}
   1.506 -	} else
   1.507 -		goto skip_check;
   1.508 -
   1.509 -	do {
   1.510 -		conf_cnt = 0;
   1.511 -		check_conf(&rootmenu);
   1.512 -	} while (conf_cnt);
   1.513 -	if (conf_write(NULL)) {
   1.514 -		fprintf(stderr, _("\n*** Error during writing of "PROJECT_NAME" configuration.\n\n"));
   1.515 -		return 1;
   1.516  	}
   1.517 -skip_check:
   1.518 -
   1.519  	return 0;
   1.520  }