blob: 50e4338e1ceba3f0e1ee001dea4b6419fac108c8 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* readline.c -- a general facility for reading lines of input
2 with emacs style editing and completion. */
3
Chet Rameyac50fba2014-02-26 09:36:43 -05004/* Copyright (C) 1987-2013 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00005
Jari Aalto31859422009-01-12 13:36:28 +00006 This file is part of the GNU Readline Library (Readline), a library
7 for reading lines of text with interactive input and history editing.
Jari Aalto726f6381996-08-26 18:22:31 +00008
Jari Aalto31859422009-01-12 13:36:28 +00009 Readline is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
Jari Aalto726f6381996-08-26 18:22:31 +000012 (at your option) any later version.
13
Jari Aalto31859422009-01-12 13:36:28 +000014 Readline is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jari Aalto726f6381996-08-26 18:22:31 +000017 GNU General Public License for more details.
18
Jari Aalto31859422009-01-12 13:36:28 +000019 You should have received a copy of the GNU General Public License
20 along with Readline. If not, see <http://www.gnu.org/licenses/>.
21*/
22
Jari Aalto726f6381996-08-26 18:22:31 +000023#define READLINE_LIBRARY
24
Jari Aaltoccc6cda1996-12-23 17:02:34 +000025#if defined (HAVE_CONFIG_H)
26# include <config.h>
27#endif
28
Jari Aalto726f6381996-08-26 18:22:31 +000029#include <sys/types.h>
Jari Aaltoccc6cda1996-12-23 17:02:34 +000030#include "posixstat.h"
Jari Aalto726f6381996-08-26 18:22:31 +000031#include <fcntl.h>
Jari Aaltoccc6cda1996-12-23 17:02:34 +000032#if defined (HAVE_SYS_FILE_H)
Jari Aalto726f6381996-08-26 18:22:31 +000033# include <sys/file.h>
Jari Aaltoccc6cda1996-12-23 17:02:34 +000034#endif /* HAVE_SYS_FILE_H */
Jari Aalto726f6381996-08-26 18:22:31 +000035
36#if defined (HAVE_UNISTD_H)
37# include <unistd.h>
38#endif /* HAVE_UNISTD_H */
39
40#if defined (HAVE_STDLIB_H)
41# include <stdlib.h>
42#else
43# include "ansi_stdlib.h"
44#endif /* HAVE_STDLIB_H */
45
Jari Aaltoccc6cda1996-12-23 17:02:34 +000046#if defined (HAVE_LOCALE_H)
47# include <locale.h>
48#endif
Jari Aalto726f6381996-08-26 18:22:31 +000049
Jari Aaltoccc6cda1996-12-23 17:02:34 +000050#include <stdio.h>
Jari Aaltod166f041997-06-05 14:59:13 +000051#include "posixjmp.h"
Jari Aalto06285672006-10-10 14:15:34 +000052#include <errno.h>
53
54#if !defined (errno)
Ricardo Cerqueiraa02fbff2013-07-25 22:35:34 +010055#include <errno.h>
Jari Aalto06285672006-10-10 14:15:34 +000056#endif /* !errno */
Jari Aalto726f6381996-08-26 18:22:31 +000057
Jari Aalto726f6381996-08-26 18:22:31 +000058/* System-specific feature definitions and include files. */
59#include "rldefs.h"
Jari Aalto7117c2d2002-07-17 14:10:11 +000060#include "rlmbutil.h"
Jari Aalto726f6381996-08-26 18:22:31 +000061
Jari Aaltod166f041997-06-05 14:59:13 +000062#if defined (__EMX__)
63# define INCL_DOSPROCESS
64# include <os2.h>
65#endif /* __EMX__ */
Jari Aalto726f6381996-08-26 18:22:31 +000066
67/* Some standard library routines. */
68#include "readline.h"
69#include "history.h"
70
Jari Aaltobb706242000-03-17 21:46:59 +000071#include "rlprivate.h"
72#include "rlshell.h"
73#include "xmalloc.h"
74
Jari Aaltod166f041997-06-05 14:59:13 +000075#ifndef RL_LIBRARY_VERSION
Jari Aalto95732b42005-12-07 14:08:12 +000076# define RL_LIBRARY_VERSION "5.1"
Jari Aaltof73dda02001-11-13 17:56:06 +000077#endif
78
79#ifndef RL_READLINE_VERSION
Jari Aalto95732b42005-12-07 14:08:12 +000080# define RL_READLINE_VERSION 0x0501
Jari Aaltod166f041997-06-05 14:59:13 +000081#endif
82
Jari Aalto7117c2d2002-07-17 14:10:11 +000083extern void _rl_free_history_entry PARAMS((HIST_ENTRY *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +000084
Chet Rameyac50fba2014-02-26 09:36:43 -050085#if defined (COLOR_SUPPORT)
86extern void _rl_parse_colors PARAMS((void)); /* XXX */
87#endif
88
89
Jari Aalto726f6381996-08-26 18:22:31 +000090/* Forward declarations used in this file. */
Jari Aaltof73dda02001-11-13 17:56:06 +000091static char *readline_internal PARAMS((void));
92static void readline_initialize_everything PARAMS((void));
Jari Aalto7117c2d2002-07-17 14:10:11 +000093
94static void bind_arrow_keys_internal PARAMS((Keymap));
Jari Aaltof73dda02001-11-13 17:56:06 +000095static void bind_arrow_keys PARAMS((void));
Jari Aalto726f6381996-08-26 18:22:31 +000096
Jari Aaltof73dda02001-11-13 17:56:06 +000097static void readline_default_bindings PARAMS((void));
Jari Aaltob80f6442004-07-27 13:29:18 +000098static void reset_default_bindings PARAMS((void));
Jari Aalto726f6381996-08-26 18:22:31 +000099
Jari Aalto95732b42005-12-07 14:08:12 +0000100static int _rl_subseq_result PARAMS((int, Keymap, int, int));
101static int _rl_subseq_getchar PARAMS((int));
102
Jari Aalto726f6381996-08-26 18:22:31 +0000103/* **************************************************************** */
104/* */
105/* Line editing input utility */
106/* */
107/* **************************************************************** */
108
Jari Aalto28ef6c32001-04-06 19:14:31 +0000109const char *rl_library_version = RL_LIBRARY_VERSION;
Jari Aalto726f6381996-08-26 18:22:31 +0000110
Jari Aaltof73dda02001-11-13 17:56:06 +0000111int rl_readline_version = RL_READLINE_VERSION;
112
Jari Aalto28ef6c32001-04-06 19:14:31 +0000113/* True if this is `real' readline as opposed to some stub substitute. */
Jari Aaltobb706242000-03-17 21:46:59 +0000114int rl_gnu_readline_p = 1;
115
Jari Aalto726f6381996-08-26 18:22:31 +0000116/* A pointer to the keymap that is currently in use.
117 By default, it is the standard emacs keymap. */
118Keymap _rl_keymap = emacs_standard_keymap;
119
120/* The current style of editing. */
121int rl_editing_mode = emacs_mode;
122
Jari Aalto7117c2d2002-07-17 14:10:11 +0000123/* The current insert mode: input (the default) or overwrite */
124int rl_insert_mode = RL_IM_DEFAULT;
125
Jari Aaltod166f041997-06-05 14:59:13 +0000126/* Non-zero if we called this function from _rl_dispatch(). It's present
127 so functions can find out whether they were called from a key binding
128 or directly from an application. */
129int rl_dispatching;
130
Jari Aalto726f6381996-08-26 18:22:31 +0000131/* Non-zero if the previous command was a kill command. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000132int _rl_last_command_was_kill = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000133
134/* The current value of the numeric argument specified by the user. */
135int rl_numeric_arg = 1;
136
137/* Non-zero if an argument was typed. */
138int rl_explicit_arg = 0;
139
140/* Temporary value used while generating the argument. */
141int rl_arg_sign = 1;
142
143/* Non-zero means we have been called at least once before. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000144static int rl_initialized;
Jari Aalto726f6381996-08-26 18:22:31 +0000145
Jari Aalto28ef6c32001-04-06 19:14:31 +0000146#if 0
Jari Aalto726f6381996-08-26 18:22:31 +0000147/* If non-zero, this program is running in an EMACS buffer. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000148static int running_in_emacs;
Jari Aalto28ef6c32001-04-06 19:14:31 +0000149#endif
150
151/* Flags word encapsulating the current readline state. */
152int rl_readline_state = RL_STATE_NONE;
Jari Aalto726f6381996-08-26 18:22:31 +0000153
154/* The current offset in the current input line. */
155int rl_point;
156
157/* Mark in the current input line. */
158int rl_mark;
159
160/* Length of the current input line. */
161int rl_end;
162
163/* Make this non-zero to return the current input_line. */
164int rl_done;
165
166/* The last function executed by readline. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000167rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +0000168
169/* Top level environment for readline_internal (). */
Jari Aalto31859422009-01-12 13:36:28 +0000170procenv_t _rl_top_level;
Jari Aalto726f6381996-08-26 18:22:31 +0000171
172/* The streams we interact with. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000173FILE *_rl_in_stream, *_rl_out_stream;
Jari Aalto726f6381996-08-26 18:22:31 +0000174
175/* The names of the streams that we do input and output to. */
176FILE *rl_instream = (FILE *)NULL;
177FILE *rl_outstream = (FILE *)NULL;
178
Jari Aaltof73dda02001-11-13 17:56:06 +0000179/* Non-zero means echo characters as they are read. Defaults to no echo;
180 set to 1 if there is a controlling terminal, we can get its attributes,
181 and the attributes include `echo'. Look at rltty.c:prepare_terminal_settings
182 for the code that sets it. */
Jari Aalto31859422009-01-12 13:36:28 +0000183int _rl_echoing_p = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000184
185/* Current prompt. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000186char *rl_prompt = (char *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +0000187int rl_visible_prompt_length = 0;
188
Jari Aaltobb706242000-03-17 21:46:59 +0000189/* Set to non-zero by calling application if it has already printed rl_prompt
190 and does not want readline to do it the first time. */
191int rl_already_prompted = 0;
192
Jari Aalto726f6381996-08-26 18:22:31 +0000193/* The number of characters read in order to type this complete command. */
194int rl_key_sequence_length = 0;
195
196/* If non-zero, then this is the address of a function to call just
Jari Aaltob72432f1999-02-19 17:11:39 +0000197 before readline_internal_setup () prints the first prompt. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000198rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +0000199
Jari Aaltob72432f1999-02-19 17:11:39 +0000200/* If non-zero, this is the address of a function to call just before
201 readline_internal_setup () returns and readline_internal starts
202 reading input characters. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000203rl_hook_func_t *rl_pre_input_hook = (rl_hook_func_t *)NULL;
Jari Aaltob72432f1999-02-19 17:11:39 +0000204
Jari Aalto726f6381996-08-26 18:22:31 +0000205/* What we use internally. You should always refer to RL_LINE_BUFFER. */
206static char *the_line;
207
208/* The character that can generate an EOF. Really read from
209 the terminal driver... just defaulted here. */
210int _rl_eof_char = CTRL ('D');
211
212/* Non-zero makes this the next keystroke to read. */
213int rl_pending_input = 0;
214
215/* Pointer to a useful terminal name. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000216const char *rl_terminal_name = (const char *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +0000217
218/* Non-zero means to always use horizontal scrolling in line display. */
219int _rl_horizontal_scroll_mode = 0;
220
221/* Non-zero means to display an asterisk at the starts of history lines
222 which have been modified. */
223int _rl_mark_modified_lines = 0;
224
225/* The style of `bell' notification preferred. This can be set to NO_BELL,
226 AUDIBLE_BELL, or VISIBLE_BELL. */
227int _rl_bell_preference = AUDIBLE_BELL;
228
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000229/* String inserted into the line by rl_insert_comment (). */
230char *_rl_comment_begin;
231
232/* Keymap holding the function currently being executed. */
233Keymap rl_executing_keymap;
234
Jari Aalto95732b42005-12-07 14:08:12 +0000235/* Keymap we're currently using to dispatch. */
236Keymap _rl_dispatching_keymap;
237
Jari Aaltob72432f1999-02-19 17:11:39 +0000238/* Non-zero means to erase entire line, including prompt, on empty input lines. */
239int rl_erase_empty_line = 0;
240
Jari Aaltobb706242000-03-17 21:46:59 +0000241/* Non-zero means to read only this many characters rather than up to a
242 character bound to accept-line. */
243int rl_num_chars_to_read;
244
Chet Rameyac50fba2014-02-26 09:36:43 -0500245/* Line buffer and maintenance. */
Jari Aalto726f6381996-08-26 18:22:31 +0000246char *rl_line_buffer = (char *)NULL;
247int rl_line_buffer_len = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000248
Jari Aalto95732b42005-12-07 14:08:12 +0000249/* Key sequence `contexts' */
250_rl_keyseq_cxt *_rl_kscxt = 0;
251
Chet Rameyac50fba2014-02-26 09:36:43 -0500252int rl_executing_key;
253char *rl_executing_keyseq = 0;
254int _rl_executing_keyseq_size = 0;
255
256/* Timeout (specified in milliseconds) when reading characters making up an
257 ambiguous multiple-key sequence */
258int _rl_keyseq_timeout = 500;
259
260#define RESIZE_KEYSEQ_BUFFER() \
261 do \
262 { \
263 if (rl_key_sequence_length + 2 >= _rl_executing_keyseq_size) \
264 { \
265 _rl_executing_keyseq_size += 16; \
266 rl_executing_keyseq = xrealloc (rl_executing_keyseq, _rl_executing_keyseq_size); \
267 } \
268 } \
269 while (0);
270
Jari Aaltof73dda02001-11-13 17:56:06 +0000271/* Forward declarations used by the display, termcap, and history code. */
Jari Aalto726f6381996-08-26 18:22:31 +0000272
Jari Aalto726f6381996-08-26 18:22:31 +0000273/* **************************************************************** */
274/* */
275/* `Forward' declarations */
276/* */
277/* **************************************************************** */
278
279/* Non-zero means do not parse any lines other than comments and
280 parser directives. */
281unsigned char _rl_parsing_conditionalized_out = 0;
282
Jari Aalto726f6381996-08-26 18:22:31 +0000283/* Non-zero means to convert characters with the meta bit set to
284 escape-prefixed characters so we can indirect through
285 emacs_meta_keymap or vi_escape_keymap. */
286int _rl_convert_meta_chars_to_ascii = 1;
287
288/* Non-zero means to output characters with the meta bit set directly
289 rather than as a meta-prefixed escape sequence. */
290int _rl_output_meta_chars = 0;
291
Jari Aalto95732b42005-12-07 14:08:12 +0000292/* Non-zero means to look at the termios special characters and bind
293 them to equivalent readline functions at startup. */
294int _rl_bind_stty_chars = 1;
295
Jari Aalto31859422009-01-12 13:36:28 +0000296/* Non-zero means to go through the history list at every newline (or
297 whenever rl_done is set and readline returns) and revert each line to
298 its initial state. */
299int _rl_revert_all_at_newline = 0;
300
Chet Ramey00018032011-11-21 20:51:19 -0500301/* Non-zero means to honor the termios ECHOCTL bit and echo control
302 characters corresponding to keyboard-generated signals. */
303int _rl_echo_control_chars = 1;
304
Chet Rameyac50fba2014-02-26 09:36:43 -0500305/* Non-zero means to prefix the displayed prompt with a character indicating
306 the editing mode: @ for emacs, : for vi-command, + for vi-insert. */
307int _rl_show_mode_in_prompt = 0;
308
Jari Aalto726f6381996-08-26 18:22:31 +0000309/* **************************************************************** */
310/* */
311/* Top Level Functions */
312/* */
313/* **************************************************************** */
314
315/* Non-zero means treat 0200 bit in terminal input as Meta bit. */
316int _rl_meta_flag = 0; /* Forward declaration */
317
Jari Aalto28ef6c32001-04-06 19:14:31 +0000318/* Set up the prompt and expand it. Called from readline() and
319 rl_callback_handler_install (). */
320int
321rl_set_prompt (prompt)
322 const char *prompt;
323{
324 FREE (rl_prompt);
325 rl_prompt = prompt ? savestring (prompt) : (char *)NULL;
Jari Aalto06285672006-10-10 14:15:34 +0000326 rl_display_prompt = rl_prompt ? rl_prompt : "";
Jari Aalto28ef6c32001-04-06 19:14:31 +0000327
Jari Aaltof73dda02001-11-13 17:56:06 +0000328 rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
Jari Aalto28ef6c32001-04-06 19:14:31 +0000329 return 0;
330}
331
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000332/* Read a line of input. Prompt with PROMPT. An empty PROMPT means
Jari Aalto726f6381996-08-26 18:22:31 +0000333 none. A return value of NULL means that EOF was encountered. */
334char *
335readline (prompt)
Jari Aalto28ef6c32001-04-06 19:14:31 +0000336 const char *prompt;
Jari Aalto726f6381996-08-26 18:22:31 +0000337{
338 char *value;
Jari Aalto31859422009-01-12 13:36:28 +0000339#if 0
340 int in_callback;
341#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000342
Jari Aalto726f6381996-08-26 18:22:31 +0000343 /* If we are at EOF return a NULL string. */
344 if (rl_pending_input == EOF)
345 {
Jari Aalto28ef6c32001-04-06 19:14:31 +0000346 rl_clear_pending_input ();
Jari Aalto726f6381996-08-26 18:22:31 +0000347 return ((char *)NULL);
348 }
349
Jari Aalto31859422009-01-12 13:36:28 +0000350#if 0
351 /* If readline() is called after installing a callback handler, temporarily
352 turn off the callback state to avoid ensuing messiness. Patch supplied
353 by the gdb folks. XXX -- disabled. This can be fooled and readline
354 left in a strange state by a poorly-timed longjmp. */
355 if (in_callback = RL_ISSTATE (RL_STATE_CALLBACK))
356 RL_UNSETSTATE (RL_STATE_CALLBACK);
357#endif
358
Jari Aalto28ef6c32001-04-06 19:14:31 +0000359 rl_set_prompt (prompt);
Jari Aalto726f6381996-08-26 18:22:31 +0000360
361 rl_initialize ();
Jari Aalto95732b42005-12-07 14:08:12 +0000362 if (rl_prep_term_function)
363 (*rl_prep_term_function) (_rl_meta_flag);
Jari Aalto726f6381996-08-26 18:22:31 +0000364
365#if defined (HANDLE_SIGNALS)
366 rl_set_signals ();
367#endif
368
369 value = readline_internal ();
Jari Aalto95732b42005-12-07 14:08:12 +0000370 if (rl_deprep_term_function)
371 (*rl_deprep_term_function) ();
Jari Aalto726f6381996-08-26 18:22:31 +0000372
373#if defined (HANDLE_SIGNALS)
374 rl_clear_signals ();
375#endif
376
Jari Aalto31859422009-01-12 13:36:28 +0000377#if 0
378 if (in_callback)
379 RL_SETSTATE (RL_STATE_CALLBACK);
380#endif
381
Chet Rameyac50fba2014-02-26 09:36:43 -0500382#if HAVE_DECL_AUDIT_TTY && defined (ENABLE_TTY_AUDIT_SUPPORT)
383 if (value)
384 _rl_audit_tty (value);
385#endif
386
Jari Aalto726f6381996-08-26 18:22:31 +0000387 return (value);
388}
389
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000390#if defined (READLINE_CALLBACKS)
391# define STATIC_CALLBACK
392#else
393# define STATIC_CALLBACK static
394#endif
395
396STATIC_CALLBACK void
397readline_internal_setup ()
Jari Aalto726f6381996-08-26 18:22:31 +0000398{
Jari Aaltobb706242000-03-17 21:46:59 +0000399 char *nprompt;
400
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000401 _rl_in_stream = rl_instream;
402 _rl_out_stream = rl_outstream;
Jari Aalto726f6381996-08-26 18:22:31 +0000403
Chet Rameyac50fba2014-02-26 09:36:43 -0500404 /* Enable the meta key only for the duration of readline(), if this
405 terminal has one and the terminal has been initialized */
406 if (_rl_enable_meta & RL_ISSTATE (RL_STATE_TERMPREPPED))
407 _rl_enable_meta_key ();
408
Jari Aalto726f6381996-08-26 18:22:31 +0000409 if (rl_startup_hook)
410 (*rl_startup_hook) ();
411
Chet Rameyac50fba2014-02-26 09:36:43 -0500412#if defined (VI_MODE)
413 if (rl_editing_mode == vi_mode)
414 rl_vi_insertion_mode (1, 'i'); /* don't want to reset last */
415#endif /* VI_MODE */
416
Jari Aalto7117c2d2002-07-17 14:10:11 +0000417 /* If we're not echoing, we still want to at least print a prompt, because
418 rl_redisplay will not do it for us. If the calling application has a
419 custom redisplay function, though, let that function handle it. */
Jari Aalto31859422009-01-12 13:36:28 +0000420 if (_rl_echoing_p == 0 && rl_redisplay_function == rl_redisplay)
Jari Aalto726f6381996-08-26 18:22:31 +0000421 {
Jari Aaltobb706242000-03-17 21:46:59 +0000422 if (rl_prompt && rl_already_prompted == 0)
Jari Aalto726f6381996-08-26 18:22:31 +0000423 {
Jari Aaltobb706242000-03-17 21:46:59 +0000424 nprompt = _rl_strip_prompt (rl_prompt);
425 fprintf (_rl_out_stream, "%s", nprompt);
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000426 fflush (_rl_out_stream);
Chet Ramey495aee42011-11-22 19:11:26 -0500427 xfree (nprompt);
Jari Aalto726f6381996-08-26 18:22:31 +0000428 }
429 }
430 else
431 {
Jari Aaltobb706242000-03-17 21:46:59 +0000432 if (rl_prompt && rl_already_prompted)
433 rl_on_new_line_with_prompt ();
434 else
435 rl_on_new_line ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000436 (*rl_redisplay_function) ();
Jari Aalto726f6381996-08-26 18:22:31 +0000437 }
Jari Aaltob72432f1999-02-19 17:11:39 +0000438
439 if (rl_pre_input_hook)
440 (*rl_pre_input_hook) ();
Jari Aalto17345e52009-02-19 22:21:29 +0000441
442 RL_CHECK_SIGNALS ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000443}
Jari Aalto726f6381996-08-26 18:22:31 +0000444
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000445STATIC_CALLBACK char *
446readline_internal_teardown (eof)
447 int eof;
448{
449 char *temp;
450 HIST_ENTRY *entry;
451
Jari Aalto17345e52009-02-19 22:21:29 +0000452 RL_CHECK_SIGNALS ();
453
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000454 /* Restore the original of this history line, iff the line that we
455 are editing was originally in the history, AND the line has changed. */
456 entry = current_history ();
457
458 if (entry && rl_undo_list)
Jari Aalto726f6381996-08-26 18:22:31 +0000459 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000460 temp = savestring (the_line);
461 rl_revert_line (1, 0);
Jari Aaltob72432f1999-02-19 17:11:39 +0000462 entry = replace_history_entry (where_history (), the_line, (histdata_t)NULL);
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000463 _rl_free_history_entry (entry);
464
465 strcpy (the_line, temp);
Chet Ramey495aee42011-11-22 19:11:26 -0500466 xfree (temp);
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000467 }
468
Jari Aalto31859422009-01-12 13:36:28 +0000469 if (_rl_revert_all_at_newline)
470 _rl_revert_all_lines ();
471
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000472 /* At any rate, it is highly likely that this line has an undo list. Get
473 rid of it now. */
474 if (rl_undo_list)
Jari Aalto28ef6c32001-04-06 19:14:31 +0000475 rl_free_undo_list ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000476
Chet Rameyac50fba2014-02-26 09:36:43 -0500477 /* Disable the meta key, if this terminal has one and we were told to use it.
478 The check whether or not we sent the enable string is in
479 _rl_disable_meta_key(); the flag is set in _rl_enable_meta_key */
480 _rl_disable_meta_key ();
481
Jari Aalto7117c2d2002-07-17 14:10:11 +0000482 /* Restore normal cursor, if available. */
483 _rl_set_insert_mode (RL_IM_INSERT, 0);
484
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000485 return (eof ? (char *)NULL : savestring (the_line));
486}
487
Jari Aalto95732b42005-12-07 14:08:12 +0000488void
489_rl_internal_char_cleanup ()
490{
491#if defined (VI_MODE)
492 /* In vi mode, when you exit insert mode, the cursor moves back
493 over the previous character. We explicitly check for that here. */
494 if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
495 rl_vi_check ();
496#endif /* VI_MODE */
497
498 if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read)
499 {
500 (*rl_redisplay_function) ();
501 _rl_want_redisplay = 0;
502 rl_newline (1, '\n');
503 }
504
505 if (rl_done == 0)
506 {
507 (*rl_redisplay_function) ();
508 _rl_want_redisplay = 0;
509 }
510
511 /* If the application writer has told us to erase the entire line if
512 the only character typed was something bound to rl_newline, do so. */
513 if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
514 rl_point == 0 && rl_end == 0)
515 _rl_erase_entire_line ();
516}
517
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000518STATIC_CALLBACK int
519#if defined (READLINE_CALLBACKS)
520readline_internal_char ()
521#else
522readline_internal_charloop ()
523#endif
524{
525 static int lastc, eof_found;
526 int c, code, lk;
527
528 lastc = -1;
529 eof_found = 0;
530
531#if !defined (READLINE_CALLBACKS)
532 while (rl_done == 0)
533 {
534#endif
535 lk = _rl_last_command_was_kill;
Jari Aalto726f6381996-08-26 18:22:31 +0000536
Chet Rameyac50fba2014-02-26 09:36:43 -0500537#if defined (HAVE_POSIX_SIGSETJMP)
538 code = sigsetjmp (_rl_top_level, 0);
539#else
Jari Aalto31859422009-01-12 13:36:28 +0000540 code = setjmp (_rl_top_level);
Chet Rameyac50fba2014-02-26 09:36:43 -0500541#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000542
543 if (code)
Jari Aalto95732b42005-12-07 14:08:12 +0000544 {
545 (*rl_redisplay_function) ();
546 _rl_want_redisplay = 0;
547 /* If we get here, we're not being called from something dispatched
548 from _rl_callback_read_char(), which sets up its own value of
Jari Aalto31859422009-01-12 13:36:28 +0000549 _rl_top_level (saving and restoring the old, of course), so
Jari Aalto95732b42005-12-07 14:08:12 +0000550 we can just return here. */
551 if (RL_ISSTATE (RL_STATE_CALLBACK))
552 return (0);
553 }
Jari Aalto726f6381996-08-26 18:22:31 +0000554
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000555 if (rl_pending_input == 0)
Jari Aalto726f6381996-08-26 18:22:31 +0000556 {
557 /* Then initialize the argument and number of keys read. */
Jari Aalto95732b42005-12-07 14:08:12 +0000558 _rl_reset_argument ();
Jari Aalto726f6381996-08-26 18:22:31 +0000559 rl_key_sequence_length = 0;
Chet Rameyac50fba2014-02-26 09:36:43 -0500560 rl_executing_keyseq[0] = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000561 }
562
Jari Aalto28ef6c32001-04-06 19:14:31 +0000563 RL_SETSTATE(RL_STATE_READCMD);
Jari Aalto726f6381996-08-26 18:22:31 +0000564 c = rl_read_key ();
Jari Aalto28ef6c32001-04-06 19:14:31 +0000565 RL_UNSETSTATE(RL_STATE_READCMD);
Jari Aalto726f6381996-08-26 18:22:31 +0000566
Jari Aalto06285672006-10-10 14:15:34 +0000567 /* look at input.c:rl_getc() for the circumstances under which this will
568 be returned; punt immediately on read error without converting it to
Chet Rameyac50fba2014-02-26 09:36:43 -0500569 a newline; assume that rl_read_key has already called the signal
570 handler. */
Jari Aalto06285672006-10-10 14:15:34 +0000571 if (c == READERR)
572 {
573#if defined (READLINE_CALLBACKS)
574 RL_SETSTATE(RL_STATE_DONE);
575 return (rl_done = 1);
576#else
577 eof_found = 1;
578 break;
579#endif
580 }
581
Chet Rameyac50fba2014-02-26 09:36:43 -0500582 /* EOF typed to a non-blank line is a <NL>. If we want to change this,
583 to force any existing line to be ignored when read(2) reads EOF,
584 for example, this is the place to change. */
Jari Aalto726f6381996-08-26 18:22:31 +0000585 if (c == EOF && rl_end)
586 c = NEWLINE;
587
588 /* The character _rl_eof_char typed to blank line, and not as the
589 previous character is interpreted as EOF. */
590 if (((c == _rl_eof_char && lastc != c) || c == EOF) && !rl_end)
591 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000592#if defined (READLINE_CALLBACKS)
Jari Aalto28ef6c32001-04-06 19:14:31 +0000593 RL_SETSTATE(RL_STATE_DONE);
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000594 return (rl_done = 1);
595#else
Jari Aalto726f6381996-08-26 18:22:31 +0000596 eof_found = 1;
597 break;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000598#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000599 }
600
601 lastc = c;
Jari Aaltobb706242000-03-17 21:46:59 +0000602 _rl_dispatch ((unsigned char)c, _rl_keymap);
Jari Aalto17345e52009-02-19 22:21:29 +0000603 RL_CHECK_SIGNALS ();
Jari Aalto726f6381996-08-26 18:22:31 +0000604
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000605 /* If there was no change in _rl_last_command_was_kill, then no kill
Jari Aalto726f6381996-08-26 18:22:31 +0000606 has taken place. Note that if input is pending we are reading
607 a prefix command, so nothing has changed yet. */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000608 if (rl_pending_input == 0 && lk == _rl_last_command_was_kill)
609 _rl_last_command_was_kill = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000610
Jari Aalto95732b42005-12-07 14:08:12 +0000611 _rl_internal_char_cleanup ();
Jari Aaltob72432f1999-02-19 17:11:39 +0000612
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000613#if defined (READLINE_CALLBACKS)
614 return 0;
615#else
Jari Aalto726f6381996-08-26 18:22:31 +0000616 }
617
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000618 return (eof_found);
Jari Aalto726f6381996-08-26 18:22:31 +0000619#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000620}
621
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000622#if defined (READLINE_CALLBACKS)
623static int
624readline_internal_charloop ()
Jari Aalto726f6381996-08-26 18:22:31 +0000625{
Jari Aaltob72432f1999-02-19 17:11:39 +0000626 int eof = 1;
Jari Aalto726f6381996-08-26 18:22:31 +0000627
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000628 while (rl_done == 0)
629 eof = readline_internal_char ();
630 return (eof);
631}
632#endif /* READLINE_CALLBACKS */
Jari Aalto726f6381996-08-26 18:22:31 +0000633
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000634/* Read a line of input from the global rl_instream, doing output on
635 the global rl_outstream.
636 If rl_prompt is non-null, then that is our prompt. */
637static char *
638readline_internal ()
639{
640 int eof;
Jari Aalto726f6381996-08-26 18:22:31 +0000641
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000642 readline_internal_setup ();
643 eof = readline_internal_charloop ();
644 return (readline_internal_teardown (eof));
Jari Aalto726f6381996-08-26 18:22:31 +0000645}
646
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000647void
Jari Aaltod166f041997-06-05 14:59:13 +0000648_rl_init_line_state ()
649{
Jari Aalto7117c2d2002-07-17 14:10:11 +0000650 rl_point = rl_end = rl_mark = 0;
Jari Aaltod166f041997-06-05 14:59:13 +0000651 the_line = rl_line_buffer;
652 the_line[0] = 0;
653}
654
655void
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000656_rl_set_the_line ()
657{
658 the_line = rl_line_buffer;
659}
Jari Aalto726f6381996-08-26 18:22:31 +0000660
Jari Aalto95732b42005-12-07 14:08:12 +0000661#if defined (READLINE_CALLBACKS)
662_rl_keyseq_cxt *
663_rl_keyseq_cxt_alloc ()
664{
665 _rl_keyseq_cxt *cxt;
666
667 cxt = (_rl_keyseq_cxt *)xmalloc (sizeof (_rl_keyseq_cxt));
668
669 cxt->flags = cxt->subseq_arg = cxt->subseq_retval = 0;
670
671 cxt->okey = 0;
672 cxt->ocxt = _rl_kscxt;
673 cxt->childval = 42; /* sentinel value */
674
675 return cxt;
676}
677
678void
679_rl_keyseq_cxt_dispose (cxt)
680 _rl_keyseq_cxt *cxt;
681{
Chet Ramey495aee42011-11-22 19:11:26 -0500682 xfree (cxt);
Jari Aalto95732b42005-12-07 14:08:12 +0000683}
684
685void
686_rl_keyseq_chain_dispose ()
687{
688 _rl_keyseq_cxt *cxt;
689
690 while (_rl_kscxt)
691 {
692 cxt = _rl_kscxt;
693 _rl_kscxt = _rl_kscxt->ocxt;
694 _rl_keyseq_cxt_dispose (cxt);
695 }
696}
697#endif
698
699static int
700_rl_subseq_getchar (key)
701 int key;
702{
703 int k;
704
705 if (key == ESC)
706 RL_SETSTATE(RL_STATE_METANEXT);
707 RL_SETSTATE(RL_STATE_MOREINPUT);
708 k = rl_read_key ();
709 RL_UNSETSTATE(RL_STATE_MOREINPUT);
710 if (key == ESC)
711 RL_UNSETSTATE(RL_STATE_METANEXT);
712
713 return k;
714}
715
716#if defined (READLINE_CALLBACKS)
717int
718_rl_dispatch_callback (cxt)
719 _rl_keyseq_cxt *cxt;
720{
721 int nkey, r;
722
723 /* For now */
Jari Aalto95732b42005-12-07 14:08:12 +0000724 /* The first time this context is used, we want to read input and dispatch
725 on it. When traversing the chain of contexts back `up', we want to use
726 the value from the next context down. We're simulating recursion using
727 a chain of contexts. */
728 if ((cxt->flags & KSEQ_DISPATCHED) == 0)
729 {
730 nkey = _rl_subseq_getchar (cxt->okey);
Jari Aaltof1be6662008-11-18 13:15:12 +0000731 if (nkey < 0)
732 {
733 _rl_abort_internal ();
734 return -1;
735 }
Jari Aalto95732b42005-12-07 14:08:12 +0000736 r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
737 cxt->flags |= KSEQ_DISPATCHED;
738 }
739 else
740 r = cxt->childval;
Jari Aalto95732b42005-12-07 14:08:12 +0000741
742 /* For now */
Chet Ramey00018032011-11-21 20:51:19 -0500743 if (r != -3) /* don't do this if we indicate there will be other matches */
744 r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
Jari Aalto95732b42005-12-07 14:08:12 +0000745
Jari Aalto17345e52009-02-19 22:21:29 +0000746 RL_CHECK_SIGNALS ();
Chet Ramey1233ce52014-03-28 11:53:20 -0400747 /* We only treat values < 0 specially to simulate recursion. */
748 if (r >= 0 || (r == -1 && (cxt->flags & KSEQ_SUBSEQ) == 0)) /* success! or failure! */
Jari Aalto95732b42005-12-07 14:08:12 +0000749 {
750 _rl_keyseq_chain_dispose ();
751 RL_UNSETSTATE (RL_STATE_MULTIKEY);
752 return r;
753 }
754
755 if (r != -3) /* magic value that says we added to the chain */
756 _rl_kscxt = cxt->ocxt;
757 if (_rl_kscxt)
758 _rl_kscxt->childval = r;
759 if (r != -3)
760 _rl_keyseq_cxt_dispose (cxt);
761
762 return r;
763}
764#endif /* READLINE_CALLBACKS */
765
Jari Aalto726f6381996-08-26 18:22:31 +0000766/* Do the command associated with KEY in MAP.
767 If the associated command is really a keymap, then read
768 another key, and dispatch into that map. */
769int
770_rl_dispatch (key, map)
771 register int key;
772 Keymap map;
773{
Jari Aalto95732b42005-12-07 14:08:12 +0000774 _rl_dispatching_keymap = map;
Jari Aalto7117c2d2002-07-17 14:10:11 +0000775 return _rl_dispatch_subseq (key, map, 0);
776}
777
778int
779_rl_dispatch_subseq (key, map, got_subseq)
780 register int key;
781 Keymap map;
782 int got_subseq;
783{
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000784 int r, newkey;
785 char *macro;
Jari Aalto28ef6c32001-04-06 19:14:31 +0000786 rl_command_func_t *func;
Jari Aalto95732b42005-12-07 14:08:12 +0000787#if defined (READLINE_CALLBACKS)
788 _rl_keyseq_cxt *cxt;
789#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000790
791 if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
792 {
793 if (map[ESC].type == ISKMAP)
794 {
Jari Aalto7117c2d2002-07-17 14:10:11 +0000795 if (RL_ISSTATE (RL_STATE_MACRODEF))
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000796 _rl_add_macro_char (ESC);
Chet Rameyac50fba2014-02-26 09:36:43 -0500797 RESIZE_KEYSEQ_BUFFER ();
798 rl_executing_keyseq[rl_key_sequence_length++] = ESC;
Jari Aalto726f6381996-08-26 18:22:31 +0000799 map = FUNCTION_TO_KEYMAP (map, ESC);
800 key = UNMETA (key);
Jari Aalto726f6381996-08-26 18:22:31 +0000801 return (_rl_dispatch (key, map));
802 }
803 else
Jari Aalto28ef6c32001-04-06 19:14:31 +0000804 rl_ding ();
Jari Aalto726f6381996-08-26 18:22:31 +0000805 return 0;
806 }
807
Jari Aalto7117c2d2002-07-17 14:10:11 +0000808 if (RL_ISSTATE (RL_STATE_MACRODEF))
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000809 _rl_add_macro_char (key);
Jari Aalto726f6381996-08-26 18:22:31 +0000810
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000811 r = 0;
Jari Aalto726f6381996-08-26 18:22:31 +0000812 switch (map[key].type)
813 {
814 case ISFUNC:
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000815 func = map[key].function;
Jari Aalto28ef6c32001-04-06 19:14:31 +0000816 if (func)
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000817 {
818 /* Special case rl_do_lowercase_version (). */
819 if (func == rl_do_lowercase_version)
Chet Rameyac50fba2014-02-26 09:36:43 -0500820 /* Should we do anything special if key == ANYOTHERKEY? */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000821 return (_rl_dispatch (_rl_to_lower (key), map));
Jari Aalto726f6381996-08-26 18:22:31 +0000822
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000823 rl_executing_keymap = map;
Chet Rameyac50fba2014-02-26 09:36:43 -0500824 rl_executing_key = key;
825
826 RESIZE_KEYSEQ_BUFFER();
827 rl_executing_keyseq[rl_key_sequence_length++] = key;
828 rl_executing_keyseq[rl_key_sequence_length] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +0000829
Jari Aaltod166f041997-06-05 14:59:13 +0000830 rl_dispatching = 1;
Jari Aalto28ef6c32001-04-06 19:14:31 +0000831 RL_SETSTATE(RL_STATE_DISPATCHING);
Chet Rameyac50fba2014-02-26 09:36:43 -0500832 r = (*func) (rl_numeric_arg * rl_arg_sign, key);
Jari Aalto28ef6c32001-04-06 19:14:31 +0000833 RL_UNSETSTATE(RL_STATE_DISPATCHING);
Jari Aaltod166f041997-06-05 14:59:13 +0000834 rl_dispatching = 0;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000835
836 /* If we have input pending, then the last command was a prefix
837 command. Don't change the state of rl_last_func. Otherwise,
838 remember the last command executed in this variable. */
Jari Aalto28ef6c32001-04-06 19:14:31 +0000839 if (rl_pending_input == 0 && map[key].function != rl_digit_argument)
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000840 rl_last_func = map[key].function;
Jari Aalto17345e52009-02-19 22:21:29 +0000841
842 RL_CHECK_SIGNALS ();
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000843 }
Jari Aalto7117c2d2002-07-17 14:10:11 +0000844 else if (map[ANYOTHERKEY].function)
845 {
846 /* OK, there's no function bound in this map, but there is a
847 shadow function that was overridden when the current keymap
848 was created. Return -2 to note that. */
Chet Rameyac50fba2014-02-26 09:36:43 -0500849 if (RL_ISSTATE (RL_STATE_MACROINPUT))
850 _rl_prev_macro_key ();
851 else
852 _rl_unget_char (key);
Jari Aalto7117c2d2002-07-17 14:10:11 +0000853 return -2;
854 }
855 else if (got_subseq)
856 {
857 /* Return -1 to note that we're in a subsequence, but we don't
858 have a matching key, nor was one overridden. This means
859 we need to back up the recursion chain and find the last
860 subsequence that is bound to a function. */
Chet Rameyac50fba2014-02-26 09:36:43 -0500861 if (RL_ISSTATE (RL_STATE_MACROINPUT))
862 _rl_prev_macro_key ();
863 else
864 _rl_unget_char (key);
Jari Aalto7117c2d2002-07-17 14:10:11 +0000865 return -1;
866 }
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000867 else
868 {
Jari Aalto95732b42005-12-07 14:08:12 +0000869#if defined (READLINE_CALLBACKS)
870 RL_UNSETSTATE (RL_STATE_MULTIKEY);
871 _rl_keyseq_chain_dispose ();
872#endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000873 _rl_abort_internal ();
874 return -1;
875 }
Jari Aalto726f6381996-08-26 18:22:31 +0000876 break;
877
878 case ISKMAP:
Jari Aalto28ef6c32001-04-06 19:14:31 +0000879 if (map[key].function != 0)
Jari Aalto726f6381996-08-26 18:22:31 +0000880 {
Jari Aalto7117c2d2002-07-17 14:10:11 +0000881#if defined (VI_MODE)
882 /* The only way this test will be true is if a subsequence has been
883 bound starting with ESC, generally the arrow keys. What we do is
884 check whether there's input in the queue, which there generally
885 will be if an arrow key has been pressed, and, if there's not,
886 just dispatch to (what we assume is) rl_vi_movement_mode right
Chet Rameyac50fba2014-02-26 09:36:43 -0500887 away. This is essentially an input test with a zero timeout (by
888 default) or a timeout determined by the value of `keyseq-timeout' */
889 /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
890 takes microseconds, so multiply by 1000 */
Jari Aalto7117c2d2002-07-17 14:10:11 +0000891 if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap
Chet Rameyac50fba2014-02-26 09:36:43 -0500892 && _rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0)
Jari Aalto7117c2d2002-07-17 14:10:11 +0000893 return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key)));
894#endif
895
Chet Rameyac50fba2014-02-26 09:36:43 -0500896 RESIZE_KEYSEQ_BUFFER ();
897 rl_executing_keyseq[rl_key_sequence_length++] = key;
Jari Aalto95732b42005-12-07 14:08:12 +0000898 _rl_dispatching_keymap = FUNCTION_TO_KEYMAP (map, key);
Jari Aalto28ef6c32001-04-06 19:14:31 +0000899
Jari Aalto95732b42005-12-07 14:08:12 +0000900 /* Allocate new context here. Use linked contexts (linked through
901 cxt->ocxt) to simulate recursion */
902#if defined (READLINE_CALLBACKS)
903 if (RL_ISSTATE (RL_STATE_CALLBACK))
904 {
905 /* Return 0 only the first time, to indicate success to
906 _rl_callback_read_char. The rest of the time, we're called
Chet Ramey00018032011-11-21 20:51:19 -0500907 from _rl_dispatch_callback, so we return -3 to indicate
Jari Aalto95732b42005-12-07 14:08:12 +0000908 special handling is necessary. */
909 r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0;
910 cxt = _rl_keyseq_cxt_alloc ();
Jari Aalto28ef6c32001-04-06 19:14:31 +0000911
Jari Aalto95732b42005-12-07 14:08:12 +0000912 if (got_subseq)
913 cxt->flags |= KSEQ_SUBSEQ;
914 cxt->okey = key;
915 cxt->oldmap = map;
916 cxt->dmap = _rl_dispatching_keymap;
917 cxt->subseq_arg = got_subseq || cxt->dmap[ANYOTHERKEY].function;
918
919 RL_SETSTATE (RL_STATE_MULTIKEY);
920 _rl_kscxt = cxt;
921
922 return r; /* don't indicate immediate success */
923 }
924#endif
925
Chet Rameyac50fba2014-02-26 09:36:43 -0500926 /* Tentative inter-character timeout for potential multi-key
927 sequences? If no input within timeout, abort sequence and
928 act as if we got non-matching input. */
929 /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
930 takes microseconds, so multiply by 1000 */
931 if (_rl_keyseq_timeout > 0 &&
932 (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
933 _rl_pushed_input_available () == 0 &&
934 _rl_dispatching_keymap[ANYOTHERKEY].function &&
935 _rl_input_queued (_rl_keyseq_timeout*1000) == 0)
936 return (_rl_subseq_result (-2, map, key, got_subseq));
937
Jari Aalto95732b42005-12-07 14:08:12 +0000938 newkey = _rl_subseq_getchar (key);
Jari Aaltof73dda02001-11-13 17:56:06 +0000939 if (newkey < 0)
940 {
941 _rl_abort_internal ();
942 return -1;
943 }
944
Jari Aalto95732b42005-12-07 14:08:12 +0000945 r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq || map[ANYOTHERKEY].function);
946 return _rl_subseq_result (r, map, key, got_subseq);
Jari Aalto726f6381996-08-26 18:22:31 +0000947 }
948 else
949 {
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000950 _rl_abort_internal ();
Jari Aalto726f6381996-08-26 18:22:31 +0000951 return -1;
952 }
953 break;
954
955 case ISMACR:
Jari Aalto28ef6c32001-04-06 19:14:31 +0000956 if (map[key].function != 0)
Jari Aalto726f6381996-08-26 18:22:31 +0000957 {
Chet Rameyac50fba2014-02-26 09:36:43 -0500958 rl_executing_keyseq[rl_key_sequence_length] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +0000959 macro = savestring ((char *)map[key].function);
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000960 _rl_with_macro_input (macro);
Jari Aalto726f6381996-08-26 18:22:31 +0000961 return 0;
962 }
963 break;
964 }
965#if defined (VI_MODE)
966 if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
Jari Aaltob80f6442004-07-27 13:29:18 +0000967 key != ANYOTHERKEY &&
Chet Ramey84fc3e22014-03-28 11:53:30 -0400968 _rl_dispatching_keymap == vi_movement_keymap &&
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000969 _rl_vi_textmod_command (key))
Jari Aalto726f6381996-08-26 18:22:31 +0000970 _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
971#endif
Jari Aalto95732b42005-12-07 14:08:12 +0000972
Jari Aalto726f6381996-08-26 18:22:31 +0000973 return (r);
974}
975
Jari Aalto95732b42005-12-07 14:08:12 +0000976static int
977_rl_subseq_result (r, map, key, got_subseq)
978 int r;
979 Keymap map;
980 int key, got_subseq;
981{
982 Keymap m;
983 int type, nt;
984 rl_command_func_t *func, *nf;
Chet Ramey00018032011-11-21 20:51:19 -0500985
Jari Aalto95732b42005-12-07 14:08:12 +0000986 if (r == -2)
987 /* We didn't match anything, and the keymap we're indexed into
988 shadowed a function previously bound to that prefix. Call
989 the function. The recursive call to _rl_dispatch_subseq has
990 already taken care of pushing any necessary input back onto
991 the input queue with _rl_unget_char. */
992 {
993 m = _rl_dispatching_keymap;
994 type = m[ANYOTHERKEY].type;
995 func = m[ANYOTHERKEY].function;
996 if (type == ISFUNC && func == rl_do_lowercase_version)
997 r = _rl_dispatch (_rl_to_lower (key), map);
998 else if (type == ISFUNC && func == rl_insert)
999 {
1000 /* If the function that was shadowed was self-insert, we
1001 somehow need a keymap with map[key].func == self-insert.
1002 Let's use this one. */
1003 nt = m[key].type;
1004 nf = m[key].function;
1005
1006 m[key].type = type;
1007 m[key].function = func;
1008 r = _rl_dispatch (key, m);
1009 m[key].type = nt;
1010 m[key].function = nf;
1011 }
1012 else
1013 r = _rl_dispatch (ANYOTHERKEY, m);
1014 }
1015 else if (r && map[ANYOTHERKEY].function)
1016 {
1017 /* We didn't match (r is probably -1), so return something to
1018 tell the caller that it should try ANYOTHERKEY for an
1019 overridden function. */
Chet Rameyac50fba2014-02-26 09:36:43 -05001020 if (RL_ISSTATE (RL_STATE_MACROINPUT))
1021 _rl_prev_macro_key ();
1022 else
1023 _rl_unget_char (key);
Jari Aalto95732b42005-12-07 14:08:12 +00001024 _rl_dispatching_keymap = map;
1025 return -2;
1026 }
1027 else if (r && got_subseq)
1028 {
1029 /* OK, back up the chain. */
Chet Rameyac50fba2014-02-26 09:36:43 -05001030 if (RL_ISSTATE (RL_STATE_MACROINPUT))
1031 _rl_prev_macro_key ();
1032 else
1033 _rl_unget_char (key);
Jari Aalto95732b42005-12-07 14:08:12 +00001034 _rl_dispatching_keymap = map;
1035 return -1;
1036 }
1037
1038 return r;
1039}
1040
Jari Aalto726f6381996-08-26 18:22:31 +00001041/* **************************************************************** */
1042/* */
1043/* Initializations */
1044/* */
1045/* **************************************************************** */
1046
Jari Aaltod166f041997-06-05 14:59:13 +00001047/* Initialize readline (and terminal if not already). */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001048int
Jari Aalto726f6381996-08-26 18:22:31 +00001049rl_initialize ()
1050{
1051 /* If we have never been called before, initialize the
1052 terminal and data structures. */
1053 if (!rl_initialized)
1054 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00001055 RL_SETSTATE(RL_STATE_INITIALIZING);
Jari Aalto726f6381996-08-26 18:22:31 +00001056 readline_initialize_everything ();
Jari Aalto28ef6c32001-04-06 19:14:31 +00001057 RL_UNSETSTATE(RL_STATE_INITIALIZING);
Jari Aalto726f6381996-08-26 18:22:31 +00001058 rl_initialized++;
Jari Aalto28ef6c32001-04-06 19:14:31 +00001059 RL_SETSTATE(RL_STATE_INITIALIZED);
Jari Aalto726f6381996-08-26 18:22:31 +00001060 }
1061
Chet Rameyac50fba2014-02-26 09:36:43 -05001062 /* Initialize the current line information. */
Jari Aaltod166f041997-06-05 14:59:13 +00001063 _rl_init_line_state ();
Jari Aalto726f6381996-08-26 18:22:31 +00001064
1065 /* We aren't done yet. We haven't even gotten started yet! */
1066 rl_done = 0;
Jari Aalto28ef6c32001-04-06 19:14:31 +00001067 RL_UNSETSTATE(RL_STATE_DONE);
Jari Aalto726f6381996-08-26 18:22:31 +00001068
1069 /* Tell the history routines what is going on. */
Jari Aalto7117c2d2002-07-17 14:10:11 +00001070 _rl_start_using_history ();
Jari Aalto726f6381996-08-26 18:22:31 +00001071
1072 /* Make the display buffer match the state of the line. */
1073 rl_reset_line_state ();
1074
1075 /* No such function typed yet. */
Jari Aalto28ef6c32001-04-06 19:14:31 +00001076 rl_last_func = (rl_command_func_t *)NULL;
Jari Aalto726f6381996-08-26 18:22:31 +00001077
1078 /* Parsing of key-bindings begins in an enabled state. */
1079 _rl_parsing_conditionalized_out = 0;
1080
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001081#if defined (VI_MODE)
1082 if (rl_editing_mode == vi_mode)
1083 _rl_vi_initialize_line ();
1084#endif
1085
Jari Aalto7117c2d2002-07-17 14:10:11 +00001086 /* Each line starts in insert mode (the default). */
1087 _rl_set_insert_mode (RL_IM_DEFAULT, 1);
1088
Jari Aalto726f6381996-08-26 18:22:31 +00001089 return 0;
1090}
1091
Jari Aaltobb706242000-03-17 21:46:59 +00001092#if 0
Jari Aaltod166f041997-06-05 14:59:13 +00001093#if defined (__EMX__)
1094static void
1095_emx_build_environ ()
1096{
1097 TIB *tibp;
1098 PIB *pibp;
1099 char *t, **tp;
1100 int c;
1101
1102 DosGetInfoBlocks (&tibp, &pibp);
1103 t = pibp->pib_pchenv;
1104 for (c = 1; *t; c++)
1105 t += strlen (t) + 1;
1106 tp = environ = (char **)xmalloc ((c + 1) * sizeof (char *));
1107 t = pibp->pib_pchenv;
1108 while (*t)
1109 {
1110 *tp++ = t;
1111 t += strlen (t) + 1;
1112 }
1113 *tp = 0;
1114}
1115#endif /* __EMX__ */
Jari Aaltobb706242000-03-17 21:46:59 +00001116#endif
Jari Aaltod166f041997-06-05 14:59:13 +00001117
Jari Aalto726f6381996-08-26 18:22:31 +00001118/* Initialize the entire state of the world. */
1119static void
1120readline_initialize_everything ()
1121{
Jari Aaltobb706242000-03-17 21:46:59 +00001122#if 0
Jari Aaltod166f041997-06-05 14:59:13 +00001123#if defined (__EMX__)
1124 if (environ == 0)
1125 _emx_build_environ ();
1126#endif
Jari Aaltobb706242000-03-17 21:46:59 +00001127#endif
Jari Aaltod166f041997-06-05 14:59:13 +00001128
Jari Aalto28ef6c32001-04-06 19:14:31 +00001129#if 0
1130 /* Find out if we are running in Emacs -- UNUSED. */
1131 running_in_emacs = sh_get_env_value ("EMACS") != (char *)0;
1132#endif
Jari Aalto726f6381996-08-26 18:22:31 +00001133
1134 /* Set up input and output if they are not already set up. */
1135 if (!rl_instream)
1136 rl_instream = stdin;
1137
1138 if (!rl_outstream)
1139 rl_outstream = stdout;
1140
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001141 /* Bind _rl_in_stream and _rl_out_stream immediately. These values
1142 may change, but they may also be used before readline_internal ()
1143 is called. */
1144 _rl_in_stream = rl_instream;
1145 _rl_out_stream = rl_outstream;
Jari Aalto726f6381996-08-26 18:22:31 +00001146
1147 /* Allocate data structures. */
Jari Aaltod166f041997-06-05 14:59:13 +00001148 if (rl_line_buffer == 0)
Jari Aaltof73dda02001-11-13 17:56:06 +00001149 rl_line_buffer = (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE);
Jari Aalto726f6381996-08-26 18:22:31 +00001150
1151 /* Initialize the terminal interface. */
Jari Aalto28ef6c32001-04-06 19:14:31 +00001152 if (rl_terminal_name == 0)
1153 rl_terminal_name = sh_get_env_value ("TERM");
1154 _rl_init_terminal_io (rl_terminal_name);
Jari Aalto726f6381996-08-26 18:22:31 +00001155
Jari Aalto726f6381996-08-26 18:22:31 +00001156 /* Bind tty characters to readline functions. */
1157 readline_default_bindings ();
Jari Aalto726f6381996-08-26 18:22:31 +00001158
1159 /* Initialize the function names. */
1160 rl_initialize_funmap ();
1161
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001162 /* Decide whether we should automatically go into eight-bit mode. */
1163 _rl_init_eightbit ();
Jari Aalto726f6381996-08-26 18:22:31 +00001164
1165 /* Read in the init file. */
1166 rl_read_init_file ((char *)NULL);
1167
1168 /* XXX */
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001169 if (_rl_horizontal_scroll_mode && _rl_term_autowrap)
Jari Aalto726f6381996-08-26 18:22:31 +00001170 {
Jari Aalto28ef6c32001-04-06 19:14:31 +00001171 _rl_screenwidth--;
1172 _rl_screenchars -= _rl_screenheight;
Jari Aalto726f6381996-08-26 18:22:31 +00001173 }
1174
1175 /* Override the effect of any `set keymap' assignments in the
1176 inputrc file. */
1177 rl_set_keymap_from_edit_mode ();
1178
1179 /* Try to bind a common arrow key prefix, if not already bound. */
1180 bind_arrow_keys ();
1181
1182 /* If the completion parser's default word break characters haven't
1183 been set yet, then do so now. */
1184 if (rl_completer_word_break_characters == (char *)NULL)
Jari Aaltob80f6442004-07-27 13:29:18 +00001185 rl_completer_word_break_characters = (char *)rl_basic_word_break_characters;
Chet Rameyac50fba2014-02-26 09:36:43 -05001186
1187#if defined (COLOR_SUPPORT)
1188 if (_rl_colored_stats)
1189 _rl_parse_colors ();
1190#endif
1191
1192 rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
1193 if (rl_executing_keyseq)
1194 rl_executing_keyseq[0] = '\0';
Jari Aalto726f6381996-08-26 18:22:31 +00001195}
1196
1197/* If this system allows us to look at the values of the regular
1198 input editing characters, then bind them to their readline
1199 equivalents, iff the characters are not bound to keymaps. */
1200static void
1201readline_default_bindings ()
1202{
Jari Aalto95732b42005-12-07 14:08:12 +00001203 if (_rl_bind_stty_chars)
1204 rl_tty_set_default_bindings (_rl_keymap);
Jari Aalto726f6381996-08-26 18:22:31 +00001205}
1206
Jari Aaltob80f6442004-07-27 13:29:18 +00001207/* Reset the default bindings for the terminal special characters we're
1208 interested in back to rl_insert and read the new ones. */
1209static void
1210reset_default_bindings ()
1211{
Jari Aalto95732b42005-12-07 14:08:12 +00001212 if (_rl_bind_stty_chars)
1213 {
1214 rl_tty_unset_default_bindings (_rl_keymap);
1215 rl_tty_set_default_bindings (_rl_keymap);
1216 }
Jari Aaltob80f6442004-07-27 13:29:18 +00001217}
1218
Jari Aalto7117c2d2002-07-17 14:10:11 +00001219/* Bind some common arrow key sequences in MAP. */
Jari Aalto726f6381996-08-26 18:22:31 +00001220static void
Jari Aalto7117c2d2002-07-17 14:10:11 +00001221bind_arrow_keys_internal (map)
1222 Keymap map;
Jari Aalto726f6381996-08-26 18:22:31 +00001223{
Jari Aalto7117c2d2002-07-17 14:10:11 +00001224 Keymap xkeymap;
1225
1226 xkeymap = _rl_keymap;
1227 _rl_keymap = map;
Jari Aalto726f6381996-08-26 18:22:31 +00001228
Jari Aaltobb706242000-03-17 21:46:59 +00001229#if defined (__MSDOS__)
Jari Aaltob80f6442004-07-27 13:29:18 +00001230 rl_bind_keyseq_if_unbound ("\033[0A", rl_get_previous_history);
1231 rl_bind_keyseq_if_unbound ("\033[0B", rl_backward_char);
1232 rl_bind_keyseq_if_unbound ("\033[0C", rl_forward_char);
1233 rl_bind_keyseq_if_unbound ("\033[0D", rl_get_next_history);
Jari Aaltobb706242000-03-17 21:46:59 +00001234#endif
Jari Aalto726f6381996-08-26 18:22:31 +00001235
Jari Aaltob80f6442004-07-27 13:29:18 +00001236 rl_bind_keyseq_if_unbound ("\033[A", rl_get_previous_history);
1237 rl_bind_keyseq_if_unbound ("\033[B", rl_get_next_history);
1238 rl_bind_keyseq_if_unbound ("\033[C", rl_forward_char);
1239 rl_bind_keyseq_if_unbound ("\033[D", rl_backward_char);
1240 rl_bind_keyseq_if_unbound ("\033[H", rl_beg_of_line);
1241 rl_bind_keyseq_if_unbound ("\033[F", rl_end_of_line);
Jari Aalto7117c2d2002-07-17 14:10:11 +00001242
Jari Aaltob80f6442004-07-27 13:29:18 +00001243 rl_bind_keyseq_if_unbound ("\033OA", rl_get_previous_history);
1244 rl_bind_keyseq_if_unbound ("\033OB", rl_get_next_history);
1245 rl_bind_keyseq_if_unbound ("\033OC", rl_forward_char);
1246 rl_bind_keyseq_if_unbound ("\033OD", rl_backward_char);
1247 rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line);
1248 rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line);
Jari Aalto7117c2d2002-07-17 14:10:11 +00001249
Jari Aalto95732b42005-12-07 14:08:12 +00001250#if defined (__MINGW32__)
1251 rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history);
1252 rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history);
1253 rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);
1254 rl_bind_keyseq_if_unbound ("\340K", rl_backward_char);
Chet Rameyac50fba2014-02-26 09:36:43 -05001255 rl_bind_keyseq_if_unbound ("\340G", rl_beg_of_line);
1256 rl_bind_keyseq_if_unbound ("\340O", rl_end_of_line);
1257 rl_bind_keyseq_if_unbound ("\340S", rl_delete);
1258 rl_bind_keyseq_if_unbound ("\340R", rl_overwrite_mode);
1259
1260 /* These may or may not work because of the embedded NUL. */
1261 rl_bind_keyseq_if_unbound ("\\000H", rl_get_previous_history);
1262 rl_bind_keyseq_if_unbound ("\\000P", rl_get_next_history);
1263 rl_bind_keyseq_if_unbound ("\\000M", rl_forward_char);
1264 rl_bind_keyseq_if_unbound ("\\000K", rl_backward_char);
1265 rl_bind_keyseq_if_unbound ("\\000G", rl_beg_of_line);
1266 rl_bind_keyseq_if_unbound ("\\000O", rl_end_of_line);
1267 rl_bind_keyseq_if_unbound ("\\000S", rl_delete);
1268 rl_bind_keyseq_if_unbound ("\\000R", rl_overwrite_mode);
Jari Aalto95732b42005-12-07 14:08:12 +00001269#endif
1270
Jari Aalto7117c2d2002-07-17 14:10:11 +00001271 _rl_keymap = xkeymap;
Jari Aalto726f6381996-08-26 18:22:31 +00001272}
1273
Jari Aalto7117c2d2002-07-17 14:10:11 +00001274/* Try and bind the common arrow key prefixes after giving termcap and
Jari Aalto726f6381996-08-26 18:22:31 +00001275 the inputrc file a chance to bind them and create `real' keymaps
1276 for the arrow key prefix. */
1277static void
1278bind_arrow_keys ()
1279{
Jari Aalto7117c2d2002-07-17 14:10:11 +00001280 bind_arrow_keys_internal (emacs_standard_keymap);
Jari Aalto726f6381996-08-26 18:22:31 +00001281
1282#if defined (VI_MODE)
Jari Aalto7117c2d2002-07-17 14:10:11 +00001283 bind_arrow_keys_internal (vi_movement_keymap);
Chet Ramey00018032011-11-21 20:51:19 -05001284 /* Unbind vi_movement_keymap[ESC] to allow users to repeatedly hit ESC
1285 in vi command mode while still allowing the arrow keys to work. */
1286 if (vi_movement_keymap[ESC].type == ISKMAP)
1287 rl_bind_keyseq_in_map ("\033", (rl_command_func_t *)NULL, vi_movement_keymap);
Jari Aalto7117c2d2002-07-17 14:10:11 +00001288 bind_arrow_keys_internal (vi_insertion_keymap);
Jari Aalto726f6381996-08-26 18:22:31 +00001289#endif
Jari Aalto726f6381996-08-26 18:22:31 +00001290}
Jari Aalto726f6381996-08-26 18:22:31 +00001291
Jari Aalto726f6381996-08-26 18:22:31 +00001292/* **************************************************************** */
1293/* */
Jari Aalto7117c2d2002-07-17 14:10:11 +00001294/* Saving and Restoring Readline's state */
Jari Aalto726f6381996-08-26 18:22:31 +00001295/* */
1296/* **************************************************************** */
1297
Jari Aalto726f6381996-08-26 18:22:31 +00001298int
Jari Aalto7117c2d2002-07-17 14:10:11 +00001299rl_save_state (sp)
1300 struct readline_state *sp;
Jari Aalto726f6381996-08-26 18:22:31 +00001301{
Jari Aalto7117c2d2002-07-17 14:10:11 +00001302 if (sp == 0)
Jari Aalto726f6381996-08-26 18:22:31 +00001303 return -1;
1304
Jari Aalto7117c2d2002-07-17 14:10:11 +00001305 sp->point = rl_point;
1306 sp->end = rl_end;
1307 sp->mark = rl_mark;
1308 sp->buffer = rl_line_buffer;
1309 sp->buflen = rl_line_buffer_len;
1310 sp->ul = rl_undo_list;
1311 sp->prompt = rl_prompt;
Jari Aalto726f6381996-08-26 18:22:31 +00001312
Jari Aalto7117c2d2002-07-17 14:10:11 +00001313 sp->rlstate = rl_readline_state;
1314 sp->done = rl_done;
1315 sp->kmap = _rl_keymap;
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001316
Jari Aalto7117c2d2002-07-17 14:10:11 +00001317 sp->lastfunc = rl_last_func;
1318 sp->insmode = rl_insert_mode;
1319 sp->edmode = rl_editing_mode;
1320 sp->kseqlen = rl_key_sequence_length;
1321 sp->inf = rl_instream;
1322 sp->outf = rl_outstream;
1323 sp->pendingin = rl_pending_input;
1324 sp->macro = rl_executing_macro;
Jari Aalto726f6381996-08-26 18:22:31 +00001325
Jari Aalto7117c2d2002-07-17 14:10:11 +00001326 sp->catchsigs = rl_catch_signals;
1327 sp->catchsigwinch = rl_catch_sigwinch;
Jari Aalto726f6381996-08-26 18:22:31 +00001328
Jari Aalto7117c2d2002-07-17 14:10:11 +00001329 return (0);
Jari Aalto726f6381996-08-26 18:22:31 +00001330}
1331
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001332int
Jari Aalto7117c2d2002-07-17 14:10:11 +00001333rl_restore_state (sp)
1334 struct readline_state *sp;
Jari Aalto726f6381996-08-26 18:22:31 +00001335{
Jari Aalto7117c2d2002-07-17 14:10:11 +00001336 if (sp == 0)
1337 return -1;
1338
1339 rl_point = sp->point;
1340 rl_end = sp->end;
1341 rl_mark = sp->mark;
1342 the_line = rl_line_buffer = sp->buffer;
1343 rl_line_buffer_len = sp->buflen;
1344 rl_undo_list = sp->ul;
1345 rl_prompt = sp->prompt;
1346
1347 rl_readline_state = sp->rlstate;
1348 rl_done = sp->done;
1349 _rl_keymap = sp->kmap;
1350
1351 rl_last_func = sp->lastfunc;
1352 rl_insert_mode = sp->insmode;
1353 rl_editing_mode = sp->edmode;
1354 rl_key_sequence_length = sp->kseqlen;
1355 rl_instream = sp->inf;
1356 rl_outstream = sp->outf;
1357 rl_pending_input = sp->pendingin;
1358 rl_executing_macro = sp->macro;
1359
1360 rl_catch_signals = sp->catchsigs;
1361 rl_catch_sigwinch = sp->catchsigwinch;
1362
1363 return (0);
Jari Aalto726f6381996-08-26 18:22:31 +00001364}