mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-25 21:21:47 +00:00
Replace the alias if an alias already exists
Reduces wasting memory by having multiple aliases with the same name
This commit is contained in:
parent
c55b2f2943
commit
a90151570f
1 changed files with 29 additions and 8 deletions
|
@ -692,11 +692,36 @@ static void print_alias(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void add_alias(char *newname, char *newcmd)
|
||||||
|
{
|
||||||
|
cmdalias_t *a;
|
||||||
|
|
||||||
|
// Check for existing aliases first
|
||||||
|
for (a = com_alias; a; a = a->next)
|
||||||
|
{
|
||||||
|
if (!stricmp(newname, a->name))
|
||||||
|
{
|
||||||
|
Z_Free(a->value); // Free old cmd
|
||||||
|
a->value = newcmd;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No alias found, add it instead
|
||||||
|
a = ZZ_Alloc(sizeof *a);
|
||||||
|
a->next = com_alias;
|
||||||
|
com_alias = a;
|
||||||
|
|
||||||
|
a->name = newname;
|
||||||
|
a->value = newcmd;
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a command name that replaces another command.
|
/** Creates a command name that replaces another command.
|
||||||
*/
|
*/
|
||||||
static void COM_Alias_f(void)
|
static void COM_Alias_f(void)
|
||||||
{
|
{
|
||||||
cmdalias_t *a;
|
char *name;
|
||||||
|
char *zcmd;
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
size_t i, c;
|
size_t i, c;
|
||||||
|
|
||||||
|
@ -707,11 +732,7 @@ static void COM_Alias_f(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = ZZ_Alloc(sizeof *a);
|
name = Z_StrDup(COM_Argv(1));
|
||||||
a->next = com_alias;
|
|
||||||
com_alias = a;
|
|
||||||
|
|
||||||
a->name = Z_StrDup(COM_Argv(1));
|
|
||||||
|
|
||||||
// copy the rest of the command line
|
// copy the rest of the command line
|
||||||
cmd[0] = 0; // start out with a null string
|
cmd[0] = 0; // start out with a null string
|
||||||
|
@ -723,8 +744,8 @@ static void COM_Alias_f(void)
|
||||||
strcat(cmd, " ");
|
strcat(cmd, " ");
|
||||||
}
|
}
|
||||||
strcat(cmd, "\n");
|
strcat(cmd, "\n");
|
||||||
|
zcmd = Z_StrDup(cmd);
|
||||||
a->value = Z_StrDup(cmd);
|
add_alias(name, zcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints a line of text to the console.
|
/** Prints a line of text to the console.
|
||||||
|
|
Loading…
Reference in a new issue