<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] Map command argument completion

Something I've always wanted to be able to do; allow the user to type
'map x&lt;TAB&gt;' and complete the map name starting with x, if unique. If not
unique, give the common prefix. Press TAB twice for a list of maps starting
with x.

diff -urN b/NQ/host_cmd.c head/NQ/host_cmd.c
--- b/NQ/host_cmd.c	2005-11-27 19:13:02.000000000 +1030
+++ head/NQ/host_cmd.c	2006-02-18 09:57:38.000000000 +1030
@@ -299,6 +299,21 @@
     }
 }
 
+static struct rb_string_root *
+Host_Map_Arg_f(const char *arg)
+{
+    struct rb_string_root *root;
+
+    root = Z_Malloc(sizeof(struct rb_string_root));
+    if (root) {
+	*root = RB_STRING_ROOT;
+
+	ST_AllocInit();
+	COM_ScanDir(root, "maps", arg, ".bsp", true);
+    }
+    return root;
+}
+
 /*
 ==================
 Host_Changelevel_f
@@ -1591,7 +1606,10 @@
     Cmd_AddCommand("god", Host_God_f);
     Cmd_AddCommand("notarget", Host_Notarget_f);
     Cmd_AddCommand("fly", Host_Fly_f);
+
     Cmd_AddCommand("map", Host_Map_f);
+    Cmd_SetCompletion("map", Host_Map_Arg_f);
+
     Cmd_AddCommand("restart", Host_Restart_f);
     Cmd_AddCommand("changelevel", Host_Changelevel_f);
 
diff -urN b/QW/server/sv_ccmds.c head/QW/server/sv_ccmds.c
--- b/QW/server/sv_ccmds.c	2004-07-25 15:59:58.000000000 +0930
+++ head/QW/server/sv_ccmds.c	2006-02-18 10:05:02.000000000 +1030
@@ -339,6 +339,20 @@
     SV_BroadcastCommand("reconnect\n");
 }
 
+static struct rb_string_root *
+SV_Map_Arg_f(const char *arg)
+{
+    struct rb_string_root *root;
+
+    root = Z_Malloc(sizeof(struct rb_string_root));
+    if (root) {
+	*root = RB_STRING_ROOT;
+
+	ST_AllocInit();
+	COM_ScanDir(root, "maps", arg, ".bsp", true);
+    }
+    return root;
+}
 
 /*
 ==================
@@ -877,6 +891,8 @@
     Cmd_AddCommand("status", SV_Status_f);
 
     Cmd_AddCommand("map", SV_Map_f);
+    Cmd_SetCompletion("map", SV_Map_Arg_f);
+
     Cmd_AddCommand("setmaster", SV_SetMaster_f);
 
     Cmd_AddCommand("say", SV_ConSay_f);
</pre></body></html>