scripts/kconfig/nconf: dynamically alloc dialog_input_result
[linux-3.10.git] / scripts / kconfig / nconf.gui.c
index a9d9344..d64bc1c 100644 (file)
@@ -137,7 +137,7 @@ void set_colors()
        if (has_colors()) {
                normal_color_theme();
        } else {
-               /* give deafults */
+               /* give defaults */
                no_colors_theme();
        }
 }
@@ -167,7 +167,7 @@ void print_in_middle(WINDOW *win,
        length = strlen(string);
        temp = (width - length) / 2;
        x = startx + (int)temp;
-       wattrset(win, color);
+       (void) wattrset(win, color);
        mvwprintw(win, y, x, "%s", string);
        refresh();
 }
@@ -297,11 +297,11 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
        set_menu_fore(menu, attributes[DIALOG_MENU_FORE]);
        set_menu_back(menu, attributes[DIALOG_MENU_BACK]);
 
-       wattrset(win, attributes[DIALOG_BOX]);
+       (void) wattrset(win, attributes[DIALOG_BOX]);
        box(win, 0, 0);
 
        /* print message */
-       wattrset(msg_win, attributes[DIALOG_TEXT]);
+       (void) wattrset(msg_win, attributes[DIALOG_TEXT]);
        fill_window(msg_win, msg);
 
        set_menu_win(menu, win);
@@ -356,7 +356,7 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
 
 int dialog_inputbox(WINDOW *main_window,
                const char *title, const char *prompt,
-               const char *init, char *result, int result_len)
+               const char *init, char **resultp, int *result_len)
 {
        int prompt_lines = 0;
        int prompt_width = 0;
@@ -367,7 +367,12 @@ int dialog_inputbox(WINDOW *main_window,
        int i, x, y;
        int res = -1;
        int cursor_position = strlen(init);
+       char *result = *resultp;
 
+       if (strlen(init)+1 > *result_len) {
+               *result_len = strlen(init)+1;
+               *resultp = result = realloc(result, *result_len);
+       }
 
        /* find the widest line of msg: */
        prompt_lines = get_line_no(prompt);
@@ -384,7 +389,7 @@ int dialog_inputbox(WINDOW *main_window,
        y = (LINES-(prompt_lines+4))/2;
        x = (COLS-(prompt_width+4))/2;
 
-       strncpy(result, init, result_len);
+       strncpy(result, init, *result_len);
 
        /* create the windows */
        win = newwin(prompt_lines+6, prompt_width+7, y, x);
@@ -392,16 +397,16 @@ int dialog_inputbox(WINDOW *main_window,
        form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
        keypad(form_win, TRUE);
 
-       wattrset(form_win, attributes[INPUT_FIELD]);
+       (void) wattrset(form_win, attributes[INPUT_FIELD]);
 
-       wattrset(win, attributes[INPUT_BOX]);
+       (void) wattrset(win, attributes[INPUT_BOX]);
        box(win, 0, 0);
-       wattrset(win, attributes[INPUT_HEADING]);
+       (void) wattrset(win, attributes[INPUT_HEADING]);
        if (title)
                mvwprintw(win, 0, 3, "%s", title);
 
        /* print message */
-       wattrset(prompt_win, attributes[INPUT_TEXT]);
+       (void) wattrset(prompt_win, attributes[INPUT_TEXT]);
        fill_window(prompt_win, prompt);
 
        mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
@@ -443,7 +448,7 @@ int dialog_inputbox(WINDOW *main_window,
                case KEY_UP:
                case KEY_RIGHT:
                        if (cursor_position < len &&
-                           cursor_position < min(result_len, prompt_width))
+                           cursor_position < min(*result_len, prompt_width))
                                cursor_position++;
                        break;
                case KEY_DOWN:
@@ -452,16 +457,21 @@ int dialog_inputbox(WINDOW *main_window,
                                cursor_position--;
                        break;
                default:
-                       if ((isgraph(res) || isspace(res)) &&
-                                       len-2 < result_len) {
+                       if ((isgraph(res) || isspace(res))) {
+                               /* one for new char, one for '\0' */
+                               if (len+2 > *result_len) {
+                                       *result_len = len+2;
+                                       *resultp = result = realloc(result,
+                                                               *result_len);
+                               }
                                /* insert the char at the proper position */
                                memmove(&result[cursor_position+1],
                                                &result[cursor_position],
-                                               len+1);
+                                               len-cursor_position+1);
                                result[cursor_position] = res;
                                cursor_position++;
                        } else {
-                               mvprintw(0, 0, "unknow key: %d\n", res);
+                               mvprintw(0, 0, "unknown key: %d\n", res);
                        }
                        break;
                }
@@ -531,7 +541,7 @@ void show_scroll_win(WINDOW *main_window,
 
        /* create the pad */
        pad = newpad(total_lines+10, total_cols+10);
-       wattrset(pad, attributes[SCROLLWIN_TEXT]);
+       (void) wattrset(pad, attributes[SCROLLWIN_TEXT]);
        fill_window(pad, text);
 
        win_lines = min(total_lines+4, LINES-2);
@@ -546,9 +556,9 @@ void show_scroll_win(WINDOW *main_window,
        win = newwin(win_lines, win_cols, y, x);
        keypad(win, TRUE);
        /* show the help in the help window, and show the help panel */
-       wattrset(win, attributes[SCROLLWIN_BOX]);
+       (void) wattrset(win, attributes[SCROLLWIN_BOX]);
        box(win, 0, 0);
-       wattrset(win, attributes[SCROLLWIN_HEADING]);
+       (void) wattrset(win, attributes[SCROLLWIN_HEADING]);
        mvwprintw(win, 0, 3, " %s ", title);
        panel = new_panel(win);