Upgrade to readline from bash 1.14.3

This commit is contained in:
Andrey A. Chernov 1994-12-12 03:23:04 +00:00
parent b01f0b7d76
commit f6f38b4bc9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=5073
13 changed files with 168 additions and 96 deletions

View File

@ -0,0 +1 @@
Readline from bash 1.14.3 + local fixes

View File

@ -21,6 +21,10 @@
675 Mass Ave, Cambridge, MA 02139, USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
@ -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;
}

View File

@ -21,6 +21,10 @@
675 Mass Ave, Cambridge, MA 02139, USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <stdio.h>
#include <sys/types.h>
@ -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 ();
}

View File

@ -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 <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
@ -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++)
{

View File

@ -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.

View File

@ -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 <stdlib.h>
#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;

View File

@ -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;
}
}

View File

@ -30,14 +30,14 @@
# include "config.h"
#endif
#if defined (HAVE_UNISTD_H)
# include <unistd.h> /* for _POSIX_VERSION */
#endif /* HAVE_UNISTD_H */
#if !defined (PRAGMA_ALLOCA)
# include "memalloc.h"
#endif
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#define NEW_TTY_DRIVER
#define HAVE_BSD_SIGNALS
/* #define USE_XON_XOFF */

View File

@ -27,6 +27,10 @@
#include <errno.h>
#include <stdio.h>
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#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 ();

View File

@ -29,7 +29,6 @@
# include <unistd.h>
#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);
{

View File

@ -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 */

View File

@ -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 <string.h>
#else /* !HAVE_STRING_H */
@ -34,6 +32,7 @@
#endif /* HAVE_STDLIB_H */
#include "tilde.h"
#include <sys/types.h>
#include <pwd.h>
#if defined (USG) && !defined (HAVE_GETPW_DECLS)

View File

@ -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;