client: Enable history file by default unless -r

Make -H take an argument.  Default it to ~/.empire_history, except in
-r restricted mode, where history is off unless you specify -H.
That's because restricted mode restricts the player's access to the
local system, and that includes the history file.  If you want to
grant access to a history file, you have to do so explicitly.

Thanks to the previous commit, there is no need to suppress saving to
~/.empire_history in the test suite.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-12-13 09:30:49 +01:00
parent de638fd779
commit 2fe38c1acb
2 changed files with 17 additions and 12 deletions

View file

@ -3,8 +3,9 @@
empire \- Empire client empire \- Empire client
.SH SYNOPSIS .SH SYNOPSIS
.B empire .B empire
[\fB\-hHkruv\fP] [\fB\-hkruv\fP]
[\fB\-2\fP \fIoutfile\fP] [\fB\-2\fP \fIoutfile\fP]
[\fB\-H\fP \fIhistfile\fP]
[\fB\-s\fP \fI[host:]port\fP] [\fB\-s\fP \fI[host:]port\fP]
[\fIcountry\fP [\fIcountry\fP
[\fIpassword\fP]] [\fIpassword\fP]]
@ -24,8 +25,10 @@ the thin veneer of civilization that hides the maniac within.
.B \-h .B \-h
Help. Print brief usage information and exit. Help. Print brief usage information and exit.
.TP .TP
.B \-H .BI \-H " histfile"
Save readline command history to file. Load command history from \fIhistfile\fP, and save it back. Default
is '~/.empire_history' without \fB\-r\fP, and none with \fB-r\fP. You
might want to protect your history file from prying eyes.
.IP .IP
Only available when compiled the GNU \fBreadline\fP library. Only available when compiled the GNU \fBreadline\fP library.
.TP .TP
@ -85,8 +88,8 @@ The filename for the \fBreadline\fP startup file, overriding the
default of \fI~/.inputrc\fP (see \fBREADLINE\fP below). default of \fI~/.inputrc\fP (see \fBREADLINE\fP below).
.SH READLINE .SH READLINE
When compiled with the GNU \fBreadline\fP library, the client supports When compiled with the GNU \fBreadline\fP library, the client supports
fancy line editing and, with option \fB-H\fP, persistent history. See fancy line editing and persistent history. See the readline
the readline documentation for details. documentation for details.
.SH "SEE ALSO" .SH "SEE ALSO"
\fIemp_server\fR(6), \fIreadline\fR(3). \fIemp_server\fR(6), \fIreadline\fR(3).
.SH FILES .SH FILES

View file

@ -77,7 +77,8 @@ print_usage(char *program_name)
" -s [HOST:]PORT Specify server HOST and PORT\n" " -s [HOST:]PORT Specify server HOST and PORT\n"
" -u Use UTF-8\n" " -u Use UTF-8\n"
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
" -H Save readline command history to file\n" " -H FILE Load and save command history from FILE\n"
" (default ~/.empire_history with -r, none without -r)\n"
#endif /* HAVE_LIBREADLINE */ #endif /* HAVE_LIBREADLINE */
" -h display this help and exit\n" " -h display this help and exit\n"
" -v display version information and exit\n", " -v display version information and exit\n",
@ -89,7 +90,7 @@ main(int argc, char **argv)
{ {
int opt; int opt;
char *auxfname = NULL; char *auxfname = NULL;
int use_history_file = 0; char *history_file = NULL;
int send_kill = 0; int send_kill = 0;
char *host = NULL; char *host = NULL;
char *port = NULL; char *port = NULL;
@ -101,16 +102,15 @@ main(int argc, char **argv)
char *udir; char *udir;
char *colon; char *colon;
int sock; int sock;
char *history_file;
while ((opt = getopt(argc, argv, "2:Hkrs:uhv")) != EOF) { while ((opt = getopt(argc, argv, "2:H:krs:uhv")) != EOF) {
switch (opt) { switch (opt) {
case '2': case '2':
auxfname = optarg; auxfname = optarg;
break; break;
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
case 'H': case 'H':
use_history_file = 1; history_file = optarg;
break; break;
#endif /* HAVE_LIBREADLINE */ #endif /* HAVE_LIBREADLINE */
case 'k': case 'k':
@ -191,8 +191,10 @@ main(int argc, char **argv)
sock = tcp_connect(host, port); sock = tcp_connect(host, port);
if (use_history_file) if (!restricted && !history_file)
history_file = fnameat(".empire_history", udir); history_file = ".empire_history";
if (history_file)
history_file = fnameat(history_file, udir);
if (!login(sock, uname, country, passwd, send_kill, utf8)) if (!login(sock, uname, country, passwd, send_kill, utf8))
exit(1); exit(1);