diff options
author | Werner Koch <[email protected]> | 2004-09-09 17:04:44 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2004-09-09 17:04:44 +0000 |
commit | bfc45cc8bc1a2dcdc0d54ac88ff0f7bf3d9c8551 (patch) | |
tree | bcc8b1bc3c4e35b9142afd23d731ddc71482472c | |
parent | * photoid.c: Include ttyio.h. (diff) | |
download | gnupg-bfc45cc8bc1a2dcdc0d54ac88ff0f7bf3d9c8551.tar.gz gnupg-bfc45cc8bc1a2dcdc0d54ac88ff0f7bf3d9c8551.zip |
* configure.ac: Check for readline.
* signal.c (got_fatal_signal): Do readline cleanup. Print signal
number if we can't print the name. Use new autoconf macro
HAVE_DECL_SYS_SIGLIST.
(get_signal_name): Removed.
* ttyio.c (tty_get): Add readline support.
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | g10/ChangeLog | 5 | ||||
-rw-r--r-- | g10/signal.c | 43 | ||||
-rw-r--r-- | util/ChangeLog | 2 | ||||
-rw-r--r-- | util/ttyio.c | 47 |
7 files changed, 93 insertions, 17 deletions
@@ -1,3 +1,7 @@ +2004-09-09 Werner Koch <[email protected]> + + * configure.ac: Check for readline. + 2004-07-27 Werner Koch <[email protected]> * configure.ac (AM_GNU_GETTEXT_VERSION): New. @@ -1,6 +1,9 @@ Noteworthy changes in version 1.3.6 (2004-05-22) ------------------------------------------------ + * Readline support at all prompt if the systems provides a + readline library. + * New --keyid-format option that selects short (99242560), long (DB698D7199242560), 0xshort (0x99242560), or 0xlong (0xDB698D7199242560) keyid displays. This lets users tune the diff --git a/configure.ac b/configure.ac index 1cad46d76..9bde51804 100644 --- a/configure.ac +++ b/configure.ac @@ -706,6 +706,7 @@ dnl Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(unistd.h langinfo.h termio.h locale.h getopt.h) + dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_INLINE @@ -1083,6 +1084,11 @@ if test "$card_support" = yes; then fi AC_SUBST(LIBUSB_LIBS) +# +# Check for readline support +# +AC_CHECK_LIB(readline, add_history) +AC_CHECK_HEADERS([readline/readline.h]) # Allow users to append something to the version string without diff --git a/g10/ChangeLog b/g10/ChangeLog index 01f956bec..bd01c8725 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,5 +1,10 @@ 2004-09-09 Werner Koch <[email protected]> + * signal.c (got_fatal_signal): Do readline cleanup. Print signal + number if we can't print the name. Use new autoconf macro + HAVE_DECL_SYS_SIGLIST. + (get_signal_name): Removed. + * photoid.c: Include ttyio.h. * parse-packet.c (skip_rest): Removed. Changed all callers to use diff --git a/g10/signal.c b/g10/signal.c index ced507b83..44c8a8f21 100644 --- a/g10/signal.c +++ b/g10/signal.c @@ -1,5 +1,6 @@ /* signal.c - signal handling - * Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2003, + * 2004 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -26,6 +27,10 @@ #include <string.h> #include <errno.h> #include <assert.h> +#ifdef HAVE_READLINE_READLINE_H +#include <readline/readline.h> +#include <readline/history.h> +#endif #include "options.h" #include "errors.h" @@ -67,17 +72,6 @@ init_one_signal (int sig, RETSIGTYPE (*handler)(int), int check_ign ) #endif /*!HAVE_DOSISH_SYSTEM*/ } -static const char * -get_signal_name( int signum ) -{ -#if defined(SYS_SIGLIST_DECLARED) && defined(NSIG) - return (signum >= 0 && signum < NSIG) ? sys_siglist[signum] : "?"; -#else - return "some signal"; -#endif -} - - static RETSIGTYPE got_fatal_signal( int sig ) { @@ -88,14 +82,33 @@ got_fatal_signal( int sig ) caught_fatal_sig = 1; secmem_term(); - /* better don't transtale these messages */ + +#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE) + rl_free_line_state (); + rl_cleanup_after_signal (); +#endif + + /* Better don't translate these messages. */ write(2, "\n", 1 ); s = log_get_name(); if( s ) write(2, s, strlen(s) ); write(2, ": ", 2 ); - s = get_signal_name(sig); write(2, s, strlen(s) ); + +#if defined(HAVE_DECL_SYS_SIGLIST) && defined(NSIG) + s = (sig >= 0 && sig < NSIG) ? sys_siglist[sig] : "?"; + write (2, s, strlen(s) ); +#else + write (2, "signal ", 7 ); + if (sig < 0 || sig >=100) + write (2, "?", 1); + else { + if (sig >= 10) + write (2, "0123456789"+(sig/10), 1 ); + write (2, "0123456789"+(sig%10), 1 ); + } +#endif write(2, " caught ... exiting\n", 20 ); - /* reset action to default action and raise signal again */ + /* Reset action to default action and raise signal again. */ init_one_signal (sig, SIG_DFL, 0); remove_lockfiles (); #ifdef __riscos__ diff --git a/util/ChangeLog b/util/ChangeLog index 9b70ca6e1..fd87232ad 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,5 +1,7 @@ 2004-09-09 Werner Koch <[email protected]> + * ttyio.c (tty_get): Add readline support. + * iobuf.c (iobuf_skip_rest): New. Orginal patch by Florian Weimer. Added new argument PARTIAL. diff --git a/util/ttyio.c b/util/ttyio.c index 076ab7c67..add7467ce 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -1,5 +1,6 @@ /* ttyio.c - tty i/O functions - * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, + * 2004 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -45,6 +46,11 @@ #endif #include <errno.h> #include <ctype.h> +#ifdef HAVE_READLINE_READLINE_H +#include <readline/readline.h> +#include <readline/history.h> +#endif + #include "util.h" #include "memory.h" #include "ttyio.h" @@ -156,6 +162,10 @@ init_ttyfp(void) tty_get_ttyname (), strerror(errno) ); exit(2); } +#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE) + rl_catch_signals = 0; + rl_instream = rl_outstream = ttyfp; +#endif #endif #ifdef HAVE_TCGETATTR atexit( cleanup ); @@ -502,7 +512,40 @@ do_get( const char *prompt, int hidden ) char * tty_get( const char *prompt ) { - return do_get( prompt, 0 ); +#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE) + if (!batchmode && !no_terminal) { + char *line; + char *buf; + + if( !initialized ) + init_ttyfp(); + + last_prompt_len = 0; + + line = readline (prompt?prompt:""); + + /* We need to copy it to memory controlled by our malloc + implementations; further we need to convert an EOF to our + convention. */ + buf = m_alloc(line? strlen(line)+1:2); + if (line) + { + strcpy (buf, line); + trim_spaces (buf); + if (strlen (buf) > 2 ) + add_history (line); /* Note that we test BUF but add LINE. */ + free (line); + } + else + { + buf[0] = CONTROL_D; + buf[1] = 0; + } + return buf; + } + else +#endif /* HAVE_READLINE_READLINE_H && HAVE_LIBREADLINE */ + return do_get( prompt, 0 ); } char * |