From 0219bcb4c833fc1035a2a8bc94707d4b2eb5e70e Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Mon, 30 Jul 2001 01:01:39 +0000 Subject: [PATCH] Make the help command work with commands too. (moved to cmd.c while I was at it) --- libs/util/cmd.c | 34 ++++++++++++++++++++++++++++++++++ libs/util/cvar.c | 23 ----------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/libs/util/cmd.c b/libs/util/cmd.c index 83fb6a566..d6b3226bb 100644 --- a/libs/util/cmd.c +++ b/libs/util/cmd.c @@ -451,6 +451,7 @@ Cmd_UnAlias_f (void) } } + /* COMMAND EXECUTION */ @@ -957,6 +958,38 @@ Cmd_CmdList_f (void) Con_Printf ("------------\n%d commands\n", i); } +void +Cmd_Help_f (void) +{ + const char *name; + cvar_t *var; + cmd_function_t *cmd; + + if (Cmd_Argc () != 2) { + Con_Printf ("usage: help \n"); + return; + } + + name = Cmd_Argv (1); + + for (cmd = cmd_functions; cmd && strcasecmp (name, cmd->name); cmd = cmd->next) + ; + if (cmd) { + Con_Printf ("%s\n", cmd->description); + return; + } + + var = Cvar_FindVar (name); + if (!var) + var = Cvar_FindAlias (name); + if (var) { + Con_Printf ("%s\n", var->description); + return; + } + + Con_Printf ("variable/command not found\n"); +} + static void cmd_alias_free (void *_a, void *unused) { @@ -1011,6 +1044,7 @@ Cmd_Init (void) Cmd_AddCommand ("unalias", Cmd_UnAlias_f, "Remove the selected alias"); Cmd_AddCommand ("wait", Cmd_Wait_f, "Wait a game tic"); Cmd_AddCommand ("cmdlist", Cmd_CmdList_f, "List all commands"); + Cmd_AddCommand ("help", Cmd_Help_f, "Display help for a command or variable"); } diff --git a/libs/util/cvar.c b/libs/util/cvar.c index 469dfdfdd..e37fb2dbe 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -433,28 +433,6 @@ Cvar_Toggle_f (void) Cvar_Set (var, var->int_val ? "0" : "1"); } -void -Cvar_Help_f (void) -{ - const char *var_name; - cvar_t *var; - - if (Cmd_Argc () != 2) { - Con_Printf ("usage: help \n"); - return; - } - - var_name = Cmd_Argv (1); - var = Cvar_FindVar (var_name); - if (!var) - var = Cvar_FindAlias (var_name); - if (var) { - Con_Printf ("%s\n", var->description); - return; - } - Con_Printf ("variable not found\n"); -} - void Cvar_CvarList_f (void) { @@ -527,7 +505,6 @@ Cvar_Init (void) Cmd_AddCommand ("setrom", Cvar_Setrom_f, "Set the selected variable and make it read only, useful on the command line.\n" "(+setrom variablename setting)"); Cmd_AddCommand ("toggle", Cvar_Toggle_f, "Toggle a cvar on or off"); - Cmd_AddCommand ("help", Cvar_Help_f, "Display quake help"); Cmd_AddCommand ("cvarlist", Cvar_CvarList_f, "List all cvars"); }