]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
Moved the $cvar parser to Cmd_TokenizeString.
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index 41c38794562dbf90b5ab7bfec9a135bb3dad0274..3a15737f0dbdc05baf1d67e55d4099238e174b86 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -394,6 +394,51 @@ cmd_source_t cmd_source;
 
 static cmd_function_t *cmd_functions;          // possible commands to execute
 
+/*
+============
+Cmd_ExecuteAlias
+
+Called for aliases and fills in the alias into the cbuffer
+============
+*/
+static void Cmd_ExecuteAlias (cmdalias_t *alias)
+{
+       const char *text = alias->value;
+       
+       while( COM_ParseTokenConsole( &text ) ) 
+       {
+               Cbuf_AddText( "\"" );
+
+               if( com_token[0] == '$' )
+               {
+                       int argNum;
+                       argNum = atoi( &com_token[1] );
+
+                       // no number at all?
+                       if( argNum == 0 )
+                       {
+                               Cbuf_AddText( com_token );
+                       }
+                       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 );
+                               Cbuf_AddText( com_token );
+                       }
+                       else
+                       {
+                               Cbuf_AddText( Cmd_Argv( argNum ) );
+                       }
+               }
+               else 
+               {
+                       Cbuf_AddText( com_token );
+               }
+
+               Cbuf_AddText( "\"" );
+       }
+       Cbuf_AddText( "\n" );
+}
+
 /*
 ========
 Cmd_List
@@ -553,6 +598,29 @@ static void Cmd_TokenizeString (const char *text)
                if (!COM_ParseTokenConsole(&text))
                        return;
 
+               // check for $cvar 
+               // (perhaps use another target buffer?)
+               if (com_token[0] == '$' && com_token[1]) 
+               {
+                       cvar_t *cvar;
+
+                       cvar = Cvar_FindVar(&com_token[1]);
+                       if (cvar)
+                       {
+                               strcpy(com_token, cvar->string);
+                       }
+                       else if( com_token[1] == '$' )
+                       {
+                               // remove the first $
+                               char *pos;
+                       
+                               for( pos = com_token ; *pos ; pos++ )
+                               {
+                                       *pos = *(pos + 1);
+                               }
+                       }
+               }
+
                if (cmd_argc < MAX_ARGS)
                {
                        l = (int)strlen(com_token) + 1;
@@ -836,7 +904,7 @@ void Cmd_ExecuteString (const char *text, cmd_source_t src)
        {
                if (!strcasecmp (cmd_argv[0], a->name))
                {
-                       Cbuf_InsertText (a->value);
+                       Cmd_ExecuteAlias(a);
                        cmd_tokenizebufferpos = oldpos;
                        return;
                }