From b3d9ce1c22334767f0dfd38e647dcd0c75799113 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 8 Oct 2013 21:34:28 +0200 Subject: [PATCH] Provide home grown rl_echo_signal_char if readline does not provide it --- acinclude.m4 | 5 +++-- src/ui/terminal/terminal-reader.c | 33 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index ee7c9b0be6..bc4d5b9d37 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -124,8 +124,9 @@ AC_DEFUN([PSPP_READLINE], AC_MSG_CHECKING([how to link with libreadline]) AC_MSG_RESULT([$LIBREADLINE]) AC_SEARCH_LIBS([rl_outstream], [readline], - AC_DEFINE(HAVE_RL_OUTSTREAM, 1, [Define if the readline library provides rl_outstream.]) - ) + AC_DEFINE(HAVE_RL_OUTSTREAM, 1, [Define if the readline library provides rl_outstream.])) + AC_SEARCH_LIBS([rl_echo_signal_char], [readline], + AC_DEFINE(HAVE_RL_ECHO_SIGNAL_CHAR, 1, [Define if the readline library provides rl_echo_signal_char.])) else dnl If $LIBREADLINE didn't lead to a usable library, we don't dnl need $INCREADLINE either. diff --git a/src/ui/terminal/terminal-reader.c b/src/ui/terminal/terminal-reader.c index 2d72acf39c..b4eae73add 100644 --- a/src/ui/terminal/terminal-reader.c +++ b/src/ui/terminal/terminal-reader.c @@ -26,6 +26,7 @@ #if HAVE_READLINE #include #include +#include static char *history_file; @@ -107,14 +108,36 @@ terminal_reader_cast (struct lex_reader *r) return UP_CAST (r, struct terminal_reader, reader); } -/* - Older libreadline versions do not provide rl_outstream. - However, it is almost always going to be the same as stdout. - */ -#if HAVE_RL_OUTSTREAM +/* Older libreadline versions do not provide rl_outstream. + However, it is almost always going to be the same as stdout. */ +#if ! HAVE_RL_OUTSTREAM # define rl_outstream stdout #endif +/* Similarly, rl_echo_signal_char is fairly recent. + We provide our own crude version if it is not present. */ +#if ! HAVE_RL_ECHO_SIGNAL_CHAR +static void +rl_echo_signal_char (int sig) +{ + struct termios t; + if (0 == tcgetattr (0, &t)) + { + cc_t c = t.c_cc[VINTR]; + + if (c >= 0 && c <= 'Z' - 'A') + fprintf (rl_outstream, "^%c", 'A' + c - 1); + else + fprintf (rl_outstream, "%c", c); + } + else + fprintf (rl_outstream, "^C"); + + fflush (rl_outstream); +} +#endif + + static size_t terminal_reader_read (struct lex_reader *r_, char *buf, size_t n, enum prompt_style prompt_style) -- 2.30.2