All pastes #608971 Raw Edit

Unnamed

public c v1 · immutable
·published 2007-07-08 16:29 UTC
rendered paste body
/*===============Cmd_If_fCompares two cvars, if true vstr the third, if false vstr the forth===============*/void Cmd_If_f( void ) {  char	*v;  int 	v1;  int 	v2;  char	*vt;  char	*vf;  char  *op;  if (Cmd_Argc () == 6) {    v1 = Cvar_VariableIntegerValue( Cmd_Argv( 1 ) );    op = Cmd_Argv( 2 );    v2 = Cvar_VariableIntegerValue( Cmd_Argv( 3 ) );    vt = Cvar_VariableString( Cmd_Argv( 4 ) );    vf = Cvar_VariableString( Cmd_Argv( 5 ) );    if ( ( !strcmp( op, "="  ) && v1 == v2 ) ||         ( !strcmp( op, "!=" ) && v1 != v2 ) ||         ( !strcmp( op, "<"  ) && v1 <  v2 ) ||         ( !strcmp( op, "<=" ) && v1 <= v2 ) ||         ( !strcmp( op, ">"  ) && v1 >  v2 ) ||         ( !strcmp( op, ">=" ) && v1 >= v2 ) )    {      v = vt;    }    else if ( ( !strcmp( op, "="  ) && v1 != v2 ) ||              ( !strcmp( op, "!=" ) && v1 == v2 ) ||              ( !strcmp( op, "<"  ) && v1 >= v2 ) ||              ( !strcmp( op, "<=" ) && v1 >  v2 ) ||              ( !strcmp( op, ">"  ) && v1 <= v2 ) ||              ( !strcmp( op, ">=" ) && v1 <  v2 ) )    {      v = vf;    }    else    {      Com_Printf ("invalid operator in if command. valid operators are = != < > >= <=\n");      return;    }  }  else {    Com_Printf ("if <variable1> <operator> <variable2> <variablethen> <variableelse> : compares the first two variables and executes <variablethen> if true, <variableelse> if false\n");    return;  }  Cbuf_InsertText( va("%s\n", v ) );}