When players like to build alias commands they can go crazy and type long lines of stacked commands
But when you are trying to tweak your alias commands it really sucks to retype the whole alias just to change something minor.
This code, allows the user to type "alias foo" then press enter. If "foo" was already a valid alias it prints the value to the console with the cursor
at the end like
Which would allow the user to cursor back and delete the x without having to retype the whole line..] alias foo
] alias foo "echo this is just a testx!" _
Code: Select all
void Cmd_Alias_f (void)
{
cmdalias_t *a;
char cmd[1024];
int i, c;
char *s,*n;
if (cls.demoplayback)//R00k dont stuff alias commands when watching a demo.
return;
switch (Cmd_Argc())
{
case 1: //list all aliases
for (a = cmd_alias, i = 0; a; a=a->next, i++)
Con_SafePrintf (" %s: %s", a->name, a->value);
if (i)
Con_SafePrintf ("%i alias command(s)\n", i);
else
Con_SafePrintf ("no alias commands found\n");
break;
case 2: //output current alias string
n = Cmd_Argv(1);
for (a = cmd_alias ; a ; a=a->next)
if (!strcmp(Cmd_Argv(1), a->name))//R00k empty definition argument edits the current value
{
sprintf (n,"alias %s \"%s",a->name, a->value);
strcpy (key_lines[edit_line]+1, n);
key_linepos = (strlen(n) - 1);
key_lines[edit_line][key_linepos++] = '\"';
key_lines[edit_line][key_linepos] = 0;
}
break;
default: //set alias string
s = Cmd_Argv(1);
if (strlen(s) >= MAX_ALIAS_NAME)
{
Con_Printf ("Alias name is too long\n");
return;
}
// if the alias allready exists, reuse it
for (a = cmd_alias ; a ; a=a->next)
{
if (!strcmp(s, a->name))
{
Z_Free (a->value);
break;
}
}
if (!a)
{
a = Z_Malloc (sizeof(cmdalias_t));
a->next = cmd_alias;
cmd_alias = a;
}
strcpy (a->name, s);
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
c = Cmd_Argc();
for (i=2 ; i< c ; i++)
{
strcat (cmd, Cmd_Argv(i));
if ((i != c))
strcat (cmd, " ");
}
strcat (cmd, "\n");
a->value = CopyString (cmd);
break;
}
}