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:30:47 -0700
Reply-to: rt@xxxxxxxxxxx

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

And this time, without the silly whitespace problems! 
 
(Does anybody have a suggestion for a GRAPHICAL text editor that does 
NOT strip whitespace at the end of lines?  . . . and don't say emacs, 
emacs and I don't get along very well :P) 
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:26:24.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
+};
+
+/**************************************************************************
+...
+**************************************************************************/
+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]