コード例 #1
0
ファイル: MQ2Bucles.cpp プロジェクト: Cilraaz/MacroQuest2
// ***************************************************************************
// Function:    CommandWhile
// Description: Our '/while' command
// Usage:       /while (<conditions>)
// ***************************************************************************
VOID CommandWhile(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szCond[MAX_STRING] = {0};
    if (!gMacroBlock) {
        MacroError("Can only use /while during a macro.");
        return;
    }
   bRunNextCommand = TRUE;
   if (szLine[0]!='(')
   {
       FatalError("Failed to parse /while command.  Expected () around conditions.");
      SyntaxError("Usage: /while (<conditions>)");
        return;
   }
   PCHAR pEnd=&szLine[1];
   DWORD nParens=1;
   while(1)
   {
      if (*pEnd=='(')
         nParens++;
      else if (*pEnd==')')
      {
         nParens--;
         if (nParens==0)
         {
            pEnd++;
            if (*pEnd!=0)
            {
               FatalError("Failed to parse /while command. Parameters after conditions.");
               SyntaxError("Usage: /while (<conditions>)");
               return;
            }
            break;
         }
      }
      else if (*pEnd==0)
      {
         FatalError("Failed to parse /while command.  Could not find conditions to evaluate.");
         SyntaxError("Usage: /while (<conditions>)");
         return;
      }
      ++pEnd;
   } // while

   strcpy(szCond,szLine);

   DOUBLE Result=0;
   if (!Calculate(szCond,Result))
   {
      FatalError("Failed to parse /while condition '%s', non-numeric encountered",szCond);
      return;
   }
   if (Result==0)
      EndWhile(pChar, gMacroBlock);
}
コード例 #2
0
//yes this is going to work, i just need some more time testing it -eqmule
VOID WhileCmd(PSPAWNINFO pChar, PCHAR szLine)
{
    CHAR szCond[MAX_STRING] = {0};

    if (szLine[0]!='(')
    {
        FatalError("Failed to parse /while command.  Expected () around conditions.");
        SyntaxError("Usage: /while (<conditions>) <command>");
        return;
    }

    PCHAR pEnd=&szLine[1];
    DWORD nParens=1;
    while(1)
    {
        if (*pEnd=='(')
            nParens++;
        else if (*pEnd==')')
        {
            nParens--;
            if (nParens==0)
            {
                pEnd++;
                if (*pEnd!=' ')
                {
                    FatalError("Failed to parse /while command.  Could not find command to execute.");
                    SyntaxError("Usage: /while (<conditions>) <command>");
                    return;
                }
                break;
            }
        }
        else if (*pEnd==0)
        {
            FatalError("Failed to parse /while command.  Could not find command to execute.");
            SyntaxError("Usage: /while (<conditions>) <command>");
            return;
        }
        ++pEnd;
    }

    *pEnd=0;
    strcpy(szCond,szLine);
    *pEnd=' ';
    ++pEnd;



    DOUBLE Result=0;
    if (!Calculate(szCond,Result))
    {
        FatalError("Failed to parse /while condition '%s', non-numeric encountered",szCond);
        return;
    }

	//ok so we have a loop...
	//lets check all the lines within it
	//and mark the end so the interpreter knows when to exit it
	MarkWhile(pChar,pEnd);
	
	
    if (Result!=0)
        DoCommand(pChar,pEnd); 
    else 
		EndWhile(pChar,pEnd, gMacroBlock);
}