[Freeciv-Dev] (PR#9710) no readline support for show command
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9710 >
Whoops, missed the /*** ... ***/ bit. This one has an actual function
description.
diff -ruN -X freeciv/diff_ignore freeciv/server/stdinhand.c
freeciv-fix9710/server/stdinhand.c
--- freeciv/server/stdinhand.c 2004-08-21 16:26:02.000000000 -0700
+++ freeciv-fix9710/server/stdinhand.c 2004-08-21 17:32:30.000000000 -0700
@@ -166,6 +166,7 @@
N_("Vital"),
N_("Situational"),
N_("Rare") };
+#define OLEVELS_NUM 5
#define SSET_MAX_LEN 16 /* max setting name length (plus nul) */
#define TOKEN_DELIMITERS " \t\n,"
@@ -2610,6 +2611,15 @@
return settings[i].name;
}
+static const char *olvlname_accessor(int i) {
+ // for 0->4, uses option levels, otherwise returns a setting name
+ if (i < OLEVELS_NUM) {
+ return sset_level_names[i];
+ } else {
+ return settings[i-OLEVELS_NUM].name;
+ }
+}
+
/**************************************************************************
Set timeout options.
**************************************************************************/
@@ -5274,6 +5284,14 @@
}
/**************************************************************************
+The valid arguments to "show"
+**************************************************************************/
+static char *olevel_generator(const char *text, int state)
+{
+ return generic_generator(text, state, SETTINGS_NUM+OLEVELS_NUM,
olvlname_accessor);
+}
+
+/**************************************************************************
The player names.
**************************************************************************/
static const char *playername_accessor(int idx)
@@ -5476,11 +5494,12 @@
/**************************************************************************
Commands that may be followed by a server option name
+CMD_SHOW is handled by option_level_cmd, which is for both option levels
+and server options
**************************************************************************/
static const int server_option_cmd[] = {
CMD_EXPLAIN,
CMD_SET,
- CMD_SHOW,
-1
};
@@ -5501,6 +5520,30 @@
}
/**************************************************************************
+Commands that may be followed by an option level or server option
+**************************************************************************/
+static const int option_level_cmd[] = {
+ CMD_SHOW,
+ -1
+};
+
+/**************************************************************************
+Returns true if the function matches an option level or an option
+**************************************************************************/
+static bool is_option_level(int start)
+{
+ int i = 0;
+
+ while (option_level_cmd[i] != -1) {
+ if (contains_str_before_start(start, commands[option_level_cmd[i]].name,
FALSE))
+ return TRUE;
+ i++;
+ }
+
+ return FALSE;
+}
+
+/**************************************************************************
Commands that may be followed by a filename
**************************************************************************/
static const int filename_cmd[] = {
@@ -5576,6 +5619,8 @@
matches = completion_matches(text, player_generator);
} else if (is_server_option(start)) {
matches = completion_matches(text, option_generator);
+ } else if (is_option_level(start)) {
+ matches = completion_matches(text, olevel_generator);
} else if (is_filename(start)) {
/* This function we get from readline */
matches = completion_matches(text, filename_completion_function);
|
|