version 1.1.1.2, 2016/11/03 13:35:37
|
version 1.1.1.3, 2021/03/17 01:01:01
|
Line 1
|
Line 1
|
/* readline.c -- a general facility for reading lines of input |
/* readline.c -- a general facility for reading lines of input |
with emacs style editing and completion. */ |
with emacs style editing and completion. */ |
|
|
/* Copyright (C) 1987-2013 Free Software Foundation, Inc. | /* Copyright (C) 1987-2020 Free Software Foundation, Inc. |
|
|
This file is part of the GNU Readline Library (Readline), a library |
This file is part of the GNU Readline Library (Readline), a library |
for reading lines of text with interactive input and history editing. |
for reading lines of text with interactive input and history editing. |
Line 73 extern int errno;
|
Line 73 extern int errno;
|
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
#ifndef RL_LIBRARY_VERSION |
#ifndef RL_LIBRARY_VERSION |
# define RL_LIBRARY_VERSION "5.1" | # define RL_LIBRARY_VERSION "8.0" |
#endif |
#endif |
|
|
#ifndef RL_READLINE_VERSION |
#ifndef RL_READLINE_VERSION |
# define RL_READLINE_VERSION 0x0501 | # define RL_READLINE_VERSION 0x0800 |
#endif |
#endif |
|
|
extern void _rl_free_history_entry PARAMS((HIST_ENTRY *)); |
extern void _rl_free_history_entry PARAMS((HIST_ENTRY *)); |
Line 94 static void readline_initialize_everything PARAMS((voi
|
Line 94 static void readline_initialize_everything PARAMS((voi
|
static void bind_arrow_keys_internal PARAMS((Keymap)); |
static void bind_arrow_keys_internal PARAMS((Keymap)); |
static void bind_arrow_keys PARAMS((void)); |
static void bind_arrow_keys PARAMS((void)); |
|
|
|
static void bind_bracketed_paste_prefix PARAMS((void)); |
|
|
static void readline_default_bindings PARAMS((void)); |
static void readline_default_bindings PARAMS((void)); |
static void reset_default_bindings PARAMS((void)); |
static void reset_default_bindings PARAMS((void)); |
|
|
Line 149 static int running_in_emacs;
|
Line 151 static int running_in_emacs;
|
#endif |
#endif |
|
|
/* Flags word encapsulating the current readline state. */ |
/* Flags word encapsulating the current readline state. */ |
int rl_readline_state = RL_STATE_NONE; | unsigned long rl_readline_state = RL_STATE_NONE; |
|
|
/* The current offset in the current input line. */ |
/* The current offset in the current input line. */ |
int rl_point; |
int rl_point; |
Line 197 int rl_key_sequence_length = 0;
|
Line 199 int rl_key_sequence_length = 0;
|
before readline_internal_setup () prints the first prompt. */ |
before readline_internal_setup () prints the first prompt. */ |
rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL; |
rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL; |
|
|
|
/* Any readline function can set this and have it run just before the user's |
|
rl_startup_hook. */ |
|
rl_hook_func_t *_rl_internal_startup_hook = (rl_hook_func_t *)NULL; |
|
|
/* If non-zero, this is the address of a function to call just before |
/* If non-zero, this is the address of a function to call just before |
readline_internal_setup () returns and readline_internal starts |
readline_internal_setup () returns and readline_internal starts |
reading input characters. */ |
reading input characters. */ |
Line 212 int _rl_eof_char = CTRL ('D');
|
Line 218 int _rl_eof_char = CTRL ('D');
|
/* Non-zero makes this the next keystroke to read. */ |
/* Non-zero makes this the next keystroke to read. */ |
int rl_pending_input = 0; |
int rl_pending_input = 0; |
|
|
|
/* If non-zero when readline_internal returns, it means we found EOF */ |
|
int _rl_eof_found = 0; |
|
|
/* Pointer to a useful terminal name. */ |
/* Pointer to a useful terminal name. */ |
const char *rl_terminal_name = (const char *)NULL; |
const char *rl_terminal_name = (const char *)NULL; |
|
|
Line 220 int _rl_horizontal_scroll_mode = 0;
|
Line 229 int _rl_horizontal_scroll_mode = 0;
|
|
|
/* Non-zero means to display an asterisk at the starts of history lines |
/* Non-zero means to display an asterisk at the starts of history lines |
which have been modified. */ |
which have been modified. */ |
int _rl_mark_modified_lines = 0; | int _rl_mark_modified_lines = 0; |
|
|
/* The style of `bell' notification preferred. This can be set to NO_BELL, |
/* The style of `bell' notification preferred. This can be set to NO_BELL, |
AUDIBLE_BELL, or VISIBLE_BELL. */ |
AUDIBLE_BELL, or VISIBLE_BELL. */ |
Line 240 int rl_erase_empty_line = 0;
|
Line 249 int rl_erase_empty_line = 0;
|
|
|
/* Non-zero means to read only this many characters rather than up to a |
/* Non-zero means to read only this many characters rather than up to a |
character bound to accept-line. */ |
character bound to accept-line. */ |
int rl_num_chars_to_read; | int rl_num_chars_to_read = 0; |
|
|
/* Line buffer and maintenance. */ |
/* Line buffer and maintenance. */ |
char *rl_line_buffer = (char *)NULL; |
char *rl_line_buffer = (char *)NULL; |
Line 253 int rl_executing_key;
|
Line 262 int rl_executing_key;
|
char *rl_executing_keyseq = 0; |
char *rl_executing_keyseq = 0; |
int _rl_executing_keyseq_size = 0; |
int _rl_executing_keyseq_size = 0; |
|
|
|
struct _rl_cmd _rl_pending_command; |
|
struct _rl_cmd *_rl_command_to_execute = (struct _rl_cmd *)NULL; |
|
|
/* Timeout (specified in milliseconds) when reading characters making up an |
/* Timeout (specified in milliseconds) when reading characters making up an |
ambiguous multiple-key sequence */ |
ambiguous multiple-key sequence */ |
int _rl_keyseq_timeout = 500; |
int _rl_keyseq_timeout = 500; |
Line 306 int _rl_echo_control_chars = 1;
|
Line 318 int _rl_echo_control_chars = 1;
|
the editing mode: @ for emacs, : for vi-command, + for vi-insert. */ |
the editing mode: @ for emacs, : for vi-command, + for vi-insert. */ |
int _rl_show_mode_in_prompt = 0; |
int _rl_show_mode_in_prompt = 0; |
|
|
|
/* Non-zero means to attempt to put the terminal in `bracketed paste mode', |
|
where it will prefix pasted text with an escape sequence and send |
|
another to mark the end of the paste. */ |
|
int _rl_enable_bracketed_paste = BRACKETED_PASTE_DEFAULT; |
|
int _rl_enable_active_region = BRACKETED_PASTE_DEFAULT; |
|
|
/* **************************************************************** */ |
/* **************************************************************** */ |
/* */ |
/* */ |
/* Top Level Functions */ |
/* Top Level Functions */ |
Line 318 int _rl_meta_flag = 0; /* Forward declaration */
|
Line 336 int _rl_meta_flag = 0; /* Forward declaration */
|
/* Set up the prompt and expand it. Called from readline() and |
/* Set up the prompt and expand it. Called from readline() and |
rl_callback_handler_install (). */ |
rl_callback_handler_install (). */ |
int |
int |
rl_set_prompt (prompt) | rl_set_prompt (const char *prompt) |
const char *prompt; | |
{ |
{ |
FREE (rl_prompt); |
FREE (rl_prompt); |
rl_prompt = prompt ? savestring (prompt) : (char *)NULL; |
rl_prompt = prompt ? savestring (prompt) : (char *)NULL; |
Line 332 rl_set_prompt (prompt)
|
Line 349 rl_set_prompt (prompt)
|
/* Read a line of input. Prompt with PROMPT. An empty PROMPT means |
/* Read a line of input. Prompt with PROMPT. An empty PROMPT means |
none. A return value of NULL means that EOF was encountered. */ |
none. A return value of NULL means that EOF was encountered. */ |
char * |
char * |
readline (prompt) | readline (const char *prompt) |
const char *prompt; | |
{ |
{ |
char *value; |
char *value; |
#if 0 |
#if 0 |
Line 379 readline (prompt)
|
Line 395 readline (prompt)
|
RL_SETSTATE (RL_STATE_CALLBACK); |
RL_SETSTATE (RL_STATE_CALLBACK); |
#endif |
#endif |
|
|
#if HAVE_DECL_AUDIT_TTY && defined (ENABLE_TTY_AUDIT_SUPPORT) | #if HAVE_DECL_AUDIT_USER_TTY && defined (HAVE_LIBAUDIT_H) && defined (ENABLE_TTY_AUDIT_SUPPORT) |
if (value) |
if (value) |
_rl_audit_tty (value); |
_rl_audit_tty (value); |
#endif |
#endif |
Line 394 readline (prompt)
|
Line 410 readline (prompt)
|
#endif |
#endif |
|
|
STATIC_CALLBACK void |
STATIC_CALLBACK void |
readline_internal_setup () | readline_internal_setup (void) |
{ |
{ |
char *nprompt; |
char *nprompt; |
|
|
Line 409 readline_internal_setup ()
|
Line 425 readline_internal_setup ()
|
if (rl_startup_hook) |
if (rl_startup_hook) |
(*rl_startup_hook) (); |
(*rl_startup_hook) (); |
|
|
|
if (_rl_internal_startup_hook) |
|
(*_rl_internal_startup_hook) (); |
|
|
|
rl_deactivate_mark (); |
|
|
#if defined (VI_MODE) |
#if defined (VI_MODE) |
if (rl_editing_mode == vi_mode) |
if (rl_editing_mode == vi_mode) |
rl_vi_insertion_mode (1, 'i'); /* don't want to reset last */ |
rl_vi_insertion_mode (1, 'i'); /* don't want to reset last */ |
|
else |
#endif /* VI_MODE */ |
#endif /* VI_MODE */ |
|
if (_rl_show_mode_in_prompt) |
|
_rl_reset_prompt (); |
|
|
/* If we're not echoing, we still want to at least print a prompt, because |
/* If we're not echoing, we still want to at least print a prompt, because |
rl_redisplay will not do it for us. If the calling application has a |
rl_redisplay will not do it for us. If the calling application has a |
Line 443 readline_internal_setup ()
|
Line 467 readline_internal_setup ()
|
} |
} |
|
|
STATIC_CALLBACK char * |
STATIC_CALLBACK char * |
readline_internal_teardown (eof) | readline_internal_teardown (int eof) |
int eof; | |
{ |
{ |
char *temp; |
char *temp; |
HIST_ENTRY *entry; |
HIST_ENTRY *entry; |
Line 486 readline_internal_teardown (eof)
|
Line 509 readline_internal_teardown (eof)
|
} |
} |
|
|
void |
void |
_rl_internal_char_cleanup () | _rl_internal_char_cleanup (void) |
{ |
{ |
#if defined (VI_MODE) |
#if defined (VI_MODE) |
/* In vi mode, when you exit insert mode, the cursor moves back |
/* In vi mode, when you exit insert mode, the cursor moves back |
Line 517 _rl_internal_char_cleanup ()
|
Line 540 _rl_internal_char_cleanup ()
|
|
|
STATIC_CALLBACK int |
STATIC_CALLBACK int |
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
readline_internal_char () | readline_internal_char (void) |
#else |
#else |
readline_internal_charloop () | readline_internal_charloop (void) |
#endif |
#endif |
{ |
{ |
static int lastc, eof_found; |
static int lastc, eof_found; |
int c, code, lk; | int c, code, lk, r; |
|
|
lastc = -1; | lastc = EOF; |
eof_found = 0; | |
|
|
#if !defined (READLINE_CALLBACKS) |
#if !defined (READLINE_CALLBACKS) |
|
eof_found = 0; |
while (rl_done == 0) |
while (rl_done == 0) |
{ |
{ |
#endif |
#endif |
Line 556 readline_internal_charloop ()
|
Line 579 readline_internal_charloop ()
|
{ |
{ |
/* Then initialize the argument and number of keys read. */ |
/* Then initialize the argument and number of keys read. */ |
_rl_reset_argument (); |
_rl_reset_argument (); |
rl_key_sequence_length = 0; | rl_executing_keyseq[rl_key_sequence_length = 0] = '\0'; |
rl_executing_keyseq[0] = 0; | |
} |
} |
|
|
RL_SETSTATE(RL_STATE_READCMD); |
RL_SETSTATE(RL_STATE_READCMD); |
Line 579 readline_internal_charloop ()
|
Line 601 readline_internal_charloop ()
|
#endif |
#endif |
} |
} |
|
|
/* EOF typed to a non-blank line is a <NL>. If we want to change this, | /* EOF typed to a non-blank line is ^D the first time, EOF the second |
to force any existing line to be ignored when read(2) reads EOF, | time in a row. This won't return any partial line read from the tty. |
for example, this is the place to change. */ | If we want to change this, to force any existing line to be returned |
| when read(2) reads EOF, for example, this is the place to change. */ |
if (c == EOF && rl_end) |
if (c == EOF && rl_end) |
c = NEWLINE; | { |
| if (RL_SIG_RECEIVED ()) |
| { |
| RL_CHECK_SIGNALS (); |
| if (rl_signal_event_hook) |
| (*rl_signal_event_hook) (); /* XXX */ |
| } |
|
|
|
/* XXX - reading two consecutive EOFs returns EOF */ |
|
if (RL_ISSTATE (RL_STATE_TERMPREPPED)) |
|
{ |
|
if (lastc == _rl_eof_char || lastc == EOF) |
|
rl_end = 0; |
|
else |
|
c = _rl_eof_char; |
|
} |
|
else |
|
c = NEWLINE; |
|
} |
|
|
/* The character _rl_eof_char typed to blank line, and not as the |
/* The character _rl_eof_char typed to blank line, and not as the |
previous character is interpreted as EOF. */ | previous character is interpreted as EOF. This doesn't work when |
if (((c == _rl_eof_char && lastc != c) || c == EOF) && !rl_end) | READLINE_CALLBACKS is defined, so hitting a series of ^Ds will |
| erase all the chars on the line and then return EOF. */ |
| if (((c == _rl_eof_char && lastc != c) || c == EOF) && rl_end == 0) |
{ |
{ |
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
RL_SETSTATE(RL_STATE_DONE); |
RL_SETSTATE(RL_STATE_DONE); |
Line 599 readline_internal_charloop ()
|
Line 642 readline_internal_charloop ()
|
} |
} |
|
|
lastc = c; |
lastc = c; |
_rl_dispatch ((unsigned char)c, _rl_keymap); | r = _rl_dispatch ((unsigned char)c, _rl_keymap); |
RL_CHECK_SIGNALS (); |
RL_CHECK_SIGNALS (); |
|
|
|
if (_rl_command_to_execute) |
|
{ |
|
(*rl_redisplay_function) (); |
|
|
|
rl_executing_keymap = _rl_command_to_execute->map; |
|
rl_executing_key = _rl_command_to_execute->key; |
|
|
|
rl_dispatching = 1; |
|
RL_SETSTATE(RL_STATE_DISPATCHING); |
|
r = (*(_rl_command_to_execute->func)) (_rl_command_to_execute->count, _rl_command_to_execute->key); |
|
_rl_command_to_execute = 0; |
|
RL_UNSETSTATE(RL_STATE_DISPATCHING); |
|
rl_dispatching = 0; |
|
|
|
RL_CHECK_SIGNALS (); |
|
} |
|
|
/* If there was no change in _rl_last_command_was_kill, then no kill |
/* If there was no change in _rl_last_command_was_kill, then no kill |
has taken place. Note that if input is pending we are reading |
has taken place. Note that if input is pending we are reading |
a prefix command, so nothing has changed yet. */ |
a prefix command, so nothing has changed yet. */ |
if (rl_pending_input == 0 && lk == _rl_last_command_was_kill) |
if (rl_pending_input == 0 && lk == _rl_last_command_was_kill) |
_rl_last_command_was_kill = 0; |
_rl_last_command_was_kill = 0; |
|
|
|
if (_rl_keep_mark_active) |
|
_rl_keep_mark_active = 0; |
|
else if (rl_mark_active_p ()) |
|
rl_deactivate_mark (); |
|
|
_rl_internal_char_cleanup (); |
_rl_internal_char_cleanup (); |
|
|
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
Line 621 readline_internal_charloop ()
|
Line 686 readline_internal_charloop ()
|
|
|
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
static int |
static int |
readline_internal_charloop () | readline_internal_charloop (void) |
{ |
{ |
int eof = 1; |
int eof = 1; |
|
|
Line 635 readline_internal_charloop ()
|
Line 700 readline_internal_charloop ()
|
the global rl_outstream. |
the global rl_outstream. |
If rl_prompt is non-null, then that is our prompt. */ |
If rl_prompt is non-null, then that is our prompt. */ |
static char * |
static char * |
readline_internal () | readline_internal (void) |
{ |
{ |
int eof; |
|
|
|
readline_internal_setup (); |
readline_internal_setup (); |
eof = readline_internal_charloop (); | _rl_eof_found = readline_internal_charloop (); |
return (readline_internal_teardown (eof)); | return (readline_internal_teardown (_rl_eof_found)); |
} |
} |
|
|
void |
void |
_rl_init_line_state () | _rl_init_line_state (void) |
{ |
{ |
rl_point = rl_end = rl_mark = 0; |
rl_point = rl_end = rl_mark = 0; |
the_line = rl_line_buffer; |
the_line = rl_line_buffer; |
Line 653 _rl_init_line_state ()
|
Line 716 _rl_init_line_state ()
|
} |
} |
|
|
void |
void |
_rl_set_the_line () | _rl_set_the_line (void) |
{ |
{ |
the_line = rl_line_buffer; |
the_line = rl_line_buffer; |
} |
} |
|
|
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
_rl_keyseq_cxt * |
_rl_keyseq_cxt * |
_rl_keyseq_cxt_alloc () | _rl_keyseq_cxt_alloc (void) |
{ |
{ |
_rl_keyseq_cxt *cxt; |
_rl_keyseq_cxt *cxt; |
|
|
Line 676 _rl_keyseq_cxt_alloc ()
|
Line 739 _rl_keyseq_cxt_alloc ()
|
} |
} |
|
|
void |
void |
_rl_keyseq_cxt_dispose (cxt) | _rl_keyseq_cxt_dispose (_rl_keyseq_cxt *cxt) |
_rl_keyseq_cxt *cxt; | |
{ |
{ |
xfree (cxt); |
xfree (cxt); |
} |
} |
|
|
void |
void |
_rl_keyseq_chain_dispose () | _rl_keyseq_chain_dispose (void) |
{ |
{ |
_rl_keyseq_cxt *cxt; |
_rl_keyseq_cxt *cxt; |
|
|
Line 697 _rl_keyseq_chain_dispose ()
|
Line 759 _rl_keyseq_chain_dispose ()
|
#endif |
#endif |
|
|
static int |
static int |
_rl_subseq_getchar (key) | _rl_subseq_getchar (int key) |
int key; | |
{ |
{ |
int k; |
int k; |
|
|
Line 715 _rl_subseq_getchar (key)
|
Line 776 _rl_subseq_getchar (key)
|
|
|
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
int |
int |
_rl_dispatch_callback (cxt) | _rl_dispatch_callback (_rl_keyseq_cxt *cxt) |
_rl_keyseq_cxt *cxt; | |
{ |
{ |
int nkey, r; |
int nkey, r; |
|
|
Line 767 _rl_dispatch_callback (cxt)
|
Line 827 _rl_dispatch_callback (cxt)
|
If the associated command is really a keymap, then read |
If the associated command is really a keymap, then read |
another key, and dispatch into that map. */ |
another key, and dispatch into that map. */ |
int |
int |
_rl_dispatch (key, map) | _rl_dispatch (register int key, Keymap map) |
register int key; | |
Keymap map; | |
{ |
{ |
_rl_dispatching_keymap = map; |
_rl_dispatching_keymap = map; |
return _rl_dispatch_subseq (key, map, 0); |
return _rl_dispatch_subseq (key, map, 0); |
} |
} |
|
|
int |
int |
_rl_dispatch_subseq (key, map, got_subseq) | _rl_dispatch_subseq (register int key, Keymap map, int got_subseq) |
register int key; | |
Keymap map; | |
int got_subseq; | |
{ |
{ |
int r, newkey; |
int r, newkey; |
char *macro; |
char *macro; |
Line 818 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 873 _rl_dispatch_subseq (key, map, got_subseq)
|
/* Special case rl_do_lowercase_version (). */ |
/* Special case rl_do_lowercase_version (). */ |
if (func == rl_do_lowercase_version) |
if (func == rl_do_lowercase_version) |
/* Should we do anything special if key == ANYOTHERKEY? */ |
/* Should we do anything special if key == ANYOTHERKEY? */ |
return (_rl_dispatch (_rl_to_lower (key), map)); | return (_rl_dispatch (_rl_to_lower ((unsigned char)key), map)); |
|
|
rl_executing_keymap = map; |
rl_executing_keymap = map; |
rl_executing_key = key; |
rl_executing_key = key; |
Line 836 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 891 _rl_dispatch_subseq (key, map, got_subseq)
|
/* If we have input pending, then the last command was a prefix |
/* If we have input pending, then the last command was a prefix |
command. Don't change the state of rl_last_func. Otherwise, |
command. Don't change the state of rl_last_func. Otherwise, |
remember the last command executed in this variable. */ |
remember the last command executed in this variable. */ |
|
#if defined (VI_MODE) |
|
if (rl_pending_input == 0 && map[key].function != rl_digit_argument && map[key].function != rl_vi_arg_digit) |
|
#else |
if (rl_pending_input == 0 && map[key].function != rl_digit_argument) |
if (rl_pending_input == 0 && map[key].function != rl_digit_argument) |
|
#endif |
rl_last_func = map[key].function; |
rl_last_func = map[key].function; |
|
|
RL_CHECK_SIGNALS (); |
RL_CHECK_SIGNALS (); |
Line 850 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 909 _rl_dispatch_subseq (key, map, got_subseq)
|
_rl_prev_macro_key (); |
_rl_prev_macro_key (); |
else |
else |
_rl_unget_char (key); |
_rl_unget_char (key); |
|
if (rl_key_sequence_length > 0) |
|
rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
return -2; |
return -2; |
} |
} |
else if (got_subseq) |
else if (got_subseq) |
Line 862 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 923 _rl_dispatch_subseq (key, map, got_subseq)
|
_rl_prev_macro_key (); |
_rl_prev_macro_key (); |
else |
else |
_rl_unget_char (key); |
_rl_unget_char (key); |
|
if (rl_key_sequence_length > 0) |
|
rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
return -1; |
return -1; |
} |
} |
else |
else |
Line 888 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 951 _rl_dispatch_subseq (key, map, got_subseq)
|
default) or a timeout determined by the value of `keyseq-timeout' */ |
default) or a timeout determined by the value of `keyseq-timeout' */ |
/* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued |
/* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued |
takes microseconds, so multiply by 1000 */ |
takes microseconds, so multiply by 1000 */ |
if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap | if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap && |
&& _rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0) | (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) && |
| _rl_pushed_input_available () == 0 && |
| _rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0) |
return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key))); |
return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key))); |
|
/* This is a very specific test. It can possibly be generalized in |
|
the future, but for now it handles a specific case of ESC being |
|
the last character in a keyboard macro. */ |
|
if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap && |
|
(RL_ISSTATE (RL_STATE_INPUTPENDING) == 0) && |
|
(RL_ISSTATE (RL_STATE_MACROINPUT) && _rl_peek_macro_key () == 0) && |
|
_rl_pushed_input_available () == 0 && |
|
_rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0) |
|
return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key))); |
#endif |
#endif |
|
|
RESIZE_KEYSEQ_BUFFER (); |
RESIZE_KEYSEQ_BUFFER (); |
Line 900 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 974 _rl_dispatch_subseq (key, map, got_subseq)
|
/* Allocate new context here. Use linked contexts (linked through |
/* Allocate new context here. Use linked contexts (linked through |
cxt->ocxt) to simulate recursion */ |
cxt->ocxt) to simulate recursion */ |
#if defined (READLINE_CALLBACKS) |
#if defined (READLINE_CALLBACKS) |
|
# if defined (VI_MODE) |
|
/* If we're redoing a vi mode command and we know there is a shadowed |
|
function corresponding to this key, just call it -- all the redoable |
|
vi mode commands already have all the input they need, and rl_vi_redo |
|
assumes that one call to rl_dispatch is sufficient to complete the |
|
command. */ |
|
if (_rl_vi_redoing && RL_ISSTATE (RL_STATE_CALLBACK) && |
|
map[ANYOTHERKEY].function != 0) |
|
return (_rl_subseq_result (-2, map, key, got_subseq)); |
|
# endif |
if (RL_ISSTATE (RL_STATE_CALLBACK)) |
if (RL_ISSTATE (RL_STATE_CALLBACK)) |
{ |
{ |
/* Return 0 only the first time, to indicate success to |
/* Return 0 only the first time, to indicate success to |
Line 933 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 1017 _rl_dispatch_subseq (key, map, got_subseq)
|
_rl_pushed_input_available () == 0 && |
_rl_pushed_input_available () == 0 && |
_rl_dispatching_keymap[ANYOTHERKEY].function && |
_rl_dispatching_keymap[ANYOTHERKEY].function && |
_rl_input_queued (_rl_keyseq_timeout*1000) == 0) |
_rl_input_queued (_rl_keyseq_timeout*1000) == 0) |
return (_rl_subseq_result (-2, map, key, got_subseq)); | { |
| if (rl_key_sequence_length > 0) |
| rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
| return (_rl_subseq_result (-2, map, key, got_subseq)); |
| } |
|
|
newkey = _rl_subseq_getchar (key); |
newkey = _rl_subseq_getchar (key); |
if (newkey < 0) |
if (newkey < 0) |
Line 947 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 1035 _rl_dispatch_subseq (key, map, got_subseq)
|
} |
} |
else |
else |
{ |
{ |
_rl_abort_internal (); | _rl_abort_internal (); /* XXX */ |
return -1; |
return -1; |
} |
} |
break; |
break; |
Line 962 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 1050 _rl_dispatch_subseq (key, map, got_subseq)
|
} |
} |
break; |
break; |
} |
} |
|
|
#if defined (VI_MODE) |
#if defined (VI_MODE) |
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap && |
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap && |
key != ANYOTHERKEY && |
key != ANYOTHERKEY && |
Line 974 _rl_dispatch_subseq (key, map, got_subseq)
|
Line 1063 _rl_dispatch_subseq (key, map, got_subseq)
|
} |
} |
|
|
static int |
static int |
_rl_subseq_result (r, map, key, got_subseq) | _rl_subseq_result (int r, Keymap map, int key, int got_subseq) |
int r; | |
Keymap map; | |
int key, got_subseq; | |
{ |
{ |
Keymap m; |
Keymap m; |
int type, nt; |
int type, nt; |
Line 994 _rl_subseq_result (r, map, key, got_subseq)
|
Line 1080 _rl_subseq_result (r, map, key, got_subseq)
|
type = m[ANYOTHERKEY].type; |
type = m[ANYOTHERKEY].type; |
func = m[ANYOTHERKEY].function; |
func = m[ANYOTHERKEY].function; |
if (type == ISFUNC && func == rl_do_lowercase_version) |
if (type == ISFUNC && func == rl_do_lowercase_version) |
r = _rl_dispatch (_rl_to_lower (key), map); | r = _rl_dispatch (_rl_to_lower ((unsigned char)key), map); |
else if (type == ISFUNC && func == rl_insert) | else if (type == ISFUNC) |
{ |
{ |
/* If the function that was shadowed was self-insert, we | /* If we shadowed a function, whatever it is, we somehow need a |
somehow need a keymap with map[key].func == self-insert. | keymap with map[key].func == shadowed-function. |
Let's use this one. */ | Let's use this one. Then we can dispatch using the original |
| key, since there are commands (e.g., in vi mode) for which it |
| matters. */ |
nt = m[key].type; |
nt = m[key].type; |
nf = m[key].function; |
nf = m[key].function; |
|
|
m[key].type = type; |
m[key].type = type; |
m[key].function = func; |
m[key].function = func; |
r = _rl_dispatch (key, m); | /* Don't change _rl_dispatching_keymap, set it here */ |
| _rl_dispatching_keymap = map; /* previous map */ |
| r = _rl_dispatch_subseq (key, m, 0); |
m[key].type = nt; |
m[key].type = nt; |
m[key].function = nf; |
m[key].function = nf; |
} |
} |
else |
else |
|
/* We probably shadowed a keymap, so keep going. */ |
r = _rl_dispatch (ANYOTHERKEY, m); |
r = _rl_dispatch (ANYOTHERKEY, m); |
} |
} |
else if (r && map[ANYOTHERKEY].function) | else if (r < 0 && map[ANYOTHERKEY].function) |
{ |
{ |
/* We didn't match (r is probably -1), so return something to |
/* We didn't match (r is probably -1), so return something to |
tell the caller that it should try ANYOTHERKEY for an |
tell the caller that it should try ANYOTHERKEY for an |
Line 1021 _rl_subseq_result (r, map, key, got_subseq)
|
Line 1112 _rl_subseq_result (r, map, key, got_subseq)
|
_rl_prev_macro_key (); |
_rl_prev_macro_key (); |
else |
else |
_rl_unget_char (key); |
_rl_unget_char (key); |
|
if (rl_key_sequence_length > 0) |
|
rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
_rl_dispatching_keymap = map; |
_rl_dispatching_keymap = map; |
return -2; |
return -2; |
} |
} |
else if (r && got_subseq) | else if (r < 0 && got_subseq) /* XXX */ |
{ |
{ |
/* OK, back up the chain. */ |
/* OK, back up the chain. */ |
if (RL_ISSTATE (RL_STATE_MACROINPUT)) |
if (RL_ISSTATE (RL_STATE_MACROINPUT)) |
_rl_prev_macro_key (); |
_rl_prev_macro_key (); |
else |
else |
_rl_unget_char (key); |
_rl_unget_char (key); |
|
if (rl_key_sequence_length > 0) |
|
rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
_rl_dispatching_keymap = map; |
_rl_dispatching_keymap = map; |
return -1; |
return -1; |
} |
} |
Line 1046 _rl_subseq_result (r, map, key, got_subseq)
|
Line 1141 _rl_subseq_result (r, map, key, got_subseq)
|
|
|
/* Initialize readline (and terminal if not already). */ |
/* Initialize readline (and terminal if not already). */ |
int |
int |
rl_initialize () | rl_initialize (void) |
{ |
{ |
/* If we have never been called before, initialize the |
/* If we have never been called before, initialize the |
terminal and data structures. */ |
terminal and data structures. */ |
if (!rl_initialized) | if (rl_initialized == 0) |
{ |
{ |
RL_SETSTATE(RL_STATE_INITIALIZING); |
RL_SETSTATE(RL_STATE_INITIALIZING); |
readline_initialize_everything (); |
readline_initialize_everything (); |
Line 1058 rl_initialize ()
|
Line 1153 rl_initialize ()
|
rl_initialized++; |
rl_initialized++; |
RL_SETSTATE(RL_STATE_INITIALIZED); |
RL_SETSTATE(RL_STATE_INITIALIZED); |
} |
} |
|
else |
|
(void)_rl_init_locale (); /* check current locale */ |
|
|
/* Initialize the current line information. */ |
/* Initialize the current line information. */ |
_rl_init_line_state (); |
_rl_init_line_state (); |
Line 1092 rl_initialize ()
|
Line 1189 rl_initialize ()
|
#if 0 |
#if 0 |
#if defined (__EMX__) |
#if defined (__EMX__) |
static void |
static void |
_emx_build_environ () | _emx_build_environ (void) |
{ |
{ |
TIB *tibp; |
TIB *tibp; |
PIB *pibp; |
PIB *pibp; |
Line 1117 _emx_build_environ ()
|
Line 1214 _emx_build_environ ()
|
|
|
/* Initialize the entire state of the world. */ |
/* Initialize the entire state of the world. */ |
static void |
static void |
readline_initialize_everything () | readline_initialize_everything (void) |
{ |
{ |
#if 0 |
#if 0 |
#if defined (__EMX__) |
#if defined (__EMX__) |
Line 1179 readline_initialize_everything ()
|
Line 1276 readline_initialize_everything ()
|
/* Try to bind a common arrow key prefix, if not already bound. */ |
/* Try to bind a common arrow key prefix, if not already bound. */ |
bind_arrow_keys (); |
bind_arrow_keys (); |
|
|
|
/* Bind the bracketed paste prefix assuming that the user will enable |
|
it on terminals that support it. */ |
|
bind_bracketed_paste_prefix (); |
|
|
/* If the completion parser's default word break characters haven't |
/* If the completion parser's default word break characters haven't |
been set yet, then do so now. */ |
been set yet, then do so now. */ |
if (rl_completer_word_break_characters == (char *)NULL) |
if (rl_completer_word_break_characters == (char *)NULL) |
rl_completer_word_break_characters = (char *)rl_basic_word_break_characters; |
rl_completer_word_break_characters = (char *)rl_basic_word_break_characters; |
|
|
#if defined (COLOR_SUPPORT) |
#if defined (COLOR_SUPPORT) |
if (_rl_colored_stats) | if (_rl_colored_stats || _rl_colored_completion_prefix) |
_rl_parse_colors (); |
_rl_parse_colors (); |
#endif |
#endif |
|
|
rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16); |
rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16); |
if (rl_executing_keyseq) |
if (rl_executing_keyseq) |
rl_executing_keyseq[0] = '\0'; | rl_executing_keyseq[rl_key_sequence_length = 0] = '\0'; |
} |
} |
|
|
/* If this system allows us to look at the values of the regular |
/* If this system allows us to look at the values of the regular |
input editing characters, then bind them to their readline |
input editing characters, then bind them to their readline |
equivalents, iff the characters are not bound to keymaps. */ |
equivalents, iff the characters are not bound to keymaps. */ |
static void |
static void |
readline_default_bindings () | readline_default_bindings (void) |
{ |
{ |
if (_rl_bind_stty_chars) |
if (_rl_bind_stty_chars) |
rl_tty_set_default_bindings (_rl_keymap); |
rl_tty_set_default_bindings (_rl_keymap); |
Line 1207 readline_default_bindings ()
|
Line 1308 readline_default_bindings ()
|
/* Reset the default bindings for the terminal special characters we're |
/* Reset the default bindings for the terminal special characters we're |
interested in back to rl_insert and read the new ones. */ |
interested in back to rl_insert and read the new ones. */ |
static void |
static void |
reset_default_bindings () | reset_default_bindings (void) |
{ |
{ |
if (_rl_bind_stty_chars) |
if (_rl_bind_stty_chars) |
{ |
{ |
Line 1218 reset_default_bindings ()
|
Line 1319 reset_default_bindings ()
|
|
|
/* Bind some common arrow key sequences in MAP. */ |
/* Bind some common arrow key sequences in MAP. */ |
static void |
static void |
bind_arrow_keys_internal (map) | bind_arrow_keys_internal (Keymap map) |
Keymap map; | |
{ |
{ |
Keymap xkeymap; |
Keymap xkeymap; |
|
|
Line 1247 bind_arrow_keys_internal (map)
|
Line 1347 bind_arrow_keys_internal (map)
|
rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line); |
rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line); |
rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line); |
rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line); |
|
|
|
/* Key bindings for control-arrow keys */ |
|
rl_bind_keyseq_if_unbound ("\033[1;5C", rl_forward_word); |
|
rl_bind_keyseq_if_unbound ("\033[1;5D", rl_backward_word); |
|
rl_bind_keyseq_if_unbound ("\033[3;5~", rl_kill_word); |
|
|
|
/* Key bindings for alt-arrow keys */ |
|
rl_bind_keyseq_if_unbound ("\033[1;3C", rl_forward_word); |
|
rl_bind_keyseq_if_unbound ("\033[1;3D", rl_backward_word); |
|
|
#if defined (__MINGW32__) |
#if defined (__MINGW32__) |
rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history); |
rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history); |
rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history); |
rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history); |
Line 1275 bind_arrow_keys_internal (map)
|
Line 1384 bind_arrow_keys_internal (map)
|
the inputrc file a chance to bind them and create `real' keymaps |
the inputrc file a chance to bind them and create `real' keymaps |
for the arrow key prefix. */ |
for the arrow key prefix. */ |
static void |
static void |
bind_arrow_keys () | bind_arrow_keys (void) |
{ |
{ |
bind_arrow_keys_internal (emacs_standard_keymap); |
bind_arrow_keys_internal (emacs_standard_keymap); |
|
|
Line 1289 bind_arrow_keys ()
|
Line 1398 bind_arrow_keys ()
|
#endif |
#endif |
} |
} |
|
|
|
static void |
|
bind_bracketed_paste_prefix (void) |
|
{ |
|
Keymap xkeymap; |
|
|
|
xkeymap = _rl_keymap; |
|
|
|
_rl_keymap = emacs_standard_keymap; |
|
rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_bracketed_paste_begin); |
|
|
|
#if defined (VI_MODE) |
|
_rl_keymap = vi_insertion_keymap; |
|
rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_bracketed_paste_begin); |
|
/* XXX - is there a reason to do this in the vi command keymap? */ |
|
#endif |
|
|
|
_rl_keymap = xkeymap; |
|
} |
|
|
/* **************************************************************** */ |
/* **************************************************************** */ |
/* */ |
/* */ |
/* Saving and Restoring Readline's state */ |
/* Saving and Restoring Readline's state */ |
Line 1296 bind_arrow_keys ()
|
Line 1424 bind_arrow_keys ()
|
/* **************************************************************** */ |
/* **************************************************************** */ |
|
|
int |
int |
rl_save_state (sp) | rl_save_state (struct readline_state *sp) |
struct readline_state *sp; | |
{ |
{ |
if (sp == 0) |
if (sp == 0) |
return -1; |
return -1; |
Line 1317 rl_save_state (sp)
|
Line 1444 rl_save_state (sp)
|
sp->lastfunc = rl_last_func; |
sp->lastfunc = rl_last_func; |
sp->insmode = rl_insert_mode; |
sp->insmode = rl_insert_mode; |
sp->edmode = rl_editing_mode; |
sp->edmode = rl_editing_mode; |
|
sp->kseq = rl_executing_keyseq; |
sp->kseqlen = rl_key_sequence_length; |
sp->kseqlen = rl_key_sequence_length; |
sp->inf = rl_instream; |
sp->inf = rl_instream; |
sp->outf = rl_outstream; |
sp->outf = rl_outstream; |
Line 1326 rl_save_state (sp)
|
Line 1454 rl_save_state (sp)
|
sp->catchsigs = rl_catch_signals; |
sp->catchsigs = rl_catch_signals; |
sp->catchsigwinch = rl_catch_sigwinch; |
sp->catchsigwinch = rl_catch_sigwinch; |
|
|
|
sp->entryfunc = rl_completion_entry_function; |
|
sp->menuentryfunc = rl_menu_completion_entry_function; |
|
sp->ignorefunc = rl_ignore_some_completions_function; |
|
sp->attemptfunc = rl_attempted_completion_function; |
|
sp->wordbreakchars = rl_completer_word_break_characters; |
|
|
return (0); |
return (0); |
} |
} |
|
|
int |
int |
rl_restore_state (sp) | rl_restore_state (struct readline_state *sp) |
struct readline_state *sp; | |
{ |
{ |
if (sp == 0) |
if (sp == 0) |
return -1; |
return -1; |
Line 1351 rl_restore_state (sp)
|
Line 1484 rl_restore_state (sp)
|
rl_last_func = sp->lastfunc; |
rl_last_func = sp->lastfunc; |
rl_insert_mode = sp->insmode; |
rl_insert_mode = sp->insmode; |
rl_editing_mode = sp->edmode; |
rl_editing_mode = sp->edmode; |
|
rl_executing_keyseq = sp->kseq; |
rl_key_sequence_length = sp->kseqlen; |
rl_key_sequence_length = sp->kseqlen; |
rl_instream = sp->inf; |
rl_instream = sp->inf; |
rl_outstream = sp->outf; |
rl_outstream = sp->outf; |
Line 1360 rl_restore_state (sp)
|
Line 1494 rl_restore_state (sp)
|
rl_catch_signals = sp->catchsigs; |
rl_catch_signals = sp->catchsigs; |
rl_catch_sigwinch = sp->catchsigwinch; |
rl_catch_sigwinch = sp->catchsigwinch; |
|
|
|
rl_completion_entry_function = sp->entryfunc; |
|
rl_menu_completion_entry_function = sp->menuentryfunc; |
|
rl_ignore_some_completions_function = sp->ignorefunc; |
|
rl_attempted_completion_function = sp->attemptfunc; |
|
rl_completer_word_break_characters = sp->wordbreakchars; |
|
|
|
rl_deactivate_mark (); |
|
|
return (0); |
return (0); |
|
} |
|
|
|
/* Functions to manage the string that is the current key sequence. */ |
|
|
|
void |
|
_rl_init_executing_keyseq (void) |
|
{ |
|
rl_executing_keyseq[rl_key_sequence_length = 0] = '\0'; |
|
} |
|
|
|
void |
|
_rl_term_executing_keyseq (void) |
|
{ |
|
rl_executing_keyseq[rl_key_sequence_length] = '\0'; |
|
} |
|
|
|
void |
|
_rl_end_executing_keyseq (void) |
|
{ |
|
if (rl_key_sequence_length > 0) |
|
rl_executing_keyseq[--rl_key_sequence_length] = '\0'; |
|
} |
|
|
|
void |
|
_rl_add_executing_keyseq (int key) |
|
{ |
|
RESIZE_KEYSEQ_BUFFER (); |
|
rl_executing_keyseq[rl_key_sequence_length++] = key; |
} |
} |