diff options
Diffstat (limited to 'readline/callback.c')
-rw-r--r-- | readline/callback.c | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/readline/callback.c b/readline/callback.c index 200f3cc37f9..a8f4323c929 100644 --- a/readline/callback.c +++ b/readline/callback.c @@ -7,7 +7,7 @@ The GNU Readline Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,7 +18,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -29,22 +29,20 @@ #if defined (READLINE_CALLBACKS) -#include <stdlib.h> #include <sys/types.h> + +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#else +# include "ansi_stdlib.h" +#endif + #include <stdio.h> /* System-specific feature definitions and include files. */ #include "rldefs.h" #include "readline.h" - -extern void readline_internal_setup (); -extern char *readline_internal_teardown (); -extern int readline_internal_char (); -extern void _rl_init_line_state (); - -extern int _rl_meta_flag; -extern char *rl_prompt; -extern int rl_visible_prompt_length; +#include "rlprivate.h" /* **************************************************************** */ /* */ @@ -61,7 +59,7 @@ extern int rl_visible_prompt_length; text read in at each end of line. The terminal is kept prepped and signals handled all the time, except during calls to the user's function. */ -VFunction *rl_linefunc; /* user callback function */ +rl_vcpfunc_t *rl_linefunc; /* user callback function */ static int in_handler; /* terminal_prepped and signals set? */ /* Make sure the terminal is set up, initialize readline, and prompt. */ @@ -87,11 +85,10 @@ _rl_callback_newline () /* Install a readline handler, set up the terminal, and issue the prompt. */ void rl_callback_handler_install (prompt, linefunc) - char *prompt; - VFunction *linefunc; + const char *prompt; + rl_vcpfunc_t *linefunc; { - rl_prompt = prompt; - rl_visible_prompt_length = rl_prompt ? rl_expand_prompt (rl_prompt) : 0; + rl_set_prompt (prompt); rl_linefunc = linefunc; _rl_callback_newline (); } @@ -111,24 +108,33 @@ rl_callback_read_char () eof = readline_internal_char (); - if (rl_done) + /* We loop in case some function has pushed input back with rl_execute_next. */ + for (;;) { - line = readline_internal_teardown (eof); + if (rl_done) + { + line = readline_internal_teardown (eof); - (*rl_deprep_term_function) (); + (*rl_deprep_term_function) (); #if defined (HANDLE_SIGNALS) - rl_clear_signals (); + rl_clear_signals (); #endif - in_handler = 0; - (*rl_linefunc) (line); - - /* If the user did not clear out the line, do it for him. */ - if (rl_line_buffer[0]) - _rl_init_line_state (); - - /* Redisplay the prompt if readline_handler_{install,remove} not called. */ - if (in_handler == 0 && rl_linefunc) - _rl_callback_newline (); + in_handler = 0; + (*rl_linefunc) (line); + + /* If the user did not clear out the line, do it for him. */ + if (rl_line_buffer[0]) + _rl_init_line_state (); + + /* Redisplay the prompt if readline_handler_{install,remove} + not called. */ + if (in_handler == 0 && rl_linefunc) + _rl_callback_newline (); + } + if (rl_pending_input) + eof = readline_internal_char (); + else + break; } } |