From 5d803d126f21efc914464761804e4e42032c6afa Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sat, 30 May 2020 19:59:12 +0000 Subject: [PATCH] Add Cvar_PrintHelp to unify cvar info printing and reduce code duplication git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12613 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 3 ++- cvar.c | 14 +++++++++++--- cvar.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index a06f39ce..4f13c0a9 100644 --- a/cmd.c +++ b/cmd.c @@ -1442,7 +1442,8 @@ static void Cmd_Apropos_f(cmd_state_t *cmd) if (!matchpattern_with_separator(cvar->name, partial, true, "", false)) if (!matchpattern_with_separator(cvar->description, partial, true, "", false)) continue; - Con_Printf ("cvar ^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description); + Con_Printf ("cvar "); + Cvar_PrintHelp(cvar, true); count++; } for (func = cmd->userdefined->csqc_functions; func; func = func->next) diff --git a/cvar.c b/cvar.c index b4c41b7d..affdc556 100644 --- a/cvar.c +++ b/cvar.c @@ -251,6 +251,14 @@ const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, in return buf; } +void Cvar_PrintHelp(cvar_t *cvar, qboolean full) +{ + Con_Printf("^3%s^7 is \"%s\" [\"%s\"] ", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring); + if (full) + Con_Printf("%s", cvar->description); + Con_Printf("\n"); +} + // written by LadyHavoc void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, int neededflags) { @@ -259,7 +267,7 @@ void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, int needed // Loop through the command list and print all matches for (cvar = cvars->vars; cvar; cvar = cvar->next) if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags)) - Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description); + Cvar_PrintHelp(cvar, true); } // check if a cvar is held by some progs @@ -700,7 +708,7 @@ qboolean Cvar_Command (cmd_state_t *cmd) // perform a variable print or set if (Cmd_Argc(cmd) == 1) { - Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, ((v->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : v->string), v->defstring); + Cvar_PrintHelp(v, true); return true; } @@ -934,7 +942,7 @@ void Cvar_List_f(cmd_state_t *cmd) if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len))) continue; - Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring, cvar->description); + Cvar_PrintHelp(cvar, true); count++; } diff --git a/cvar.h b/cvar.h index fd7cd6ea..4838824c 100644 --- a/cvar.h +++ b/cvar.h @@ -203,6 +203,8 @@ const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, int // attempts to match a partial variable name for command line completion // returns NULL if nothing fits +void Cvar_PrintHelp(cvar_t *cvar, qboolean full); + void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, int neededflags); qboolean Cvar_Command (cmd_state_t *cmd); -- 2.39.2