Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9710) no readline support for show command
Home

[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]
To: chrisk@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#9710) no readline support for show command
From: "Gregor Richards" <akaquinn@xxxxxxxxxxx>
Date: Sat, 21 Aug 2004 17:19:19 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9710 >

> [chrisk - Mon Aug 16 13:34:13 2004]: 
>  
>  
> CVS 16 AUG 2004 GTK2 
>  
> The server commands 'show situational', 'show rare' have no 
autocompletion 
> for the second argument. 
>  
> Christian 
>  
>  
 
Fixed. 
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:14:32.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,"
@@ -192,7 +193,7 @@
   enum sset_category category;
   enum sset_level level;
 
-  /* 
+  /*
    * About the *_validate functions: If the function is non-NULL, it
    * is called with the new value, and returns whether the change is
    * legal. The char * is an error message in the case of reject. 
@@ -647,7 +648,7 @@
             "will always move into the tile they attacked if they win "
             "the combat (and no enemy units remain in the tile).  If "
             "set to a value between 0 and 100, this will be used as "
-            "the percent chance of \"occupying\" territory."), NULL, 
+            "the percent chance of \"occupying\" territory."), NULL,
          GAME_MIN_OCCUPYCHANCE, GAME_MAX_OCCUPYCHANCE, 
          GAME_DEFAULT_OCCUPYCHANCE)
 
@@ -1977,7 +1978,7 @@
                H_AWAY,
  /* novice */   H_RATES | H_TARGETS | H_HUTS | H_NOPLANES 
                         | H_DIPLOMAT | H_LIMITEDHUTS | H_DEFENSIVE,
- /* easy */    H_RATES | H_TARGETS | H_HUTS | H_NOPLANES 
+ /* easy */    H_RATES | H_TARGETS | H_HUTS | H_NOPLANES
                         | H_DIPLOMAT | H_LIMITEDHUTS | H_DEFENSIVE,
                H_NONE,
  /* medium */  H_RATES | H_TARGETS | H_HUTS | H_DIPLOMAT,
@@ -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
+};
+
+/**************************************************************************
+...
+**************************************************************************/
+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);

[Prev in Thread] Current Thread [Next in Thread]