From 43ab905823df0ae44607cda41da9c105e009c1e5 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 21 Sep 2006 13:30:45 +0000 Subject: Various updates --- common/ttyio.c | 85 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 34 deletions(-) (limited to 'common/ttyio.c') diff --git a/common/ttyio.c b/common/ttyio.c index 38883afa5..8b8f8835f 100644 --- a/common/ttyio.c +++ b/common/ttyio.c @@ -47,15 +47,10 @@ #endif #include #include -#ifdef HAVE_LIBREADLINE -#include -#include -#endif - #include "util.h" -#include "memory.h" #include "ttyio.h" +#include "common-defs.h" #define CONTROL_D ('D' - 'A' + 1) @@ -82,6 +77,11 @@ static int no_terminal; static int restore_termios; #endif +/* Hooks set by gpgrlhelp.c if required. */ +static void (*my_rl_set_completer) (rl_completion_func_t *); +static void (*my_rl_inhibit_completion) (int); +static void (*my_rl_cleanup_after_signal) (void); + /* This is a wrapper around ttyname so that we can use it even when @@ -181,34 +181,6 @@ init_ttyfp(void) } -#ifdef HAVE_LIBREADLINE -void -tty_enable_completion(rl_completion_func_t *completer) -{ -/* if( no_terminal ) */ -/* return; */ - -/* if( !initialized ) */ -/* init_ttyfp(); */ - -/* rl_attempted_completion_function=completer; */ -/* rl_inhibit_completion=0; */ -} - -void -tty_disable_completion(void) -{ -/* if( no_terminal ) */ -/* return; */ - -/* if( !initialized ) */ -/* init_ttyfp(); */ - -/* rl_inhibit_completion=1; */ -} -#endif /*HAVE_LIBREADLINE*/ - - int tty_batchmode( int onoff ) { @@ -597,3 +569,48 @@ tty_get_answer_is_yes( const char *prompt ) xfree(p); return yes; } + + +/* Called by gnupg_rl_initialize to setup the reradline support. */ +void +tty_private_set_rl_hooks (void (*set_completer) (rl_completion_func_t*), + void (*inhibit_completion) (int), + void (*cleanup_after_signal) (void)) +{ + my_rl_set_completer = set_completer; + my_rl_inhibit_completion = inhibit_completion; + my_rl_cleanup_after_signal = cleanup_after_signal; +} + + +void +tty_enable_completion (rl_completion_func_t *completer) +{ + if (no_terminal || !my_rl_set_completer ) + return; + + if (!initialized) + init_ttyfp(); + + my_rl_set_completer (completer); +} + +void +tty_disable_completion (void) +{ + if (no_terminal || !my_rl_inhibit_completion) + return; + + if (!initialized) + init_ttyfp(); + + my_rl_inhibit_completion (1); +} + + +void +tty_cleanup_rl_after_signal (void) +{ + if (my_rl_cleanup_after_signal) + my_rl_cleanup_after_signal (); +} -- cgit v1.2.3