diff options
author | unknown <vva@eagle.mysql.r18.ru> | 2003-01-18 20:53:46 +0400 |
---|---|---|
committer | unknown <vva@eagle.mysql.r18.ru> | 2003-01-18 20:53:46 +0400 |
commit | ced07d7f6551d28df5c82c39bda63c711b78d815 (patch) | |
tree | b7bd5d680489b53e3078fbc3f102260170be04e5 /cmd-line-utils/readline/callback.c | |
parent | 316029ab011dd51d2a652a76a4a72a633b9eb938 (diff) | |
download | mariadb-git-ced07d7f6551d28df5c82c39bda63c711b78d815.tar.gz |
move readline to cmd-line-utils
cmd-line-utils/readline/.cvsignore:
mvdir
cmd-line-utils/readline/COPYING:
mvdir
cmd-line-utils/readline/INSTALL:
mvdir
cmd-line-utils/readline/Makefile.am:
mvdir
cmd-line-utils/readline/README:
mvdir
cmd-line-utils/readline/ansi_stdlib.h:
mvdir
cmd-line-utils/readline/bind.c:
mvdir
cmd-line-utils/readline/callback.c:
mvdir
cmd-line-utils/readline/chardefs.h:
mvdir
cmd-line-utils/readline/complete.c:
mvdir
cmd-line-utils/readline/configure.in:
mvdir
cmd-line-utils/readline/display.c:
mvdir
cmd-line-utils/readline/emacs_keymap.c:
mvdir
cmd-line-utils/readline/funmap.c:
mvdir
cmd-line-utils/readline/histexpand.c:
mvdir
cmd-line-utils/readline/histfile.c:
mvdir
cmd-line-utils/readline/histlib.h:
mvdir
cmd-line-utils/readline/history.c:
mvdir
cmd-line-utils/readline/history.h:
mvdir
cmd-line-utils/readline/histsearch.c:
mvdir
cmd-line-utils/readline/input.c:
mvdir
cmd-line-utils/readline/isearch.c:
mvdir
cmd-line-utils/readline/keymaps.c:
mvdir
cmd-line-utils/readline/keymaps.h:
mvdir
cmd-line-utils/readline/kill.c:
mvdir
cmd-line-utils/readline/macro.c:
mvdir
cmd-line-utils/readline/mbutil.c:
mvdir
cmd-line-utils/readline/misc.c:
mvdir
cmd-line-utils/readline/nls.c:
mvdir
cmd-line-utils/readline/parens.c:
mvdir
cmd-line-utils/readline/posixdir.h:
mvdir
cmd-line-utils/readline/posixjmp.h:
mvdir
cmd-line-utils/readline/posixstat.h:
mvdir
cmd-line-utils/readline/readline.c:
mvdir
cmd-line-utils/readline/readline.h:
mvdir
cmd-line-utils/readline/rlconf.h:
mvdir
cmd-line-utils/readline/rldefs.h:
mvdir
cmd-line-utils/readline/rlmbutil.h:
mvdir
cmd-line-utils/readline/rlprivate.h:
mvdir
cmd-line-utils/readline/rlshell.h:
mvdir
cmd-line-utils/readline/rlstdc.h:
mvdir
cmd-line-utils/readline/rltty.c:
mvdir
cmd-line-utils/readline/rltty.h:
mvdir
cmd-line-utils/readline/rltypedefs.h:
mvdir
cmd-line-utils/readline/rlwinsize.h:
mvdir
cmd-line-utils/readline/search.c:
mvdir
cmd-line-utils/readline/shell.c:
mvdir
cmd-line-utils/readline/signals.c:
mvdir
cmd-line-utils/readline/tcap.h:
mvdir
cmd-line-utils/readline/terminal.c:
mvdir
cmd-line-utils/readline/text.c:
mvdir
cmd-line-utils/readline/tilde.c:
mvdir
cmd-line-utils/readline/tilde.h:
mvdir
cmd-line-utils/readline/undo.c:
mvdir
cmd-line-utils/readline/util.c:
mvdir
cmd-line-utils/readline/vi_keymap.c:
mvdir
cmd-line-utils/readline/vi_mode.c:
mvdir
cmd-line-utils/readline/xmalloc.c:
mvdir
cmd-line-utils/readline/xmalloc.h:
mvdir
Diffstat (limited to 'cmd-line-utils/readline/callback.c')
-rw-r--r-- | cmd-line-utils/readline/callback.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/cmd-line-utils/readline/callback.c b/cmd-line-utils/readline/callback.c new file mode 100644 index 00000000000..a8f4323c929 --- /dev/null +++ b/cmd-line-utils/readline/callback.c @@ -0,0 +1,156 @@ +/* callback.c -- functions to use readline as an X `callback' mechanism. */ + +/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. + + This file is part of the GNU Readline Library, a library for + reading lines of text with interactive input and history editing. + + 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 2, or + (at your option) any later version. + + The GNU Readline Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + 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, + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ +#define READLINE_LIBRARY + +#if defined (HAVE_CONFIG_H) +# include <config.h> +#endif + +#include "rlconf.h" + +#if defined (READLINE_CALLBACKS) + +#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" +#include "rlprivate.h" + +/* **************************************************************** */ +/* */ +/* Callback Readline Functions */ +/* */ +/* **************************************************************** */ + +/* Allow using readline in situations where a program may have multiple + things to handle at once, and dispatches them via select(). Call + rl_callback_handler_install() with the prompt and a function to call + whenever a complete line of input is ready. The user must then + call rl_callback_read_char() every time some input is available, and + rl_callback_read_char() will call the user's function with the complete + 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. */ + +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. */ +static void +_rl_callback_newline () +{ + rl_initialize (); + + if (in_handler == 0) + { + in_handler = 1; + + (*rl_prep_term_function) (_rl_meta_flag); + +#if defined (HANDLE_SIGNALS) + rl_set_signals (); +#endif + } + + readline_internal_setup (); +} + +/* Install a readline handler, set up the terminal, and issue the prompt. */ +void +rl_callback_handler_install (prompt, linefunc) + const char *prompt; + rl_vcpfunc_t *linefunc; +{ + rl_set_prompt (prompt); + rl_linefunc = linefunc; + _rl_callback_newline (); +} + +/* Read one character, and dispatch to the handler if it ends the line. */ +void +rl_callback_read_char () +{ + char *line; + int eof; + + if (rl_linefunc == NULL) + { + fprintf (stderr, "readline: readline_callback_read_char() called with no handler!\r\n"); + abort (); + } + + eof = readline_internal_char (); + + /* We loop in case some function has pushed input back with rl_execute_next. */ + for (;;) + { + if (rl_done) + { + line = readline_internal_teardown (eof); + + (*rl_deprep_term_function) (); +#if defined (HANDLE_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 (); + } + if (rl_pending_input) + eof = readline_internal_char (); + else + break; + } +} + +/* Remove the handler, and make sure the terminal is in its normal state. */ +void +rl_callback_handler_remove () +{ + rl_linefunc = NULL; + if (in_handler) + { + in_handler = 0; + (*rl_deprep_term_function) (); +#if defined (HANDLE_SIGNALS) + rl_clear_signals (); +#endif + } +} + +#endif |