kconfig: gettext support for xconfig
[firefly-linux-kernel-4.4.55.git] / scripts / kconfig / mconf.c
index d2c2a429887b30152b57d26eaea78086a41bd3c3..ee9ed30594728d77628c7f791269e2e01ef8edc6 100644 (file)
@@ -8,17 +8,13 @@
  * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  */
 
-#include <sys/ioctl.h>
-#include <sys/wait.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
-#include <signal.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
 #include <unistd.h>
 #include <locale.h>
 
@@ -35,9 +31,13 @@ static const char mconf_readme[] = N_(
 "kernel parameters which are not really features, but must be\n"
 "entered in as decimal or hexadecimal numbers or possibly text.\n"
 "\n"
-"Menu items beginning with [*], <M> or [ ] represent features\n"
-"configured to be built in, modularized or removed respectively.\n"
-"Pointed brackets <> represent module capable features.\n"
+"Menu items beginning with following braces represent features that\n"
+"  [ ] can be built in or removed\n"
+"  < > can be built in, modularized or removed\n"
+"  { } can be built in or modularized (selected by other feature)\n"
+"  - - are selected by other feature,\n"
+"while *, M or whitespace inside braces means to build in, build as\n"
+"a module or to exclude the feature respectively.\n"
 "\n"
 "To change any of these features, highlight it with the cursor\n"
 "keys and press <Y> to build it in, <M> to make it a module or\n"
@@ -271,8 +271,6 @@ search_help[] = N_(
        "\n");
 
 static int indent;
-static struct termios ios_org;
-static int rows = 0, cols = 0;
 static struct menu *current_menu;
 static int child_count;
 static int single_menu_mode;
@@ -286,41 +284,6 @@ static void show_textbox(const char *title, const char *text, int r, int c);
 static void show_helptext(const char *title, const char *text);
 static void show_help(struct menu *menu);
 
-static void init_wsize(void)
-{
-       struct winsize ws;
-       char *env;
-
-       if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
-               rows = ws.ws_row;
-               cols = ws.ws_col;
-       }
-
-       if (!rows) {
-               env = getenv("LINES");
-               if (env)
-                       rows = atoi(env);
-               if (!rows)
-                       rows = 24;
-       }
-       if (!cols) {
-               env = getenv("COLUMNS");
-               if (env)
-                       cols = atoi(env);
-               if (!cols)
-                       cols = 80;
-       }
-
-       if (rows < 19 || cols < 80) {
-               fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
-               fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
-               exit(1);
-       }
-
-       rows -= 4;
-       cols -= 5;
-}
-
 static void get_prompt_str(struct gstr *r, struct property *prop)
 {
        int i, j;
@@ -357,8 +320,9 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym)
        bool hit;
        struct property *prop;
 
-       str_printf(r, "Symbol: %s [=%s]\n", sym->name,
-                                      sym_get_string_value(sym));
+       if (sym && sym->name)
+               str_printf(r, "Symbol: %s [=%s]\n", sym->name,
+                                                   sym_get_string_value(sym));
        for_all_prompts(sym, prop)
                get_prompt_str(r, prop);
        hit = false;
@@ -481,6 +445,14 @@ static void build_conf(struct menu *menu)
                                if (single_menu_mode && menu->data)
                                        goto conf_childs;
                                return;
+                       case P_COMMENT:
+                               if (prompt) {
+                                       child_count++;
+                                       item_make("   %*c*** %s ***", indent + 1, ' ', prompt);
+                                       item_set_tag(':');
+                                       item_set_data(menu);
+                               }
+                               break;
                        default:
                                if (prompt) {
                                        child_count++;
@@ -560,7 +532,7 @@ static void build_conf(struct menu *menu)
                                if (sym_is_changable(sym))
                                        item_make("[%c]", val == no ? ' ' : '*');
                                else
-                                       item_make("---");
+                                       item_make("-%c-", val == no ? ' ' : '*');
                                item_set_tag('t');
                                item_set_data(menu);
                                break;
@@ -570,10 +542,13 @@ static void build_conf(struct menu *menu)
                                case mod: ch = 'M'; break;
                                default:  ch = ' '; break;
                                }
-                               if (sym_is_changable(sym))
-                                       item_make("<%c>", ch);
-                               else
-                                       item_make("---");
+                               if (sym_is_changable(sym)) {
+                                       if (sym->rev_dep.tri == mod)
+                                               item_make("{%c}", ch);
+                                       else
+                                               item_make("<%c>", ch);
+                               } else
+                                       item_make("-%c-", ch);
                                item_set_tag('t');
                                item_set_data(menu);
                                break;
@@ -725,11 +700,11 @@ static void show_help(struct menu *menu)
        struct gstr help = str_new();
        struct symbol *sym = menu->sym;
 
-       if (sym->help)
+       if (menu_has_help(menu))
        {
                if (sym->name) {
                        str_printf(&help, "CONFIG_%s:\n\n", sym->name);
-                       str_append(&help, _(sym->help));
+                       str_append(&help, _(menu_get_help(menu)));
                        str_append(&help, "\n");
                }
        } else {
@@ -884,13 +859,9 @@ static void conf_save(void)
        }
 }
 
-static void conf_cleanup(void)
-{
-       tcsetattr(1, TCSAFLUSH, &ios_org);
-}
-
 int main(int ac, char **av)
 {
+       int saved_x, saved_y;
        char *mode;
        int res;
 
@@ -907,11 +878,13 @@ int main(int ac, char **av)
                        single_menu_mode = 1;
        }
 
-       tcgetattr(1, &ios_org);
-       atexit(conf_cleanup);
-       init_wsize();
-       reset_dialog();
-       init_dialog(NULL);
+       getyx(stdscr, saved_y, saved_x);
+       if (init_dialog(NULL)) {
+               fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
+               fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
+               return 1;
+       }
+
        set_config_filename(conf_get_configname());
        do {
                conf(&rootmenu);
@@ -925,7 +898,7 @@ int main(int ac, char **av)
                else
                        res = -1;
        } while (res == KEY_ESC);
-       end_dialog();
+       end_dialog(saved_x, saved_y);
 
        switch (res) {
        case 0: