diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/configure.in workdir/configure.in --- freeciv/configure.in Thu Jun 1 14:47:37 2000 +++ workdir/configure.in Thu Jun 1 14:48:22 2000 @@ -93,6 +93,16 @@ WITH_XAW3D=1 ) +dnl shall we compile readline into the server? +AC_ARG_WITH(readline, +[ --enable-readline support fancy command line editing], +[case "${enableval}" in + yes) readline=true ;; + no) readline=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-readline) ;; +esac], [readline=true]) +AM_CONDITIONAL(READLINE, test x$readline = xtrue) + AC_ARG_ENABLE(make_data, [ --disable-make-data do not recurse make into data directories (ok to disable unless you will 'make install')], @@ -358,6 +368,19 @@ AC_CHECK_FUNC(connect) if test $ac_cv_func_connect = no; then AC_CHECK_LIB(socket, connect, SERVER_LIBS="-lsocket $SERVER_LIBS") + fi + if test x$readline = xtrue; then + AC_CHECK_LIB(readline, rl_callback_handler_install,, + readline=false + AC_MSG_WARN(could not find the required readline library, configuring without readline.)) + AC_CHECK_HEADERS(readline/readline.h readline/history.h,, + readline=false + AC_MSG_WARN(could not find the required readline headers, configuring without readline.)) + + if test x$readline = xtrue; then + CFLAGS="$CFLAGS -DREADLINE" + CPPFLAGS="$CPPFLAGS -DREADLINE" + fi fi fi AC_SUBST(SERVER_LIBS) diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/civserver.c workdir/server/civserver.c --- freeciv/server/civserver.c Thu Jun 1 14:48:09 2000 +++ workdir/server/civserver.c Thu Jun 1 14:48:22 2000 @@ -331,6 +331,10 @@ if (script_filename) read_init_script(script_filename); +#ifdef READLINE + install_readline(); +#endif + while(server_state==PRE_GAME_STATE) sniff_packets(); diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/console.c workdir/server/console.c --- freeciv/server/console.c Thu Jun 1 14:48:09 2000 +++ workdir/server/console.c Thu Jun 1 15:30:18 2000 @@ -18,6 +18,11 @@ #include #include +#ifdef READLINE +#include "readline/readline.h" +extern int inside_readline; +#endif + #include "fcintl.h" #include "log.h" #include "support.h" @@ -51,7 +56,14 @@ if (console_prompt_is_showing || !console_show_prompt) return; +#ifdef READLINE + if (inside_readline) + inside_readline = 0; + else + rl_forced_update_display(); +#else con_dump(C_READY,"> "); +#endif con_flush(); console_prompt_is_showing = 1; } @@ -173,14 +185,24 @@ } /************************************************************************ +... +************************************************************************/ +void start_comment(void) +{ + con_puts(C_COMMENT, ""); + con_puts(C_COMMENT, "For introductory help, type 'help'."); +} + +/************************************************************************ Make sure a prompt is printed, and re-printed after every message. ************************************************************************/ void con_prompt_on(void) { static int first = 1; if (first) { - con_puts(C_COMMENT, ""); - con_puts(C_COMMENT, _("For introductory help, type 'help'.")); +#ifndef READLINE + start_comment(); +#endif first = 0; } console_show_prompt=1; diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/console.h workdir/server/console.h --- freeciv/server/console.h Thu Jun 1 14:48:09 2000 +++ workdir/server/console.h Thu Jun 1 15:30:45 2000 @@ -50,6 +50,8 @@ /* ensure timely update */ void con_flush(void); +void start_comment(void); + /* make sure a prompt is printed, and re-printed after every message */ void con_prompt_on(void); diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/sernet.c workdir/server/sernet.c --- freeciv/server/sernet.c Thu Jun 1 14:48:10 2000 +++ workdir/server/sernet.c Thu Jun 1 18:24:47 2000 @@ -62,6 +62,11 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef READLINE +#include "readline/readline.h" +#include "readline/history.h" +int inside_readline = 1; +#endif #include "log.h" #include "packets.h" @@ -87,7 +92,6 @@ #endif extern int force_end_of_sniff; - /*****************************************************************************/ void close_connection(struct connection *pconn) { @@ -109,6 +113,22 @@ close(sock); } +#ifdef READLINE +void handle_readline_input(char *line) +{ + con_prompt_enter(); /* why not. just to be consistent */ + if (*line) /* != '\0' */ + add_history (line); + handle_stdin_input((struct player *)NULL, line); +} + +void install_readline(void) +{ + start_comment(); + rl_callback_handler_install("> ", handle_readline_input); +} +#endif + /***************************************************************************** Get and handle: - new connections, @@ -184,6 +204,10 @@ } #ifndef SOCKET_ZERO_ISNT_STDIN else if(FD_ISSET(0, &readfs)) { /* input from server operator */ +#ifdef READLINE + inside_readline = 1; + rl_callback_read_char(); +#else int didget; char buf[BUF_SIZE+1]; @@ -194,6 +218,7 @@ *(buf+didget)='\0'; con_prompt_enter(); /* will need a new prompt, regardless */ handle_stdin_input((struct player *)NULL, buf); +#endif } #else else if(!feof(stdin)) { /* input from server operator */ diff -Nur -X/home/thue/freeciv-dev/freeciv/diff_ignore freeciv/server/sernet.h workdir/server/sernet.h --- freeciv/server/sernet.h Thu Jun 1 14:48:10 2000 +++ workdir/server/sernet.h Thu Jun 1 15:30:31 2000 @@ -26,4 +26,8 @@ void init_connections(void); void close_connection(struct connection *pconn); +#ifdef READLINE +void install_readline(void); +#endif + #endif /* FC__SERNET_H */