Dependency on WINAPI completely removed.

dev-ui
Zaba999 2012-07-10 22:58:52 +02:00
parent dbd62c96aa
commit 1910219518
9 changed files with 3582 additions and 3909 deletions

View File

@ -12,9 +12,10 @@ find_package(SDL_image REQUIRED)
# Build with debugging symbols
set(CMAKE_BUILD_TYPE debug)
# Global compile flags
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall -std=gnu++0x")
# Subdirectory with sources
add_subdirectory(src bin)

File diff suppressed because it is too large Load Diff

View File

@ -1,279 +0,0 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// French (France) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
ID_IF "if"
ID_ELSE "else"
ID_WHILE "while"
ID_DO "do"
ID_FOR "for"
ID_BREAK "break"
ID_CONTINUE "continue"
ID_SWITCH "switch"
ID_CASE "case"
ID_DEFAULT "default"
ID_TRY "try"
ID_THROW "throw"
ID_CATCH "catch"
ID_FINALLY "finally"
ID_TXT_AND "and"
ID_TXT_OR "or"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_DEBUGDD "STARTDEBUGDD"
ID_INT "int"
ID_FLOAT "float"
ID_BOOLEAN "boolean"
ID_STRING "string"
ID_VOID "void"
ID_BOOL "bool"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TXT_NOT "not"
ID_RETURN "return"
ID_CLASS "class"
ID_EXTENDS "extends"
ID_SYNCHO "synchronized"
ID_NEW "new"
ID_PUBLIC "public"
ID_EXTERN "extern"
ID_FINAL "final"
ID_STATIC "static"
ID_PROTECTED "protected"
ID_PRIVATE "private"
ID_REPEAT "repeat"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_OPENPAR "Il manque une parenthèse ouvrante."
TX_CLOSEPAR "Il manque une parenthèse fermante."
TX_NOTBOOL "L'expression doit être un boolean."
TX_UNDEFVAR "Variable non déclarée."
TX_BADLEFT "Assignation impossible."
TX_ENDOF "Terminateur point-virgule non trouvé."
TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
TX_NOTERM "Instructions après la fin."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_CLOSEBLK "Il manque la fin du bloc."
TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
TX_OPENBLK "Début d'un bloc attendu."
TX_BADTYPE "Mauvais type de résultat pour l'assignation."
TX_REDEFVAR "Redéfinition d'une variable."
TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
TX_UNDEFCALL "Routine inconnue."
TX_MISDOTS "Séparateur "" : "" attendu."
TX_WHILE "Manque le mot ""while""."
TX_BREAK "Instruction ""break"" en dehors d'une boucle."
TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"" ou un ""do""."
TX_NOLABEL "Cette étiquette n'existe pas"
TX_NOCASE "Manque une instruction ""case""."
TX_BADNUM "Un nombre est attendu."
TX_VOID "Paramètre void."
TX_NOTYP "Déclaration de type attendu."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_DIVZERO "Division par zéro."
TX_NOTINIT "Variable non initialisée."
TX_BADTHROW "Valeur négative refusée pour ""throw""."
TX_NORETVAL "La fonction n'a pas retourné de résultat"
TX_NORUN "Pas de fonction en exécution"
TX_NOCALL "Appel d'une fonction inexistante"
TX_NOCLASS "Cette classe n'existe pas"
TX_NULLPT "Pointeur nul."
TX_OPNAN "Opération sur un ""nan"""
TX_OUTARRAY "Accès hors du tableau"
TX_STACKOVER "Dépassement de la pile"
TX_DELETEDPT "Pointeur à un objet détruit"
TX_FILEOPEN "Ouverture du fichier impossible"
TX_NOTOPEN "Fichier pas ouvert"
TX_ERRREAD "Erreur de lecture"
TX_ERRWRITE "Erreur d'écriture"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_NOVAR "Nom d'une variable attendu."
TX_NOFONC "Nom de la fonction attendu."
TX_OVERPARAM "Trop de paramètres."
TX_REDEF "Cette fonction existe déjà."
TX_LOWPARAM "Pas assez de paramètres."
TX_BADPARAM "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)."
TX_NUMPARAM "Aucune fonction de ce nom n'accepte ce nombre de paramètres."
TX_NOITEM "Cet élément n'existe pas dans cette classe."
TX_DOT "L'objet n'est pas une instance d'une classe."
TX_NOCONST "Il n'y a pas de constructeur approprié."
TX_REDEFCLASS "Cette classe existe déjà."
TX_CLBRK """ ] "" attendu."
TX_RESERVED "Ce mot est réservé."
TX_BADNEW "Mauvais argument pour ""new""."
TX_OPBRK """ [ "" attendu."
TX_BADSTRING "Une chaîne de caractère est attendue."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_BADINDEX "Mauvais type d'index"
TX_PRIVATE "Membre privé de la classe"
TX_NOPUBLIC """public"" manque"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_OPENPAR "("
ID_CLOSEPAR ")"
ID_OPBLK "{"
ID_CLBLK "}"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SEP ";"
ID_COMMA ","
ID_DOTS ":"
ID_DOT "."
ID_OPBRK "["
ID_CLBRK "]"
ID_DBLDOTS "::"
ID_LOGIC "?"
ID_ADD "+"
ID_SUB "-"
ID_MUL "*"
ID_DIV "/"
ID_ASS "="
ID_ASSADD "+="
ID_ASSSUB "-="
ID_ASSMUL "*="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TRUE "true"
ID_FALSE "false"
ID_NULL "null"
ID_NAN "nan"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_ASSDIV "/="
ID_ASSOR "|="
ID_ASSAND "&="
ID_ASSXOR "^="
ID_ASSSL "<<="
ID_ASSSR ">>>="
ID_ASSASR ">>="
ID_SL "<<"
ID_SR ">>>"
ID_ASR ">>"
ID_INC "++"
ID_DEC "--"
ID_LO "<"
ID_HI ">"
ID_LS "<="
ID_HS ">="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_EQ "=="
ID_NE "!="
ID_AND "&"
ID_XOR "^"
ID_OR "|"
ID_LOG_AND "&&"
ID_LOG_OR "||"
ID_LOG_NOT "!"
ID_NOT "~"
ID_MODULO "%"
ID_POWER "**"
ID_ASSMODULO "%="
END
STRINGTABLE DISCARDABLE
BEGIN
TX_UNDEF "undefined"
TX_NAN "not a number"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SUPER "super"
END
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,12 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////
// gestion de la pile (stack)
/**
* \file CBotStack.cpp
* \brief Management of the stack
*/
#include "CBot.h"
#include <cstdlib>

View File

@ -13,53 +13,145 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
// gestion de chaine
// basé sur le CString de MFC
// mais moins complet
//strings management
#include "CBot.h"
#include <cstdlib>
#include <cstring>
#include <algorithm>
/// TODO need to be implemented to be able to load library
// HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // how to retrieve it otherwise ??
//Map is filled with id-string pars that are needed for CBot language parsing
const std::map<EID, const char const *> CBotString::s_keywordString =
{
{ID_IF, "if"},
{ID_ELSE, "else"},
{ID_WHILE, "while"},
{ID_DO, "do"},
{ID_FOR, "for"},
{ID_BREAK, "break"},
{ID_CONTINUE, "continue"},
{ID_SWITCH, "switch"},
{ID_CASE, "case"},
{ID_DEFAULT, "default"},
{ID_TRY, "try"},
{ID_THROW, "throw"},
{ID_CATCH, "catch"},
{ID_FINALLY, "finally"},
{ID_TXT_AND, "and"},
{ID_TXT_OR, "or"},
{ID_TXT_NOT, "not"},
{ID_RETURN, "return"},
{ID_CLASS, "class"},
{ID_EXTENDS, "extends"},
{ID_SYNCHO, "synchronized"},
{ID_NEW, "new"},
{ID_PUBLIC, "public"},
{ID_EXTERN, "extern"},
{ID_FINAL, "final"},
{ID_STATIC, "static"},
{ID_PROTECTED, "protected"},
{ID_PRIVATE, "private"},
{ID_REPEAT, "repeat"},
{ID_DEBUGDD, "STARTDEBUGDD"},
{ID_INT, "int"},
{ID_FLOAT, "float"},
{ID_BOOLEAN, "boolean"},
{ID_STRING, "string"},
{ID_VOID, "void"},
{ID_BOOL, "bool"},
{ID_TRUE, "true"},
{ID_FALSE, "false"},
{ID_NULL, "null"},
{ID_NAN, "nan"},
{ID_OPENPAR, "("},
{ID_CLOSEPAR, ")"},
{ID_OPBLK, "{"},
{ID_CLBLK, "}"},
{ID_SEP, "},"},
{ID_COMMA, ","},
{ID_DOTS, ":"},
{ID_DOT, "."},
{ID_OPBRK, "["},
{ID_CLBRK, "]"},
{ID_DBLDOTS, "::"},
{ID_LOGIC, "?"},
{ID_ADD, "+"},
{ID_SUB, "-"},
{ID_MUL, "*"},
{ID_DIV, "/"},
{ID_ASS, "="},
{ID_ASSADD, "+="},
{ID_ASSSUB, "-="},
{ID_ASSMUL, "*="},
{ID_ASSDIV, "/="},
{ID_ASSOR, "|="},
{ID_ASSAND, "&="},
{ID_ASSXOR, "^="},
{ID_ASSSL, "<<="},
{ID_ASSSR, ">>>="},
{ID_ASSASR, ">>="},
{ID_SL, "<<"},
{ID_SR, ">>"},
{ID_ASR, ">>"},
{ID_INC, "++"},
{ID_DEC, "--"},
{ID_LO, "<"},
{ID_HI, ">"},
{ID_LS, "<<"},
{ID_HS, ">="},
{ID_EQ, "=="},
{ID_NE, "!="},
{ID_AND, "&"},
{ID_XOR, "^"},
{ID_OR, "|"},
{ID_LOG_AND, "&&"},
{ID_LOG_OR, "||"},
{ID_LOG_NOT, "!"},
{ID_NOT, "~"},
{ID_MODULO, "%"},
{ID_POWER, "**"},
{ID_ASSMODULO, "%="},
{TX_UNDEF, "undefined"},
{TX_NAN, "not a number"},
{ID_SUPER, "super"}
};
CBotString::CBotString()
{
m_ptr = NULL; // chaine vide
m_lg = 0;
m_ptr = NULL;
m_lg = 0;
}
CBotString::~CBotString()
{
if (m_ptr != NULL) free(m_ptr);
free(m_ptr); //we can call free on null pointer as it's save
}
CBotString::CBotString(const char* p)
{
m_lg = strlen( p );
m_lg = strlen(p);
m_ptr = NULL;
if (m_lg>0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, p);
}
m_ptr = NULL;
if (m_lg>0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, p);
}
}
CBotString::CBotString(const CBotString& srcString)
{
m_lg = srcString.m_lg;
m_lg = srcString.m_lg;
m_ptr = NULL;
if (m_lg>0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, srcString.m_ptr);
}
m_ptr = NULL;
if (m_lg>0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, srcString.m_ptr);
}
}
@ -67,539 +159,533 @@ CBotString::CBotString(const CBotString& srcString)
int CBotString::GivLength()
{
if ( m_ptr == NULL ) return 0;
return strlen( m_ptr );
if (m_ptr == NULL) return 0;
return strlen( m_ptr );
}
CBotString CBotString::Left(int nCount) const
{
char chaine[2000];
int i;
for (i = 0; i < m_lg && i < nCount && i < 1999; i++)
{
chaine[i] = m_ptr[i];
}
chaine[i] = 0 ;
char chain[2000];
return CBotString( chaine );
size_t i;
for (i = 0; i < m_lg && i < nCount && i < 1999; ++i)
{
chain[i] = m_ptr[i];
}
chain[i] = 0 ;
return CBotString(chain);
}
CBotString CBotString::Right(int nCount) const
{
char chaine[2000];
int i = m_lg - nCount;
if ( i < 0 ) i = 0;
char chain[2000];
int j;
for ( j = 0 ; i < m_lg && i < 1999; i++)
{
chaine[j++] = m_ptr[i];
}
chaine[j] = 0 ;
int i = m_lg - nCount;
if ( i < 0 ) i = 0;
return CBotString( chaine );
size_t j;
for (size_t j = 0 ; i < m_lg && i < 1999; ++i)
{
chain[j++] = m_ptr[i];
}
chain[j] = 0 ;
return CBotString(chain);
}
CBotString CBotString::Mid(int nFirst, int nCount) const
{
char chaine[2000];
int i;
char chain[2000];
for ( i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; i++)
{
chaine[i] = m_ptr[i];
}
chaine[i] = 0 ;
size_t i;
for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i)
{
chain[i] = m_ptr[i];
}
chain[i] = 0 ;
return CBotString( chaine );
return CBotString(chain);
}
CBotString CBotString::Mid(int nFirst) const
{
char chaine[2000];
int i;
char chain[2000];
for ( i = nFirst; i < m_lg && i < 1999 ; i++)
{
chaine[i] = m_ptr[i];
}
chaine[i] = 0 ;
size_t i;
for (i = nFirst; i < m_lg && i < 1999 ; ++i)
{
chain[i] = m_ptr[i];
}
chain[i] = 0 ;
return CBotString( chaine );
return CBotString(chain);
}
int CBotString::Find(const char c)
{
int i;
for (i = 0; i < m_lg; i++)
{
if (m_ptr[i] == c) return i;
}
return -1;
for (size_t i = 0; i < m_lg; ++i)
{
if (m_ptr[i] == c) return i;
}
return -1;
}
int CBotString::Find(const char * lpsz)
{
int i, j;
int l = strlen(lpsz);
int l = strlen(lpsz);
for (i = 0; i <= m_lg-l; i++)
{
for (j = 0; j < l; j++)
{
if (m_ptr[i+j] != lpsz[j]) goto bad;
}
return i;
for (size_t i = 0; i <= m_lg-l; ++i)
{
for (size_t j = 0; j < l; ++j)
{
if (m_ptr[i+j] != lpsz[j]) goto bad;
}
return i;
bad:;
}
return -1;
}
return -1;
}
int CBotString::ReverseFind(const char c)
{
int i;
for (i = m_lg-1; i >= 0; i--)
{
if (m_ptr[i] == c) return i;
}
return -1;
int i;
for (i = m_lg-1; i >= 0; --i)
{
if (m_ptr[i] == c) return i;
}
return -1;
}
int CBotString::ReverseFind(const char * lpsz)
{
int i, j;
int l = strlen(lpsz);
int i, j;
int l = strlen(lpsz);
for (i = m_lg-l; i >= 0; i--)
{
for (j = 0; j < l; j++)
{
if (m_ptr[i+j] != lpsz[j]) goto bad;
}
return i;
for (i = m_lg-l; i >= 0; --i)
{
for (j = 0; j < l; ++j)
{
if (m_ptr[i+j] != lpsz[j]) goto bad;
}
return i;
bad:;
}
return -1;
}
return -1;
}
CBotString CBotString::Mid(int start, int lg)
{
CBotString res;
if (start >= m_lg) return res;
CBotString res;
if (start >= m_lg) return res;
if ( lg < 0 ) lg = m_lg - start;
if ( lg < 0 ) lg = m_lg - start;
char* p = (char*)malloc(m_lg+1);
strcpy(p, m_ptr+start);
p[lg] = 0;
char* p = (char*)malloc(m_lg+1);
strcpy(p, m_ptr+start);
p[lg] = 0;
res = p;
free(p);
return res;
res = p;
free(p);
return res;
}
void CBotString::MakeUpper()
{
int i;
for ( i = 0; i < m_lg && i < 1999 ; i++)
{
char c = m_ptr[i];
if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
}
for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
{
char c = m_ptr[i];
if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
}
}
void CBotString::MakeLower()
{
int i;
for ( i = 0; i < m_lg && i < 1999 ; i++)
{
char c = m_ptr[i];
if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
}
for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
{
char c = m_ptr[i];
if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
}
}
#define MAXSTRING 256
bool CBotString::LoadString(unsigned int id)
{
char buffer[MAXSTRING];
/// \TODO implement loading strings from resources. Figure out how to do it
// m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING );
const char * str = NULL;
str = MapIdToString((EID)id);
if (m_ptr != NULL) free(m_ptr);
if (m_ptr != NULL) free(m_ptr);
m_ptr = NULL;
if (m_lg > 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, buffer);
return true;
}
return false;
m_lg = strlen(str);
m_ptr = NULL;
if (m_lg > 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, str);
return true;
}
return false;
}
const CBotString& CBotString::operator=(const CBotString& stringSrc)
{
if (m_ptr != NULL) free(m_ptr);
free(m_ptr);
m_ptr = NULL;
m_lg = stringSrc.m_lg;
m_ptr = NULL;
m_lg = stringSrc.m_lg;
if (m_lg > 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, stringSrc.m_ptr);
}
if (m_lg > 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, stringSrc.m_ptr);
}
return *this;
return *this;
}
CBotString operator+(const CBotString& string, const char * lpsz)
{
CBotString s ( string );
s += lpsz;
return s;
CBotString s(string);
s += lpsz;
return s;
}
const CBotString& CBotString::operator+(const CBotString& stringSrc)
{
char* p = (char*)malloc(m_lg+stringSrc.m_lg+1);
char* p = (char*)malloc(m_lg+stringSrc.m_lg+1);
strcpy(p, m_ptr);
char* pp = p + m_lg;
strcpy(pp, stringSrc.m_ptr);
strcpy(p, m_ptr);
char* pp = p + m_lg;
strcpy(pp, stringSrc.m_ptr);
if (m_ptr != NULL) free(m_ptr);
m_ptr = p;
m_lg += stringSrc.m_lg;
free(m_ptr);
m_ptr = p;
m_lg += stringSrc.m_lg;
return *this;
return *this;
}
const CBotString& CBotString::operator=(const char ch)
{
if (m_ptr != NULL) free(m_ptr);
free(m_ptr);
m_lg = 1;
m_lg = 1;
m_ptr = (char*)malloc(2);
m_ptr[0] = ch;
m_ptr[1] = 0;
return *this;
m_ptr = (char*)malloc(2);
m_ptr[0] = ch;
m_ptr[1] = 0;
return *this;
}
const CBotString& CBotString::operator=(const char* pString)
{
if (m_ptr != NULL) free(m_ptr);
m_ptr = NULL;
free(m_ptr);
m_ptr = NULL;
if ( pString != NULL )
{
m_lg = strlen(pString);
if (pString != NULL)
{
m_lg = strlen(pString);
if (m_lg != 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, pString);
}
}
return *this;
if (m_lg != 0)
{
m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, pString);
}
}
return *this;
}
const CBotString& CBotString::operator+=(const char ch)
{
char* p = (char*)malloc(m_lg+2);
char* p = (char*)malloc(m_lg+2);
if (m_ptr!=NULL) strcpy(p, m_ptr);
p[m_lg++] = ch;
p[m_lg] = 0;
if (m_ptr!=NULL) strcpy(p, m_ptr);
p[m_lg++] = ch;
p[m_lg] = 0;
if (m_ptr != NULL) free(m_ptr);
free(m_ptr);
m_ptr = p;
m_ptr = p;
return *this;
return *this;
}
const CBotString& CBotString::operator+=(const CBotString& str)
{
char* p = (char*)malloc(m_lg+str.m_lg+1);
char* p = (char*)malloc(m_lg+str.m_lg+1);
strcpy(p, m_ptr);
char* pp = p + m_lg;
strcpy(pp, str.m_ptr);
strcpy(p, m_ptr);
char* pp = p + m_lg;
strcpy(pp, str.m_ptr);
m_lg = m_lg + str.m_lg;
m_lg = m_lg + str.m_lg;
if (m_ptr != NULL) free(m_ptr);
free(m_ptr);
m_ptr = p;
m_ptr = p;
return *this;
return *this;
}
bool CBotString::operator==(const CBotString& str)
{
return Compare(str) == 0;
return Compare(str) == 0;
}
bool CBotString::operator==(const char* p)
{
return Compare(p) == 0;
return Compare(p) == 0;
}
bool CBotString::operator!=(const CBotString& str)
{
return Compare(str) != 0;
return Compare(str) != 0;
}
bool CBotString::operator!=(const char* p)
{
return Compare(p) != 0;
return Compare(p) != 0;
}
bool CBotString::operator>(const CBotString& str)
{
return Compare(str) > 0;
return Compare(str) > 0;
}
bool CBotString::operator>(const char* p)
{
return Compare(p) > 0;
return Compare(p) > 0;
}
bool CBotString::operator>=(const CBotString& str)
{
return Compare(str) >= 0;
return Compare(str) >= 0;
}
bool CBotString::operator>=(const char* p)
{
return Compare(p) >= 0;
return Compare(p) >= 0;
}
bool CBotString::operator<(const CBotString& str)
{
return Compare(str) < 0;
return Compare(str) < 0;
}
bool CBotString::operator<(const char* p)
{
return Compare(p) < 0;
return Compare(p) < 0;
}
bool CBotString::operator<=(const CBotString& str)
{
return Compare(str) <= 0;
return Compare(str) <= 0;
}
bool CBotString::operator<=(const char* p)
{
return Compare(p) <= 0;
return Compare(p) <= 0;
}
bool CBotString::IsEmpty() const
{
return (m_lg == 0);
return (m_lg == 0);
}
void CBotString::Empty()
{
if (m_ptr != NULL) free(m_ptr);
m_ptr = NULL;
m_lg = 0;
free(m_ptr);
m_ptr = NULL;
m_lg = 0;
}
static char emptyString[] = {0};
CBotString::operator const char * () const
{
if (this == NULL || m_ptr == NULL) return emptyString;
return m_ptr;
if (this == NULL || m_ptr == NULL) return emptyString;
return m_ptr;
}
int CBotString::Compare(const char * lpsz) const
{
char* p = m_ptr;
if (lpsz == NULL) lpsz = emptyString;
if (m_ptr == NULL) p = emptyString;
return strcmp(p, lpsz); // wcscmp
char* p = m_ptr;
if (lpsz == NULL) lpsz = emptyString;
if (m_ptr == NULL) p = emptyString;
return strcmp(p, lpsz); // wcscmp
}
const char * CBotString::MapIdToString(EID id)
{
if (s_keywordString.find(id) != s_keywordString.end())
{
return s_keywordString.at(id);
}
else
{
return emptyString;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// tableaux de chaines
// arrays of strings
CBotStringArray::CBotStringArray()
{
m_pData = NULL;
m_nSize = m_nMaxSize = 0;
m_pData = NULL;
m_nSize = m_nMaxSize = 0;
}
CBotStringArray::~CBotStringArray()
{
SetSize(0); // détruit les données !
SetSize(0); // destroys data !
}
int CBotStringArray::GivSize()
{
return m_nSize;
return m_nSize;
}
void CBotStringArray::Add(const CBotString& str)
{
SetSize(m_nSize+1);
SetSize(m_nSize+1);
m_pData[m_nSize-1] = str;
m_pData[m_nSize-1] = str;
}
///////////////////////////////////////////////////////////////////////
// routines utilitaires
// utility routines
static inline void ConstructElement(CBotString* pNewData)
{
memset(pNewData, 0, sizeof(CBotString));
memset(pNewData, 0, sizeof(CBotString));
}
static inline void DestructElement(CBotString* pOldData)
{
pOldData->~CBotString();
pOldData->~CBotString();
}
static inline void CopyElement(CBotString* pSrc, CBotString* pDest)
{
*pSrc = *pDest;
*pSrc = *pDest;
}
static void ConstructElements(CBotString* pNewData, int nCount)
{
while (nCount--)
{
ConstructElement(pNewData);
pNewData++;
}
while (nCount--)
{
ConstructElement(pNewData);
pNewData++;
}
}
static void DestructElements(CBotString* pOldData, int nCount)
{
while (nCount--)
{
DestructElement(pOldData);
pOldData++;
}
while (nCount--)
{
DestructElement(pOldData);
pOldData++;
}
}
static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
{
while (nCount--)
{
*pDest = *pSrc;
++pDest;
++pSrc;
}
while (nCount--)
{
*pDest = *pSrc;
++pDest;
++pSrc;
}
}
// sélect la taille du tableau
// set the array size
void CBotStringArray::SetSize(int nNewSize)
{
if (nNewSize == 0)
{
// shrink to nothing
if (nNewSize == 0)
{
// shrink to nothing
DestructElements(m_pData, m_nSize);
delete[] (unsigned char *)m_pData;
m_pData = NULL;
m_nSize = m_nMaxSize = 0;
}
else if (m_pData == NULL)
{
// create one with exact size
m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)];
DestructElements(m_pData, m_nSize);
delete[] (unsigned char *)m_pData;
m_pData = NULL;
m_nSize = m_nMaxSize = 0;
}
else if (m_pData == NULL)
{
// create one with exact size
m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)];
ConstructElements(m_pData, nNewSize);
ConstructElements(m_pData, nNewSize);
m_nSize = m_nMaxSize = nNewSize;
}
else if (nNewSize <= m_nMaxSize)
{
// it fits
if (nNewSize > m_nSize)
{
// initialize the new elements
m_nSize = m_nMaxSize = nNewSize;
}
else if (nNewSize <= m_nMaxSize)
{
// it fits
if (nNewSize > m_nSize)
{
// initialize the new elements
ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize);
ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize);
}
}
else if (m_nSize > nNewSize) // destroy the old elements
DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
else if (m_nSize > nNewSize) // destroy the old elements
DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
m_nSize = nNewSize;
}
else
{
// otherwise, grow array
int nGrowBy;
{
// heuristically determine growth when nGrowBy == 0
// (this avoids heap fragmentation in many situations)
nGrowBy = std::min(1024, std::max(4, m_nSize / 8));
}
int nNewMax;
if (nNewSize < m_nMaxSize + nGrowBy)
nNewMax = m_nMaxSize + nGrowBy; // granularity
else
nNewMax = nNewSize; // no slush
m_nSize = nNewSize;
}
else
{
// otherwise, grow array
int nGrowBy;
{
// heuristically determine growth when nGrowBy == 0
// (this avoids heap fragmentation in many situations)
nGrowBy = std::min(1024, std::max(4, m_nSize / 8));
}
int nNewMax;
if (nNewSize < m_nMaxSize + nGrowBy)
nNewMax = m_nMaxSize + nGrowBy; // granularity
else
nNewMax = nNewSize; // no slush
CBotString* pNewData = (CBotString*) new unsigned char[nNewMax * sizeof(CBotString)];
CBotString* pNewData = (CBotString*) new unsigned char[nNewMax * sizeof(CBotString)];
// copy new data from old
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
// copy new data from old
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
// construct remaining elements
ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
// construct remaining elements
ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
// Ret rid of old stuff (note: no destructors called)
delete[] (unsigned char *)m_pData;
m_pData = pNewData;
m_nSize = nNewSize;
m_nMaxSize = nNewMax;
}
// Get rid of old stuff (note: no destructors called)
delete[] (unsigned char *)m_pData;
m_pData = pNewData;
m_nSize = nNewSize;
m_nMaxSize = nNewMax;
}
}
CBotString& CBotStringArray::operator[](int nIndex)
{
return ElementAt(nIndex);
return ElementAt(nIndex);
}
CBotString& CBotStringArray::ElementAt(int nIndex)
{
return m_pData[nIndex];
return m_pData[nIndex];
}

View File

@ -464,6 +464,7 @@ bool CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
// reprend la liste des mots clefs dans les ressources
/// \todo Fixme Figure out how this should work.
void CBotToken::LoadKeyWords()
{
CBotString s;

View File

@ -10,7 +10,6 @@ CBotToken.cpp
CBotTwoOpExpr.cpp
CBotVar.cpp
CBotWhile.cpp
CBot.rc
)
add_library(CBot SHARED ${SOURCES})

View File

@ -15,98 +15,105 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by CBot.rc
//
#define ID_KEYWORDS 2000
#define ID_IF 2000
#define ID_ELSE 2001
#define ID_WHILE 2002
#define ID_DO 2003
#define ID_FOR 2004
#define ID_BREAK 2005
#define ID_CONTINUE 2006
#define ID_SWITCH 2007
#define ID_CASE 2008
#define ID_DEFAULT 2009
#define ID_TRY 2010
#define ID_THROW 2011
#define ID_CATCH 2012
#define ID_FINALLY 2013
#define ID_TXT_AND 2014
#define ID_TXT_OR 2015
#define ID_TXT_NOT 2016
#define ID_RETURN 2017
#define ID_CLASS 2018
#define ID_EXTENDS 2019
#define ID_SYNCHO 2020
#define ID_NEW 2021
#define ID_PUBLIC 2022
#define ID_EXTERN 2023
#define ID_FINAL 2024
#define ID_STATIC 2025
#define ID_PROTECTED 2026
#define ID_PRIVATE 2027
#define ID_REPEAT 2028
#define ID_DEBUGDD 2099
#define ID_INT 2100
#define ID_FLOAT 2101
#define ID_BOOLEAN 2102
#define ID_STRING 2103
#define ID_VOID 2104
#define ID_BOOL 2105
#define ID_TRUE 2200
#define ID_FALSE 2201
#define ID_NULL 2202
#define ID_NAN 2203
#define ID_OPENPAR 2300
#define ID_CLOSEPAR 2301
#define ID_OPBLK 2302
#define ID_CLBLK 2303
#define ID_SEP 2304
#define ID_COMMA 2305
#define ID_DOTS 2306
#define ID_DOT 2307
#define ID_OPBRK 2308
#define ID_CLBRK 2309
#define ID_DBLDOTS 2310
#define ID_LOGIC 2311
#define ID_ADD 2312
#define ID_SUB 2313
#define ID_MUL 2314
#define ID_DIV 2315
#define ID_ASS 2316
#define ID_ASSADD 2317
#define ID_ASSSUB 2318
#define ID_ASSMUL 2319
#define ID_ASSDIV 2320
#define ID_ASSOR 2321
#define ID_ASSAND 2322
#define ID_ASSXOR 2323
#define ID_ASSSL 2324
#define ID_ASSSR 2325
#define ID_ASSASR 2326
#define ID_SL 2327
#define ID_SR 2328
#define ID_ASR 2329
#define ID_INC 2330
#define ID_DEC 2331
#define ID_LO 2332
#define ID_HI 2333
#define ID_LS 2334
#define ID_HS 2335
#define ID_EQ 2336
#define ID_NE 2337
#define ID_AND 2338
#define ID_XOR 2339
#define ID_OR 2340
#define ID_LOG_AND 2341
#define ID_LOG_OR 2342
#define ID_LOG_NOT 2343
#define ID_NOT 2344
#define ID_MODULO 2345
#define ID_POWER 2346
#define ID_ASSMODULO 2347
#define TX_UNDEF 4000
#define TX_NAN 4001
#ifndef _RESOURCE_H_
#define _RESOURCE_H_
enum EID
{
ID_IF = 2000,
ID_ELSE,
ID_WHILE,
ID_DO,
ID_FOR,
ID_BREAK,
ID_CONTINUE,
ID_SWITCH,
ID_CASE,
ID_DEFAULT,
ID_TRY,
ID_THROW,
ID_CATCH,
ID_FINALLY,
ID_TXT_AND,
ID_TXT_OR,
ID_TXT_NOT,
ID_RETURN,
ID_CLASS,
ID_EXTENDS,
ID_SYNCHO,
ID_NEW,
ID_PUBLIC,
ID_EXTERN,
ID_FINAL,
ID_STATIC,
ID_PROTECTED,
ID_PRIVATE,
ID_REPEAT,
ID_DEBUGDD,
ID_INT,
ID_FLOAT,
ID_BOOLEAN,
ID_STRING,
ID_VOID,
ID_BOOL,
ID_TRUE = 2200,
ID_FALSE,
ID_NULL,
ID_NAN,
ID_OPENPAR = 2300,
ID_CLOSEPAR,
ID_OPBLK,
ID_CLBLK,
ID_SEP,
ID_COMMA,
ID_DOTS,
ID_DOT,
ID_OPBRK,
ID_CLBRK,
ID_DBLDOTS,
ID_LOGIC,
ID_ADD,
ID_SUB,
ID_MUL,
ID_DIV,
ID_ASS,
ID_ASSADD,
ID_ASSSUB,
ID_ASSMUL,
ID_ASSDIV,
ID_ASSOR,
ID_ASSAND,
ID_ASSXOR,
ID_ASSSL,
ID_ASSSR,
ID_ASSASR,
ID_SL,
ID_SR,
ID_ASR,
ID_INC,
ID_DEC,
ID_LO,
ID_HI,
ID_LS,
ID_HS,
ID_EQ,
ID_NE,
ID_AND,
ID_XOR,
ID_OR,
ID_LOG_AND,
ID_LOG_OR,
ID_LOG_NOT,
ID_NOT,
ID_MODULO,
ID_POWER,
ID_ASSMODULO,
TX_UNDEF = 4000,
TX_NAN,
ID_SUPER = 6000
};
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
@ -166,15 +173,6 @@
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
#define ID_SUPER 62020
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
#endif //_RESOURCE_H_