client: Tie up a few lose readline ends

Document readline in more detail in man/empire.6.

Make @history_file local to main().

main() silently truncates the home directory name to 1000 characters
when constructing the history file name; mark FIXME.

Set @rl_already_prompted just once.

Write history file on unsuccessful exit, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-12-13 09:10:08 +01:00
parent f1fc0df03d
commit 0cb6690600
4 changed files with 36 additions and 21 deletions

View file

@ -29,6 +29,7 @@
* Known contributors to this file:
* Markus Armbruster, 2007-2017
* Ron Koenderink, 2007-2009
* Martin Haukeli, 2015
*/
#include <config.h>
@ -436,7 +437,6 @@ recv_output(int sock)
return n;
}
char *history_file = NULL;
#ifdef HAVE_LIBREADLINE
static char *input_from_rl;
static int has_rl_input;
@ -446,7 +446,6 @@ input_handler(char *line)
{
input_from_rl = line;
has_rl_input = 1;
rl_already_prompted = 1;
#ifdef HAVE_READLINE_HISTORY
if (line && *line)
add_history(line);
@ -536,11 +535,12 @@ intr(int sig)
/*
* Play on @sock.
* @history_file is the name of the history file, or null.
* The session must be in the playing phase.
* Return 0 when the session ended, -1 on error.
*/
int
play(int sock)
play(int sock, char *history_file)
{
/*
* Player input flows from INPUT_FD through recv_input() into ring
@ -564,6 +564,7 @@ play(int sock)
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
#ifdef HAVE_LIBREADLINE
rl_already_prompted = 1;
#ifdef HAVE_READLINE_HISTORY
if (history_file)
read_history(history_file);
@ -665,19 +666,18 @@ play(int sock)
break;
}
if (n == 0) {
#ifdef HAVE_LIBREADLINE
#ifdef HAVE_READLINE_HISTORY
if (history_file)
write_history(history_file);
#endif /* HAVE_READLINE_HISTORY */
#endif /* HAVE_LIBREADLINE */
ret = 0;
break;
}
}
}
#ifdef HAVE_LIBREADLINE
rl_callback_handler_remove();
#ifdef HAVE_READLINE_HISTORY
if (history_file)
write_history(history_file);
#endif /* HAVE_READLINE_HISTORY */
#endif
return ret;
}