From f6f38b4bc989d3568b26b75fd9550b51eb942a5f Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Mon, 12 Dec 1994 03:23:04 +0000 Subject: [PATCH] Upgrade to readline from bash 1.14.3 --- gnu/lib/libreadline/VERSION | 1 + gnu/lib/libreadline/complete.c | 28 ++++++++++----- gnu/lib/libreadline/display.c | 58 ++++++++++++++++++++++++++++-- gnu/lib/libreadline/history.c | 13 +++---- gnu/lib/libreadline/history.h | 5 +-- gnu/lib/libreadline/keymaps.c | 6 +++- gnu/lib/libreadline/readline.c | 65 ++++++++++++++++++++-------------- gnu/lib/libreadline/rldefs.h | 8 ++--- gnu/lib/libreadline/rltty.c | 34 +++++++++++------- gnu/lib/libreadline/search.c | 7 ++-- gnu/lib/libreadline/signals.c | 26 +++----------- gnu/lib/libreadline/tilde.c | 3 +- gnu/lib/libreadline/vi_mode.c | 10 +++--- 13 files changed, 168 insertions(+), 96 deletions(-) create mode 100644 gnu/lib/libreadline/VERSION diff --git a/gnu/lib/libreadline/VERSION b/gnu/lib/libreadline/VERSION new file mode 100644 index 000000000000..d2f0387da33f --- /dev/null +++ b/gnu/lib/libreadline/VERSION @@ -0,0 +1 @@ +Readline from bash 1.14.3 + local fixes diff --git a/gnu/lib/libreadline/complete.c b/gnu/lib/libreadline/complete.c index 218013255588..c1c3b7740153 100644 --- a/gnu/lib/libreadline/complete.c +++ b/gnu/lib/libreadline/complete.c @@ -21,6 +21,10 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ #define READLINE_LIBRARY +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + #include #include #include @@ -546,8 +550,12 @@ rl_complete_internal (what_to_do) /* Sort the items. */ /* It is safe to sort this array, because the lowest common denominator found in matches[0] will remain in place. */ - for (i = 0; matches[i]; i++); - qsort (matches, i, sizeof (char *), compare_strings); + for (i = 0; matches[i]; i++) + ; + /* Try sorting the array without matches[0], since we need it to + stay in place no matter what. */ + if (i) + qsort (matches+1, i-1, sizeof (char *), compare_strings); /* Remember the lowest common denominator for it may be unique. */ lowest_common = savestring (matches[0]); @@ -846,19 +854,18 @@ rl_complete_internal (what_to_do) count = (len + (limit - 1)) / limit; /* Watch out for special case. If LEN is less than LIMIT, then - just do the inner printing loop. */ - if (len < limit) - count = 1; + just do the inner printing loop. + 0 < len <= limit implies count = 1. */ /* Sort the items if they are not already sorted. */ if (!rl_ignore_completion_duplicates) - qsort (matches, len, sizeof (char *), compare_strings); + qsort (matches + 1, len - 1, sizeof (char *), compare_strings); /* Print the sorted items, up-and-down alphabetically, like ls might. */ crlf (); - for (i = 1; i < count + 1; i++) + for (i = 1; i <= count; i++) { for (j = 0, l = i; j < limit; j++) { @@ -1002,8 +1009,11 @@ username_completion_function (text, state) while (entry = getpwent ()) { - if ((username[0] == entry->pw_name[0]) && - (strncmp (username, entry->pw_name, namelen) == 0)) + /* Null usernames should result in all users as possible completions. */ + if (namelen == 0) + break; + else if ((username[0] == entry->pw_name[0]) && + (strncmp (username, entry->pw_name, namelen) == 0)) break; } diff --git a/gnu/lib/libreadline/display.c b/gnu/lib/libreadline/display.c index 8204570f238f..ea1598bfb636 100644 --- a/gnu/lib/libreadline/display.c +++ b/gnu/lib/libreadline/display.c @@ -21,6 +21,10 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ #define READLINE_LIBRARY +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + #include #include @@ -459,7 +463,8 @@ rl_redisplay () (_rl_last_c_pos < visible_first_line_len)) { nleft = screenwidth + wrap_offset - _rl_last_c_pos; - clear_to_eol (nleft); + if (nleft) + clear_to_eol (nleft); } /* Since the new first line is now visible, save its length. */ @@ -485,7 +490,7 @@ rl_redisplay () /* Move the cursor where it should be. */ /* Which line? */ - nleft = c_pos - wrap_offset - term_xn + 1; + nleft = c_pos - wrap_offset + term_xn - 1; cursor_linenum = (nleft > 0) ? nleft / screenwidth : 0; /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a @@ -1217,3 +1222,52 @@ _rl_update_final () fflush (rl_outstream); rl_display_fixed++; } + +/* Move to the start of the current line. */ +static void +cr () +{ + if (term_cr) + { + tputs (term_cr, 1, _rl_output_character_function); + _rl_last_c_pos = 0; + } +} + +/* Redisplay the current line after a SIGWINCH is received. */ +void +_rl_redisplay_after_sigwinch () +{ + char *t, *oldp; + + /* Clear the current line and put the cursor at column 0. Make sure + the right thing happens if we have wrapped to a new screen line. */ + if (term_cr) + { + tputs (term_cr, 1, _rl_output_character_function); + _rl_last_c_pos = 0; + if (term_clreol) + tputs (term_clreol, 1, _rl_output_character_function); + else + { + space_to_eol (screenwidth); + tputs (term_cr, 1, _rl_output_character_function); + } + if (_rl_last_v_pos > 0) + _rl_move_vert (0); + } + else + crlf (); + + /* Redraw only the last line of a multi-line prompt. */ + t = strrchr (rl_display_prompt, '\n'); + if (t) + { + oldp = rl_display_prompt; + rl_display_prompt = ++t; + rl_forced_update_display (); + rl_display_prompt = oldp; + } + else + rl_forced_update_display (); +} diff --git a/gnu/lib/libreadline/history.c b/gnu/lib/libreadline/history.c index 68e99cf1cbe4..f33cd60ec90b 100644 --- a/gnu/lib/libreadline/history.c +++ b/gnu/lib/libreadline/history.c @@ -25,10 +25,6 @@ you can call. I think I have done that. */ #define READLINE_LIBRARY -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - #include #include #include @@ -1536,9 +1532,9 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line) j += sl; \ if (j >= result_len) \ { \ - while (j >= result_len) \ - result_len += 128; \ - result = xrealloc (result, result_len); \ + while (j >= result_len) \ + result_len += 128; \ + result = xrealloc (result, result_len); \ } \ strcpy (result + j - sl, s); \ } \ @@ -1906,13 +1902,14 @@ history_arg_extract (first, last, string) last++; - if (first > len || last > len || first < 0 || last < 0) + if (first >= len || last > len || first < 0 || last < 0 || first > last) result = ((char *)NULL); else { for (size = 0, i = first; i < last; i++) size += strlen (list[i]) + 1; result = xmalloc (size + 1); + result[0] = '\0'; for (i = first; i < last; i++) { diff --git a/gnu/lib/libreadline/history.h b/gnu/lib/libreadline/history.h index 745e61cce5e1..6935efd20d13 100644 --- a/gnu/lib/libreadline/history.h +++ b/gnu/lib/libreadline/history.h @@ -105,9 +105,10 @@ extern HIST_ENTRY *next_history (); found in. Otherwise, nothing is changed, and a -1 is returned. */ extern int history_search (); -extern int history_search_prefix (); -/* Search the history for @var{string}, starting at history_offset. +/* Search the history for STRING, starting at history_offset. The search is anchored: matching lines must begin with string. */ +extern int history_search_prefix (); + /* Search for STRING in the history list, starting at POS, an absolute index into the list. DIR, if negative, says to search backwards from POS, else forwards. diff --git a/gnu/lib/libreadline/keymaps.c b/gnu/lib/libreadline/keymaps.c index da59b69be35d..e1be552cdcc2 100644 --- a/gnu/lib/libreadline/keymaps.c +++ b/gnu/lib/libreadline/keymaps.c @@ -20,6 +20,10 @@ Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #define READLINE_LIBRARY +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + #if defined (HAVE_STDLIB_H) # include #else @@ -101,7 +105,7 @@ rl_make_keymap () newmap = rl_make_bare_keymap (); /* All ASCII printing characters are self-inserting. */ - for (i = ' '; i < 126; i++) + for (i = ' '; i < 127; i++) newmap[i].function = rl_insert; newmap[TAB].function = rl_insert; diff --git a/gnu/lib/libreadline/readline.c b/gnu/lib/libreadline/readline.c index 930a0a87eb64..ef45f5a0ab04 100644 --- a/gnu/lib/libreadline/readline.c +++ b/gnu/lib/libreadline/readline.c @@ -284,7 +284,7 @@ readline (prompt) return ((char *)NULL); } - rl_visible_prompt_length = rl_expand_prompt (rl_prompt); + rl_visible_prompt_length = (rl_prompt && *rl_prompt) ? rl_expand_prompt (rl_prompt) : 0; rl_initialize (); rl_prep_terminal (_rl_meta_flag); @@ -624,13 +624,12 @@ _rl_dispatch (key, map) { int r = 0; - if (defining_kbd_macro) - add_macro_char (key); - if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii) { if (map[ESC].type == ISKMAP) { + if (defining_kbd_macro) + add_macro_char (ESC); map = FUNCTION_TO_KEYMAP (map, ESC); key = UNMETA (key); rl_key_sequence_length += 2; @@ -641,6 +640,9 @@ _rl_dispatch (key, map) return 0; } + if (defining_kbd_macro) + add_macro_char (key); + switch (map[key].type) { case ISFUNC: @@ -921,8 +923,6 @@ _rl_kill_kbd_macro () /* Initliaze readline (and terminal if not already). */ rl_initialize () { - char *t, *t1; - /* If we have never been called before, initialize the terminal and data structures. */ if (!rl_initialized) @@ -939,20 +939,6 @@ rl_initialize () /* We aren't done yet. We haven't even gotten started yet! */ rl_done = 0; - /* Check for LC_CTYPE and use its value to decide the defaults for - 8-bit character input and output. */ - t = getenv ("LC_CTYPE"); - t1 = getenv ("LANG"); - if (t && (strstr (t, "8859-1") != NULL || strstr (t, "8859_1") != NULL || - strstr (t, "KOI8-R") != NULL || strstr (t, "koi8-r") != NULL) || - t1 && (strstr (t1, "8859-1") != NULL || strstr (t1, "8859_1") != NULL || - strstr (t1, "KOI8-R") != NULL || strstr (t1, "koi8-r") != NULL)) - { - _rl_meta_flag = 1; - _rl_convert_meta_chars_to_ascii = 0; - _rl_output_meta_chars = 1; - } - /* Tell the history routines what is going on. */ start_using_history (); @@ -972,6 +958,8 @@ rl_initialize () static void readline_initialize_everything () { + char *t, *t1; + /* Find out if we are running in Emacs. */ running_in_emacs = getenv ("EMACS") != (char *)0; @@ -1002,6 +990,20 @@ readline_initialize_everything () /* Initialize the function names. */ rl_initialize_funmap (); + /* Check for LC_CTYPE and use its value to decide the defaults for + 8-bit character input and output. */ + t = getenv ("LC_CTYPE"); + t1 = getenv ("LANG"); + if (t && (strstr (t, "8859-1") != NULL || strstr (t, "8859_1") != NULL || + strstr (t, "KOI8-R") != NULL || strstr (t, "koi8-r") != NULL) || + t1 && (strstr (t1, "8859-1") != NULL || strstr (t1, "8859_1") != NULL || + strstr (t1, "KOI8-R") != NULL || strstr (t1, "koi8-r") != NULL)) + { + _rl_meta_flag = 1; + _rl_convert_meta_chars_to_ascii = 0; + _rl_output_meta_chars = 1; + } + /* Read in the init file. */ rl_read_init_file ((char *)NULL); @@ -1181,8 +1183,8 @@ int dumb_term = 0; #undef PC #if !defined (__linux__) -/* If this causes problems, remove the `extern'. */ -extern char PC, *BC, *UP; +/* If this causes problems, add back the `extern'. */ +/*extern*/ char PC, *BC, *UP; #endif /* __linux__ */ /* Some strings to control terminal actions. These are output by tputs (). */ @@ -1713,6 +1715,10 @@ rl_delete_text (from, to) from = to; to = t; } + + if (to > rl_end) + to = rl_end; + text = rl_copy_text (from, to); /* Some versions of strncpy() can't handle overlapping arguments. */ @@ -2264,12 +2270,17 @@ rl_unix_word_rubout (count, key) else { int orig_point = rl_point; + if (count <= 0) + count = 1; - while (rl_point && whitespace (the_line[rl_point - 1])) - rl_point--; + while (count--) + { + while (rl_point && whitespace (the_line[rl_point - 1])) + rl_point--; - while (rl_point && !whitespace (the_line[rl_point - 1])) - rl_point--; + while (rl_point && !whitespace (the_line[rl_point - 1])) + rl_point--; + } rl_kill_text (orig_point, rl_point); } @@ -2390,7 +2401,7 @@ rl_change_case (count, op) break; default: - abort (); + ding (); return -1; } } diff --git a/gnu/lib/libreadline/rldefs.h b/gnu/lib/libreadline/rldefs.h index 214fb950509f..9ad9e597b7c5 100644 --- a/gnu/lib/libreadline/rldefs.h +++ b/gnu/lib/libreadline/rldefs.h @@ -30,14 +30,14 @@ # include "config.h" #endif -#if defined (HAVE_UNISTD_H) -# include /* for _POSIX_VERSION */ -#endif /* HAVE_UNISTD_H */ - #if !defined (PRAGMA_ALLOCA) # include "memalloc.h" #endif +#if defined (HAVE_UNISTD_H) +# include +#endif /* HAVE_UNISTD_H */ + #define NEW_TTY_DRIVER #define HAVE_BSD_SIGNALS /* #define USE_XON_XOFF */ diff --git a/gnu/lib/libreadline/rltty.c b/gnu/lib/libreadline/rltty.c index ebb84130eb44..a007beb88e29 100644 --- a/gnu/lib/libreadline/rltty.c +++ b/gnu/lib/libreadline/rltty.c @@ -27,6 +27,10 @@ #include #include +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + #if defined (HAVE_UNISTD_H) # include #endif /* HAVE_UNISTD_H */ @@ -46,8 +50,6 @@ extern int _rl_eof_char; # undef HANDLE_SIGNALS #endif /* __GO32__ */ -static int output_was_flushed; - /* **************************************************************** */ /* */ /* Signal Management */ @@ -145,6 +147,7 @@ control_meta_key (on) } } +#if 0 static void control_keypad (on) int on; @@ -154,6 +157,7 @@ control_keypad (on) else if (!on && term_ke) tputs (term_ke, 1, outchar); } +#endif /* **************************************************************** */ /* */ @@ -377,6 +381,7 @@ get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { + int ioctl_ret; #if !defined (SHELL) && defined (TIOCGWINSZ) struct winsize w; @@ -386,12 +391,12 @@ get_tty_settings (tty, tiop) /* Keep looping if output is being flushed after a ^O (or whatever the flush character is). */ - while (GETATTR (tty, tiop) < 0 || OUTPUT_BEING_FLUSHED (tiop)) + while ((ioctl_ret = GETATTR (tty, tiop)) < 0 || OUTPUT_BEING_FLUSHED (tiop)) { + if (ioctl_ret < 0 && errno != EINTR) + return -1; if (OUTPUT_BEING_FLUSHED (tiop)) continue; - if (errno != EINTR) - return -1; errno = 0; } return 0; @@ -467,12 +472,13 @@ prepare_terminal_settings (meta_flag, otio, tiop) tiop->c_cc[VMIN] = 1; tiop->c_cc[VTIME] = 0; - if (tiop->c_lflag & FLUSHO) +#if defined (FLUSHO) + if (OUTPUT_BEING_FLUSHED (tiop)) { - output_was_flushed = 1; tiop->c_lflag &= ~FLUSHO; otio.c_lflag &= ~FLUSHO; } +#endif /* Turn off characters that we need on Posix systems with job control, just to be sure. This includes ^Y and ^V. This should not really @@ -522,11 +528,10 @@ rl_prep_terminal (meta_flag) return; } - if (output_was_flushed) - output_was_flushed = 0; - control_meta_key (1); +#if 0 control_keypad (1); +#endif fflush (rl_outstream); terminal_prepped = 1; @@ -547,15 +552,18 @@ rl_deprep_terminal () /* Try to keep this function from being INTerrupted. */ block_sigint (); + control_meta_key (0); +#if 0 + control_keypad (0); +#endif + fflush (rl_outstream); + if (set_tty_settings (tty, &otio) < 0) { release_sigint (); return; } - control_meta_key (0); - control_keypad (0); - fflush (rl_outstream); terminal_prepped = 0; release_sigint (); diff --git a/gnu/lib/libreadline/search.c b/gnu/lib/libreadline/search.c index a2b8c5e0af7d..0f97295ca929 100644 --- a/gnu/lib/libreadline/search.c +++ b/gnu/lib/libreadline/search.c @@ -29,7 +29,6 @@ # include #endif -#include "memalloc.h" #include "rldefs.h" #include "readline.h" #include "history.h" @@ -44,6 +43,7 @@ extern char *xmalloc (), *xrealloc (); /* Variables imported from readline.c */ extern int rl_point, rl_end, rl_line_buffer_len; extern Keymap _rl_keymap; +extern int rl_editing_mode; extern char *rl_prompt; extern char *rl_line_buffer; extern HIST_ENTRY *saved_line_for_history; @@ -94,7 +94,7 @@ noninc_dosearch (string, dir) int oldpos, pos; HIST_ENTRY *entry; - if (string == 0 || *string == 0 || noninc_history_pos < 0) + if (string == 0 || *string == '\0' || noninc_history_pos < 0) { ding (); return; @@ -116,6 +116,9 @@ noninc_dosearch (string, dir) oldpos = where_history (); history_set_pos (noninc_history_pos); entry = current_history (); +#if defined (VI_MODE) + if (rl_editing_mode != vi_mode) +#endif history_set_pos (oldpos); { diff --git a/gnu/lib/libreadline/signals.c b/gnu/lib/libreadline/signals.c index a9fda5cfcf8f..ae113733ee45 100644 --- a/gnu/lib/libreadline/signals.c +++ b/gnu/lib/libreadline/signals.c @@ -58,16 +58,10 @@ extern int errno; #include "readline.h" #include "history.h" -static void cr (); - extern int readline_echoing_p; extern int rl_pending_input; -extern char *term_cr; - extern int _rl_meta_flag; -extern int _rl_output_character_function (); - extern void free_undo_list (); #if defined (VOID_SIGHANDLER) @@ -107,9 +101,7 @@ rl_handle_sigwinch (sig) if (readline_echoing_p) { _rl_set_screen_size (fileno (rl_instream), 1); - - cr (); /* was crlf () */ - rl_forced_update_display (); + _rl_redisplay_after_sigwinch (); } if (old_sigwinch && @@ -276,28 +268,20 @@ rl_clear_signals () #if !defined (SHELL) #if defined (SIGTSTP) - signal (SIGTSTP, old_tstp); + rl_set_sighandler (SIGTSTP, old_tstp); #endif #if defined (SIGTTOU) - signal (SIGTTOU, old_ttou); - signal (SIGTTIN, old_ttin); + rl_set_sighandler (SIGTTOU, old_ttou); + rl_set_sighandler (SIGTTIN, old_ttin); #endif /* SIGTTOU */ #endif /* !SHELL */ #if defined (SIGWINCH) - signal (SIGWINCH, old_sigwinch); + rl_set_sighandler (SIGWINCH, old_sigwinch); #endif return 0; } - -/* Move to the start of the current line. */ -static void -cr () -{ - if (term_cr) - tputs (term_cr, 1, _rl_output_character_function); -} #endif /* HANDLE_SIGNALS */ diff --git a/gnu/lib/libreadline/tilde.c b/gnu/lib/libreadline/tilde.c index 89168a03b76a..84c24b745c51 100644 --- a/gnu/lib/libreadline/tilde.c +++ b/gnu/lib/libreadline/tilde.c @@ -19,8 +19,6 @@ along with Readline; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "memalloc.h" - #if defined (HAVE_STRING_H) # include #else /* !HAVE_STRING_H */ @@ -34,6 +32,7 @@ #endif /* HAVE_STDLIB_H */ #include "tilde.h" +#include #include #if defined (USG) && !defined (HAVE_GETPW_DECLS) diff --git a/gnu/lib/libreadline/vi_mode.c b/gnu/lib/libreadline/vi_mode.c index f8975f72ba2a..66d2d403e327 100644 --- a/gnu/lib/libreadline/vi_mode.c +++ b/gnu/lib/libreadline/vi_mode.c @@ -796,7 +796,7 @@ rl_vi_delete_to (count, key) /* These are the motion commands that do not require adjusting the mark. */ - if ((strchr (" l|h^0%bB", c) == 0) && (rl_mark < rl_end)) + if ((strchr (" l|h^0bB", c) == 0) && (rl_mark < rl_end)) rl_mark++; rl_kill_text (rl_point, rl_mark); @@ -824,7 +824,7 @@ rl_vi_change_to (count, key) /* These are the motion commands that do not require adjusting the mark. c[wW] are handled by special-case code in rl_vi_domove(), and already leave the mark at the correct location. */ - if ((strchr (" l|hwW^0%bB", c) == 0) && (rl_mark < rl_end)) + if ((strchr (" l|hwW^0bB", c) == 0) && (rl_mark < rl_end)) rl_mark++; /* The cursor never moves with c[wW]. */ @@ -905,7 +905,7 @@ rl_vi_comment (count, key) rl_insert_text (VI_COMMENT_BEGIN_DEFAULT); /* Default. */ rl_redisplay (); - rl_newline (1, '\010'); + rl_newline (1, '\n'); return (0); } @@ -1149,7 +1149,7 @@ rl_vi_subst (count, key) rl_kill_line (1); } else - rl_delete (count, key); + rl_delete_text (rl_point, rl_point+count); rl_end_undo_group (); @@ -1232,7 +1232,7 @@ rl_vi_replace (count, key) { vi_replace_map = rl_make_bare_keymap (); - for (i = ' '; i < 127; i++) + for (i = ' '; i < KEYMAP_SIZE; i++) vi_replace_map[i].function = rl_vi_overstrike; vi_replace_map[RUBOUT].function = rl_vi_overstrike_delete;