[PATCH] Add cvars to an STree

I want to get rid of the old completion code and move over to the common STree
functions. This patch adds an stree_node to the cvar struct and inserts it
properly at registration time. The Cvar_FindVar function is re-implemented
using STree_Find.

diff -urN a/common/cvar.c head/common/cvar.c
--- a/common/cvar.c	2006-02-19 15:40:25.000000000 +1030
+++ head/common/cvar.c	2006-02-19 14:15:47.000000000 +1030
@@ -46,6 +46,8 @@
 cvar_t *cvar_vars;
 static char *cvar_null_string = "";
 
+static DECLARE_STREE_ROOT(cvar_tree);
+
 /*
 ============
 Cvar_FindVar
@@ -54,13 +56,14 @@
 cvar_t *
 Cvar_FindVar(const char *var_name)
 {
-    cvar_t *var;
+    struct cvar_s *ret = NULL;
+    struct stree_node *n;
 
-    for (var = cvar_vars; var; var = var->next)
-	if (!strcmp(var_name, var->name))
-	    return var;
+    n = STree_Find(&cvar_tree, var_name);
+    if (n)
+	ret = container_of(n, struct cvar_s, stree);
 
-    return NULL;
+    return ret;
 }
 
 /*
@@ -201,22 +204,25 @@
     char value[512];		// FIXME - magic numbers...
     float old_developer;
 
-// first check to see if it has allready been defined
+    /* first check to see if it has allready been defined */
     if (Cvar_FindVar(variable->name)) {
 	Con_Printf("Can't register variable %s, allready defined\n",
 		   variable->name);
 	return;
     }
-// check for overlap with a command
+    /* check for overlap with a command */
     if (Cmd_Exists(variable->name)) {
 	Con_Printf("Cvar_RegisterVariable: %s is a command\n",
 		   variable->name);
 	return;
     }
-// link the variable in
+    /* link the variable in */
     variable->next = cvar_vars;
     cvar_vars = variable;
 
+    variable->stree.string = variable->name;
+    STree_Insert(&cvar_tree, &variable->stree);
+
 // copy the value off, because future sets will Z_Free it
     strncpy(value, variable->string, 511);
     value[511] = '\0';
diff -urN a/include/cvar.h head/include/cvar.h
--- a/include/cvar.h	2006-02-19 15:48:53.000000000 +1030
+++ head/include/cvar.h	2006-02-19 14:09:18.000000000 +1030
@@ -93,7 +93,7 @@
     unsigned flags;
 
     struct completion index; /* for searching through vars and commands */
-
+    struct stree_node stree; /* string tree for cvar names */
 } cvar_t;
 
 #define CVAR_DEVELOPER (1U << 0) /* can't set during normal play */
diff -urN a/include/shell.h head/include/shell.h
--- a/include/shell.h	2006-02-19 15:54:31.000000000 +1030
+++ head/include/shell.h	2006-02-19 15:30:38.000000000 +1030
@@ -36,6 +36,13 @@
 };
 
 #define STREE_ROOT (struct stree_root) { 0, 0, -1, RB_ROOT }
+#define DECLARE_STREE_ROOT(_x) \
+	struct stree_root _x = { \
+		.entries = 0,    \
+		.maxlen = 0,     \
+		.minlen = -1,    \
+      		.root = RB_ROOT  \
+	}
 
 /*
  * String node is simply an rb_tree node using the string as the index (and
