From 43ab905823df0ae44607cda41da9c105e009c1e5 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 21 Sep 2006 13:30:45 +0000 Subject: [PATCH] Various updates --- common/ChangeLog | 10 ++++++ common/Makefile.am | 5 ++- common/common-defs.h | 32 +++++++++++++++++ common/iobuf.c | 1 - common/ttyio.c | 85 ++++++++++++++++++++++++++------------------ common/ttyio.h | 19 +++------- common/util.h | 9 +++++ doc/gpgsm.texi | 4 ++- doc/yat2m.c | 2 +- g10/ChangeLog | 11 ++++++ g10/Makefile.am | 5 +-- g10/card-util.c | 1 + g10/comment.c | 1 - g10/gpg.c | 3 +- g10/gpgv.c | 2 +- g10/keyedit.c | 2 +- g10/signal.c | 9 +---- sm/ChangeLog | 2 ++ sm/gpgsm.c | 1 + 19 files changed, 138 insertions(+), 66 deletions(-) create mode 100644 common/common-defs.h 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 + + * 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 * 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 #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 #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 (); +} 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 -#include -#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 --*/ diff --git a/doc/gpgsm.texi b/doc/gpgsm.texi index d56cb8119..ed9d6f34c 100644 --- a/doc/gpgsm.texi +++ b/doc/gpgsm.texi @@ -189,7 +189,9 @@ utilizes the @code{dirmngr} service. Same as @option{--list-keys} but also prints all keys making up the chain. -@item --dump-keys +@item --dump-cert +@itemx --dump-keys +@opindex dump-cert @opindex dump-keys List all available certificates stored in the local key database using a format useful mainly for debugging. diff --git a/doc/yat2m.c b/doc/yat2m.c index 266107c1d..90581232e 100644 --- a/doc/yat2m.c +++ b/doc/yat2m.c @@ -822,7 +822,7 @@ parse_file (const char *fname, FILE *fp, char **section_name, int in_pause) lnr++; if (!n || line[n-1] != '\n') { - err ("%s:$d: trailing linefeed missing, line too long or " + err ("%s:%d: trailing linefeed missing, line too long or " "embedded Nul character", fname, lnr); break; } diff --git a/g10/ChangeLog b/g10/ChangeLog index fd1d62eea..6c6d2181d 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,14 @@ +2006-09-21 Werner Koch + + * signal.c (got_fatal_signal): Replaced readline stuff by a tty + function. + + * Makefile.am (LDADD): Include libgpgrl.a. + + * gpg.c (main): Call gpg_rl_initialize. + + * keyedit.c: Removed double inclusion of stdio.h. + 2006-09-20 Werner Koch * call-agent.c: Include asshelp.h. diff --git a/g10/Makefile.am b/g10/Makefile.am index a49925b43..580ac7605 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -108,12 +108,13 @@ gpgv2_SOURCES = gpgv.c \ # ks-db.h \ # $(common_source) -LDADD = $(needed_libs) $(ZLIBS) $(DNSLIBS) $(LIBREADLINE) \ +LDADD = $(needed_libs) ../common/libgpgrl.a \ + $(ZLIBS) $(DNSLIBS) $(LIBREADLINE) \ $(LIBINTL) $(CAPLIBS) $(W32LIBS) gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) -$(PROGRAMS): $(needed_libs) +$(PROGRAMS): $(needed_libs) ../common/libgpgrl.a install-data-local: $(mkinstalldirs) $(DESTDIR)$(pkgdatadir) diff --git a/g10/card-util.c b/g10/card-util.c index b7da1ba98..2738cbebf 100644 --- a/g10/card-util.c +++ b/g10/card-util.c @@ -38,6 +38,7 @@ #include "keyserver-internal.h" #if GNUPG_MAJOR_VERSION == 1 # ifdef HAVE_LIBREADLINE +# define GNUPG_LIBREADLINE_H_INCLUDED # include # include # endif /*HAVE_LIBREADLINE*/ diff --git a/g10/comment.c b/g10/comment.c index 193087107..e19ed3994 100644 --- a/g10/comment.c +++ b/g10/comment.c @@ -30,7 +30,6 @@ #include "packet.h" #include "errors.h" #include "iobuf.h" -#include "memory.h" #include "util.h" #include "main.h" #include "keydb.h" diff --git a/g10/gpg.c b/g10/gpg.c index 472dc50d0..e7f05f0dd 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -1771,7 +1771,8 @@ main (int argc, char **argv ) when adding any stuff between here and the call to secmem_init() somewhere after the option parsing. */ reopen_std (); - trap_unaligned(); + trap_unaligned (); + gnupg_rl_initialize (); set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); /* We don't need any locking in libgcrypt unless we use any kind of diff --git a/g10/gpgv.c b/g10/gpgv.c index eff7489e9..a9884a31d 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -31,7 +31,7 @@ #include /* for setmode() */ #endif #ifdef HAVE_LIBREADLINE -#include +#define GNUPG_LIBREADLINE_H_INCLUDED #include #endif diff --git a/g10/keyedit.c b/g10/keyedit.c index 80d714adc..6b3fbe818 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -28,7 +28,7 @@ #include #include #ifdef HAVE_LIBREADLINE -#include +#define GNUPG_LIBREADLINE_H_INCLUDED #include #endif diff --git a/g10/signal.c b/g10/signal.c index aaeb89841..6055b1c2c 100644 --- a/g10/signal.c +++ b/g10/signal.c @@ -28,10 +28,6 @@ #include #include #include -#ifdef HAVE_LIBREADLINE -#include -#include -#endif #include "gpg.h" #include "options.h" @@ -86,10 +82,7 @@ got_fatal_signal( int sig ) gcry_control (GCRYCTL_TERM_SECMEM ); -#ifdef HAVE_LIBREADLINE - rl_free_line_state (); - rl_cleanup_after_signal (); -#endif + tty_cleanup_rl_after_signal (); /* Better don't translate these messages. */ write(2, "\n", 1 ); diff --git a/sm/ChangeLog b/sm/ChangeLog index 986432f2f..3d67226e9 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,5 +1,7 @@ 2006-09-20 Werner Koch + * gpgsm.c: Add alias command --dump-cert. + * Makefile.am: Changes to allow parallel make runs. 2006-09-18 Werner Koch diff --git a/sm/gpgsm.c b/sm/gpgsm.c index f7b2c7aed..6769a486d 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -268,6 +268,7 @@ static ARGPARSE_OPTS opts[] = { { aPasswd, "passwd", 256, N_("change a passphrase")}, { aGPGConfList, "gpgconf-list", 256, "@" }, + { aDumpKeys, "dump-cert", 256, "@"}, { aDumpKeys, "dump-keys", 256, "@"}, { aDumpChain, "dump-chain", 256, "@"}, { aDumpExternalKeys, "dump-external-keys", 256, "@"},