diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 10 | ||||
-rw-r--r-- | common/Makefile.am | 5 | ||||
-rw-r--r-- | common/common-defs.h | 32 | ||||
-rw-r--r-- | common/iobuf.c | 1 | ||||
-rw-r--r-- | common/ttyio.c | 85 | ||||
-rw-r--r-- | common/ttyio.h | 19 | ||||
-rw-r--r-- | common/util.h | 9 |
7 files changed, 111 insertions, 50 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 8be1ce5c2..cde4c4b3d 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,13 @@ +2006-09-21 Werner Koch <[email protected]> + + * ttyio.c (tty_private_set_rl_hooks): New. + (tty_enable_completion, tty_disable_completion): Use a hook to + enable readline support. Now always available. + (tty_cleanup_rl_after_signal): New. + + * ttyio.h: Removed readline specific stuff. Included util.h. + * common-defs.h: New. + 2006-09-15 Werner Koch <[email protected]> * convert.c: New. diff --git a/common/Makefile.am b/common/Makefile.am index 28d396490..52b56e94c 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -20,7 +20,7 @@ ## Process this file with automake to produce Makefile.in -noinst_LIBRARIES = libcommon.a libsimple-pwquery.a +noinst_LIBRARIES = libcommon.a libsimple-pwquery.a libgpgrl.a noinst_PROGRAMS = $(module_tests) TESTS = $(module_tests) @@ -30,6 +30,7 @@ AM_CFLAGS = $(LIBGCRYPT_CFLAGS) $(LIBASSUAN_CFLAGS) $(KSBA_CFLAGS) \ $(PTH_CFLAGS) libcommon_a_SOURCES = \ + common-defs.h \ util.h i18n.h \ errors.h \ openpgpdefs.h \ @@ -63,6 +64,8 @@ libcommon_a_SOURCES = \ libsimple_pwquery_a_SOURCES = \ simple-pwquery.c simple-pwquery.h asshelp.c asshelp.h +libgpgrl_a_SOURCES = \ + gpgrlhelp.c # # Module tests diff --git a/common/common-defs.h b/common/common-defs.h new file mode 100644 index 000000000..0a6403a2c --- /dev/null +++ b/common/common-defs.h @@ -0,0 +1,32 @@ +/* common-defs.h - Private declarations for common/ + * Copyright (C) 2006 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG 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 of the License, or + * (at your option) any later version. + * + * GnuPG 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ + +#ifndef GNUPG_COMMON_COMMON_DEFS_H +#define GNUPG_COMMON_COMMON_DEFS_H + +/*-- ttyio.c --*/ +void tty_private_set_rl_hooks (void (*set_completer) (rl_completion_func_t*), + void (*inhibit_completion) (int), + void (*cleanup_after_signal) (void) ); + + + +#endif /*GNUPG_COMMON_COMMON_DEFS_H*/ diff --git a/common/iobuf.c b/common/iobuf.c index b15d76a0a..8100883e3 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -39,7 +39,6 @@ #include <swis.h> #endif /* __riscos__ */ -#include "memory.h" #include "util.h" #include "iobuf.h" 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 <errno.h> #include <ctype.h> -#ifdef HAVE_LIBREADLINE -#include <readline/readline.h> -#include <readline/history.h> -#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 (); +} diff --git a/common/ttyio.h b/common/ttyio.h index 32d159863..d93906eab 100644 --- a/common/ttyio.h +++ b/common/ttyio.h @@ -21,10 +21,8 @@ #ifndef GNUPG_COMMON_TTYIO_H #define GNUPG_COMMON_TTYIO_H -#ifdef HAVE_LIBREADLINE -#include <stdio.h> -#include <readline/readline.h> -#endif +#include "util.h" /* Make sure our readline typedef is available. */ + const char *tty_get_ttyname (void); int tty_batchmode (int onoff); @@ -46,16 +44,9 @@ void tty_kill_prompt (void); int tty_get_answer_is_yes (const char *prompt); int tty_no_terminal (int onoff); -#ifdef HAVE_LIBREADLINE -void tty_enable_completion(rl_completion_func_t *completer); -void tty_disable_completion(void); -#else -/* Use a macro to stub out these functions since a macro has no need - to typedef a "rl_completion_func_t" which would be undefined - without readline. */ -#define tty_enable_completion(x) -#define tty_disable_completion() -#endif +void tty_enable_completion (rl_completion_func_t *completer); +void tty_disable_completion (void); +void tty_cleanup_rl_after_signal (void); #endif /*GNUPG_COMMON_TTYIO_H*/ diff --git a/common/util.h b/common/util.h index da1e098cb..86c963cda 100644 --- a/common/util.h +++ b/common/util.h @@ -45,6 +45,13 @@ #include "../jnlib/dotlock.h" #include "../jnlib/utf8conv.h" +/* We need this type even if we are not using libreadline and or we + did not include libreadline in the current file. */ +#ifndef GNUPG_LIBREADLINE_H_INCLUDED +typedef char **rl_completion_func_t (const char *, int, int); +#endif /*!GNUPG_LIBREADLINE_H_INCLUDED*/ + + /* Handy malloc macros - please use only them. */ #define xtrymalloc(a) gcry_malloc ((a)) #define xtrymalloc_secure(a) gcry_malloc_secure ((a)) @@ -153,6 +160,8 @@ char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf); /*-- homedir.c --*/ const char *default_homedir (void); +/*-- gpgrlhelp.c --*/ +void gnupg_rl_initialize (void); /*-- miscellaneous.c --*/ |