diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/configure.in freeciv/configure.in --- FreecivCVS/configure.in Mon Jul 10 07:56:38 2000 +++ freeciv/configure.in Thu Jul 13 21:29:52 2000 @@ -67,6 +67,12 @@ esac], [server=true]) AM_CONDITIONAL(SERVER, test x$server = xtrue) +AC_ARG_WITH(readline, +[ --with-readline support fancy command line editing], +WITH_READLINE=$withval, dnl yes/no - required to use / never use +WITH_READLINE="maybe" dnl maybe - use if found [default] +) + dnl no=do not compile client, yes=guess it, *=use this client or error AC_ARG_ENABLE(client, [ --enable-client[=no/yes/type] @@ -358,6 +364,20 @@ AC_CHECK_FUNC(connect) if test $ac_cv_func_connect = no; then AC_CHECK_LIB(socket, connect, SERVER_LIBS="-lsocket $SERVER_LIBS") + fi + dnl looking for readline library and header + if test "$WITH_READLINE" = "yes"; then + AC_CHECK_LIB(readline, rl_callback_handler_install, , + AC_MSG_ERROR([Specified --with-readline but did not find library.]), + $SERVER_LIBS) + AC_CHECK_HEADER(readline/readline.h, , + AC_MSG_ERROR([Specified --with-readline; found library but not header file. +You may need to install a readline \"development\" package.])) + elif test "$WITH_READLINE" = "maybe"; then + AC_CHECK_HEADER(readline/readline.h, have_readline_h=1, have_readline_h=0) + if test "$have_readline_h" = "1"; then + AC_CHECK_LIB(readline, rl_callback_handler_install, , , $SERVER_LIBS) + fi fi fi AC_SUBST(SERVER_LIBS) diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/console.c freeciv/server/console.c --- FreecivCVS/server/console.c Wed Jan 5 06:55:36 2000 +++ freeciv/server/console.c Thu Jul 13 21:29:52 2000 @@ -18,6 +18,10 @@ #include #include +#ifdef HAVE_LIBREADLINE +#include +#endif + #include "fcintl.h" #include "log.h" #include "support.h" @@ -29,6 +33,9 @@ static int console_show_prompt=0; static int console_prompt_is_showing=0; static int console_rfcstyle=0; +#ifdef HAVE_LIBREADLINE +static int readline_received_enter = 1; +#endif /************************************************************************ Function to handle log messages. @@ -50,9 +57,18 @@ { if (console_prompt_is_showing || !console_show_prompt) return; - + +#ifdef HAVE_LIBREADLINE + if (readline_received_enter) { + readline_received_enter = 0; + } else { + rl_forced_update_display(); + } +#else con_dump(C_READY,"> "); con_flush(); +#endif + console_prompt_is_showing = 1; } @@ -173,9 +189,9 @@ } /************************************************************************ -Make sure a prompt is printed, and re-printed after every message. +Initialize prompt; display initial message. ************************************************************************/ -void con_prompt_on(void) +void con_prompt_init(void) { static int first = 1; if (first) { @@ -183,7 +199,14 @@ con_puts(C_COMMENT, _("For introductory help, type 'help'.")); first = 0; } - console_show_prompt=1; +} + +/************************************************************************ +Make sure a prompt is printed, and re-printed after every message. +************************************************************************/ +void con_prompt_on(void) +{ + console_show_prompt = 1; con_update_prompt(); } @@ -192,7 +215,7 @@ ************************************************************************/ void con_prompt_off(void) { - console_show_prompt=0; + console_show_prompt = 0; } /************************************************************************ @@ -201,5 +224,18 @@ void con_prompt_enter(void) { console_prompt_is_showing = 0; +#ifdef HAVE_LIBREADLINE + readline_received_enter = 1; +#endif } +/************************************************************************ +Clear "user pressed enter" state (used in special cases). +************************************************************************/ +void con_prompt_enter_clear(void) +{ + console_prompt_is_showing = 1; +#ifdef HAVE_LIBREADLINE + readline_received_enter = 0; +#endif +} diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/console.h freeciv/server/console.h --- FreecivCVS/server/console.h Sat Jun 12 03:42:00 1999 +++ freeciv/server/console.h Thu Jul 13 21:29:52 2000 @@ -50,6 +50,9 @@ /* ensure timely update */ void con_flush(void); +/* initialize prompt; display initial message */ +void con_prompt_init(void); + /* make sure a prompt is printed, and re-printed after every message */ void con_prompt_on(void); @@ -58,6 +61,9 @@ /* user pressed enter: will need a new prompt */ void con_prompt_enter(void); + +/* clear "user pressed enter" state (used in special cases) */ +void con_prompt_enter_clear(void); /* set rfc-style */ void con_set_style(int i); diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/sernet.c freeciv/server/sernet.c --- FreecivCVS/server/sernet.c Sun Jul 9 16:52:33 2000 +++ freeciv/server/sernet.c Thu Jul 13 22:05:52 2000 @@ -57,7 +57,13 @@ #include #endif +#ifdef HAVE_LIBREADLINE +#include +#include +#endif + #include "log.h" +#include "mem.h" #include "netintf.h" #include "packets.h" #include "shared.h" @@ -94,7 +100,34 @@ #endif -/*****************************************************************************/ +#ifdef HAVE_LIBREADLINE +/****************************************************************************/ + +#define HISTORY_FILENAME ".civserver_history" +#define HISTORY_LENGTH 100 + +static char *history_file = NULL; + +static int readline_handled_input = 0; + +/***************************************************************************** +... +*****************************************************************************/ +static void handle_readline_input_callback(char *line) +{ + if (line) { + if (*line) + add_history(line); + con_prompt_enter(); /* just got an 'Enter' hit */ + handle_stdin_input((struct player *)NULL, line); + } + readline_handled_input = 1; +} + +#endif +/***************************************************************************** +... +*****************************************************************************/ void close_connection(struct connection *pconn) { close(pconn->sock); @@ -102,7 +135,9 @@ pconn->access_level=ALLOW_NONE; } -/*****************************************************************************/ +/***************************************************************************** +... +*****************************************************************************/ void close_connections_and_socket(void) { int i; @@ -113,8 +148,18 @@ } } close(sock); + +#ifdef HAVE_LIBREADLINE + if (history_file) { + write_history(history_file); + history_truncate_file(history_file, HISTORY_LENGTH); + } +#endif } +/***************************************************************************** +... +*****************************************************************************/ static void close_socket_callback(struct connection *pc) { lost_connection_to_player(pc); @@ -144,7 +189,35 @@ char buf[BUF_SIZE+1]; char *bufptr = buf; #endif - + + con_prompt_init(); + +#ifdef HAVE_LIBREADLINE + { + static int readline_initialized = 0; + + if (!readline_initialized) { + char *home_dir = user_home_dir(); + if (home_dir) { + history_file = + fc_malloc(strlen(home_dir) + 1 + strlen(HISTORY_FILENAME) + 1); + if (history_file) { + strcpy(history_file, home_dir); + strcat(history_file, "/"); + strcat(history_file, HISTORY_FILENAME); + using_history(); + read_history(history_file); + } + } + + rl_initialize(); + rl_callback_handler_install("> ", handle_readline_input_callback); + + readline_initialized = 1; + } + } +#endif + if(year!=game.year) { if (server_state == RUN_GAME_STATE) year=game.year; } @@ -169,6 +242,7 @@ FD_SET(0, &readfs); #endif FD_SET(sock, &readfs); + FD_SET(sock, &exceptfs); max_desc=sock; for(i=0; i=0) { @@ -262,11 +348,12 @@ close_socket_callback(&connections[i]); } } + } } break; } con_prompt_off(); - + if((game.timeout) && (time(NULL)>game.turn_start + game.timeout)) return 0;