<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] Add Cmd_CommandCmplet{ions,e}

Analogous to the arg completion functions, these find the command completions
by looking through the cmd, cmdalias and cvar trees. This will replace usage
of find_completions in the next patch.

diff -urN a/NQ/cmd.c head/NQ/cmd.c
--- a/NQ/cmd.c	2006-02-25 12:53:01.000000000 +1030
+++ head/NQ/cmd.c	2006-02-25 13:06:38.000000000 +1030
@@ -23,6 +23,7 @@
 #include "cmd.h"
 #include "common.h"
 #include "console.h"
+#include "cvar.h"
 #include "host.h"
 #include "protocol.h"
 #include "quakedef.h"
@@ -742,3 +743,33 @@
 
     return 0;
 }
+
+struct stree_root *
+Cmd_CommandCompletions(const char *buf)
+{
+    struct stree_root *root;
+
+    root = Z_Malloc(sizeof(struct stree_root));
+    *root = STREE_ROOT;
+
+    STree_AllocInit();
+
+    STree_Completions(root, &amp;cmd_tree, buf);
+    STree_Completions(root, &amp;cmdalias_tree, buf);
+    STree_Completions(root, &amp;cvar_tree, buf);
+
+    return root;
+}
+
+char *
+Cmd_CommandComplete(const char *buf)
+{
+    struct stree_root *root;
+    char *ret;
+
+    root = Cmd_CommandCompletions(buf);
+    ret = STree_MaxMatch(root, buf);
+    Z_Free(root);
+
+    return ret;
+}
diff -urN a/NQ/cmd.h head/NQ/cmd.h
--- a/NQ/cmd.h	2006-02-25 12:53:01.000000000 +1030
+++ head/NQ/cmd.h	2006-02-25 13:06:46.000000000 +1030
@@ -103,6 +103,9 @@
 char *Cmd_ArgComplete(const char *name, const char *buf);
 struct stree_root *Cmd_ArgCompletions(const char *name, const char *buf);
 
+struct stree_root *Cmd_CommandCompletions(const char *buf);
+char *Cmd_CommandComplete(const char *buf);
+
 // called by the init functions of other parts of the program to
 // register commands and functions to call for them.
 // The cmd_name is referenced later, so it should not be in temp memory
diff -urN a/QW/client/cmd.h head/QW/client/cmd.h
--- a/QW/client/cmd.h	2006-02-25 12:53:01.000000000 +1030
+++ head/QW/client/cmd.h	2006-02-25 12:42:46.000000000 +1030
@@ -89,6 +89,9 @@
 char *Cmd_ArgComplete(const char *name, const char *buf);
 struct stree_root *Cmd_ArgCompletions(const char *name, const char *buf);
 
+struct stree_root *Cmd_CommandCompletions(const char *buf);
+char *Cmd_CommandComplete(const char *buf);
+
 // called by the init functions of other parts of the program to
 // register commands and functions to call for them.
 // The cmd_name is referenced later, so it should not be in temp memory
diff -urN a/QW/common/cmd.c head/QW/common/cmd.c
--- a/QW/common/cmd.c	2006-02-25 12:53:02.000000000 +1030
+++ head/QW/common/cmd.c	2006-02-25 13:06:21.000000000 +1030
@@ -23,6 +23,7 @@
 #include "cmd.h"
 #include "common.h"
 #include "console.h"
+#include "cvar.h"
 #include "quakedef.h"
 #include "shell.h"
 #include "sys.h"
@@ -783,3 +784,33 @@
 
     return 0;
 }
+
+struct stree_root *
+Cmd_CommandCompletions(const char *buf)
+{
+    struct stree_root *root;
+
+    root = Z_Malloc(sizeof(struct stree_root));
+    *root = STREE_ROOT;
+
+    STree_AllocInit();
+
+    STree_Completions(root, &amp;cmd_tree, buf);
+    STree_Completions(root, &amp;cmdalias_tree, buf);
+    STree_Completions(root, &amp;cvar_tree, buf);
+
+    return root;
+}
+
+char *
+Cmd_CommandComplete(const char *buf)
+{
+    struct stree_root *root;
+    char *ret;
+
+    root = Cmd_CommandCompletions(buf);
+    ret = STree_MaxMatch(root, buf);
+    Z_Free(root);
+
+    return ret;
+}
diff -urN a/common/cvar.c head/common/cvar.c
--- a/common/cvar.c	2006-02-21 20:58:24.000000000 +1030
+++ head/common/cvar.c	2006-02-22 20:58:11.000000000 +1030
@@ -46,7 +46,7 @@
 static char *cvar_null_string = "";
 
 #define cvar_entry(ptr) container_of(ptr, struct cvar_s, stree)
-static DECLARE_STREE_ROOT(cvar_tree);
+DECLARE_STREE_ROOT(cvar_tree);
 
 /*
 ============
diff -urN a/include/cvar.h head/include/cvar.h
--- a/include/cvar.h	2006-02-21 20:58:25.000000000 +1030
+++ head/include/cvar.h	2006-02-25 10:08:38.000000000 +1030
@@ -138,4 +138,6 @@
 cvar_t *Cvar_NextServerVar(const char *var_name);
 #endif
 
+struct stree_root cvar_tree;
+
 #endif /* CVAR_H */
</pre></body></html>