Added a bonus feature: %i evaluation in aliases. Just put %i in an alias

and it will get replaced with the ith argument to the alias, 0 being the
name of the alias itself.  %% will get replaced by %, out of range
numbers will simply be removed, and non-numbers will be ignored.
This commit is contained in:
Brian Koropoff 2002-03-04 02:37:40 +00:00
parent 7241d69036
commit 669ca72e4f

View file

@ -684,6 +684,33 @@ Cmd_ProcessEscapes (dstring_t *dstr) {
}
}
/*
Cmd_ProcessPercents
Replaces %i with Cmd_Argv(i)
*/
void Cmd_ProcessPercents (dstring_t *dstr) {
int i, n;
long int num;
char *str = dstr->str;
for (i = 0; i < strlen(str); i++) {
if (str[i] == '%') {
if (str[i+1] == '%') {
dstring_snip (dstr, i, 1);
continue;
}
for (n = 1; isdigit(str[i+n]); n++);
if (n < 2)
continue;
num = strtol(str+i+1, 0, 10);
dstring_snip (dstr, i, n);
dstring_insertstr (dstr, Cmd_Argv(num), i);
}
}
}
/*
Cmd_TokenizeString
@ -725,7 +752,7 @@ Cmd_TokenizeString (const char *text, qboolean filter)
}
len = Cmd_GetToken (str + i);
if (!len)
return;
break;
cmd_argc++;
if (cmd_argc > cmd_maxargc) {
cmd_argv = realloc(cmd_argv, sizeof(dstring_t *)*cmd_argc);
@ -1023,13 +1050,18 @@ Cmd_ExecuteString (const char *text, cmd_source_t src)
// check alias
a = (cmdalias_t*)Hash_Find (cmd_alias_hash, cmd_argv[0]->str);
if (a) {
Cbuf_InsertText ("\n");
Cbuf_InsertText (a->value);
dstring_t *temp = dstring_newstr ();
dstring_appendstr (temp, "\n");
dstring_appendstr (temp, a->value);
Cmd_ProcessPercents (temp);
Cbuf_InsertText (temp->str);
dstring_delete (temp);
return;
}
if (cmd_warncmd->int_val || developer->int_val)
Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0));
cmd_argc = 0;
}
/*