+/*
+ CVar_CompleteCountPossible
+
+ New function for tab-completion system
+ Added by EvilTypeGuy
+ Thanks to Fett erich@heintz.com
+
+*/
+int
+Cvar_CompleteCountPossible (char *partial)
+{
+ cvar_t *cvar;
+ int len;
+ int h;
+
+ h = 0;
+ len = strlen(partial);
+
+ if (!len)
+ return 0;
+
+ // Loop through the cvars and count all possible matches
+ for (cvar = cvar_vars; cvar; cvar = cvar->next)
+ if (!strncasecmp(partial, cvar->name, len))
+ h++;
+
+ return h;
+}
+
+/*
+ CVar_CompleteBuildList
+
+ New function for tab-completion system
+ Added by EvilTypeGuy
+ Thanks to Fett erich@heintz.com
+ Thanks to taniwha
+
+*/
+char **
+Cvar_CompleteBuildList (char *partial)
+{
+ cvar_t *cvar;
+ int len = 0;
+ int bpos = 0;
+ int sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (char *);
+ char **buf;
+
+ len = strlen(partial);
+ buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *));
+ // Loop through the alias list and print all matches
+ for (cvar = cvar_vars; cvar; cvar = cvar->next)
+ if (!strncasecmp(partial, cvar->name, len))
+ buf[bpos++] = cvar->name;
+
+ buf[bpos] = NULL;
+ return buf;
+}
+