]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Print cvar aliases in apropos and cvarlist output properly
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 9 Jun 2020 14:58:45 +0000 (14:58 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 9 Jun 2020 14:58:45 +0000 (14:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12659 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
cvar.c

diff --git a/cmd.c b/cmd.c
index 81f9660307731973755a28ab27a03a31c3d734dc..d2369157273c4a0c7a794989e0c6a56999f69de1 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -1429,7 +1429,6 @@ static void Cmd_Apropos_f(cmd_state_t *cmd)
        int count;
        qboolean ispattern;
        char vabuf[1024];
-       char *cvar_name;
 
        if (Cmd_Argc(cmd) > 1)
                partial = Cmd_Args(cmd);
@@ -1446,26 +1445,22 @@ static void Cmd_Apropos_f(cmd_state_t *cmd)
        count = 0;
        for (cvar = cmd->cvars->vars; cvar; cvar = cvar->next)
        {
-               if (!matchpattern_with_separator(cvar->name, partial, true, "", false) &&
-                   !matchpattern_with_separator(cvar->description, partial, true, "", false))
+               if (matchpattern_with_separator(cvar->name, partial, true, "", false) ||
+                   matchpattern_with_separator(cvar->description, partial, true, "", false))
                {
-                       for (int i = 0; i < cvar->aliasindex; i++)
-                       {
-                               if (!matchpattern_with_separator(cvar->aliases[i], partial, true, "", false)) {
-                                       continue;
-                               } else {
-                                       cvar_name = cvar->aliases[i];
-                                       goto print;
-                               }
-                       }       
-                       continue;
-               } else {
-                       cvar_name = (char *)cvar->name;
-print:
                        Con_Printf ("cvar ");
-                       Cvar_PrintHelp(cvar, cvar_name, true);
+                       Cvar_PrintHelp(cvar, cvar->name, true);
                        count++;
                }
+               for (int i = 0; i < cvar->aliasindex; i++)
+               {
+                       if (matchpattern_with_separator(cvar->aliases[i], partial, true, "", false))
+                       {
+                               Con_Printf ("cvar ");
+                               Cvar_PrintHelp(cvar, cvar->aliases[i], true);
+                               count++;
+                       }
+               }
        }
        for (func = cmd->userdefined->csqc_functions; func; func = func->next)
        {
diff --git a/cvar.c b/cvar.c
index 7022f085d21c16085d0f34ff50eb308bcdb7b11d..7e73bec455e0b4dc7a0c948c55cb7dbd41a72c98 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -1002,39 +1002,47 @@ void Cvar_List_f(cmd_state_t *cmd)
        cvar_state_t *cvars = cmd->cvars;
        cvar_t *cvar;
        const char *partial;
-       size_t len;
        int count;
        qboolean ispattern;
+       char vabuf[1024];
 
        if (Cmd_Argc(cmd) > 1)
        {
                partial = Cmd_Argv(cmd, 1);
-               len = strlen(partial);
                ispattern = (strchr(partial, '*') || strchr(partial, '?'));
+               if(!ispattern)
+                       partial = va(vabuf, sizeof(vabuf), "%s*", partial);
        }
        else
        {
-               partial = NULL;
-               len = 0;
+               partial = va(vabuf, sizeof(vabuf), "*");
                ispattern = false;
        }
 
        count = 0;
        for (cvar = cvars->vars; cvar; cvar = cvar->next)
        {
-               if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len)))
-                       continue;
-
-               Cvar_PrintHelp(cvar, cvar->name, true);
-               count++;
+               if (matchpattern_with_separator(cvar->name, partial, false, "", false))
+               {
+                       Cvar_PrintHelp(cvar, cvar->name, true);
+                       count++;
+               }
+               for (int i = 0; i < cvar->aliasindex; i++)
+               {
+                       if (matchpattern_with_separator(cvar->aliases[i], partial, false, "", false))
+                       {
+                               Cvar_PrintHelp(cvar, cvar->aliases[i], true);
+                               count++;
+                       }
+               }
        }
 
-       if (len)
+       if (Cmd_Argc(cmd) > 1)
        {
                if(ispattern)
                        Con_Printf("%i cvar%s matching \"%s\"\n", count, (count > 1) ? "s" : "", partial);
                else
-                       Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", partial);
+                       Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", Cmd_Argv(cmd,1));
        }
        else
                Con_Printf("%i cvar(s)\n", count);