]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Add Cvar_PrintHelp to unify cvar info printing and reduce code duplication
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 30 May 2020 19:59:12 +0000 (19:59 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 30 May 2020 19:59:12 +0000 (19:59 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12613 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
cvar.c
cvar.h

diff --git a/cmd.c b/cmd.c
index a06f39ce889e5707b4f589446a5f1d1e66f7e571..4f13c0a9f578bcdb7f92623cbba3e3d136ad892d 100644 (file)
--- 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 b4c41b7d71139b3a4a72785f08763312bc348e6e..affdc5565d8ac716e48222bc79e429ed4283d510 100644 (file)
--- 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 fd7cd6ea879ee71110015565a7105bdd8b652b85..4838824c39b709ebe7ee8de3cc6d7b7fb7e8a3cd 100644 (file)
--- 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);