Apply post-1.20.0 patches, bump version to 1.20.1
[oweals/busybox.git] / libbb / lineedit.c
index 1390ed62d9b381f2ecfcd9a126724a1ca6d5acd2..b89748a1c64f4df14e003e2649ac95cd138e479e 100644 (file)
@@ -1352,8 +1352,7 @@ static void load_history(line_input_t *st_parm)
                /* fill temp_h[], retaining only last MAX_HISTORY lines */
                memset(temp_h, 0, sizeof(temp_h));
                idx = 0;
-               if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
-                       st_parm->cnt_history_in_file = 0;
+               st_parm->cnt_history_in_file = 0;
                while ((line = xmalloc_fgetline(fp)) != NULL) {
                        if (line[0] == '\0') {
                                free(line);
@@ -1361,8 +1360,7 @@ static void load_history(line_input_t *st_parm)
                        }
                        free(temp_h[idx]);
                        temp_h[idx] = line;
-                       if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
-                               st_parm->cnt_history_in_file++;
+                       st_parm->cnt_history_in_file++;
                        idx++;
                        if (idx == st_parm->max_history)
                                idx = 0;
@@ -2206,14 +2204,17 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
 #define command command_must_not_be_used
 
        new_settings = initial_settings;
-       new_settings.c_lflag &= ~ICANON;        /* unbuffered input */
-       /* Turn off echoing and CTRL-C, so we can trap it */
-       new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
-       /* Hmm, in linux c_cc[] is not parsed if ICANON is off */
+       /* ~ICANON: unbuffered input (most c_cc[] are disabled, VMIN/VTIME are enabled) */
+       /* ~ECHO, ~ECHONL: turn off echoing, including newline echoing */
+       /* ~ISIG: turn off INTR (ctrl-C), QUIT, SUSP */
+       new_settings.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG);
+       /* reads would block only if < 1 char is available */
        new_settings.c_cc[VMIN] = 1;
+       /* no timeout (reads block forever) */
        new_settings.c_cc[VTIME] = 0;
-       /* Turn off CTRL-C, so we can trap it */
-       new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
+       /* Should be not needed if ISIG is off: */
+       /* Turn off CTRL-C */
+       /* new_settings.c_cc[VINTR] = _POSIX_VDISABLE; */
        tcsetattr_stdin_TCSANOW(&new_settings);
 
 #if ENABLE_USERNAME_OR_HOMEDIR
@@ -2514,7 +2515,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
                        switch (ic) {
                                //case KEYCODE_LEFT: - bash doesn't do this
                                case 'b':
-                                       ctrl_left();
+                                       ctrl_left();
                                        break;
                                //case KEYCODE_RIGHT: - bash doesn't do this
                                case 'f':