add "find" command to search for for cvars
its better than "help", more organized and it shows any variable containing what you searched for from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2217
This commit is contained in:
1 parent
d77ccd0dfc
commit
38c612a752
2 files changed
+81
-38
No files matched your search
+77
-24
@@ -49,6 +49,7 @@ static void COM_CEchoDuration_f(void);
|
||||
static void COM_Exec_f(void);
|
||||
static void COM_Wait_f(void);
|
||||
static void COM_Help_f(void);
|
||||
static void COM_Find_f(void);
|
||||
static void COM_Toggle_f(void);
|
||||
static void COM_Add_f(void);
|
||||
|
||||
@@ -299,6 +300,7 @@ void COM_Init(void)
|
||||
COM_AddCommand("exec", COM_Exec_f);
|
||||
COM_AddCommand("wait", COM_Wait_f);
|
||||
COM_AddCommand("help", COM_Help_f);
|
||||
COM_AddCommand("find", COM_Find_f);
|
||||
COM_AddCommand("toggle", COM_Toggle_f);
|
||||
COM_AddCommand("add", COM_Add_f);
|
||||
RegisterNetXCmd(XD_NETVAR, Got_NetVar);
|
||||
@@ -820,7 +822,7 @@ static void COM_Help_f(void)
|
||||
if (cvar)
|
||||
{
|
||||
CONS_Printf("\x82""Variable %s:\n", cvar->name);
|
||||
CONS_Printf(M_GetText(" flags :"));
|
||||
CONS_Printf(M_GetText(" flags: "));
|
||||
if (cvar->flags & CV_SAVE)
|
||||
CONS_Printf("AUTOSAVE ");
|
||||
if (cvar->flags & CV_FLOAT)
|
||||
@@ -874,30 +876,9 @@ static void COM_Help_f(void)
|
||||
return;
|
||||
}
|
||||
|
||||
CONS_Printf("No exact match, searching...\n");
|
||||
// commands
|
||||
CONS_Printf("\x82""Commands:\n");
|
||||
for (cmd = com_commands; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (!strstr(cmd->name, help))
|
||||
continue;
|
||||
CONS_Printf("%s ",cmd->name);
|
||||
i++;
|
||||
}
|
||||
CONS_Printf("No variable or command named %s", help);
|
||||
CONS_Printf("\x82""\nCheck wiki.srb2.org for more or try typing help without arguments\n");
|
||||
|
||||
// variables
|
||||
CONS_Printf("\x82""\nVariables:\n");
|
||||
for (cvar = consvar_vars; cvar; cvar = cvar->next)
|
||||
{
|
||||
if ((cvar->flags & CV_NOSHOWHELP) || (!strstr(cvar->name, help)))
|
||||
continue;
|
||||
CONS_Printf("%s ", cvar->name);
|
||||
i++;
|
||||
}
|
||||
|
||||
CONS_Printf("\x82""\nCheck wiki.srb2.org for more or type help <command or variable>\n");
|
||||
|
||||
CONS_Debug(DBG_GAMELOGIC, "\x87Total : %d\n", i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -927,6 +908,78 @@ static void COM_Help_f(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void COM_Find_f(void)
|
||||
{
|
||||
static char prefix[80];
|
||||
xcommand_t *cmd;
|
||||
consvar_t *cvar;
|
||||
cmdalias_t *alias;
|
||||
const char *match;
|
||||
const char *help;
|
||||
size_t helplen;
|
||||
boolean matchesany;
|
||||
|
||||
if (COM_Argc() != 2)
|
||||
{
|
||||
CONS_Printf(M_GetText("find <text>: Search for variables, commands and aliases containing <text>\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
help = COM_Argv(1);
|
||||
helplen = strlen(help);
|
||||
CONS_Printf("\x82""Variables:\n");
|
||||
matchesany = false;
|
||||
for (cvar = consvar_vars; cvar; cvar = cvar->next)
|
||||
{
|
||||
if (cvar->flags & CV_NOSHOWHELP)
|
||||
continue;
|
||||
match = strstr(cvar->name, help);
|
||||
if (match != NULL)
|
||||
{
|
||||
memcpy(prefix, cvar->name, match - cvar->name);
|
||||
prefix[match - cvar->name] = '\0';
|
||||
CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]);
|
||||
matchesany = true;
|
||||
}
|
||||
}
|
||||
if (!matchesany)
|
||||
CONS_Printf(" (none)\n");
|
||||
|
||||
CONS_Printf("\x82""Commands:\n");
|
||||
matchesany = false;
|
||||
for (cmd = com_commands; cmd; cmd = cmd->next)
|
||||
{
|
||||
match = strstr(cmd->name, help);
|
||||
if (match != NULL)
|
||||
{
|
||||
memcpy(prefix, cmd->name, match - cmd->name);
|
||||
prefix[match - cmd->name] = '\0';
|
||||
CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]);
|
||||
matchesany = true;
|
||||
}
|
||||
}
|
||||
if (!matchesany)
|
||||
CONS_Printf(" (none)\n");
|
||||
|
||||
CONS_Printf("\x82""Aliases:\n");
|
||||
matchesany = false;
|
||||
for (alias = com_alias; alias; alias = alias->next)
|
||||
{
|
||||
match = strstr(alias->name, help);
|
||||
if (match != NULL)
|
||||
{
|
||||
memcpy(prefix, alias->name, match - alias->name);
|
||||
prefix[match - alias->name] = '\0';
|
||||
CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]);
|
||||
matchesany = true;
|
||||
}
|
||||
}
|
||||
if (!matchesany)
|
||||
CONS_Printf(" (none)\n");
|
||||
}
|
||||
|
||||
|
||||
/** Toggles a console variable. Useful for on/off values.
|
||||
*
|
||||
* This works on on/off, yes/no values only
|
||||
|
||||
+4
-14
@@ -869,7 +869,9 @@ boolean CON_Responder(event_t *ev)
|
||||
static UINT8 consdown = false; // console is treated differently due to rare usage
|
||||
|
||||
// sequential completions a la 4dos
|
||||
static char completion[80];
|
||||
static char completioncmd[80 + sizeof("find ")] = "find ";
|
||||
static char *completion = &completioncmd[sizeof("find ")-1];
|
||||
|
||||
static INT32 comskips, varskips;
|
||||
|
||||
const char *cmd = "";
|
||||
@@ -948,7 +950,6 @@ boolean CON_Responder(event_t *ev)
|
||||
// show all cvars/commands that match what we have inputted
|
||||
if (key == KEY_TAB)
|
||||
{
|
||||
size_t i, len;
|
||||
|
||||
if (!completion[0])
|
||||
{
|
||||
@@ -957,19 +958,8 @@ boolean CON_Responder(event_t *ev)
|
||||
strcpy(completion, inputlines[inputline]);
|
||||
comskips = varskips = 0;
|
||||
}
|
||||
len = strlen(completion);
|
||||
|
||||
//first check commands
|
||||
CONS_Printf("\nCommands:\n");
|
||||
for (i = 0, cmd = COM_CompleteCommand(completion, i); cmd; cmd = COM_CompleteCommand(completion, ++i))
|
||||
CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len);
|
||||
if (i == 0) CONS_Printf(" (none)\n");
|
||||
|
||||
//now we move on to CVARs
|
||||
CONS_Printf("Variables:\n");
|
||||
for (i = 0, cmd = CV_CompleteVar(completion, i); cmd; cmd = CV_CompleteVar(completion, ++i))
|
||||
CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len);
|
||||
if (i == 0) CONS_Printf(" (none)\n");
|
||||
COM_BufInsertText(completioncmd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user