mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 06:51:47 +00:00
Changed aliases to be handled by the command registering system in
preparation of separating GIB into its own module. Command-related functions will stay in util, but the buffer handling code and interpreter will be moved out of cmd.c.
This commit is contained in:
parent
84b46d720e
commit
13d6898fe0
3 changed files with 38 additions and 129 deletions
|
@ -99,6 +99,9 @@ typedef struct cmd_thread_s {
|
||||||
struct cmd_thread_s *prev, *next; // Linked list
|
struct cmd_thread_s *prev, *next; // Linked list
|
||||||
} cmd_thread_t;
|
} cmd_thread_t;
|
||||||
|
|
||||||
|
typedef struct cmd_event_s {
|
||||||
|
struct dstring_s *name, *command;
|
||||||
|
} cmd_event_t;
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void escape (dstring_t * dstr, const char *clist);
|
void escape (dstring_t * dstr, const char *clist);
|
||||||
|
@ -124,7 +127,7 @@ void Cbuf_Init (void);
|
||||||
void Cbuf_AddTextTo (cmd_buffer_t *buffer, const char *text);
|
void Cbuf_AddTextTo (cmd_buffer_t *buffer, const char *text);
|
||||||
// adds text to the end of a specific buffer
|
// adds text to the end of a specific buffer
|
||||||
void Cbuf_AddText (const char *text);
|
void Cbuf_AddText (const char *text);
|
||||||
// adds text to the end of the active buffer. By default this is the console bufer
|
// adds text to the end of the active buffer. By default this is the console buffer.
|
||||||
|
|
||||||
void Cbuf_InsertText (const char *text);
|
void Cbuf_InsertText (const char *text);
|
||||||
// inserts text at the beginning of the active buffer, ahead of other commands
|
// inserts text at the beginning of the active buffer, ahead of other commands
|
||||||
|
@ -172,8 +175,6 @@ const char *Cmd_CompleteCommand (const char *partial);
|
||||||
// attempts to match a partial command for automatic command line completion
|
// attempts to match a partial command for automatic command line completion
|
||||||
// returns NULL if nothing fits
|
// returns NULL if nothing fits
|
||||||
|
|
||||||
int Cmd_CompleteAliasCountPossible (const char *partial);
|
|
||||||
const char **Cmd_CompleteAliasBuildList (const char *partial);
|
|
||||||
int Cmd_CompleteCountPossible (const char *partial);
|
int Cmd_CompleteCountPossible (const char *partial);
|
||||||
const char **Cmd_CompleteBuildList (const char *partial);
|
const char **Cmd_CompleteBuildList (const char *partial);
|
||||||
const char *Cmd_CompleteAlias (const char *partial);
|
const char *Cmd_CompleteAlias (const char *partial);
|
||||||
|
|
|
@ -57,7 +57,7 @@ Con_BasicCompleteCommandLine (inputline_t *il)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
const char *cmd = "", **list[3] = {0, 0, 0};
|
const char *cmd = "", **list[3] = {0, 0, 0};
|
||||||
int cmd_len, a, c, i, v;
|
int cmd_len, c, i, v;
|
||||||
|
|
||||||
s = il->lines[il->edit_line] + 1;
|
s = il->lines[il->edit_line] + 1;
|
||||||
if (*s == '\\' || *s == '/')
|
if (*s == '\\' || *s == '/')
|
||||||
|
@ -66,18 +66,15 @@ Con_BasicCompleteCommandLine (inputline_t *il)
|
||||||
// Count number of possible matches
|
// Count number of possible matches
|
||||||
c = Cmd_CompleteCountPossible(s);
|
c = Cmd_CompleteCountPossible(s);
|
||||||
v = Cvar_CompleteCountPossible(s);
|
v = Cvar_CompleteCountPossible(s);
|
||||||
a = Cmd_CompleteAliasCountPossible(s);
|
|
||||||
|
|
||||||
if (!(c + v + a)) // No possible matches
|
if (!(c + v)) // No possible matches
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (c + v + a == 1) {
|
if (c + v == 1) {
|
||||||
if (c)
|
if (c)
|
||||||
list[0] = Cmd_CompleteBuildList(s);
|
list[0] = Cmd_CompleteBuildList(s);
|
||||||
else if (v)
|
|
||||||
list[0] = Cvar_CompleteBuildList(s);
|
|
||||||
else
|
else
|
||||||
list[0] = Cmd_CompleteAliasBuildList(s);
|
list[0] = Cvar_CompleteBuildList(s);
|
||||||
cmd = *list[0];
|
cmd = *list[0];
|
||||||
cmd_len = strlen (cmd);
|
cmd_len = strlen (cmd);
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,8 +82,6 @@ Con_BasicCompleteCommandLine (inputline_t *il)
|
||||||
cmd = *(list[0] = Cmd_CompleteBuildList(s));
|
cmd = *(list[0] = Cmd_CompleteBuildList(s));
|
||||||
if (v)
|
if (v)
|
||||||
cmd = *(list[1] = Cvar_CompleteBuildList(s));
|
cmd = *(list[1] = Cvar_CompleteBuildList(s));
|
||||||
if (a)
|
|
||||||
cmd = *(list[2] = Cmd_CompleteAliasBuildList(s));
|
|
||||||
|
|
||||||
cmd_len = strlen (s);
|
cmd_len = strlen (s);
|
||||||
do {
|
do {
|
||||||
|
@ -119,18 +114,13 @@ Con_BasicCompleteCommandLine (inputline_t *il)
|
||||||
Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":");
|
Con_Printf("%i possible variable%s\n", v, (v > 1) ? "s: " : ":");
|
||||||
Con_DisplayList(list[1], con_linewidth);
|
Con_DisplayList(list[1], con_linewidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a) {
|
|
||||||
Con_Printf("%i possible aliases%s\n", a, (a > 1) ? "s: " : ":");
|
|
||||||
Con_DisplayList(list[2], con_linewidth);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
il->lines[il->edit_line][1] = '/';
|
il->lines[il->edit_line][1] = '/';
|
||||||
strncpy(il->lines[il->edit_line] + 2, cmd, cmd_len);
|
strncpy(il->lines[il->edit_line] + 2, cmd, cmd_len);
|
||||||
il->linepos = cmd_len + 2;
|
il->linepos = cmd_len + 2;
|
||||||
if (c + v + a == 1) {
|
if (c + v == 1) {
|
||||||
il->lines[il->edit_line][il->linepos] = ' ';
|
il->lines[il->edit_line][il->linepos] = ' ';
|
||||||
il->linepos++;
|
il->linepos++;
|
||||||
}
|
}
|
||||||
|
|
140
libs/util/cmd.c
140
libs/util/cmd.c
|
@ -1510,7 +1510,6 @@ void
|
||||||
Cmd_ExecuteParsed (cmd_source_t src)
|
Cmd_ExecuteParsed (cmd_source_t src)
|
||||||
{
|
{
|
||||||
cmd_function_t *cmd;
|
cmd_function_t *cmd;
|
||||||
cmdalias_t *a;
|
|
||||||
|
|
||||||
cmd_source = src;
|
cmd_source = src;
|
||||||
|
|
||||||
|
@ -1536,20 +1535,7 @@ Cmd_ExecuteParsed (cmd_source_t src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check alias
|
// check alias
|
||||||
a = (cmdalias_t *) Hash_Find (cmd_alias_hash, Cmd_Argv (0));
|
|
||||||
if (a) {
|
|
||||||
int i;
|
|
||||||
cmd_buffer_t *sub; // Create a new buffer to execute the alias in
|
|
||||||
sub = Cmd_NewBuffer (true);
|
|
||||||
sub->restricted = a->restricted;
|
|
||||||
sub->legacy = a->legacy;
|
|
||||||
Cbuf_InsertTextTo (sub, a->value);
|
|
||||||
for (i = 0; i < Cmd_Argc (); i++)
|
|
||||||
Cmd_SetLocal (sub, va ("%i", i), Cmd_Argv (i));
|
|
||||||
Cmd_SetLocal (sub, "argn", va ("%i", Cmd_Argc ()));
|
|
||||||
Cbuf_ExecuteSubroutine (sub);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_warncmd->int_val || developer->int_val)
|
if (cmd_warncmd->int_val || developer->int_val)
|
||||||
Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0));
|
Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0));
|
||||||
|
@ -1584,11 +1570,6 @@ Cmd_AddCommand (const char *cmd_name, xcommand_t function,
|
||||||
cmd_function_t *cmd;
|
cmd_function_t *cmd;
|
||||||
cmd_function_t **c;
|
cmd_function_t **c;
|
||||||
|
|
||||||
// fail if the command is a variable name
|
|
||||||
if (Cvar_FindVar (cmd_name)) {
|
|
||||||
Sys_Printf ("Cmd_AddCommand: %s already defined as a var\n", cmd_name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// fail if the command already exists
|
// fail if the command already exists
|
||||||
cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name);
|
cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name);
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
|
@ -1748,95 +1729,6 @@ Cmd_CompleteBuildList (const char *partial)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Cmd_CompleteAlias
|
|
||||||
|
|
||||||
New function for tab-completion system
|
|
||||||
Added by EvilTypeGuy
|
|
||||||
Thanks to Fett erich@heintz.com
|
|
||||||
Thanks to taniwha
|
|
||||||
*/
|
|
||||||
const char *
|
|
||||||
Cmd_CompleteAlias (const char *partial)
|
|
||||||
{
|
|
||||||
cmdalias_t *alias;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = strlen (partial);
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// Check functions
|
|
||||||
for (alias = cmd_alias; alias; alias = alias->next)
|
|
||||||
if (!strncasecmp (partial, alias->name, len))
|
|
||||||
return alias->name;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Cmd_CompleteAliasCountPossible
|
|
||||||
|
|
||||||
New function for tab-completion system
|
|
||||||
Added by EvilTypeGuy
|
|
||||||
Thanks to Fett erich@heintz.com
|
|
||||||
Thanks to taniwha
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
Cmd_CompleteAliasCountPossible (const char *partial)
|
|
||||||
{
|
|
||||||
cmdalias_t *alias;
|
|
||||||
int len;
|
|
||||||
int h;
|
|
||||||
|
|
||||||
h = 0;
|
|
||||||
|
|
||||||
len = strlen (partial);
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Loop through the command list and count all partial matches
|
|
||||||
for (alias = cmd_alias; alias; alias = alias->next)
|
|
||||||
if (!strncasecmp (partial, alias->name, len))
|
|
||||||
h++;
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Cmd_CompleteAliasBuildList
|
|
||||||
|
|
||||||
New function for tab-completion system
|
|
||||||
Added by EvilTypeGuy
|
|
||||||
Thanks to Fett erich@heintz.com
|
|
||||||
Thanks to taniwha
|
|
||||||
*/
|
|
||||||
const char **
|
|
||||||
Cmd_CompleteAliasBuildList (const char *partial)
|
|
||||||
{
|
|
||||||
cmdalias_t *alias;
|
|
||||||
int len = 0;
|
|
||||||
int bpos = 0;
|
|
||||||
int sizeofbuf = (Cmd_CompleteAliasCountPossible (partial) + 1) *
|
|
||||||
sizeof (char *);
|
|
||||||
const char **buf;
|
|
||||||
|
|
||||||
len = strlen (partial);
|
|
||||||
buf = malloc (sizeofbuf + sizeof (char *));
|
|
||||||
|
|
||||||
SYS_CHECKMEM (buf);
|
|
||||||
// Loop through the alias list and print all matches
|
|
||||||
for (alias = cmd_alias; alias; alias = alias->next)
|
|
||||||
if (!strncasecmp (partial, alias->name, len))
|
|
||||||
buf[bpos++] = alias->name;
|
|
||||||
|
|
||||||
buf[bpos] = NULL;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cmd_CheckParm
|
Cmd_CheckParm
|
||||||
|
|
||||||
|
@ -1933,6 +1825,30 @@ cmd_get_key (void *c, void *unused)
|
||||||
return cmd->name;
|
return cmd->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cmd_Runalias_f (void)
|
||||||
|
{
|
||||||
|
cmdalias_t *a;
|
||||||
|
|
||||||
|
a = (cmdalias_t *) Hash_Find (cmd_alias_hash, Cmd_Argv (0));
|
||||||
|
|
||||||
|
if (a) {
|
||||||
|
int i;
|
||||||
|
cmd_buffer_t *sub; // Create a new buffer to execute the alias in
|
||||||
|
sub = Cmd_NewBuffer (true);
|
||||||
|
sub->restricted = a->restricted;
|
||||||
|
sub->legacy = a->legacy;
|
||||||
|
Cbuf_InsertTextTo (sub, a->value);
|
||||||
|
for (i = 0; i < Cmd_Argc (); i++)
|
||||||
|
Cmd_SetLocal (sub, va ("%i", i), Cmd_Argv (i));
|
||||||
|
Cmd_SetLocal (sub, "argn", va ("%i", Cmd_Argc ()));
|
||||||
|
Cbuf_ExecuteSubroutine (sub);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Sys_Printf ("BUG: No alias found for registered command. Please report this to the QuakeForge development team.");
|
||||||
|
Cmd_Error ("Fatal bug encountered. Execution aborted. Please contact the QuakeForge team.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cmd_Alias_f
|
Cmd_Alias_f
|
||||||
|
|
||||||
|
@ -1962,9 +1878,9 @@ Cmd_Alias_f (void)
|
||||||
Sys_Printf("alias \"%s\" {%s}\n", alias->name, alias->value);
|
Sys_Printf("alias \"%s\" {%s}\n", alias->name, alias->value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (alias) {
|
if (alias)
|
||||||
free ((char *) alias->value);
|
free ((char *) alias->value);
|
||||||
} else {
|
else {
|
||||||
cmdalias_t **a;
|
cmdalias_t **a;
|
||||||
|
|
||||||
alias = calloc (1, sizeof (cmdalias_t));
|
alias = calloc (1, sizeof (cmdalias_t));
|
||||||
|
@ -1976,6 +1892,7 @@ Cmd_Alias_f (void)
|
||||||
break;
|
break;
|
||||||
alias->next = *a;
|
alias->next = *a;
|
||||||
*a = alias;
|
*a = alias;
|
||||||
|
Cmd_AddCommand (alias->name, Cmd_Runalias_f, "User-created command.");
|
||||||
}
|
}
|
||||||
// copy the rest of the command line
|
// copy the rest of the command line
|
||||||
cmd = malloc (strlen (Cmd_Args (1)) + 2); // can never be longer
|
cmd = malloc (strlen (Cmd_Args (1)) + 2); // can never be longer
|
||||||
|
@ -2018,6 +1935,7 @@ Cmd_UnAlias_f (void)
|
||||||
free ((char *) alias->name);
|
free ((char *) alias->name);
|
||||||
free ((char *) alias->value);
|
free ((char *) alias->value);
|
||||||
free (alias);
|
free (alias);
|
||||||
|
Cmd_RemoveCommand (Cmd_Argv(1));
|
||||||
} else {
|
} else {
|
||||||
Sys_Printf ("Unknown alias \"%s\"\n", s);
|
Sys_Printf ("Unknown alias \"%s\"\n", s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue