Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.174 diff -u -r1.174 stdinhand.c --- server/stdinhand.c 2001/02/27 19:37:04 1.174 +++ server/stdinhand.c 2001/04/10 11:44:25 @@ -3210,7 +3210,7 @@ num is number of possible completions, and index2str is a function which returns each possible completion string by index. **************************************************************************/ -static char *generic_generator(char *text, int state, int num, +static char *generic_generator(const char *text, int state, int num, const char*(*index2str)(int)) { static int list_index, len; @@ -3240,7 +3240,7 @@ /************************************************************************** The valid commands at the root of the prompt. **************************************************************************/ -static char *command_generator(char *text, int state) +static char *command_generator(const char *text, int state) { return generic_generator(text, state, CMD_NUM, cmdname_accessor); } @@ -3248,7 +3248,7 @@ /************************************************************************** The valid arguments to "set" and "explain" **************************************************************************/ -static char *option_generator(char *text, int state) +static char *option_generator(const char *text, int state) { return generic_generator(text, state, SETTINGS_NUM, optname_accessor); } @@ -3260,7 +3260,7 @@ { return get_player(idx)->name; } -static char *player_generator(char *text, int state) +static char *player_generator(const char *text, int state) { return generic_generator(text, state, game.nplayers, playername_accessor); } @@ -3272,7 +3272,7 @@ { return conn_list_get(&game.all_connections, idx)->name; } -static char *connection_generator(char *text, int state) +static char *connection_generator(const char *text, int state) { return generic_generator(text, state, conn_list_size(&game.all_connections), connection_name_accessor); @@ -3281,7 +3281,7 @@ /************************************************************************** The valid arguments to "rulesout". **************************************************************************/ -static char *rulesout_generator(char *text, int state) +static char *rulesout_generator(const char *text, int state) { return generic_generator(text, state, RULESOUT_NUM, rulesout_accessor); } @@ -3294,7 +3294,7 @@ { return cmdlevel_name(idx); } -static char *cmdlevel_arg1_generator(char *text, int state) +static char *cmdlevel_arg1_generator(const char *text, int state) { return generic_generator(text, state, ALLOW_NUM, cmdlevel_arg1_accessor); } @@ -3309,7 +3309,7 @@ (idx==1) ? "new" : connection_name_accessor(idx-2)); } -static char *cmdlevel_arg2_generator(char *text, int state) +static char *cmdlevel_arg2_generator(const char *text, int state) { return generic_generator(text, state, 2 + conn_list_size(&game.all_connections), @@ -3319,7 +3319,7 @@ /************************************************************************** The valid first arguments to "help". **************************************************************************/ -static char *help_generator(char *text, int state) +static char *help_generator(const char *text, int state) { return generic_generator(text, state, HELP_ARG_NUM, helparg_accessor); } @@ -3327,7 +3327,7 @@ /************************************************************************** The valid first arguments to "list". **************************************************************************/ -static char *list_generator(char *text, int state) +static char *list_generator(const char *text, int state) { return generic_generator(text, state, LIST_ARG_NUM, listarg_accessor); } @@ -3542,6 +3542,23 @@ return contains_str_before_start(start, commands[CMD_LIST].name, 0); } +/* The readline folks though they would change the name of this function + * from 4.1 -> 4.2. Since they didn't define their version we have to make + * this hack to figure out which function to use. + * + * rl_completion_matches was an unpublished interface, which is why they + * though they could change the name without providing backward + * compatibility. Here we test against a define new to 4.2 to detect it. + * The define here is in the published interfaces and as + * such can be expected to remain. + * + * The macro preprocessor really needs a way to test if a function is + * defined... + */ +#ifndef RL_STATE_NONE +#define rl_completion_matches(a, b) completion_matches(a, b) +#endif + /************************************************************************** Attempt to complete on the contents of TEXT. START and END bound the region of rl_line_buffer that contains the word to complete. TEXT is @@ -3549,36 +3566,38 @@ in case we want to do some simple parsing. Return the array of matches, or NULL if there aren't any. **************************************************************************/ -char **freeciv_completion(char *text, int start, int end) +char **freeciv_completion(const char *text, int start, int end) { char **matches = (char **)NULL; + /* Don't try to complete with filenames */ + rl_attempted_completion_over = 1; + if (is_help(start)) { - matches = completion_matches(text, help_generator); + matches = rl_completion_matches(text, help_generator); } else if (is_command(start)) { - matches = completion_matches(text, command_generator); + matches = rl_completion_matches(text, command_generator); } else if (is_rulesout(start)) { - matches = completion_matches(text, rulesout_generator); + matches = rl_completion_matches(text, rulesout_generator); } else if (is_list(start)) { - matches = completion_matches(text, list_generator); + matches = rl_completion_matches(text, list_generator); } else if (is_cmdlevel_arg2(start)) { - matches = completion_matches(text, cmdlevel_arg2_generator); + matches = rl_completion_matches(text, cmdlevel_arg2_generator); } else if (is_cmdlevel_arg1(start)) { - matches = completion_matches(text, cmdlevel_arg1_generator); + matches = rl_completion_matches(text, cmdlevel_arg1_generator); } else if (is_connection(start)) { - matches = completion_matches(text, connection_generator); + matches = rl_completion_matches(text, connection_generator); } else if (is_player(start)) { - matches = completion_matches(text, player_generator); + matches = rl_completion_matches(text, player_generator); } else if (is_server_option(start)) { - matches = completion_matches(text, option_generator); + matches = rl_completion_matches(text, option_generator); } else if (is_filename(start)) { - /* This function we get from readline */ - matches = completion_matches(text, filename_completion_function); - } else /* We have no idea what to do */ matches = NULL; - - /* Don't automatically try to complete with filenames */ - rl_attempted_completion_over = 1; + /* Try to complete with filenames */ + rl_attempted_completion_over = 0; + } else { /* We have no idea what to do */ + matches = NULL; + } return (matches); } Index: server/stdinhand.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.h,v retrieving revision 1.19 diff -u -r1.19 stdinhand.h --- server/stdinhand.h 2000/09/11 06:49:35 1.19 +++ server/stdinhand.h 2001/04/10 11:44:25 @@ -37,7 +37,7 @@ void notify_if_first_access_level_is_available(void); #ifdef HAVE_LIBREADLINE -char **freeciv_completion(char *text, int start, int end); +char **freeciv_completion(const char *text, int start, int end); #endif #endif /* FC__STDINHAND_H */