+ // don't crash if there's no room in the outtext buffer
+ if( maxoutlen == 0 ) {
+ return;
+ }
+ maxoutlen--; // because of \0
+
+ in = intext;
+ outlen = 0;
+ inquote = 0;
+
+ while( *in && outlen < maxoutlen ) {
+ if( *in == '$' && !inquote ) {
+ // this is some kind of expansion, see what comes after the $
+ in++;
+ // replacements that can always be used:
+ // $$ is replaced with $, to allow escaping $
+ // $<cvarname> is replaced with the contents of the cvar
+ //
+ // the following can be used in aliases only:
+ // $* is replaced with all formal parameters (including name of the alias - this probably is not desirable)
+ // $0 is replaced with the name of this alias
+ // $<number> is replaced with an argument to this alias (or copied as-is if no such parameter exists), can be multiple digits
+ if( *in == '$' ) {
+ outtext[outlen++] = *in++;
+ } else if( *in == '*' && alias ) {
+ const char *linein = Cmd_Args();
+
+ // include all parameters
+ if (linein) {
+ while( *linein && outlen < maxoutlen ) {
+ outtext[outlen++] = *linein++;
+ }
+ }
+
+ in++;
+ } else if( '0' <= *in && *in <= '9' && alias ) {
+ char *nexttoken;
+ int argnum;
+
+ argnum = strtol( in, &nexttoken, 10 );
+
+ if( 0 <= argnum && argnum < Cmd_Argc() ) {
+ const char *param = Cmd_Argv( argnum );
+ while( *param && outlen < maxoutlen ) {
+ outtext[outlen++] = *param++;
+ }
+ in = nexttoken;
+ } else if( argnum >= Cmd_Argc() ) {
+ Con_Printf( "Warning: Not enough parameters passed to alias '%s', at least %i expected:\n %s\n", alias->name, argnum, alias->value );
+ outtext[outlen++] = '$';
+ }
+ } else {
+ cvar_t *cvar;
+ const char *tempin = in;
+
+ COM_ParseTokenConsole( &tempin );
+ if ((cvar = Cvar_FindVar(&com_token[0]))) {
+ const char *cvarcontent = cvar->string;
+ while( *cvarcontent && outlen < maxoutlen ) {
+ outtext[outlen++] = *cvarcontent++;
+ }
+ in = tempin;
+ } else {
+ if( alias ) {
+ Con_Printf( "Warning: could not find cvar %s when expanding alias %s\n %s\n", com_token, alias->name, alias->value );
+ } else {
+ Con_Printf( "Warning: could not find cvar %s\n", com_token );
+ }
+ outtext[outlen++] = '$';
+ }
+ }
+ } else {
+ if( *in == '"' ) {
+ inquote ^= 1;
+ }
+ outtext[outlen++] = *in++;
+ }
+ }
+ outtext[outlen] = 0;
+}
+
+/*
+============
+Cmd_ExecuteAlias
+
+Called for aliases and fills in the alias into the cbuffer
+============
+*/
+static void Cmd_ExecuteAlias (cmdalias_t *alias)
+{
+ static char buffer[ MAX_INPUTLINE + 2 ];
+ Cmd_PreprocessString( alias->value, buffer, sizeof(buffer) - 2, alias );
+ // insert at start of command buffer, so that aliases execute in order
+ // (fixes bug introduced by Black on 20050705)
+ Cbuf_InsertText( buffer );
+}
+
+/*
+========
+Cmd_List
+
+ CmdList Added by EvilTypeGuy eviltypeguy@qeradiant.com
+ Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
+
+========
+*/
+static void Cmd_List_f (void)
+{
+ cmd_function_t *cmd;
+ const char *partial;
+ int len, count;
+
+ if (Cmd_Argc() > 1)
+ {
+ partial = Cmd_Argv (1);
+ len = (int)strlen(partial);
+ }
+ else
+ {
+ partial = NULL;
+ len = 0;
+ }
+
+ count = 0;
+ for (cmd = cmd_functions; cmd; cmd = cmd->next)
+ {
+ if (partial && strncmp(partial, cmd->name, len))
+ continue;
+ Con_Printf("%s : %s\n", cmd->name, cmd->description);
+ count++;
+ }
+
+ if (partial)
+ Con_Printf("%i Command%s beginning with \"%s\"\n\n", count, (count > 1) ? "s" : "", partial);
+ else
+ Con_Printf("%i Command%s\n\n", count, (count > 1) ? "s" : "");
+}