From 335c71afe81c5d4d0b2efd2d1c3e49589e1dadb7 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Tue, 9 Jun 2020 14:58:45 +0000 Subject: [PATCH] Print cvar aliases in apropos and cvarlist output properly git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12659 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 29 ++++++++++++----------------- cvar.c | 30 +++++++++++++++++++----------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/cmd.c b/cmd.c index 81f96603..d2369157 100644 --- 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 7022f085..7e73bec4 100644 --- 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); -- 2.39.2