Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //original botscript IF statement
- static void parse_If( FILE *pFile )
- {
- ULONG ulSavedBufferPosition;
- LONG lJumpAddressPointer;
- MAIN_DebugMessage( "--- parse_If ---\n" );
- TOKEN_NextTokenMustBe( pFile, TOKEN_LPAREN, "Missing ( after if statement!\n" );
- TOKEN_GetNextToken( pFile );
- parse_EvaluateExpression( pFile );
- TOKEN_TokenMustBe( TOKEN_RPAREN, "Missing ) after if statement!\n" );
- BUFFER_WriteHeader( DH_IFNOTGOTO );
- lJumpAddressPointer = BUFFER_GetCurrentPosition( );
- ulSavedBufferPosition = BUFFER_GetCurrentPosition( );
- BUFFER_SkipLong( );
- TOKEN_GetNextToken( pFile );
- if ( parse_ProcessStatement( pFile, STATEMENT_IF ) == false )
- ERROR_Error( "Invalid statement, %s, after \"if\"!\n", TOKEN_GetCurrentTokenString( ));
- if ( TOKEN_GetCurrentToken( ) == TOKEN_ELSE )
- {
- ULONG ulCurrentBufferPosition;
- ULONG ulSavedBufferPosition2;
- BUFFER_WriteHeader( DH_GOTO );
- ulSavedBufferPosition2 = BUFFER_GetCurrentPosition( );
- BUFFER_SkipLong( );
- // Save the current buffer position, since we'll need to get back to this.
- ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
- // Go to the longword after the "IFNOTGOTO" header, and write the current buffer
- // address, since that's where the script should go to if the condition is false.
- /*
- BUFFER_SetCurrentPosition( ulSavedBufferPosition );
- BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
- BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
- */
- BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition );
- TOKEN_GetNextToken( pFile );
- if ( parse_ProcessStatement( pFile, STATEMENT_ELSE ) == false )
- ERROR_Error( "Invalid statement after \"else\"!\n" );
- ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
- /*
- BUFFER_SetCurrentPosition( ulSavedBufferPosition2 );
- BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
- BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
- */
- BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition2 );
- }
- else
- {
- ULONG ulCurrentBufferPosition;
- // Save the current buffer position, since we'll need to get back to this.
- ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
- /*
- // Go to the longword after the "IFNOTGOTO" header, and write the current buffer
- // address, since that's where the script should go to if the condition is false.
- BUFFER_SetCurrentPosition( ulSavedBufferPosition );
- BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
- // Set the buffer back to the "current" position.
- BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
- */
- BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition );
- }
- }
- //acc 1.5 IF statement
- static void LeadingIf(void)
- {
- int jumpAddrPtr1;
- int jumpAddrPtr2;
- MS_Message(MSG_DEBUG, "---- LeadingIf ----\n");
- TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN);
- TK_NextToken();
- EvalExpression();
- TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN);
- PC_AppendCmd(PCD_IFNOTGOTO);
- jumpAddrPtr1 = pc_Address;
- PC_SkipInt();
- TK_NextToken();
- if(ProcessStatement(STMT_IF) == NO)
- {
- ERR_Error(ERR_INVALID_STATEMENT, YES);
- }
- if(tk_Token == TK_ELSE)
- {
- PC_AppendCmd(PCD_GOTO);
- jumpAddrPtr2 = pc_Address;
- PC_SkipInt();
- PC_WriteInt(pc_Address, jumpAddrPtr1);
- TK_NextToken();
- if(ProcessStatement(STMT_ELSE) == NO)
- {
- ERR_Error(ERR_INVALID_STATEMENT, YES);
- }
- PC_WriteInt(pc_Address, jumpAddrPtr2);
- }
- else
- {
- PC_WriteInt(pc_Address, jumpAddrPtr1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement