From 449895baf29da51030a04b4577d8d714d98e1c87 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Thu, 17 Sep 2020 12:31:14 +0000 Subject: [PATCH] Revert "cmd: Reduce duplicate code with command lookup" This reverts commit 47015126a6457cafc71849edb16d2cac80c34c5c. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12930 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 73 +++++++++++++++++++++++++++++++---------------------------- cmd.h | 2 -- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/cmd.c b/cmd.c index 3b3fdfd1..d0ef7750 100644 --- 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 9ef9a9ab..cba96ef2 100644 --- 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); -- 2.39.2