kconfig/mconf.c
branchgcc-4.4
changeset 1368 ec1cffe6d30b
parent 94 f32c4f663805
child 2448 a103abae1560
     1.1 --- a/kconfig/mconf.c	Mon May 14 19:28:14 2007 +0000
     1.2 +++ b/kconfig/mconf.c	Thu May 21 19:00:55 2009 +0000
     1.3 @@ -8,17 +8,13 @@
     1.4   * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
     1.5   */
     1.6  
     1.7 -#include <sys/ioctl.h>
     1.8 -#include <sys/wait.h>
     1.9  #include <ctype.h>
    1.10  #include <errno.h>
    1.11  #include <fcntl.h>
    1.12  #include <limits.h>
    1.13 -#include <signal.h>
    1.14  #include <stdarg.h>
    1.15  #include <stdlib.h>
    1.16  #include <string.h>
    1.17 -#include <termios.h>
    1.18  #include <unistd.h>
    1.19  #include <locale.h>
    1.20  
    1.21 @@ -26,7 +22,6 @@
    1.22  #include "lkc.h"
    1.23  #include "lxdialog/dialog.h"
    1.24  
    1.25 -static char menu_backtitle[128];
    1.26  static const char mconf_readme[] = N_(
    1.27  "Overview\n"
    1.28  "--------\n"
    1.29 @@ -36,9 +31,13 @@
    1.30  "kernel parameters which are not really features, but must be\n"
    1.31  "entered in as decimal or hexadecimal numbers or possibly text.\n"
    1.32  "\n"
    1.33 -"Menu items beginning with [*], <M> or [ ] represent features\n"
    1.34 -"configured to be built in, modularized or removed respectively.\n"
    1.35 -"Pointed brackets <> represent module capable features.\n"
    1.36 +"Menu items beginning with following braces represent features that\n"
    1.37 +"  [ ] can be built in or removed\n"
    1.38 +"  < > can be built in, modularized or removed\n"
    1.39 +"  { } can be built in or modularized (selected by other feature)\n"
    1.40 +"  - - are selected by other feature,\n"
    1.41 +"while *, M or whitespace inside braces means to build in, build as\n"
    1.42 +"a module or to exclude the feature respectively.\n"
    1.43  "\n"
    1.44  "To change any of these features, highlight it with the cursor\n"
    1.45  "keys and press <Y> to build it in, <M> to make it a module or\n"
    1.46 @@ -271,10 +270,7 @@
    1.47  	"          USB$ => find all CT_ symbols ending with USB\n"
    1.48  	"\n");
    1.49  
    1.50 -static char filename[PATH_MAX+1] = ".config";
    1.51  static int indent;
    1.52 -static struct termios ios_org;
    1.53 -static int rows = 0, cols = 0;
    1.54  static struct menu *current_menu;
    1.55  static int child_count;
    1.56  static int single_menu_mode;
    1.57 @@ -288,51 +284,16 @@
    1.58  static void show_helptext(const char *title, const char *text);
    1.59  static void show_help(struct menu *menu);
    1.60  
    1.61 -static void init_wsize(void)
    1.62 -{
    1.63 -	struct winsize ws;
    1.64 -	char *env;
    1.65 -
    1.66 -	if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
    1.67 -		rows = ws.ws_row;
    1.68 -		cols = ws.ws_col;
    1.69 -	}
    1.70 -
    1.71 -	if (!rows) {
    1.72 -		env = getenv("LINES");
    1.73 -		if (env)
    1.74 -			rows = atoi(env);
    1.75 -		if (!rows)
    1.76 -			rows = 24;
    1.77 -	}
    1.78 -	if (!cols) {
    1.79 -		env = getenv("COLUMNS");
    1.80 -		if (env)
    1.81 -			cols = atoi(env);
    1.82 -		if (!cols)
    1.83 -			cols = 80;
    1.84 -	}
    1.85 -
    1.86 -	if (rows < 19 || cols < 80) {
    1.87 -		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
    1.88 -		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
    1.89 -		exit(1);
    1.90 -	}
    1.91 -
    1.92 -	rows -= 4;
    1.93 -	cols -= 5;
    1.94 -}
    1.95 -
    1.96  static void get_prompt_str(struct gstr *r, struct property *prop)
    1.97  {
    1.98  	int i, j;
    1.99  	struct menu *submenu[8], *menu;
   1.100  
   1.101 -	str_printf(r, "Prompt: %s\n", prop->text);
   1.102 -	str_printf(r, "  Defined at %s:%d\n", prop->menu->file->name,
   1.103 +	str_printf(r, _("Prompt: %s\n"), _(prop->text));
   1.104 +	str_printf(r, _("  Defined at %s:%d\n"), prop->menu->file->name,
   1.105  		prop->menu->lineno);
   1.106  	if (!expr_is_yes(prop->visible.expr)) {
   1.107 -		str_append(r, "  Depends on: ");
   1.108 +		str_append(r, _("  Depends on: "));
   1.109  		expr_gstr_print(prop->visible.expr, r);
   1.110  		str_append(r, "\n");
   1.111  	}
   1.112 @@ -340,13 +301,13 @@
   1.113  	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
   1.114  		submenu[i++] = menu;
   1.115  	if (i > 0) {
   1.116 -		str_printf(r, "  Location:\n");
   1.117 +		str_printf(r, _("  Location:\n"));
   1.118  		for (j = 4; --i >= 0; j += 2) {
   1.119  			menu = submenu[i];
   1.120 -			str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
   1.121 +			str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu)));
   1.122  			if (menu->sym) {
   1.123  				str_printf(r, " (%s [=%s])", menu->sym->name ?
   1.124 -					menu->sym->name : "<choice>",
   1.125 +					menu->sym->name : _("<choice>"),
   1.126  					sym_get_string_value(menu->sym));
   1.127  			}
   1.128  			str_append(r, "\n");
   1.129 @@ -359,8 +320,9 @@
   1.130  	bool hit;
   1.131  	struct property *prop;
   1.132  
   1.133 -	str_printf(r, "Symbol: %s [=%s]\n", sym->name,
   1.134 -	                               sym_get_string_value(sym));
   1.135 +	if (sym && sym->name)
   1.136 +		str_printf(r, "Symbol: %s [=%s]\n", sym->name,
   1.137 +		                                    sym_get_string_value(sym));
   1.138  	for_all_prompts(sym, prop)
   1.139  		get_prompt_str(r, prop);
   1.140  	hit = false;
   1.141 @@ -375,7 +337,7 @@
   1.142  	if (hit)
   1.143  		str_append(r, "\n");
   1.144  	if (sym->rev_dep.expr) {
   1.145 -		str_append(r, "  Selected by: ");
   1.146 +		str_append(r, _("  Selected by: "));
   1.147  		expr_gstr_print(sym->rev_dep.expr, r);
   1.148  		str_append(r, "\n");
   1.149  	}
   1.150 @@ -391,19 +353,43 @@
   1.151  	for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
   1.152  		get_symbol_str(&res, sym);
   1.153  	if (!i)
   1.154 -		str_append(&res, "No matches found.\n");
   1.155 +		str_append(&res, _("No matches found.\n"));
   1.156  	return res;
   1.157  }
   1.158  
   1.159 +static char filename[PATH_MAX+1];
   1.160 +static void set_config_filename(const char *config_filename)
   1.161 +{
   1.162 +	static char menu_backtitle[PATH_MAX+128];
   1.163 +	int size;
   1.164 +	struct symbol *sym;
   1.165 +
   1.166 +	sym = sym_lookup("PROJECTVERSION", 0);
   1.167 +	sym_calc_value(sym);
   1.168 +	size = snprintf(menu_backtitle, sizeof(menu_backtitle),
   1.169 +	                _(PACKAGE " v%s Configuration - %s"),
   1.170 +		        sym_get_string_value(sym), config_filename);
   1.171 +	if (size >= sizeof(menu_backtitle))
   1.172 +		menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
   1.173 +	set_dialog_backtitle(menu_backtitle);
   1.174 +
   1.175 +	size = snprintf(filename, sizeof(filename), "%s", config_filename);
   1.176 +	if (size >= sizeof(filename))
   1.177 +		filename[sizeof(filename)-1] = '\0';
   1.178 +}
   1.179 +
   1.180 +
   1.181  static void search_conf(void)
   1.182  {
   1.183  	struct symbol **sym_arr;
   1.184  	struct gstr res;
   1.185 +	char *dialog_input;
   1.186  	int dres;
   1.187  again:
   1.188  	dialog_clear();
   1.189  	dres = dialog_inputbox(_("Search Configuration Parameter"),
   1.190 -			      _("Enter CT_ (sub)string to search for (omit CT_)"),
   1.191 +			      _("Enter CT_ (sub)string to search for "
   1.192 +				"(with or without \"CT\")"),
   1.193  			      10, 75, "");
   1.194  	switch (dres) {
   1.195  	case 0:
   1.196 @@ -415,7 +401,12 @@
   1.197  		return;
   1.198  	}
   1.199  
   1.200 -	sym_arr = sym_re_search(dialog_input_result);
   1.201 +	/* strip CT_ if necessary */
   1.202 +	dialog_input = dialog_input_result;
   1.203 +	if (strncasecmp(dialog_input_result, "CT_", 3) == 0)
   1.204 +		dialog_input += 7;
   1.205 +
   1.206 +	sym_arr = sym_re_search(dialog_input);
   1.207  	res = get_relations_str(sym_arr);
   1.208  	free(sym_arr);
   1.209  	show_textbox(_("Search Results"), str_get(&res), 0, 0);
   1.210 @@ -442,6 +433,7 @@
   1.211  			switch (prop->type) {
   1.212  			case P_MENU:
   1.213  				child_count++;
   1.214 +				prompt = _(prompt);
   1.215  				if (single_menu_mode) {
   1.216  					item_make("%s%*c%s",
   1.217  						  menu->data ? "-->" : "++>",
   1.218 @@ -454,10 +446,18 @@
   1.219  				if (single_menu_mode && menu->data)
   1.220  					goto conf_childs;
   1.221  				return;
   1.222 +			case P_COMMENT:
   1.223 +				if (prompt) {
   1.224 +					child_count++;
   1.225 +					item_make("   %*c*** %s ***", indent + 1, ' ', _(prompt));
   1.226 +					item_set_tag(':');
   1.227 +					item_set_data(menu);
   1.228 +				}
   1.229 +				break;
   1.230  			default:
   1.231  				if (prompt) {
   1.232  					child_count++;
   1.233 -					item_make("---%*c%s", indent + 1, ' ', prompt);
   1.234 +					item_make("---%*c%s", indent + 1, ' ', _(prompt));
   1.235  					item_set_tag(':');
   1.236  					item_set_data(menu);
   1.237  				}
   1.238 @@ -501,10 +501,10 @@
   1.239  			item_set_data(menu);
   1.240  		}
   1.241  
   1.242 -		item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
   1.243 +		item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
   1.244  		if (val == yes) {
   1.245  			if (def_menu) {
   1.246 -				item_add_str(" (%s)", menu_get_prompt(def_menu));
   1.247 +				item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
   1.248  				item_add_str("  --->");
   1.249  				if (def_menu->list) {
   1.250  					indent += 2;
   1.251 @@ -516,7 +516,7 @@
   1.252  		}
   1.253  	} else {
   1.254  		if (menu == current_menu) {
   1.255 -			item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
   1.256 +			item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
   1.257  			item_set_tag(':');
   1.258  			item_set_data(menu);
   1.259  			goto conf_childs;
   1.260 @@ -533,7 +533,7 @@
   1.261  				if (sym_is_changable(sym))
   1.262  					item_make("[%c]", val == no ? ' ' : '*');
   1.263  				else
   1.264 -					item_make("---");
   1.265 +					item_make("-%c-", val == no ? ' ' : '*');
   1.266  				item_set_tag('t');
   1.267  				item_set_data(menu);
   1.268  				break;
   1.269 @@ -543,10 +543,13 @@
   1.270  				case mod: ch = 'M'; break;
   1.271  				default:  ch = ' '; break;
   1.272  				}
   1.273 -				if (sym_is_changable(sym))
   1.274 -					item_make("<%c>", ch);
   1.275 -				else
   1.276 -					item_make("---");
   1.277 +				if (sym_is_changable(sym)) {
   1.278 +					if (sym->rev_dep.tri == mod)
   1.279 +						item_make("{%c}", ch);
   1.280 +					else
   1.281 +						item_make("<%c>", ch);
   1.282 +				} else
   1.283 +					item_make("-%c-", ch);
   1.284  				item_set_tag('t');
   1.285  				item_set_data(menu);
   1.286  				break;
   1.287 @@ -556,17 +559,17 @@
   1.288  				tmp = indent - tmp + 4;
   1.289  				if (tmp < 0)
   1.290  					tmp = 0;
   1.291 -				item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
   1.292 +				item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
   1.293  					     (sym_has_value(sym) || !sym_is_changable(sym)) ?
   1.294 -					     "" : " (NEW)");
   1.295 +					     "" : _(" (NEW)"));
   1.296  				item_set_tag('s');
   1.297  				item_set_data(menu);
   1.298  				goto conf_childs;
   1.299  			}
   1.300  		}
   1.301 -		item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
   1.302 +		item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
   1.303  			  (sym_has_value(sym) || !sym_is_changable(sym)) ?
   1.304 -			  "" : " (NEW)");
   1.305 +			  "" : _(" (NEW)"));
   1.306  		if (menu->prompt->type == P_MENU) {
   1.307  			item_add_str("  --->");
   1.308  			return;
   1.309 @@ -604,7 +607,7 @@
   1.310  			item_set_tag('S');
   1.311  		}
   1.312  		dialog_clear();
   1.313 -		res = dialog_menu(prompt ? prompt : _("Main Menu"),
   1.314 +		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
   1.315  				  _(menu_instructions),
   1.316  				  active_menu, &s_scroll);
   1.317  		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
   1.318 @@ -651,7 +654,7 @@
   1.319  			if (sym)
   1.320  				show_help(submenu);
   1.321  			else
   1.322 -				show_helptext("README", _(mconf_readme));
   1.323 +				show_helptext(_("README"), _(mconf_readme));
   1.324  			break;
   1.325  		case 3:
   1.326  			if (item_is_tag('t')) {
   1.327 @@ -698,24 +701,24 @@
   1.328  	struct gstr help = str_new();
   1.329  	struct symbol *sym = menu->sym;
   1.330  
   1.331 -	if (sym->help)
   1.332 +	if (menu_has_help(menu))
   1.333  	{
   1.334  		if (sym->name) {
   1.335  			str_printf(&help, "CT_%s:\n\n", sym->name);
   1.336 -			str_append(&help, _(sym->help));
   1.337 +			str_append(&help, _(menu_get_help(menu)));
   1.338  			str_append(&help, "\n");
   1.339  		}
   1.340  	} else {
   1.341  		str_append(&help, nohelp_text);
   1.342  	}
   1.343  	get_symbol_str(&help, sym);
   1.344 -	show_helptext(menu_get_prompt(menu), str_get(&help));
   1.345 +	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
   1.346  	str_free(&help);
   1.347  }
   1.348  
   1.349  static void conf_choice(struct menu *menu)
   1.350  {
   1.351 -	const char *prompt = menu_get_prompt(menu);
   1.352 +	const char *prompt = _(menu_get_prompt(menu));
   1.353  	struct menu *child;
   1.354  	struct symbol *active;
   1.355  
   1.356 @@ -729,7 +732,7 @@
   1.357  		for (child = menu->list; child; child = child->next) {
   1.358  			if (!menu_is_visible(child))
   1.359  				continue;
   1.360 -			item_make("%s", menu_get_prompt(child));
   1.361 +			item_make("%s", _(menu_get_prompt(child)));
   1.362  			item_set_data(child);
   1.363  			if (child->sym == active)
   1.364  				item_set_selected(1);
   1.365 @@ -737,7 +740,7 @@
   1.366  				item_set_tag('X');
   1.367  		}
   1.368  		dialog_clear();
   1.369 -		res = dialog_checklist(prompt ? prompt : _("Main Menu"),
   1.370 +		res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
   1.371  					_(radiolist_instructions),
   1.372  					 15, 70, 6);
   1.373  		selected = item_activate_selected();
   1.374 @@ -770,7 +773,7 @@
   1.375  
   1.376  	while (1) {
   1.377  		int res;
   1.378 -		char *heading;
   1.379 +		const char *heading;
   1.380  
   1.381  		switch (sym_get_type(menu->sym)) {
   1.382  		case S_INT:
   1.383 @@ -783,10 +786,10 @@
   1.384  			heading = _(inputbox_instructions_string);
   1.385  			break;
   1.386  		default:
   1.387 -			heading = "Internal mconf error!";
   1.388 +			heading = _("Internal mconf error!");
   1.389  		}
   1.390  		dialog_clear();
   1.391 -		res = dialog_inputbox(prompt ? prompt : _("Main Menu"),
   1.392 +		res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
   1.393  				      heading, 10, 75,
   1.394  				      sym_get_string_value(menu->sym));
   1.395  		switch (res) {
   1.396 @@ -816,8 +819,11 @@
   1.397  		case 0:
   1.398  			if (!dialog_input_result[0])
   1.399  				return;
   1.400 -			if (!conf_read(dialog_input_result))
   1.401 +			if (!conf_read(dialog_input_result)) {
   1.402 +				set_config_filename(dialog_input_result);
   1.403 +				sym_set_change_count(1);
   1.404  				return;
   1.405 +			}
   1.406  			show_textbox(NULL, _("File does not exist!"), 5, 38);
   1.407  			break;
   1.408  		case 1:
   1.409 @@ -840,8 +846,10 @@
   1.410  		case 0:
   1.411  			if (!dialog_input_result[0])
   1.412  				return;
   1.413 -			if (!conf_write(dialog_input_result))
   1.414 +			if (!conf_write(dialog_input_result)) {
   1.415 +				set_config_filename(dialog_input_result);
   1.416  				return;
   1.417 +			}
   1.418  			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
   1.419  			break;
   1.420  		case 1:
   1.421 @@ -853,14 +861,9 @@
   1.422  	}
   1.423  }
   1.424  
   1.425 -static void conf_cleanup(void)
   1.426 -{
   1.427 -	tcsetattr(1, TCSAFLUSH, &ios_org);
   1.428 -}
   1.429 -
   1.430  int main(int ac, char **av)
   1.431  {
   1.432 -	struct symbol *sym;
   1.433 +	int saved_x, saved_y;
   1.434  	char *mode;
   1.435  	int res;
   1.436  
   1.437 @@ -871,49 +874,49 @@
   1.438  	conf_parse(av[1]);
   1.439  	conf_read(NULL);
   1.440  
   1.441 -	sym = sym_lookup("PROJECTVERSION", 0);
   1.442 -	sym_calc_value(sym);
   1.443 -	sprintf(menu_backtitle, _(PROJECT_NAME" v%s Configuration"),
   1.444 -		sym_get_string_value(sym));
   1.445 -
   1.446  	mode = getenv("MENUCONFIG_MODE");
   1.447  	if (mode) {
   1.448  		if (!strcasecmp(mode, "single_menu"))
   1.449  			single_menu_mode = 1;
   1.450  	}
   1.451  
   1.452 -	tcgetattr(1, &ios_org);
   1.453 -	atexit(conf_cleanup);
   1.454 -	init_wsize();
   1.455 -	reset_dialog();
   1.456 -	init_dialog(menu_backtitle);
   1.457 +	getyx(stdscr, saved_y, saved_x);
   1.458 +	if (init_dialog(NULL)) {
   1.459 +		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
   1.460 +		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
   1.461 +		return 1;
   1.462 +	}
   1.463 +
   1.464 +	set_config_filename(conf_get_configname());
   1.465  	do {
   1.466  		conf(&rootmenu);
   1.467  		dialog_clear();
   1.468  		if (conf_get_changed())
   1.469  			res = dialog_yesno(NULL,
   1.470  					   _("Do you wish to save your "
   1.471 -					     "new "PROJECT_NAME" configuration?\n"
   1.472 +					     "new " PACKAGE " configuration?\n"
   1.473  					     "<ESC><ESC> to continue."),
   1.474  					   6, 60);
   1.475  		else
   1.476  			res = -1;
   1.477  	} while (res == KEY_ESC);
   1.478 -	end_dialog();
   1.479 +	end_dialog(saved_x, saved_y);
   1.480  
   1.481  	switch (res) {
   1.482  	case 0:
   1.483 -		if (conf_write(NULL)) {
   1.484 -			fprintf(stderr,
   1.485 -				_( "Error during writing of "PROJECT_NAME" configuration.\n"
   1.486 -				   "Your configuration changes were NOT saved.\n"));
   1.487 +		if (conf_write(filename)) {
   1.488 +			fprintf(stderr, _("\n\n"
   1.489 +				"Error during writing of " PACKAGE " configuration.\n"
   1.490 +				"Your " PACKAGE " configuration changes were NOT saved."
   1.491 +				"\n\n"));
   1.492  			return 1;
   1.493  		}
   1.494  	case -1:
   1.495  		break;
   1.496  	default:
   1.497 -		fprintf(stderr, _( "Your configuration changes were NOT saved.\n"));
   1.498 +		fprintf(stderr, _("Your configuration changes were NOT saved.\n"));
   1.499  	}
   1.500  
   1.501  	return 0;
   1.502  }
   1.503 +