Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1.  
  2. //original botscript IF statement
  3. static void parse_If( FILE *pFile )
  4. {
  5.     ULONG   ulSavedBufferPosition;
  6.     LONG    lJumpAddressPointer;
  7.  
  8.     MAIN_DebugMessage( "--- parse_If ---\n" );
  9.     TOKEN_NextTokenMustBe( pFile, TOKEN_LPAREN, "Missing ( after if statement!\n" );
  10.     TOKEN_GetNextToken( pFile );
  11.     parse_EvaluateExpression( pFile );
  12.     TOKEN_TokenMustBe( TOKEN_RPAREN, "Missing ) after if statement!\n" );
  13.  
  14.     BUFFER_WriteHeader( DH_IFNOTGOTO );
  15.  
  16.     lJumpAddressPointer = BUFFER_GetCurrentPosition( );
  17.  
  18.     ulSavedBufferPosition = BUFFER_GetCurrentPosition( );
  19.     BUFFER_SkipLong( );
  20.  
  21.     TOKEN_GetNextToken( pFile );
  22.     if ( parse_ProcessStatement( pFile, STATEMENT_IF ) == false )
  23.         ERROR_Error( "Invalid statement, %s, after \"if\"!\n", TOKEN_GetCurrentTokenString( ));
  24.  
  25.     if ( TOKEN_GetCurrentToken( ) == TOKEN_ELSE )
  26.     {
  27.         ULONG   ulCurrentBufferPosition;
  28.         ULONG   ulSavedBufferPosition2;
  29.  
  30.         BUFFER_WriteHeader( DH_GOTO );
  31.  
  32.         ulSavedBufferPosition2 = BUFFER_GetCurrentPosition( );
  33.  
  34.         BUFFER_SkipLong( );
  35.  
  36.         // Save the current buffer position, since we'll need to get back to this.
  37.         ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
  38.  
  39.         // Go to the longword after the "IFNOTGOTO" header, and write the current buffer
  40.         // address, since that's where the script should go to if the condition is false.
  41. /*
  42.         BUFFER_SetCurrentPosition( ulSavedBufferPosition );
  43.         BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
  44.         BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
  45. */
  46.         BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition );
  47.  
  48.         TOKEN_GetNextToken( pFile );
  49.         if ( parse_ProcessStatement( pFile, STATEMENT_ELSE ) == false )
  50.             ERROR_Error( "Invalid statement after \"else\"!\n" );
  51.  
  52.         ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
  53. /*
  54.         BUFFER_SetCurrentPosition( ulSavedBufferPosition2 );
  55.         BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
  56.         BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
  57. */
  58.         BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition2 );
  59.     }
  60.     else
  61.     {
  62.         ULONG   ulCurrentBufferPosition;
  63.  
  64.         // Save the current buffer position, since we'll need to get back to this.
  65.         ulCurrentBufferPosition = BUFFER_GetCurrentPosition( );
  66. /*
  67.         // Go to the longword after the "IFNOTGOTO" header, and write the current buffer
  68.         // address, since that's where the script should go to if the condition is false.
  69.         BUFFER_SetCurrentPosition( ulSavedBufferPosition );
  70.         BUFFER_WriteToBuffer( (void *)&ulCurrentBufferPosition, sizeof( LONG ));
  71.  
  72.         // Set the buffer back to the "current" position.
  73.         BUFFER_SetCurrentPosition( ulCurrentBufferPosition );
  74. */
  75.         BUFFER_WriteToBufferAtPosition( (void *)&ulCurrentBufferPosition, sizeof( LONG ), ulSavedBufferPosition );
  76.     }
  77. }
  78.  
  79.  
  80.  
  81. //acc 1.5 IF statement
  82. static void LeadingIf(void)
  83. {
  84.     int jumpAddrPtr1;
  85.     int jumpAddrPtr2;
  86.  
  87.     MS_Message(MSG_DEBUG, "---- LeadingIf ----\n");
  88.     TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN);
  89.     TK_NextToken();
  90.     EvalExpression();
  91.     TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN);
  92.     PC_AppendCmd(PCD_IFNOTGOTO);
  93.     jumpAddrPtr1 = pc_Address;
  94.     PC_SkipInt();
  95.     TK_NextToken();
  96.     if(ProcessStatement(STMT_IF) == NO)
  97.     {
  98.         ERR_Error(ERR_INVALID_STATEMENT, YES);
  99.     }
  100.     if(tk_Token == TK_ELSE)
  101.     {
  102.         PC_AppendCmd(PCD_GOTO);
  103.         jumpAddrPtr2 = pc_Address;
  104.         PC_SkipInt();
  105.         PC_WriteInt(pc_Address, jumpAddrPtr1);
  106.         TK_NextToken();
  107.         if(ProcessStatement(STMT_ELSE) == NO)
  108.         {
  109.             ERR_Error(ERR_INVALID_STATEMENT, YES);
  110.         }
  111.         PC_WriteInt(pc_Address, jumpAddrPtr2);
  112.     }
  113.     else
  114.     {
  115.         PC_WriteInt(pc_Address, jumpAddrPtr1);
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement