]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Revert "cmd: Reduce duplicate code with command lookup"
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 Sep 2020 12:31:14 +0000 (12:31 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 Sep 2020 12:31:14 +0000 (12:31 +0000)
This reverts commit 47015126a6457cafc71849edb16d2cac80c34c5c.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12930 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
cmd.h

diff --git a/cmd.c b/cmd.c
index 3b3fdfd146745b184669b9952f337763517363a8..d0ef77505a872430ac6b9721444c16db46593fed 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -1906,30 +1906,6 @@ next:
        }
 }
 
-static int Cmd_Compare(const char *s1, const char *s2, size_t len, qbool casesensitive)
-{
-       if(len)
-               return (casesensitive ? strncmp(s1, s2, len) : strncasecmp(s1, s2, len));
-       else
-               return (casesensitive ? strcmp(s1, s2) : strcasecmp(s1, s2));
-}
-
-cmd_function_t *Cmd_GetCommand(cmd_state_t *cmd, const char *partial, size_t len, qbool casesensitive)
-{
-       cmd_function_t *func = NULL;
-
-       // check functions
-       for (func = cmd->userdefined->csqc_functions; func; func = func->next)
-               if (!Cmd_Compare(partial, func->name, len, casesensitive))
-                       break;
-
-       for (func=cmd->engine_functions ; func ; func=func->next)
-               if (!Cmd_Compare(partial, func->name, len, casesensitive))
-                       break;
-
-       return func;
-}
-
 /*
 ============
 Cmd_Exists
@@ -1937,11 +1913,20 @@ Cmd_Exists
 */
 qbool Cmd_Exists (cmd_state_t *cmd, const char *cmd_name)
 {
-       if(Cmd_GetCommand(cmd, cmd_name, 0, true))
-               return true;
+       cmd_function_t  *func;
+
+       for (func = cmd->userdefined->csqc_functions; func; func = func->next)
+               if (!strcmp(cmd_name, func->name))
+                       return true;
+
+       for (func=cmd->engine_functions ; func ; func=func->next)
+               if (!strcmp (cmd_name,func->name))
+                       return true;
+
        return false;
 }
 
+
 /*
 ============
 Cmd_CompleteCommand
@@ -1950,10 +1935,22 @@ Cmd_CompleteCommand
 const char *Cmd_CompleteCommand (cmd_state_t *cmd, const char *partial)
 {
        cmd_function_t *func;
+       size_t len;
+
+       len = strlen(partial);
+
+       if (!len)
+               return NULL;
+
+// check functions
+       for (func = cmd->userdefined->csqc_functions; func; func = func->next)
+               if (!strncasecmp(partial, func->name, len))
+                       return func->name;
+
+       for (func = cmd->engine_functions; func; func = func->next)
+               if (!strncasecmp(partial, func->name, len))
+                       return func->name;
 
-       func = Cmd_GetCommand(cmd, partial, strlen(partial), false);
-       if(func)
-               return func->name;
        return NULL;
 }
 
@@ -2173,12 +2170,19 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
                goto done; // no tokens
 
 // check functions
-       func = Cmd_GetCommand(cmd, cmd->argv[0], 0, false);
-       if(func)
+       for (func = cmd->userdefined->csqc_functions; func; func = func->next)
        {
-               if (func->csqcfunc && CL_VM_ConsoleCommand(text))       //[515]: csqc
-                       goto done;
-               else
+               if (!strcasecmp(cmd->argv[0], func->name))
+               {
+                       if (func->csqcfunc && CL_VM_ConsoleCommand(text))       //[515]: csqc
+                               goto done;
+                       break;
+               }
+       }
+
+       for (func = cmd->engine_functions; func; func=func->next)
+       {
+               if (!strcasecmp (cmd->argv[0], func->name))
                {
                        switch (src)
                        {
@@ -2198,6 +2202,7 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
                                        goto done;
                                }
                        }
+                       break;
                }
        }
 
diff --git a/cmd.h b/cmd.h
index 9ef9a9aba8e5fc81cbc772e647d622c85f912a83..cba96ef2d3aa8b5cb4c9d31f7b6b6c24359bfc39 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -226,8 +226,6 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
 // register commands and functions to call for them.
 // The cmd_name is referenced later, so it should not be in temp memory
 
-cmd_function_t *Cmd_GetCommand(cmd_state_t *cmd, const char *partial, size_t len, qbool casesensitive);
-
 /// used by the cvar code to check for cvar / command name overlap
 qbool Cmd_Exists (cmd_state_t *cmd, const char *cmd_name);