Transation of comments complete
parent
0844a0f7bd
commit
0919796df7
|
@ -1,142 +1,144 @@
|
|||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 + Opérande2
|
||||
// Opérande1 - Opérande2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotAddExpr::CBotAddExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotAddExpr"; // debug
|
||||
}
|
||||
|
||||
CBotAddExpr::~CBotAddExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
|
||||
// compile une instruction de type A + B
|
||||
|
||||
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
||||
{
|
||||
CBotStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
||||
|
||||
// cherche des instructions qui peuvent convenir à gauche de l'opération + ou -
|
||||
|
||||
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B à gauche
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
||||
|
||||
// est-ce qu'on a le token + ou - ensuite ?
|
||||
|
||||
if ( p->GetType() == ID_ADD ||
|
||||
p->GetType() == ID_SUB) // plus ou moins
|
||||
{
|
||||
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType(); // de quel type le premier opérande ?
|
||||
|
||||
p = p->Next(); // saute le token de l'opération
|
||||
|
||||
// cherche des instructions qui peuvent convenir à droite
|
||||
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) à droite
|
||||
{
|
||||
// il y a un second opérande acceptable
|
||||
|
||||
type2 = pStack->GetType(); // de quel type le résultat ?
|
||||
|
||||
if ( type1 == type2 ) // les résultats sont-ils compatibles
|
||||
{
|
||||
// si ok, enregistre l'opérande dans l'objet
|
||||
inst->m_leftop = left;
|
||||
// et rend l'object à qui l'a demandé
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// en cas d'erreur, libère les éléments
|
||||
delete left;
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// si on n'a pas affaire à une opération + ou -
|
||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
||||
// à la place de l'objet "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// fait l'opération d'addition ou de soustraction
|
||||
|
||||
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pSk1 == EOX ) return TRUE;
|
||||
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// passe à l'étape suivante
|
||||
pStk1->SetState(1); // prêt pour la suite
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
// qui se trouve sur la pile, justement.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
// crée une variable temporaire pour y mettre le résultat
|
||||
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
||||
|
||||
// fait l'opération selon la demande
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
||||
break;
|
||||
case ID_SUB:
|
||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
|
||||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// expressions of type Operand1 + Operand2
|
||||
// Operand1 - Operand2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// various constructors
|
||||
|
||||
CBotAddExpr::CBotAddExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL to be able to delete without further
|
||||
name = "CBotAddExpr"; // debug
|
||||
}
|
||||
|
||||
CBotAddExpr::~CBotAddExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
|
||||
// compile une instruction de type A + B
|
||||
|
||||
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
||||
{
|
||||
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
|
||||
|
||||
// looking statements that may be suitable to the left of the operation + or -
|
||||
|
||||
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
|
||||
|
||||
// do we have the token + or - next?
|
||||
|
||||
if ( p->GetType() == ID_ADD ||
|
||||
p->GetType() == ID_SUB) // more or less
|
||||
{
|
||||
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
|
||||
inst->SetToken(p); // stores the operation
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType(); // what kind of the first operand?
|
||||
|
||||
p = p->Next(); // skip the token of the operation
|
||||
|
||||
// looking statements that may be suitable for right
|
||||
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
|
||||
{
|
||||
// there is an acceptable second operand
|
||||
|
||||
type2 = pStack->GetType(); // what kind of results?
|
||||
|
||||
if ( type1 == type2 ) // are the results consistent ?
|
||||
{
|
||||
// ok so, saves the operand in the object
|
||||
inst->m_leftop = left;
|
||||
// and makes the object on demand
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// in case of error, free the elements
|
||||
delete left;
|
||||
delete inst;
|
||||
// and transmits the error that is on the stack
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// if we are not dealing with an operation + or -
|
||||
// goes to that requested, the operand (left) found
|
||||
// place the object "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// operation is addition or subtraction
|
||||
|
||||
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||
// or is found in case of recovery
|
||||
// if ( pSk1 == EOX ) return TRUE;
|
||||
|
||||
|
||||
// according to recovery, it may be in one of two states
|
||||
|
||||
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
|
||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
|
||||
|
||||
// passes to the next step
|
||||
pStk1->SetState(1); // ready for further
|
||||
|
||||
// requires a little more stack to not touch the result of the left
|
||||
// which is on the stack, precisely.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
|
||||
// or is found in case of recovery
|
||||
|
||||
// Second state, evaluates the right operand
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
|
||||
|
||||
int type1 = pStk1->GetType(); // what kind of results?
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
// creates a temporary variable to put the result
|
||||
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
||||
|
||||
// is the operation as requested
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
|
||||
break;
|
||||
case ID_SUB:
|
||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // puts the result on the stack
|
||||
|
||||
pStk1->Return(pStk2); // frees the stack
|
||||
return pStack->Return(pStk1); // transmits the result
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,131 +1,133 @@
|
|||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 > Opérande2
|
||||
// Opérande1 != Opérande2
|
||||
// etc.
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotCompExpr::CBotCompExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL;
|
||||
name = "CBotCompExpr";
|
||||
}
|
||||
|
||||
CBotCompExpr::~CBotCompExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
fichier plus utilise;
|
||||
|
||||
// compile une instruction de type A < B
|
||||
|
||||
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->AddStack();
|
||||
|
||||
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
|
||||
|
||||
if ( p->GetType() == ID_HI ||
|
||||
p->GetType() == ID_LO ||
|
||||
p->GetType() == ID_HS ||
|
||||
p->GetType() == ID_LS ||
|
||||
p->GetType() == ID_EQ ||
|
||||
p->GetType() == ID_NE) // les diverses comparaisons
|
||||
{
|
||||
CBotCompExpr* inst = new CBotCompExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType();
|
||||
|
||||
p = p->Next();
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B à droite
|
||||
{
|
||||
type2 = pStack->GetType();
|
||||
// les résultats sont-ils compatibles
|
||||
if ( type1 == type2 )
|
||||
{
|
||||
inst->m_leftop = left;
|
||||
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
||||
// le résultat est un boolean
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
delete left;
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
// fait l'opération
|
||||
|
||||
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this);
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
pStk1->SetState(1); // opération terminée
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
CBotStack* pStk2 = pStk1->AddStack();
|
||||
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType();
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
|
||||
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_LO:
|
||||
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
||||
break;
|
||||
case ID_HI:
|
||||
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
||||
break;
|
||||
case ID_LS:
|
||||
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
||||
break;
|
||||
case ID_HS:
|
||||
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
||||
break;
|
||||
case ID_EQ:
|
||||
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
||||
break;
|
||||
case ID_NE:
|
||||
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// expression of type Opérande1 > Opérande2
|
||||
// Opérande1 != Opérande2
|
||||
// etc.
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// various constructeurs
|
||||
|
||||
CBotCompExpr::CBotCompExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL;
|
||||
name = "CBotCompExpr";
|
||||
}
|
||||
|
||||
CBotCompExpr::~CBotCompExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
fichier plus utilise;
|
||||
|
||||
// compile instruction of type A < B
|
||||
|
||||
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->AddStack();
|
||||
|
||||
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // error
|
||||
|
||||
if ( p->GetType() == ID_HI ||
|
||||
p->GetType() == ID_LO ||
|
||||
p->GetType() == ID_HS ||
|
||||
p->GetType() == ID_LS ||
|
||||
p->GetType() == ID_EQ ||
|
||||
p->GetType() == ID_NE) // the various comparisons
|
||||
{
|
||||
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
|
||||
inst->SetToken(p); // stores the operation
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType();
|
||||
|
||||
p = p->Next();
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
|
||||
{
|
||||
type2 = pStack->GetType();
|
||||
// are the results compatible
|
||||
if ( type1 == type2 )
|
||||
{
|
||||
inst->m_leftop = left;
|
||||
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
||||
// the result is a boolean
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
delete left;
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
// perform the operation
|
||||
|
||||
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this);
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
|
||||
|
||||
pStk1->SetState(1); // finished
|
||||
|
||||
// requires a little more stack to not touch the result of the left
|
||||
CBotStack* pStk2 = pStk1->AddStack();
|
||||
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
|
||||
|
||||
int type1 = pStk1->GetType();
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
|
||||
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_LO:
|
||||
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
|
||||
break;
|
||||
case ID_HI:
|
||||
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
|
||||
break;
|
||||
case ID_LS:
|
||||
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
|
||||
break;
|
||||
case ID_HS:
|
||||
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
|
||||
break;
|
||||
case ID_EQ:
|
||||
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
|
||||
break;
|
||||
case ID_NE:
|
||||
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // puts the result on the stack
|
||||
|
||||
pStk1->Return(pStk2); // frees the stack
|
||||
return pStack->Return(pStk1); // transmit the result
|
||||
}
|
||||
|
||||
|
|
2234
src/CBot/CBotDll.h
2234
src/CBot/CBotDll.h
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,8 @@
|
|||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
//strings management
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
// x
|
||||
// )
|
||||
|
||||
#pragma once
|
||||
|
||||
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
||||
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -65,10 +65,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
|||
CBotString mode;
|
||||
|
||||
// accepts no parameters
|
||||
if ( pVar == NULL ) return TRUE;
|
||||
if ( pVar == NULL ) return true;
|
||||
|
||||
// must be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||
|
||||
CBotString filename = pVar->GivValString();
|
||||
PrepareFilename(filename); //DR
|
||||
|
@ -79,10 +79,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
|||
{
|
||||
// recovers the mode
|
||||
mode = pVar->GivValString();
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||
|
||||
// no third parameter, only two or one possible
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||
}
|
||||
|
||||
// save the file name
|
||||
|
@ -93,7 +93,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
|||
{
|
||||
// open the called file
|
||||
FILE* pFile = fopen( filename, mode );
|
||||
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
|
||||
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
|
||||
|
||||
m_CompteurFileOpen ++;
|
||||
|
||||
|
@ -102,7 +102,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
|||
pVar->SetValInt((long)pFile);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
@ -126,7 +126,7 @@ CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
|
|||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
}
|
||||
|
||||
// le résultat est de type void (constructeur)
|
||||
// le r<EFBFBD>sultat est de type void (constructeur)
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
|||
pVar = pThis->GivItem("handle");
|
||||
|
||||
// not open? no problem
|
||||
if ( pVar->GivInit() != IS_DEF) return TRUE;
|
||||
if ( pVar->GivInit() != IS_DEF) return true;
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
fclose(pFile);
|
||||
|
@ -148,7 +148,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
|||
|
||||
pVar->SetInit(IS_NAN);
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,10 +159,10 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
|||
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// there must be a parameter
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||
|
||||
// must be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||
|
||||
// there may be a second parameter
|
||||
if ( pVar->GivNext() != NULL )
|
||||
|
@ -180,16 +180,16 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
}
|
||||
|
||||
CBotString mode = pVar->GivValString();
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||
|
||||
// No third parameter
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||
|
||||
// retrieves the element "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
// which must not be initialized
|
||||
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return FALSE; }
|
||||
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return false; }
|
||||
|
||||
// contains filename
|
||||
pVar = pThis->GivItem("filename");
|
||||
|
@ -201,8 +201,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
FILE* pFile = fopen( filename, mode );
|
||||
if ( pFile == NULL ) //DR
|
||||
{
|
||||
pResult->SetValInt(FALSE); //DR
|
||||
return TRUE; //DR
|
||||
pResult->SetValInt(false); //DR
|
||||
return true; //DR
|
||||
}
|
||||
|
||||
m_CompteurFileOpen ++;
|
||||
|
@ -211,8 +211,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
pVar = pThis->GivItem("handle");
|
||||
pVar->SetValInt((long)pFile);
|
||||
|
||||
pResult->SetValInt(TRUE); //DR
|
||||
return TRUE;
|
||||
pResult->SetValInt(true); //DR
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
@ -253,7 +253,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
// retrieves the element "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
fclose(pFile);
|
||||
|
@ -261,7 +261,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
|
||||
pVar->SetInit(IS_NAN);
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
@ -280,26 +280,26 @@ CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
|
|||
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// there must be a parameter
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||
|
||||
// must be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||
|
||||
CBotString param = pVar->GivValString();
|
||||
|
||||
//retrieves the element "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
int res = fputs(param+CBotString("\n"), pFile);
|
||||
|
||||
// on error throws an exception
|
||||
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
|
||||
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
@ -324,12 +324,12 @@ CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
|
|||
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// there shouldn't be any parameter
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||
|
||||
//retrieves the element "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
|
@ -342,11 +342,11 @@ bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
|||
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
||||
|
||||
// on error throws an exception
|
||||
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
|
||||
if ( ferror(pFile) ) { Exception = CBotErrRead; return false; }
|
||||
|
||||
pResult->SetValString( chaine );
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
@ -365,18 +365,18 @@ CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
|
|||
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// there shouldn't be any parameter
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||
|
||||
// retrieves the element "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
pResult->SetValInt( feof( pFile ) );
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// compilation
|
||||
|
|
|
@ -1,434 +1,436 @@
|
|||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.// définition des fonctions sur les chaînes
|
||||
|
||||
|
||||
// donne la longueur d'une chaîne
|
||||
// exécution
|
||||
|
||||
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// pas de second paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// met la longueur sur la pile
|
||||
pResult->SetValInt( s.GivLength() );
|
||||
return true;
|
||||
}
|
||||
|
||||
// int xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADPARAM );
|
||||
|
||||
// pas de second paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre entier
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
|
||||
// donne la partie gauche d'une chaîne
|
||||
// exécution
|
||||
|
||||
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Left( n );
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// string xxx ( string, int )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
// donne la partie droite d'une chaîne
|
||||
// exécution
|
||||
|
||||
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Right( n );
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// donne la partie centrale d'une chaîne
|
||||
// exécution
|
||||
|
||||
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// 3e paramètre optionnel
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// récupère ce nombre
|
||||
int l = pVar->GivValInt();
|
||||
|
||||
// mais pas de 4e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Mid( n, l );
|
||||
}
|
||||
else
|
||||
{
|
||||
// prend la partie intéressante
|
||||
s = s.Mid( n );
|
||||
}
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// donne la partie centrale d'une chaîne
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// 3e paramètre optionnel
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
|
||||
pVar = pVar->GivNext();
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// pas de 4e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
}
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
// donne le nombre contenu dans une chaîne
|
||||
// exécution
|
||||
|
||||
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
float val = GivNumFloat(s);
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValFloat( val );
|
||||
return true;
|
||||
}
|
||||
|
||||
// float xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre
|
||||
return CBotTypResult( CBotTypFloat );
|
||||
}
|
||||
|
||||
|
||||
// trouve une chaine dans une autre
|
||||
// exécution
|
||||
|
||||
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// récupère ce nombre
|
||||
CBotString s2 = pVar->GivValString();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// met le résultat sur la pile
|
||||
int res = s.Find(s2);
|
||||
pResult->SetValInt( res );
|
||||
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
||||
return true;
|
||||
}
|
||||
|
||||
// int xxx ( string, string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
// donne une chaine en majuscule
|
||||
// exécution
|
||||
|
||||
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
|
||||
s.MakeUpper();
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// donne une chaine en minuscules
|
||||
// exécution
|
||||
|
||||
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
|
||||
s.MakeLower();
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// string xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
void InitStringFunctions()
|
||||
{
|
||||
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
|
||||
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
|
||||
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
|
||||
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
|
||||
|
||||
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
|
||||
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
|
||||
|
||||
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
|
||||
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
|
||||
}
|
||||
// * This file is part of the COLOBOT source code
|
||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
|
||||
// definition of string functions
|
||||
|
||||
|
||||
// gives the length of a chain
|
||||
// execution
|
||||
|
||||
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// no second parameter
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// puts the length of the stack
|
||||
pResult->SetValInt( s.GivLength() );
|
||||
return true;
|
||||
}
|
||||
|
||||
// int xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADPARAM );
|
||||
|
||||
// no second parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// the end result is an integer
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
|
||||
// gives the left side of a chain
|
||||
// execution
|
||||
|
||||
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// retrieves this number
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// no third parameter
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// takes the interesting part
|
||||
s = s.Left( n );
|
||||
|
||||
// puts on the stack
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// string xxx ( string, int )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// no third parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// the end result is a string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
// gives the right of a string
|
||||
// execution
|
||||
|
||||
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// retrieves this number
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// no third parameter
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// takes the interesting part
|
||||
s = s.Right( n );
|
||||
|
||||
// puts on the stack
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// gives the central part of a chain
|
||||
// execution
|
||||
|
||||
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// retrieves this number
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// third parameter optional
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||
|
||||
// retrieves this number
|
||||
int l = pVar->GivValInt();
|
||||
|
||||
// but no fourth parameter
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// takes the interesting part
|
||||
s = s.Mid( n, l );
|
||||
}
|
||||
else
|
||||
{
|
||||
// takes the interesting part
|
||||
s = s.Mid( n );
|
||||
}
|
||||
|
||||
// puts on the stack
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// gives the central part of a chain
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// third parameter optional
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
|
||||
pVar = pVar->GivNext();
|
||||
// which must be a number
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// no fourth parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
}
|
||||
|
||||
// the end result is a string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
// gives the number stored in a string
|
||||
// execution
|
||||
|
||||
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// but no second parameter
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
float val = GivNumFloat(s);
|
||||
|
||||
// puts the value on the stack
|
||||
pResult->SetValFloat( val );
|
||||
return true;
|
||||
}
|
||||
|
||||
// float xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// no second parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// the end result is a number
|
||||
return CBotTypResult( CBotTypFloat );
|
||||
}
|
||||
|
||||
|
||||
// find string in other
|
||||
// exécution
|
||||
|
||||
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// retrieves this number
|
||||
CBotString s2 = pVar->GivValString();
|
||||
|
||||
// no third parameter
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
// puts the result on the stack
|
||||
int res = s.Find(s2);
|
||||
pResult->SetValInt( res );
|
||||
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
||||
return true;
|
||||
}
|
||||
|
||||
// int xxx ( string, string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// it takes a second parameter
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// no third parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// the end result is a number
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
// gives a string to uppercase
|
||||
// exécution
|
||||
|
||||
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// but no second parameter
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
|
||||
s.MakeUpper();
|
||||
|
||||
// puts the value on the stack
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// gives a string to lowercase
|
||||
// exécution
|
||||
|
||||
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||
|
||||
// get the contents of the string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// but no second parameter
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||
|
||||
|
||||
s.MakeLower();
|
||||
|
||||
// puts the value on the stack
|
||||
pResult->SetValString( s );
|
||||
return true;
|
||||
}
|
||||
|
||||
// string xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// it takes a parameter
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// to be a string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// no second parameter
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// the end result is a string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
void InitStringFunctions()
|
||||
{
|
||||
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
|
||||
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
|
||||
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
|
||||
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
|
||||
|
||||
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
|
||||
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
|
||||
|
||||
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
|
||||
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue