mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-09 19:50:32 +02:00
commit bash-20090730 snapshot
This commit is contained in:
@@ -418,6 +418,13 @@ rl_generic_bind (type, keyseq, data, map)
|
||||
{
|
||||
map = FUNCTION_TO_KEYMAP (map, ic);
|
||||
ic = ANYOTHERKEY;
|
||||
/* If we're trying to override a keymap with a null function
|
||||
(e.g., trying to unbind it), we can't use a null pointer
|
||||
here because that's indistinguishable from having not been
|
||||
overridden. We use a special bindable function that does
|
||||
nothing. */
|
||||
if (type == ISFUNC && data == 0)
|
||||
data = (char *)_rl_null_function;
|
||||
}
|
||||
|
||||
map[ic].function = KEYMAP_TO_FUNCTION (data);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+10
-1
@@ -2330,7 +2330,7 @@ rl_menu_complete (count, ignore)
|
||||
|
||||
/* The first time through, we generate the list of matches and set things
|
||||
up to insert them. */
|
||||
if (rl_last_func != rl_menu_complete || full_completion)
|
||||
if ((rl_last_func != rl_menu_complete && rl_last_func != rl_backward_menu_complete) || full_completion)
|
||||
{
|
||||
/* Clean up from previous call, if any. */
|
||||
FREE (orig_text);
|
||||
@@ -2470,3 +2470,12 @@ rl_menu_complete (count, ignore)
|
||||
completion_changed_buffer = 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
rl_backward_menu_complete (count, key)
|
||||
int count, key;
|
||||
{
|
||||
/* Positive arguments to backward-menu-complete translate into negative
|
||||
arguments for menu-complete, and vice versa. */
|
||||
return (rl_menu_complete (-count, key));
|
||||
}
|
||||
|
||||
@@ -1319,7 +1319,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
||||
|
||||
if (tempwidth > 0)
|
||||
{
|
||||
int count;
|
||||
int count, i;
|
||||
bytes = ret;
|
||||
for (count = 0; count < bytes; count++)
|
||||
putc (new[count], rl_outstream);
|
||||
@@ -1330,10 +1330,13 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
||||
if (ret != 0 && bytes != 0)
|
||||
{
|
||||
if (MB_INVALIDCH (ret))
|
||||
memmove (old+bytes, old+1, strlen (old+1));
|
||||
else
|
||||
memmove (old+bytes, old+ret, strlen (old+ret));
|
||||
ret = 1;
|
||||
memmove (old+bytes, old+ret, strlen (old+ret));
|
||||
memcpy (old, new, bytes);
|
||||
/* Fix up indices if we copy data from one line to another */
|
||||
omax += bytes - ret;
|
||||
for (i = current_line+1; i < inv_botlin+1; i++)
|
||||
vis_lbreaks[i] += bytes - ret;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
+54
-22
@@ -960,6 +960,11 @@ rl_redisplay ()
|
||||
#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line)
|
||||
#define INV_LINE(line) (invisible_line + inv_lbreaks[line])
|
||||
|
||||
#define OLD_CPOS_IN_PROMPT() (cpos_adjusted == 0 && \
|
||||
_rl_last_c_pos != o_cpos && \
|
||||
_rl_last_c_pos > wrap_offset && \
|
||||
o_cpos < prompt_last_invisible)
|
||||
|
||||
/* For each line in the buffer, do the updating display. */
|
||||
for (linenum = 0; linenum <= inv_botlin; linenum++)
|
||||
{
|
||||
@@ -982,13 +987,7 @@ rl_redisplay ()
|
||||
time update_line is called, then we can assume in our
|
||||
calculations that o_cpos does not need to be adjusted by
|
||||
wrap_offset. */
|
||||
/* XXX - if this is changed, change the version down below in
|
||||
the horizontal scrolling section as well. */
|
||||
if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) &&
|
||||
cpos_adjusted == 0 &&
|
||||
_rl_last_c_pos != o_cpos &&
|
||||
_rl_last_c_pos > wrap_offset &&
|
||||
o_cpos < prompt_last_invisible)
|
||||
if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT())
|
||||
_rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */
|
||||
else if (linenum == prompt_last_screen_line && prompt_physical_chars > _rl_screenwidth &&
|
||||
(MB_CUR_MAX > 1 && rl_byte_oriented == 0) &&
|
||||
@@ -1205,14 +1204,8 @@ rl_redisplay ()
|
||||
_rl_screenwidth + (lmargin ? 0 : wrap_offset),
|
||||
0);
|
||||
|
||||
/* This should be identical to the code above in the non-horizontal
|
||||
scrolling section. */
|
||||
if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) &&
|
||||
cpos_adjusted == 0 &&
|
||||
_rl_last_c_pos != o_cpos &&
|
||||
_rl_last_c_pos > wrap_offset &&
|
||||
o_cpos < prompt_last_invisible)
|
||||
_rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */
|
||||
if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT())
|
||||
_rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */
|
||||
|
||||
/* If the visible new line is shorter than the old, but the number
|
||||
of invisible characters is greater, and we are at the end of
|
||||
@@ -1326,7 +1319,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
||||
|
||||
if (tempwidth > 0)
|
||||
{
|
||||
int count;
|
||||
int count, i;
|
||||
bytes = ret;
|
||||
for (count = 0; count < bytes; count++)
|
||||
putc (new[count], rl_outstream);
|
||||
@@ -1337,10 +1330,15 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
||||
if (ret != 0 && bytes != 0)
|
||||
{
|
||||
if (MB_INVALIDCH (ret))
|
||||
memmove (old+bytes, old+1, strlen (old+1));
|
||||
else
|
||||
memmove (old+bytes, old+ret, strlen (old+ret));
|
||||
ret = 1;
|
||||
memmove (old+bytes, old+ret, strlen (old+ret));
|
||||
memcpy (old, new, bytes);
|
||||
#if 0
|
||||
/* Fix up indices if we copy data from one line to another */
|
||||
omax += bytes - ret;
|
||||
for (i = current_line+1; i < inv_botlin+1; i++)
|
||||
vis_lbreaks[i] += bytes - ret;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1906,6 +1904,7 @@ _rl_move_cursor_relative (new, data)
|
||||
register int i;
|
||||
int woff; /* number of invisible chars on current line */
|
||||
int cpos, dpos; /* current and desired cursor positions */
|
||||
int adjust;
|
||||
|
||||
woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset);
|
||||
cpos = _rl_last_c_pos;
|
||||
@@ -1921,15 +1920,34 @@ _rl_move_cursor_relative (new, data)
|
||||
as long as we are past them and they are counted by _rl_col_width. */
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
dpos = _rl_col_width (data, 0, new);
|
||||
adjust = 1;
|
||||
/* Try to short-circuit common cases and eliminate a bunch of multibyte
|
||||
character function calls. */
|
||||
/* 1. prompt string */
|
||||
if (new == local_prompt_len && memcmp (data, local_prompt, new) == 0)
|
||||
{
|
||||
dpos = prompt_visible_length;
|
||||
cpos_adjusted = 1;
|
||||
adjust = 0;
|
||||
}
|
||||
/* 2. prompt_string + line contents */
|
||||
else if (new > local_prompt_len && local_prompt && memcmp (data, local_prompt, local_prompt_len) == 0)
|
||||
{
|
||||
dpos = prompt_visible_length + _rl_col_width (data, local_prompt_len, new);
|
||||
cpos_adjusted = 1;
|
||||
adjust = 0;
|
||||
}
|
||||
else
|
||||
dpos = _rl_col_width (data, 0, new);
|
||||
|
||||
/* Use NEW when comparing against the last invisible character in the
|
||||
prompt string, since they're both buffer indices and DPOS is a
|
||||
desired display position. */
|
||||
if ((new > prompt_last_invisible) || /* XXX - don't use woff here */
|
||||
if (adjust && ((new > prompt_last_invisible) || /* XXX - don't use woff here */
|
||||
(prompt_physical_chars >= _rl_screenwidth &&
|
||||
_rl_last_v_pos == prompt_last_screen_line &&
|
||||
wrap_offset >= woff && dpos >= woff &&
|
||||
new > (prompt_last_invisible-(_rl_screenwidth*_rl_last_v_pos)-wrap_offset)))
|
||||
new > (prompt_last_invisible-(_rl_screenwidth*_rl_last_v_pos)-wrap_offset))))
|
||||
/* XXX last comparison might need to be >= */
|
||||
{
|
||||
dpos -= woff;
|
||||
@@ -2593,6 +2611,20 @@ _rl_ttymsg ("_rl_col_width: called with MB_CUR_MAX == 1");
|
||||
point = 0;
|
||||
max = end;
|
||||
|
||||
/* Try to short-circuit common cases. The adjustment to remove wrap_offset
|
||||
is done by the caller. */
|
||||
/* 1. prompt string */
|
||||
if (start == 0 && end == local_prompt_len && memcmp (str, local_prompt, local_prompt_len) == 0)
|
||||
return (prompt_visible_length + wrap_offset);
|
||||
/* 2. prompt string + line contents */
|
||||
else if (start == 0 && end > local_prompt_len && local_prompt && memcmp (str, local_prompt, local_prompt_len) == 0)
|
||||
{
|
||||
tmp = prompt_visible_length + wrap_offset;
|
||||
/* XXX - try to call ourselves recursively with non-prompt portion */
|
||||
tmp += _rl_col_width (str, local_prompt_len, end);
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
while (point < start)
|
||||
{
|
||||
tmp = mbrlen (str + point, max, &ps);
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
.\" Case Western Reserve University
|
||||
.\" chet@ins.CWRU.Edu
|
||||
.\"
|
||||
.\" Last Change: Thu May 8 09:29:59 EDT 2008
|
||||
.\" Last Change: Thu Jul 30 09:22:50 EDT 2009
|
||||
.\"
|
||||
.TH READLINE 3 "2008 May 8" "GNU Readline 6.0"
|
||||
.TH READLINE 3 "2009 Jul 30" "GNU Readline 6.0"
|
||||
.\"
|
||||
.\" File Name macro. This used to be `.PN', for Path Name,
|
||||
.\" but Sun doesn't seem to like that very much.
|
||||
@@ -924,6 +924,11 @@ through the list.
|
||||
This command is intended to be bound to \fBTAB\fP, but is unbound
|
||||
by default.
|
||||
.TP
|
||||
.B menu\-complete-\backward
|
||||
Identical to \fBmenu\-complete\fP, but moves backward through the list
|
||||
of possible completions, as if \fBmenu\-complete\fP had been given a
|
||||
negative argument. This command is unbound by default.
|
||||
.TP
|
||||
.B delete\-char\-or\-list
|
||||
Deletes the character under the cursor if not at the beginning or
|
||||
end of the line (like \fBdelete-char\fP).
|
||||
|
||||
@@ -622,7 +622,7 @@ Readline which keymap to use.
|
||||
@deftypefun Keymap rl_make_bare_keymap (void)
|
||||
Returns a new, empty keymap. The space for the keymap is allocated with
|
||||
@code{malloc()}; the caller should free it by calling
|
||||
@code{rl_discard_keymap()} when done.
|
||||
@code{rl_free_keymap()} when done.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun Keymap rl_copy_keymap (Keymap map)
|
||||
@@ -636,7 +636,13 @@ the Meta digits bound to produce numeric arguments.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void rl_discard_keymap (Keymap keymap)
|
||||
Free the storage associated with @var{keymap}.
|
||||
Free the storage associated with the data in @var{keymap}.
|
||||
The caller should free @var{keymap}.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void rl_free_keymap (Keymap keymap)
|
||||
Free all storage associated with @var{keymap}. This calls
|
||||
@code{rl_discard_keymap} to free subordindate keymaps and macros.
|
||||
@end deftypefun
|
||||
|
||||
Readline has several internal keymaps. These functions allow you to
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1292,6 +1292,11 @@ through the list.
|
||||
This command is intended to be bound to @key{TAB}, but is unbound
|
||||
by default.
|
||||
|
||||
@item menu-complete-backward ()
|
||||
Identical to @code{menu-complete}, but moves backward through the list
|
||||
of possible completions, as if @code{menu-complete} had been given a
|
||||
negative argument.
|
||||
|
||||
@item delete-char-or-list ()
|
||||
Deletes the character under the cursor if not at the beginning or
|
||||
end of the line (like @code{delete-char}).
|
||||
|
||||
@@ -4,7 +4,7 @@ Copyright (C) 1988-2009 Free Software Foundation, Inc.
|
||||
|
||||
@set EDITION 6.0
|
||||
@set VERSION 6.0
|
||||
@set UPDATED 28 October 2008
|
||||
@set UPDATED-MONTH October 2008
|
||||
@set UPDATED 31 July 2009
|
||||
@set UPDATED-MONTH July 2009
|
||||
|
||||
@set LASTCHANGE Tue Oct 28 11:25:24 EDT 2008
|
||||
@set LASTCHANGE Fri Jul 31 20:18:23 EDT 2009
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
@ignore
|
||||
Copyright (C) 1988-2009 Free Software Foundation, Inc.
|
||||
@end ignore
|
||||
|
||||
@set EDITION 6.0
|
||||
@set VERSION 6.0
|
||||
@set UPDATED 30 July 2009
|
||||
@set UPDATED-MONTH July 2009
|
||||
|
||||
@set LASTCHANGE Thu Jul 30 09:23:36 EDT 2009
|
||||
@@ -105,6 +105,7 @@ static const FUNMAP default_funmap[] = {
|
||||
{ "kill-region", rl_kill_region },
|
||||
{ "kill-word", rl_kill_word },
|
||||
{ "menu-complete", rl_menu_complete },
|
||||
{ "menu-complete-backward", rl_backward_menu_complete },
|
||||
{ "next-history", rl_get_next_history },
|
||||
{ "non-incremental-forward-search-history", rl_noninc_forward_search },
|
||||
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search },
|
||||
|
||||
+15
-3
@@ -57,8 +57,9 @@ Keymap
|
||||
rl_make_bare_keymap ()
|
||||
{
|
||||
register int i;
|
||||
Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
|
||||
Keymap keymap;
|
||||
|
||||
keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
|
||||
for (i = 0; i < KEYMAP_SIZE; i++)
|
||||
{
|
||||
keymap[i].type = ISFUNC;
|
||||
@@ -76,7 +77,8 @@ rl_make_bare_keymap ()
|
||||
return (keymap);
|
||||
}
|
||||
|
||||
/* Return a new keymap which is a copy of MAP. */
|
||||
/* Return a new keymap which is a copy of MAP. Just copies pointers, does
|
||||
not copy text of macros or descend into child keymaps. */
|
||||
Keymap
|
||||
rl_copy_keymap (map)
|
||||
Keymap map;
|
||||
@@ -128,7 +130,7 @@ rl_discard_keymap (map)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!map)
|
||||
if (map == 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < KEYMAP_SIZE; i++)
|
||||
@@ -140,6 +142,7 @@ rl_discard_keymap (map)
|
||||
|
||||
case ISKMAP:
|
||||
rl_discard_keymap ((Keymap)map[i].function);
|
||||
free ((char *)map[i].function);
|
||||
break;
|
||||
|
||||
case ISMACR:
|
||||
@@ -148,3 +151,12 @@ rl_discard_keymap (map)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Convenience function that discards, then frees, MAP. */
|
||||
void
|
||||
rl_free_keymap (map)
|
||||
Keymap map;
|
||||
{
|
||||
rl_discard_keymap (map);
|
||||
free ((char *)map);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/* keymaps.c -- Functions and keymaps for the GNU Readline library. */
|
||||
|
||||
/* Copyright (C) 1988,1989-2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library
|
||||
for reading lines of text with interactive input and history editing.
|
||||
|
||||
Readline is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Readline is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Readline. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define READLINE_LIBRARY
|
||||
|
||||
#if defined (HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
# include "ansi_stdlib.h"
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <stdio.h> /* for FILE * definition for readline.h */
|
||||
|
||||
#include "readline.h"
|
||||
#include "rlconf.h"
|
||||
|
||||
#include "emacs_keymap.c"
|
||||
|
||||
#if defined (VI_MODE)
|
||||
#include "vi_keymap.c"
|
||||
#endif
|
||||
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Functions for manipulating Keymaps. */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
|
||||
/* Return a new, empty keymap.
|
||||
Free it with free() when you are done. */
|
||||
Keymap
|
||||
rl_make_bare_keymap ()
|
||||
{
|
||||
register int i;
|
||||
Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
|
||||
|
||||
for (i = 0; i < KEYMAP_SIZE; i++)
|
||||
{
|
||||
keymap[i].type = ISFUNC;
|
||||
keymap[i].function = (rl_command_func_t *)NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (i = 'A'; i < ('Z' + 1); i++)
|
||||
{
|
||||
keymap[i].type = ISFUNC;
|
||||
keymap[i].function = rl_do_lowercase_version;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (keymap);
|
||||
}
|
||||
|
||||
/* Return a new keymap which is a copy of MAP. */
|
||||
Keymap
|
||||
rl_copy_keymap (map)
|
||||
Keymap map;
|
||||
{
|
||||
register int i;
|
||||
Keymap temp;
|
||||
|
||||
temp = rl_make_bare_keymap ();
|
||||
for (i = 0; i < KEYMAP_SIZE; i++)
|
||||
{
|
||||
temp[i].type = map[i].type;
|
||||
temp[i].function = map[i].function;
|
||||
}
|
||||
return (temp);
|
||||
}
|
||||
|
||||
/* Return a new keymap with the printing characters bound to rl_insert,
|
||||
the uppercase Meta characters bound to run their lowercase equivalents,
|
||||
and the Meta digits bound to produce numeric arguments. */
|
||||
Keymap
|
||||
rl_make_keymap ()
|
||||
{
|
||||
register int i;
|
||||
Keymap newmap;
|
||||
|
||||
newmap = rl_make_bare_keymap ();
|
||||
|
||||
/* All ASCII printing characters are self-inserting. */
|
||||
for (i = ' '; i < 127; i++)
|
||||
newmap[i].function = rl_insert;
|
||||
|
||||
newmap[TAB].function = rl_insert;
|
||||
newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */
|
||||
newmap[CTRL('H')].function = rl_rubout;
|
||||
|
||||
#if KEYMAP_SIZE > 128
|
||||
/* Printing characters in ISO Latin-1 and some 8-bit character sets. */
|
||||
for (i = 128; i < 256; i++)
|
||||
newmap[i].function = rl_insert;
|
||||
#endif /* KEYMAP_SIZE > 128 */
|
||||
|
||||
return (newmap);
|
||||
}
|
||||
|
||||
/* Free the storage associated with MAP. */
|
||||
void
|
||||
rl_discard_keymap (map)
|
||||
Keymap map;
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
for (i = 0; i < KEYMAP_SIZE; i++)
|
||||
{
|
||||
switch (map[i].type)
|
||||
{
|
||||
case ISFUNC:
|
||||
break;
|
||||
|
||||
case ISKMAP:
|
||||
rl_discard_keymap ((Keymap)map[i].function);
|
||||
break;
|
||||
|
||||
case ISMACR:
|
||||
free ((char *)map[i].function);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1169,6 +1169,10 @@ bind_arrow_keys ()
|
||||
|
||||
#if defined (VI_MODE)
|
||||
bind_arrow_keys_internal (vi_movement_keymap);
|
||||
/* Unbind vi_movement_keymap[ESC] to allow users to repeatedly hit ESC
|
||||
in vi command mode while still allowing the arrow keys to work. */
|
||||
if (vi_movement_keymap[ESC].type == ISKMAP)
|
||||
rl_bind_keyseq_in_map ("\033", (rl_command_func_t *)NULL, vi_movement_keymap);
|
||||
bind_arrow_keys_internal (vi_insertion_keymap);
|
||||
#endif
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -151,6 +151,7 @@ extern int rl_complete PARAMS((int, int));
|
||||
extern int rl_possible_completions PARAMS((int, int));
|
||||
extern int rl_insert_completions PARAMS((int, int));
|
||||
extern int rl_menu_complete PARAMS((int, int));
|
||||
extern int rl_backward_menu_complete PARAMS((int, int));
|
||||
|
||||
/* Bindable commands for killing and yanking text, and managing the kill ring. */
|
||||
extern int rl_kill_word PARAMS((int, int));
|
||||
|
||||
@@ -349,6 +349,7 @@ extern void _rl_trace ();
|
||||
extern int _rl_tropen PARAMS((void));
|
||||
|
||||
extern int _rl_abort_internal PARAMS((void));
|
||||
extern int _rl_null_function PARAMS((int, int));
|
||||
extern char *_rl_strindex PARAMS((const char *, const char *));
|
||||
extern int _rl_qsort_string_compare PARAMS((char **, char **));
|
||||
extern int (_rl_uppercase_p) PARAMS((int));
|
||||
|
||||
@@ -300,6 +300,8 @@ extern void _rl_signal_handler PARAMS((int));
|
||||
|
||||
extern void _rl_block_sigint PARAMS((void));
|
||||
extern void _rl_release_sigint PARAMS((void));
|
||||
extern void _rl_block_sigwinch PARAMS((void));
|
||||
extern void _rl_release_sigwinch PARAMS((void));
|
||||
|
||||
/* terminal.c */
|
||||
extern void _rl_get_screen_size PARAMS((int, int));
|
||||
|
||||
@@ -120,6 +120,13 @@ rl_abort (count, key)
|
||||
return (_rl_abort_internal ());
|
||||
}
|
||||
|
||||
int
|
||||
_rl_null_function (count, key)
|
||||
int count, key;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rl_tty_status (count, key)
|
||||
int count, key;
|
||||
|
||||
@@ -0,0 +1,512 @@
|
||||
/* util.c -- readline utility functions */
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library
|
||||
for reading lines of text with interactive input and history editing.
|
||||
|
||||
Readline is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Readline is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Readline. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define READLINE_LIBRARY
|
||||
|
||||
#if defined (HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include "posixjmp.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h> /* for _POSIX_VERSION */
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#if defined (HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
# include "ansi_stdlib.h"
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* System-specific feature definitions and include files. */
|
||||
#include "rldefs.h"
|
||||
#include "rlmbutil.h"
|
||||
|
||||
#if defined (TIOCSTAT_IN_SYS_IOCTL)
|
||||
# include <sys/ioctl.h>
|
||||
#endif /* TIOCSTAT_IN_SYS_IOCTL */
|
||||
|
||||
/* Some standard library routines. */
|
||||
#include "readline.h"
|
||||
|
||||
#include "rlprivate.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Utility Functions */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Return 0 if C is not a member of the class of characters that belong
|
||||
in words, or 1 if it is. */
|
||||
|
||||
int _rl_allow_pathname_alphabetic_chars = 0;
|
||||
static const char * const pathname_alphabetic_chars = "/-_=~.#$";
|
||||
|
||||
int
|
||||
rl_alphabetic (c)
|
||||
int c;
|
||||
{
|
||||
if (ALPHABETIC (c))
|
||||
return (1);
|
||||
|
||||
return (_rl_allow_pathname_alphabetic_chars &&
|
||||
strchr (pathname_alphabetic_chars, c) != NULL);
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
int
|
||||
_rl_walphabetic (wc)
|
||||
wchar_t wc;
|
||||
{
|
||||
int c;
|
||||
|
||||
if (iswalnum (wc))
|
||||
return (1);
|
||||
|
||||
c = wc & 0177;
|
||||
return (_rl_allow_pathname_alphabetic_chars &&
|
||||
strchr (pathname_alphabetic_chars, c) != NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* How to abort things. */
|
||||
int
|
||||
_rl_abort_internal ()
|
||||
{
|
||||
rl_ding ();
|
||||
rl_clear_message ();
|
||||
_rl_reset_argument ();
|
||||
rl_clear_pending_input ();
|
||||
|
||||
RL_UNSETSTATE (RL_STATE_MACRODEF);
|
||||
while (rl_executing_macro)
|
||||
_rl_pop_executing_macro ();
|
||||
|
||||
rl_last_func = (rl_command_func_t *)NULL;
|
||||
longjmp (_rl_top_level, 1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
rl_abort (count, key)
|
||||
int count, key;
|
||||
{
|
||||
return (_rl_abort_internal ());
|
||||
}
|
||||
|
||||
int
|
||||
_rl_null_func (count, key)
|
||||
int count, key;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rl_tty_status (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (TIOCSTAT)
|
||||
ioctl (1, TIOCSTAT, (char *)0);
|
||||
rl_refresh_line (count, key);
|
||||
#else
|
||||
rl_ding ();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return a copy of the string between FROM and TO.
|
||||
FROM is inclusive, TO is not. */
|
||||
char *
|
||||
rl_copy_text (from, to)
|
||||
int from, to;
|
||||
{
|
||||
register int length;
|
||||
char *copy;
|
||||
|
||||
/* Fix it if the caller is confused. */
|
||||
if (from > to)
|
||||
SWAP (from, to);
|
||||
|
||||
length = to - from;
|
||||
copy = (char *)xmalloc (1 + length);
|
||||
strncpy (copy, rl_line_buffer + from, length);
|
||||
copy[length] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
||||
/* Increase the size of RL_LINE_BUFFER until it has enough space to hold
|
||||
LEN characters. */
|
||||
void
|
||||
rl_extend_line_buffer (len)
|
||||
int len;
|
||||
{
|
||||
while (len >= rl_line_buffer_len)
|
||||
{
|
||||
rl_line_buffer_len += DEFAULT_BUFFER_SIZE;
|
||||
rl_line_buffer = (char *)xrealloc (rl_line_buffer, rl_line_buffer_len);
|
||||
}
|
||||
|
||||
_rl_set_the_line ();
|
||||
}
|
||||
|
||||
|
||||
/* A function for simple tilde expansion. */
|
||||
int
|
||||
rl_tilde_expand (ignore, key)
|
||||
int ignore, key;
|
||||
{
|
||||
register int start, end;
|
||||
char *homedir, *temp;
|
||||
int len;
|
||||
|
||||
end = rl_point;
|
||||
start = end - 1;
|
||||
|
||||
if (rl_point == rl_end && rl_line_buffer[rl_point] == '~')
|
||||
{
|
||||
homedir = tilde_expand ("~");
|
||||
_rl_replace_text (homedir, start, end);
|
||||
xfree (homedir);
|
||||
return (0);
|
||||
}
|
||||
else if (rl_line_buffer[start] != '~')
|
||||
{
|
||||
for (; !whitespace (rl_line_buffer[start]) && start >= 0; start--)
|
||||
;
|
||||
start++;
|
||||
}
|
||||
|
||||
end = start;
|
||||
do
|
||||
end++;
|
||||
while (whitespace (rl_line_buffer[end]) == 0 && end < rl_end);
|
||||
|
||||
if (whitespace (rl_line_buffer[end]) || end >= rl_end)
|
||||
end--;
|
||||
|
||||
/* If the first character of the current word is a tilde, perform
|
||||
tilde expansion and insert the result. If not a tilde, do
|
||||
nothing. */
|
||||
if (rl_line_buffer[start] == '~')
|
||||
{
|
||||
len = end - start + 1;
|
||||
temp = (char *)xmalloc (len + 1);
|
||||
strncpy (temp, rl_line_buffer + start, len);
|
||||
temp[len] = '\0';
|
||||
homedir = tilde_expand (temp);
|
||||
xfree (temp);
|
||||
|
||||
_rl_replace_text (homedir, start, end);
|
||||
xfree (homedir);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined (USE_VARARGS)
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
_rl_ttymsg (const char *format, ...)
|
||||
#else
|
||||
_rl_ttymsg (va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#if defined (PREFER_VARARGS)
|
||||
char *format;
|
||||
#endif
|
||||
|
||||
#if defined (PREFER_STDARG)
|
||||
va_start (args, format);
|
||||
#else
|
||||
va_start (args);
|
||||
format = va_arg (args, char *);
|
||||
#endif
|
||||
|
||||
fprintf (stderr, "readline: ");
|
||||
vfprintf (stderr, format, args);
|
||||
fprintf (stderr, "\n");
|
||||
fflush (stderr);
|
||||
|
||||
va_end (args);
|
||||
|
||||
rl_forced_update_display ();
|
||||
}
|
||||
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
_rl_errmsg (const char *format, ...)
|
||||
#else
|
||||
_rl_errmsg (va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#if defined (PREFER_VARARGS)
|
||||
char *format;
|
||||
#endif
|
||||
|
||||
#if defined (PREFER_STDARG)
|
||||
va_start (args, format);
|
||||
#else
|
||||
va_start (args);
|
||||
format = va_arg (args, char *);
|
||||
#endif
|
||||
|
||||
fprintf (stderr, "readline: ");
|
||||
vfprintf (stderr, format, args);
|
||||
fprintf (stderr, "\n");
|
||||
fflush (stderr);
|
||||
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
#else /* !USE_VARARGS */
|
||||
void
|
||||
_rl_ttymsg (format, arg1, arg2)
|
||||
char *format;
|
||||
{
|
||||
fprintf (stderr, "readline: ");
|
||||
fprintf (stderr, format, arg1, arg2);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
rl_forced_update_display ();
|
||||
}
|
||||
|
||||
void
|
||||
_rl_errmsg (format, arg1, arg2)
|
||||
char *format;
|
||||
{
|
||||
fprintf (stderr, "readline: ");
|
||||
fprintf (stderr, format, arg1, arg2);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
#endif /* !USE_VARARGS */
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* String Utility Functions */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Determine if s2 occurs in s1. If so, return a pointer to the
|
||||
match in s1. The compare is case insensitive. */
|
||||
char *
|
||||
_rl_strindex (s1, s2)
|
||||
register const char *s1, *s2;
|
||||
{
|
||||
register int i, l, len;
|
||||
|
||||
for (i = 0, l = strlen (s2), len = strlen (s1); (len - i) >= l; i++)
|
||||
if (_rl_strnicmp (s1 + i, s2, l) == 0)
|
||||
return ((char *) (s1 + i));
|
||||
return ((char *)NULL);
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRPBRK
|
||||
/* Find the first occurrence in STRING1 of any character from STRING2.
|
||||
Return a pointer to the character in STRING1. */
|
||||
char *
|
||||
_rl_strpbrk (string1, string2)
|
||||
const char *string1, *string2;
|
||||
{
|
||||
register const char *scan;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
mbstate_t ps;
|
||||
register int i, v;
|
||||
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
#endif
|
||||
|
||||
for (; *string1; string1++)
|
||||
{
|
||||
for (scan = string2; *scan; scan++)
|
||||
{
|
||||
if (*string1 == *scan)
|
||||
return ((char *)string1);
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
v = _rl_get_char_len (string1, &ps);
|
||||
if (v > 1)
|
||||
string1 += v - 1; /* -1 to account for auto-increment in loop */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ((char *)NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_STRCASECMP)
|
||||
/* Compare at most COUNT characters from string1 to string2. Case
|
||||
doesn't matter. */
|
||||
int
|
||||
_rl_strnicmp (string1, string2, count)
|
||||
char *string1, *string2;
|
||||
int count;
|
||||
{
|
||||
register char ch1, ch2;
|
||||
|
||||
while (count)
|
||||
{
|
||||
ch1 = *string1++;
|
||||
ch2 = *string2++;
|
||||
if (_rl_to_upper(ch1) == _rl_to_upper(ch2))
|
||||
count--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
/* strcmp (), but caseless. */
|
||||
int
|
||||
_rl_stricmp (string1, string2)
|
||||
char *string1, *string2;
|
||||
{
|
||||
register char ch1, ch2;
|
||||
|
||||
while (*string1 && *string2)
|
||||
{
|
||||
ch1 = *string1++;
|
||||
ch2 = *string2++;
|
||||
if (_rl_to_upper(ch1) != _rl_to_upper(ch2))
|
||||
return (1);
|
||||
}
|
||||
return (*string1 - *string2);
|
||||
}
|
||||
#endif /* !HAVE_STRCASECMP */
|
||||
|
||||
/* Stupid comparison routine for qsort () ing strings. */
|
||||
int
|
||||
_rl_qsort_string_compare (s1, s2)
|
||||
char **s1, **s2;
|
||||
{
|
||||
#if defined (HAVE_STRCOLL)
|
||||
return (strcoll (*s1, *s2));
|
||||
#else
|
||||
int result;
|
||||
|
||||
result = **s1 - **s2;
|
||||
if (result == 0)
|
||||
result = strcmp (*s1, *s2);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Function equivalents for the macros defined in chardefs.h. */
|
||||
#define FUNCTION_FOR_MACRO(f) int (f) (c) int c; { return f (c); }
|
||||
|
||||
FUNCTION_FOR_MACRO (_rl_digit_p)
|
||||
FUNCTION_FOR_MACRO (_rl_digit_value)
|
||||
FUNCTION_FOR_MACRO (_rl_lowercase_p)
|
||||
FUNCTION_FOR_MACRO (_rl_pure_alphabetic)
|
||||
FUNCTION_FOR_MACRO (_rl_to_lower)
|
||||
FUNCTION_FOR_MACRO (_rl_to_upper)
|
||||
FUNCTION_FOR_MACRO (_rl_uppercase_p)
|
||||
|
||||
/* A convenience function, to force memory deallocation to be performed
|
||||
by readline. DLLs on Windows apparently require this. */
|
||||
void
|
||||
rl_free (mem)
|
||||
void *mem;
|
||||
{
|
||||
if (mem)
|
||||
free (mem);
|
||||
}
|
||||
|
||||
/* Backwards compatibility, now that savestring has been removed from
|
||||
all `public' readline header files. */
|
||||
#undef _rl_savestring
|
||||
char *
|
||||
_rl_savestring (s)
|
||||
const char *s;
|
||||
{
|
||||
return (strcpy ((char *)xmalloc (1 + (int)strlen (s)), (s)));
|
||||
}
|
||||
|
||||
#if defined (USE_VARARGS)
|
||||
static FILE *_rl_tracefp;
|
||||
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
_rl_trace (const char *format, ...)
|
||||
#else
|
||||
_rl_trace (va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
#if defined (PREFER_VARARGS)
|
||||
char *format;
|
||||
#endif
|
||||
|
||||
#if defined (PREFER_STDARG)
|
||||
va_start (args, format);
|
||||
#else
|
||||
va_start (args);
|
||||
format = va_arg (args, char *);
|
||||
#endif
|
||||
|
||||
if (_rl_tracefp == 0)
|
||||
_rl_tropen ();
|
||||
vfprintf (_rl_tracefp, format, args);
|
||||
fprintf (_rl_tracefp, "\n");
|
||||
fflush (_rl_tracefp);
|
||||
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
int
|
||||
_rl_tropen ()
|
||||
{
|
||||
char fnbuf[128];
|
||||
|
||||
if (_rl_tracefp)
|
||||
fclose (_rl_tracefp);
|
||||
sprintf (fnbuf, "/var/tmp/rltrace.%ld", getpid());
|
||||
unlink(fnbuf);
|
||||
_rl_tracefp = fopen (fnbuf, "w+");
|
||||
return _rl_tracefp != 0;
|
||||
}
|
||||
|
||||
int
|
||||
_rl_trclose ()
|
||||
{
|
||||
int r;
|
||||
|
||||
r = fclose (_rl_tracefp);
|
||||
_rl_tracefp = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -326,9 +326,9 @@ KEYMAP_ENTRY_ARRAY vi_insertion_keymap = {
|
||||
{ ISFUNC, rl_insert }, /* Control-k */
|
||||
{ ISFUNC, rl_insert }, /* Control-l */
|
||||
{ ISFUNC, rl_newline }, /* Control-m */
|
||||
{ ISFUNC, rl_insert }, /* Control-n */
|
||||
{ ISFUNC, rl_menu_complete}, /* Control-n */
|
||||
{ ISFUNC, rl_insert }, /* Control-o */
|
||||
{ ISFUNC, rl_insert }, /* Control-p */
|
||||
{ ISFUNC, rl_backward_menu_complete }, /* Control-p */
|
||||
{ ISFUNC, rl_insert }, /* Control-q */
|
||||
{ ISFUNC, rl_reverse_search_history }, /* Control-r */
|
||||
{ ISFUNC, rl_forward_search_history }, /* Control-s */
|
||||
|
||||
Reference in New Issue
Block a user