commit bash-20150529 snapshot

This commit is contained in:
Chet Ramey
2015-06-05 11:50:38 -04:00
parent 3bf257a5d9
commit ff7c092e19
27 changed files with 520 additions and 34 deletions
+23
View File
@@ -291,4 +291,27 @@ _rl_callback_data_dispose (arg)
xfree (arg);
}
/* Make sure that this agrees with cases in rl_callback_read_char */
void
rl_callback_sigcleanup ()
{
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
return;
if (RL_ISSTATE (RL_STATE_ISEARCH))
_rl_isearch_cleanup (_rl_iscxt, 0);
else if (RL_ISSTATE (RL_STATE_NSEARCH))
_rl_nsearch_cleanup (_rl_nscxt, 0);
else if (RL_ISSTATE (RL_STATE_VIMOTION))
RL_UNSETSTATE (RL_STATE_VIMOTION);
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
_rl_argcxt = 0;
RL_UNSETSTATE (RL_STATE_NUMERICARG);
}
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
RL_UNSETSTATE (RL_STATE_MULTIKEY);
_rl_callback_func = 0;
}
#endif
+8
View File
@@ -1328,6 +1328,14 @@ the terminal settings are modified for Readline's use again.
@code{NULL} line.
@end deftypefun
@deftypefun void rl_callback_sigcleanup (void)
Clean up any internal state the callback interface uses to maintain state
between calls to rl_callback_read_char (e.g., the state of any active
incremental searches). This is intended to be used by applications that
wish to perform their own signal handling; Readline's internal signal handler
calls this when appropriate.
@end deftypefun
@deftypefun void rl_callback_handler_remove (void)
Restore the terminal to its initial state and remove the line handler.
You may call this function from within a callback as well as independently.
+2 -2
View File
@@ -4,7 +4,7 @@ Copyright (C) 1988-2015 Free Software Foundation, Inc.
@set EDITION 6.4
@set VERSION 6.4
@set UPDATED 24 May 2015
@set UPDATED 28 May 2015
@set UPDATED-MONTH May 2015
@set LASTCHANGE Sun May 24 18:01:45 EDT 2015
@set LASTCHANGE Thu May 28 16:58:07 EDT 2015
+143
View File
@@ -0,0 +1,143 @@
/* Standard include files. stdio.h is required. */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Used for select(2) */
#include <sys/types.h>
#include <sys/select.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
/* Standard readline include files. */
#if defined (READLINE_LIBRARY)
# include "readline.h"
# include "history.h"
#else
# include <readline/readline.h>
# include <readline/history.h>
#endif
static void cb_linehandler (char *);
static void sigint_sighandler (int);
static int sigint_handler (int);
static int saw_signal = 0;
int running;
const char *prompt = "rltest$ ";
char *input_string;
/* Callback function called for each line when accept-line executed, EOF
seen, or EOF character read. This sets a flag and returns; it could
also call exit(3). */
static void
cb_linehandler (char *line)
{
if (line && *line)
add_history (line);
printf ("input line: %s\n", line ? line : "");
input_string = line;
rl_callback_handler_remove ();
}
static char *
cb_readline ()
{
fd_set fds;
int r, err;
char *not_done = "";
/* Install the line handler. */
rl_callback_handler_install (prompt, cb_linehandler);
if (RL_ISSTATE (RL_STATE_ISEARCH))
fprintf(stderr, "cb_readline: after handler install, state (ISEARCH) = %d", rl_readline_state);
else if (RL_ISSTATE (RL_STATE_NSEARCH))
fprintf(stderr, "cb_readline: after handler install, state (NSEARCH) = %d", rl_readline_state);
/* MULTIKEY VIMOTION NUMERICARG _rl_callback_func */
FD_ZERO (&fds);
FD_SET (fileno (rl_instream), &fds);
input_string = not_done;
while (input_string == not_done)
{
r = err = 0;
/* Enter a simple event loop. This waits until something is available
to read on readline's input stream (defaults to standard input) and
calls the builtin character read callback to read it. It does not
have to modify the user's terminal settings. */
while (r == 0)
{
struct timeval timeout = {0, 100000};
struct timeval *timeoutp = NULL;
timeoutp = &timeout;
FD_SET (fileno (rl_instream), &fds);
r = select (FD_SETSIZE, &fds, NULL, NULL, timeoutp);
err = errno;
}
if (saw_signal)
sigint_handler (saw_signal);
if (r < 0)
{
perror ("rltest: select");
rl_callback_handler_remove ();
break;
}
/* if (FD_ISSET (fileno (rl_instream), &fds)) */
if (r > 0)
rl_callback_read_char ();
}
return input_string;
}
void
sigint_sighandler (s)
int s;
{
saw_signal = s;
}
int
sigint_handler (s)
int s;
{
rl_free_line_state ();
rl_callback_sigcleanup ();
rl_cleanup_after_signal ();
rl_callback_handler_remove ();
saw_signal = 0;
fprintf(stderr, "sigint_handler: readline state = %d\r\n", rl_readline_state);
return s;
}
int
main (int c, char **v)
{
char *p;
running = 1;
rl_catch_signals = 1;
rl_bind_key_in_map ('r', rl_history_search_backward, emacs_meta_keymap);
rl_bind_key_in_map ('s', rl_history_search_forward, emacs_meta_keymap);
signal (SIGINT, sigint_sighandler);
while (running)
{
p = cb_readline ();
if (p == 0 || strcmp (p, "exit") == 0)
break;
}
printf ("rl-callbacktest2: Event loop has exited\n");
return 0;
}
+1 -1
View File
@@ -178,7 +178,7 @@ static const FUNMAP default_funmap[] = {
{ "vi-fword", rl_vi_fword },
{ "vi-goto-mark", rl_vi_goto_mark },
{ "vi-insert-beg", rl_vi_insert_beg },
{ "vi-insertion-mode", rl_vi_insertion_mode },
{ "vi-insertion-mode", rl_vi_insert_mode },
{ "vi-match", rl_vi_match },
{ "vi-movement-mode", rl_vi_movement_mode },
{ "vi-next-word", rl_vi_next_word },
+1 -2
View File
@@ -66,7 +66,6 @@ static int rl_search_history PARAMS((int, int));
static _rl_search_cxt *_rl_isearch_init PARAMS((int));
static void _rl_isearch_fini PARAMS((_rl_search_cxt *));
static int _rl_isearch_cleanup PARAMS((_rl_search_cxt *, int));
/* Last line found by the current incremental search, so we don't `find'
identical lines many times in a row. Now part of isearch context. */
@@ -724,7 +723,7 @@ add_character:
return 1;
}
static int
int
_rl_isearch_cleanup (cxt, r)
_rl_search_cxt *cxt;
int r;
+4 -3
View File
@@ -39,9 +39,9 @@ extern "C" {
#endif
/* Hex-encoded Readline version number. */
#define RL_READLINE_VERSION 0x0604 /* Readline 6.4 */
#define RL_VERSION_MAJOR 6
#define RL_VERSION_MINOR 4
#define RL_READLINE_VERSION 0x0700 /* Readline 7.0 */
#define RL_VERSION_MAJOR 7
#define RL_VERSION_MINOR 0
/* Readline data structures. */
@@ -220,6 +220,7 @@ extern int rl_insert_close PARAMS((int, int));
extern void rl_callback_handler_install PARAMS((const char *, rl_vcpfunc_t *));
extern void rl_callback_read_char PARAMS((void));
extern void rl_callback_handler_remove PARAMS((void));
extern void rl_callback_sigcleanup PARAMS((void));
/* Things for vi mode. Not available unless readline is compiled -DVI_MODE. */
/* VI-mode bindable commands. */
+2
View File
@@ -292,6 +292,7 @@ extern void _rl_scxt_dispose PARAMS((_rl_search_cxt *, int));
extern int _rl_isearch_dispatch PARAMS((_rl_search_cxt *, int));
extern int _rl_isearch_callback PARAMS((_rl_search_cxt *));
extern int _rl_isearch_cleanup PARAMS((_rl_search_cxt *, int));
extern int _rl_search_getchar PARAMS((_rl_search_cxt *));
@@ -346,6 +347,7 @@ extern int _rl_restore_tty_signals PARAMS((void));
/* search.c */
extern int _rl_nsearch_callback PARAMS((_rl_search_cxt *));
extern int _rl_nsearch_cleanup PARAMS((_rl_search_cxt *, int));
/* signals.c */
extern void _rl_signal_handler PARAMS((int));
+1 -2
View File
@@ -80,7 +80,6 @@ static int rl_history_search_internal PARAMS((int, int));
static void rl_history_search_reinit PARAMS((int));
static _rl_search_cxt *_rl_nsearch_init PARAMS((int, int));
static int _rl_nsearch_cleanup PARAMS((_rl_search_cxt *, int));
static void _rl_nsearch_abort PARAMS((_rl_search_cxt *));
static int _rl_nsearch_dispatch PARAMS((_rl_search_cxt *, int));
@@ -224,7 +223,7 @@ _rl_nsearch_init (dir, pchar)
return cxt;
}
static int
int
_rl_nsearch_cleanup (cxt, r)
_rl_search_cxt *cxt;
int r;
+4
View File
@@ -213,6 +213,10 @@ _rl_handle_signal (sig)
case SIGINT:
_rl_reset_completion_state ();
rl_free_line_state ();
#if defined (READLINE_CALLBACKS)
rl_callback_sigcleanup ();
#endif
/* FALLTHROUGH */
#if defined (SIGTSTP)