]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
apropos command
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 May 2009 16:07:32 +0000 (16:07 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 May 2009 16:07:32 +0000 (16:07 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8995 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
console.c
cvar.c

diff --git a/cmd.c b/cmd.c
index 366b33b8c4eb25977219f03a5484f0dd68b9e592..133865c931aacbe965287f3da20f090dba57b49f 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -608,7 +608,7 @@ static void Cmd_Alias_f (void)
        {
                Con_Print("Current alias commands:\n");
                for (a = cmd_alias ; a ; a=a->next)
-                       Con_Printf("%s : %s\n", a->name, a->value);
+                       Con_Printf("%s : %s", a->name, a->value);
                return;
        }
 
@@ -659,6 +659,8 @@ static void Cmd_Alias_f (void)
        strlcat (cmd, "\n", sizeof (cmd));
 
        alloclen = strlen (cmd) + 1;
+       if(alloclen >= 2)
+               cmd[alloclen - 2] = '\n'; // to make sure a newline is appended even if too long
        a->value = (char *)Z_Malloc (alloclen);
        memcpy (a->value, cmd, alloclen);
 }
@@ -1022,12 +1024,14 @@ static void Cmd_List_f (void)
 {
        cmd_function_t *cmd;
        const char *partial;
-       int len, count;
+       size_t len;
+       int count;
+       qboolean ispattern;
 
        if (Cmd_Argc() > 1)
        {
                partial = Cmd_Argv (1);
-               len = (int)strlen(partial);
+               len = strlen(partial);
        }
        else
        {
@@ -1035,21 +1039,86 @@ static void Cmd_List_f (void)
                len = 0;
        }
 
+       ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
+
        count = 0;
        for (cmd = cmd_functions; cmd; cmd = cmd->next)
        {
-               if (partial && strncmp(partial, cmd->name, len))
+               if (partial && (ispattern ? !matchpattern_with_separator(cmd->name, partial, false, "", false) : strncmp(partial, cmd->name, len)))
                        continue;
                Con_Printf("%s : %s\n", cmd->name, cmd->description);
                count++;
        }
 
-       if (partial)
-               Con_Printf("%i Command%s beginning with \"%s\"\n\n", count, (count > 1) ? "s" : "", partial);
+       if (len)
+       {
+               if(ispattern)
+                       Con_Printf("%i Command%s matching \"%s\"\n\n", count, (count > 1) ? "s" : "", partial);
+               else
+                       Con_Printf("%i Command%s beginning with \"%s\"\n\n", count, (count > 1) ? "s" : "", partial);
+       }
        else
                Con_Printf("%i Command%s\n\n", count, (count > 1) ? "s" : "");
 }
 
+static void Cmd_Apropos_f(void)
+{
+       cmd_function_t *cmd;
+       cvar_t *cvar;
+       cmdalias_t *alias;
+       const char *partial;
+       size_t len;
+       int count;
+       qboolean ispattern;
+
+       if (Cmd_Argc() > 1)
+       {
+               partial = Cmd_Args();
+               len = strlen(partial);
+       }
+       else
+       {
+               Con_Printf("usage: apropos <string>\n");
+               return;
+       }
+
+       ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
+       if(!ispattern)
+       {
+               partial = va("*%s*", partial);
+               len += 2;
+       }
+
+       count = 0;
+       Con_Printf("Cvars:\n");
+       for (cvar = cvar_vars; cvar; cvar = cvar->next)
+       {
+               if (!matchpattern_with_separator(cvar->name, partial, false, "", false))
+               if (!matchpattern_with_separator(cvar->description, partial, false, "", false))
+                       continue;
+               Con_Printf("^3%s^7: %s\n", cvar->name, cvar->description);
+               count++;
+       }
+       Con_Printf("Commands:\n");
+       for (cmd = cmd_functions; cmd; cmd = cmd->next)
+       {
+               if (!matchpattern_with_separator(cmd->name, partial, false, "", false))
+               if (!matchpattern_with_separator(cmd->description, partial, false, "", false))
+                       continue;
+               Con_Printf("^3%s^7: %s\n", cmd->name, cmd->description);
+               count++;
+       }
+       Con_Printf("Aliases:\n");
+       for (alias = cmd_alias; alias; alias = alias->next)
+       {
+               if (!matchpattern_with_separator(alias->name, partial, false, "", false))
+               if (!matchpattern_with_separator(alias->value, partial, false, "", false))
+                       continue;
+               Con_Printf("^3%s^7: %s", alias->name, alias->value);
+               count++;
+       }
+}
+
 /*
 ============
 Cmd_Init
@@ -1082,6 +1151,7 @@ void Cmd_Init_Commands (void)
        // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
        Cmd_AddCommand ("cmdlist", Cmd_List_f, "lists all console commands beginning with the specified prefix");
        Cmd_AddCommand ("cvarlist", Cvar_List_f, "lists all console variables beginning with the specified prefix");
+       Cmd_AddCommand ("apropos", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description");
 
        Cmd_AddCommand ("cvar_lockdefaults", Cvar_LockDefaults_f, "stores the current values of all cvars into their default values, only used once during startup after parsing default.cfg");
        Cmd_AddCommand ("cvar_resettodefaults_all", Cvar_ResetToDefaults_All_f, "sets all cvars to their locked default values");
index fb66ac8ec624343b1cd65ea990ecd5a48d42fff9..c8bdf140fd1e2fa70a17b33de0687cbac4f9e82d 100644 (file)
--- a/console.c
+++ b/console.c
@@ -75,9 +75,9 @@ cvar_t con_nickcompletion_flags = {CVAR_SAVE, "con_nickcompletion_flags", "11",
 #define NICKS_ALPHANUMERICS_ONLY 8
 #define NICKS_NO_SPACES 16
 
-cvar_t con_completion_playdemo = {CVAR_SAVE, "con_completion_playdemo", "*.dem"};
-cvar_t con_completion_timedemo = {CVAR_SAVE, "con_completion_timedemo", "*.dem"};
-cvar_t con_completion_exec = {CVAR_SAVE, "con_completion_exec", "*.cfg"};
+cvar_t con_completion_playdemo = {CVAR_SAVE, "con_completion_playdemo", "*.dem", "completion pattern for the playdemo command"};
+cvar_t con_completion_timedemo = {CVAR_SAVE, "con_completion_timedemo", "*.dem", "completion pattern for the timedemo command"};
+cvar_t con_completion_exec = {CVAR_SAVE, "con_completion_exec", "*.cfg", "completion pattern for the exec command"};
 
 int con_linewidth;
 int con_vislines;
diff --git a/cvar.c b/cvar.c
index 75ff70f44ad1242b7d2b630190d79b756d49605e..6cc80770a274b79f7318a0713a644887451cd6d7 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -701,9 +701,9 @@ void Cvar_List_f (void)
        if (len)
        {
                if(ispattern)
-                       Con_Printf("%i cvar(s) matching \"%s\"\n", count, partial);
+                       Con_Printf("%i cvar%s matching \"%s\"\n", count, (count > 1) ? "s" : "", partial);
                else
-                       Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial);
+                       Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", partial);
        }
        else
                Con_Printf("%i cvar(s)\n", count);