By Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
You all know the commands "cmdlist" and "cvarlist" from Quake II and Quake 3 Arena, which are lacking in Classic Quake. This tutorial will show you how to add them. For "cmdlist" we need a new function in cmd.c, which you should add before all other functions. It is based on the existing functions Cmd_Exists() and Cmd_CompleteCommand(), it loops through the linked list of all commands. If a parameter is stated, it also compares the beginning of the command with it, so "cmdlist cl" displays only client variables. You shouldn't have any problems to understand as there's no special logic in it. // 2000-01-09 CmdList command by Maddes start /* ======== Cmd_List ======== */ void Cmd_List_f (void) { cmd_function_t *cmd; char *partial; int len; int count; if (Cmd_Argc() > 1) { partial = Cmd_Argv (1); len = Q_strlen(partial); } else { partial = NULL; len = 0; } count=0; for (cmd=cmd_functions ; cmd ; cmd=cmd->next) { if (partial && Q_strncmp (partial,cmd->name, len)) { continue; } Con_Printf ("\"%s\"\n", cmd->name); count++; } Con_Printf ("%i command(s)", count); if (partial) { Con_Printf (" beginning with \"%s\"", partial); } Con_Printf ("\n"); } // 2000-01-09 CmdList command by Maddes end Cmd_AddCommand ("cmdlist", Cmd_List_f); // 2000-01-09 CmdList command by Maddes // 2000-01-09 CvarList command by Maddes start /* ========= Cvar_List ========= */ void Cvar_List_f (void) { cvar_t *cvar; char *partial; int len; int count; if (Cmd_Argc() > 1) { partial = Cmd_Argv (1); len = Q_strlen(partial); } else { partial = NULL; len = 0; } count=0; for (cvar=cvar_vars ; cvar ; cvar=cvar->next) { if (partial && Q_strncmp (partial,cvar->name, len)) { continue; } Con_Printf ("\"%s\" is \"%s\"\n", cvar->name, cvar->string); count++; } Con_Printf ("%i cvar(s)", count); if (partial) { Con_Printf (" beginning with \"%s\"", partial); } Con_Printf ("\n"); } // 2000-01-09 CvarList command by Maddes end Cmd_AddCommand ("cvarlist", Cvar_List_f); // 2000-01-09 CvarList command by Maddes void Cvar_List_f (void); // 2000-01-09 CvarList command by Maddes |