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 # Build with debugging symbols
set(CMAKE_BUILD_TYPE debug) set(CMAKE_BUILD_TYPE debug)
# Global compile flags # Global compile flags
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall") set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall -std=gnu++0x")
# Subdirectory with sources # Subdirectory with sources
add_subdirectory(src bin) 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 // * 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/.//////////////////////////////////////////////////////////////////////
// gestion de la pile (stack)
/**
* \file CBotStack.cpp
* \brief Management of the stack
*/
#include "CBot.h" #include "CBot.h"
#include <cstdlib> #include <cstdlib>

View File

@ -13,53 +13,145 @@
// * // *
// * You should have received a copy of the GNU General Public License // * 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/./////////////////////////////////////////////////////
// gestion de chaine
// basé sur le CString de MFC //strings management
// mais moins complet
#include "CBot.h" #include "CBot.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <algorithm> #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() CBotString::CBotString()
{ {
m_ptr = NULL; // chaine vide m_ptr = NULL;
m_lg = 0; m_lg = 0;
} }
CBotString::~CBotString() 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) CBotString::CBotString(const char* p)
{ {
m_lg = strlen( p ); m_lg = strlen(p);
m_ptr = NULL; m_ptr = NULL;
if (m_lg>0) if (m_lg>0)
{ {
m_ptr = (char*)malloc(m_lg+1); m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, p); strcpy(m_ptr, p);
} }
} }
CBotString::CBotString(const CBotString& srcString) CBotString::CBotString(const CBotString& srcString)
{ {
m_lg = srcString.m_lg; m_lg = srcString.m_lg;
m_ptr = NULL; m_ptr = NULL;
if (m_lg>0) if (m_lg>0)
{ {
m_ptr = (char*)malloc(m_lg+1); m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, srcString.m_ptr); strcpy(m_ptr, srcString.m_ptr);
} }
} }
@ -67,539 +159,533 @@ CBotString::CBotString(const CBotString& srcString)
int CBotString::GivLength() int CBotString::GivLength()
{ {
if ( m_ptr == NULL ) return 0; if (m_ptr == NULL) return 0;
return strlen( m_ptr ); return strlen( m_ptr );
} }
CBotString CBotString::Left(int nCount) const CBotString CBotString::Left(int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i;
for (i = 0; i < m_lg && i < nCount && i < 1999; i++)
{
chaine[i] = m_ptr[i];
}
chaine[i] = 0 ;
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 CBotString CBotString::Right(int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i = m_lg - nCount;
if ( i < 0 ) i = 0;
int j; int i = m_lg - nCount;
for ( j = 0 ; i < m_lg && i < 1999; i++) if ( i < 0 ) i = 0;
{
chaine[j++] = m_ptr[i];
}
chaine[j] = 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 CBotString CBotString::Mid(int nFirst, int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i;
for ( i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; i++) size_t i;
{ for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i)
chaine[i] = m_ptr[i]; {
} chain[i] = m_ptr[i];
chaine[i] = 0 ; }
chain[i] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
CBotString CBotString::Mid(int nFirst) const CBotString CBotString::Mid(int nFirst) const
{ {
char chaine[2000]; char chain[2000];
int i;
for ( i = nFirst; i < m_lg && i < 1999 ; i++) size_t i;
{ for (i = nFirst; i < m_lg && i < 1999 ; ++i)
chaine[i] = m_ptr[i]; {
} chain[i] = m_ptr[i];
chaine[i] = 0 ; }
chain[i] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
int CBotString::Find(const char c) int CBotString::Find(const char c)
{ {
int i; for (size_t i = 0; i < m_lg; ++i)
for (i = 0; i < m_lg; i++) {
{ if (m_ptr[i] == c) return i;
if (m_ptr[i] == c) return i; }
} return -1;
return -1;
} }
int CBotString::Find(const char * lpsz) 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 (size_t i = 0; i <= m_lg-l; ++i)
{ {
for (j = 0; j < l; j++) for (size_t j = 0; j < l; ++j)
{ {
if (m_ptr[i+j] != lpsz[j]) goto bad; if (m_ptr[i+j] != lpsz[j]) goto bad;
} }
return i; return i;
bad:; bad:;
} }
return -1; return -1;
} }
int CBotString::ReverseFind(const char c) int CBotString::ReverseFind(const char c)
{ {
int i; int i;
for (i = m_lg-1; i >= 0; i--) for (i = m_lg-1; i >= 0; --i)
{ {
if (m_ptr[i] == c) return i; if (m_ptr[i] == c) return i;
} }
return -1; return -1;
} }
int CBotString::ReverseFind(const char * lpsz) int CBotString::ReverseFind(const char * lpsz)
{ {
int i, j; int i, j;
int l = strlen(lpsz); int l = strlen(lpsz);
for (i = m_lg-l; i >= 0; i--) for (i = m_lg-l; i >= 0; --i)
{ {
for (j = 0; j < l; j++) for (j = 0; j < l; ++j)
{ {
if (m_ptr[i+j] != lpsz[j]) goto bad; if (m_ptr[i+j] != lpsz[j]) goto bad;
} }
return i; return i;
bad:; bad:;
} }
return -1; return -1;
} }
CBotString CBotString::Mid(int start, int lg) CBotString CBotString::Mid(int start, int lg)
{ {
CBotString res; CBotString res;
if (start >= m_lg) return 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); char* p = (char*)malloc(m_lg+1);
strcpy(p, m_ptr+start); strcpy(p, m_ptr+start);
p[lg] = 0; p[lg] = 0;
res = p; res = p;
free(p); free(p);
return res; return res;
} }
void CBotString::MakeUpper() void CBotString::MakeUpper()
{ {
int i; for (size_t i = 0; i < m_lg && i < 1999 ; ++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';
char c = m_ptr[i]; }
if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
}
} }
void CBotString::MakeLower() void CBotString::MakeLower()
{ {
int i; for (size_t i = 0; i < m_lg && i < 1999 ; ++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';
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) bool CBotString::LoadString(unsigned int id)
{ {
char buffer[MAXSTRING]; const char * str = NULL;
/// \TODO implement loading strings from resources. Figure out how to do it str = MapIdToString((EID)id);
// m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING ); if (m_ptr != NULL) free(m_ptr);
if (m_ptr != NULL) free(m_ptr); m_lg = strlen(str);
m_ptr = NULL;
m_ptr = NULL; if (m_lg > 0)
if (m_lg > 0) {
{ m_ptr = (char*)malloc(m_lg+1);
m_ptr = (char*)malloc(m_lg+1); strcpy(m_ptr, str);
strcpy(m_ptr, buffer); return true;
return true; }
} return false;
return false;
} }
const CBotString& CBotString::operator=(const CBotString& stringSrc) 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_lg = stringSrc.m_lg;
m_ptr = NULL;
if (m_lg > 0) if (m_lg > 0)
{ {
m_ptr = (char*)malloc(m_lg+1); m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, stringSrc.m_ptr); strcpy(m_ptr, stringSrc.m_ptr);
} }
return *this; return *this;
} }
CBotString operator+(const CBotString& string, const char * lpsz) CBotString operator+(const CBotString& string, const char * lpsz)
{ {
CBotString s ( string ); CBotString s(string);
s += lpsz; s += lpsz;
return s; return s;
} }
const CBotString& CBotString::operator+(const CBotString& stringSrc) 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); strcpy(p, m_ptr);
char* pp = p + m_lg; char* pp = p + m_lg;
strcpy(pp, stringSrc.m_ptr); strcpy(pp, stringSrc.m_ptr);
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = p; m_ptr = p;
m_lg += stringSrc.m_lg; m_lg += stringSrc.m_lg;
return *this; return *this;
} }
const CBotString& CBotString::operator=(const char ch) 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 = (char*)malloc(2);
m_ptr[0] = ch; m_ptr[0] = ch;
m_ptr[1] = 0; m_ptr[1] = 0;
return *this; return *this;
} }
const CBotString& CBotString::operator=(const char* pString) const CBotString& CBotString::operator=(const char* pString)
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = NULL; m_ptr = NULL;
if ( pString != NULL ) if (pString != NULL)
{ {
m_lg = strlen(pString); m_lg = strlen(pString);
if (m_lg != 0) if (m_lg != 0)
{ {
m_ptr = (char*)malloc(m_lg+1); m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, pString); strcpy(m_ptr, pString);
} }
} }
return *this; return *this;
} }
const CBotString& CBotString::operator+=(const char ch) 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); if (m_ptr!=NULL) strcpy(p, m_ptr);
p[m_lg++] = ch; p[m_lg++] = ch;
p[m_lg] = 0; 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) 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); strcpy(p, m_ptr);
char* pp = p + m_lg; char* pp = p + m_lg;
strcpy(pp, str.m_ptr); 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) bool CBotString::operator==(const CBotString& str)
{ {
return Compare(str) == 0; return Compare(str) == 0;
} }
bool CBotString::operator==(const char* p) bool CBotString::operator==(const char* p)
{ {
return Compare(p) == 0; return Compare(p) == 0;
} }
bool CBotString::operator!=(const CBotString& str) bool CBotString::operator!=(const CBotString& str)
{ {
return Compare(str) != 0; return Compare(str) != 0;
} }
bool CBotString::operator!=(const char* p) bool CBotString::operator!=(const char* p)
{ {
return Compare(p) != 0; return Compare(p) != 0;
} }
bool CBotString::operator>(const CBotString& str) bool CBotString::operator>(const CBotString& str)
{ {
return Compare(str) > 0; return Compare(str) > 0;
} }
bool CBotString::operator>(const char* p) bool CBotString::operator>(const char* p)
{ {
return Compare(p) > 0; return Compare(p) > 0;
} }
bool CBotString::operator>=(const CBotString& str) bool CBotString::operator>=(const CBotString& str)
{ {
return Compare(str) >= 0; return Compare(str) >= 0;
} }
bool CBotString::operator>=(const char* p) bool CBotString::operator>=(const char* p)
{ {
return Compare(p) >= 0; return Compare(p) >= 0;
} }
bool CBotString::operator<(const CBotString& str) bool CBotString::operator<(const CBotString& str)
{ {
return Compare(str) < 0; return Compare(str) < 0;
} }
bool CBotString::operator<(const char* p) bool CBotString::operator<(const char* p)
{ {
return Compare(p) < 0; return Compare(p) < 0;
} }
bool CBotString::operator<=(const CBotString& str) bool CBotString::operator<=(const CBotString& str)
{ {
return Compare(str) <= 0; return Compare(str) <= 0;
} }
bool CBotString::operator<=(const char* p) bool CBotString::operator<=(const char* p)
{ {
return Compare(p) <= 0; return Compare(p) <= 0;
} }
bool CBotString::IsEmpty() const bool CBotString::IsEmpty() const
{ {
return (m_lg == 0); return (m_lg == 0);
} }
void CBotString::Empty() void CBotString::Empty()
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = NULL; m_ptr = NULL;
m_lg = 0; m_lg = 0;
} }
static char emptyString[] = {0}; static char emptyString[] = {0};
CBotString::operator const char * () const CBotString::operator const char * () const
{ {
if (this == NULL || m_ptr == NULL) return emptyString; if (this == NULL || m_ptr == NULL) return emptyString;
return m_ptr; return m_ptr;
} }
int CBotString::Compare(const char * lpsz) const int CBotString::Compare(const char * lpsz) const
{ {
char* p = m_ptr; char* p = m_ptr;
if (lpsz == NULL) lpsz = emptyString; if (lpsz == NULL) lpsz = emptyString;
if (m_ptr == NULL) p = emptyString; if (m_ptr == NULL) p = emptyString;
return strcmp(p, lpsz); // wcscmp 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() CBotStringArray::CBotStringArray()
{ {
m_pData = NULL; m_pData = NULL;
m_nSize = m_nMaxSize = 0; m_nSize = m_nMaxSize = 0;
} }
CBotStringArray::~CBotStringArray() CBotStringArray::~CBotStringArray()
{ {
SetSize(0); // détruit les données ! SetSize(0); // destroys data !
} }
int CBotStringArray::GivSize() int CBotStringArray::GivSize()
{ {
return m_nSize; return m_nSize;
} }
void CBotStringArray::Add(const CBotString& str) 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) static inline void ConstructElement(CBotString* pNewData)
{ {
memset(pNewData, 0, sizeof(CBotString)); memset(pNewData, 0, sizeof(CBotString));
} }
static inline void DestructElement(CBotString* pOldData) static inline void DestructElement(CBotString* pOldData)
{ {
pOldData->~CBotString(); pOldData->~CBotString();
} }
static inline void CopyElement(CBotString* pSrc, CBotString* pDest) static inline void CopyElement(CBotString* pSrc, CBotString* pDest)
{ {
*pSrc = *pDest; *pSrc = *pDest;
} }
static void ConstructElements(CBotString* pNewData, int nCount) static void ConstructElements(CBotString* pNewData, int nCount)
{ {
while (nCount--) while (nCount--)
{ {
ConstructElement(pNewData); ConstructElement(pNewData);
pNewData++; pNewData++;
} }
} }
static void DestructElements(CBotString* pOldData, int nCount) static void DestructElements(CBotString* pOldData, int nCount)
{ {
while (nCount--) while (nCount--)
{ {
DestructElement(pOldData); DestructElement(pOldData);
pOldData++; pOldData++;
} }
} }
static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount) static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
{ {
while (nCount--) while (nCount--)
{ {
*pDest = *pSrc; *pDest = *pSrc;
++pDest; ++pDest;
++pSrc; ++pSrc;
} }
} }
// sélect la taille du tableau // set the array size
void CBotStringArray::SetSize(int nNewSize) void CBotStringArray::SetSize(int nNewSize)
{ {
if (nNewSize == 0) if (nNewSize == 0)
{ {
// shrink to nothing // shrink to nothing
DestructElements(m_pData, m_nSize); DestructElements(m_pData, m_nSize);
delete[] (unsigned char *)m_pData; delete[] (unsigned char *)m_pData;
m_pData = NULL; m_pData = NULL;
m_nSize = m_nMaxSize = 0; m_nSize = m_nMaxSize = 0;
} }
else if (m_pData == NULL) else if (m_pData == NULL)
{ {
// create one with exact size // create one with exact size
m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)]; m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)];
ConstructElements(m_pData, nNewSize); ConstructElements(m_pData, nNewSize);
m_nSize = m_nMaxSize = nNewSize; m_nSize = m_nMaxSize = nNewSize;
} }
else if (nNewSize <= m_nMaxSize) else if (nNewSize <= m_nMaxSize)
{ {
// it fits // it fits
if (nNewSize > m_nSize) if (nNewSize > m_nSize)
{ {
// initialize the new elements // 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 else if (m_nSize > nNewSize) // destroy the old elements
DestructElements(&m_pData[nNewSize], m_nSize-nNewSize); DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
m_nSize = nNewSize; m_nSize = nNewSize;
} }
else else
{ {
// otherwise, grow array // otherwise, grow array
int nGrowBy; int nGrowBy;
{ {
// heuristically determine growth when nGrowBy == 0 // heuristically determine growth when nGrowBy == 0
// (this avoids heap fragmentation in many situations) // (this avoids heap fragmentation in many situations)
nGrowBy = std::min(1024, std::max(4, m_nSize / 8)); nGrowBy = std::min(1024, std::max(4, m_nSize / 8));
} }
int nNewMax; int nNewMax;
if (nNewSize < m_nMaxSize + nGrowBy) if (nNewSize < m_nMaxSize + nGrowBy)
nNewMax = m_nMaxSize + nGrowBy; // granularity nNewMax = m_nMaxSize + nGrowBy; // granularity
else else
nNewMax = nNewSize; // no slush 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 // copy new data from old
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
// construct remaining elements // construct remaining elements
ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize); ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
// Ret rid of old stuff (note: no destructors called) // Get rid of old stuff (note: no destructors called)
delete[] (unsigned char *)m_pData; delete[] (unsigned char *)m_pData;
m_pData = pNewData; m_pData = pNewData;
m_nSize = nNewSize; m_nSize = nNewSize;
m_nMaxSize = nNewMax; m_nMaxSize = nNewMax;
} }
} }
CBotString& CBotStringArray::operator[](int nIndex) CBotString& CBotStringArray::operator[](int nIndex)
{ {
return ElementAt(nIndex); return ElementAt(nIndex);
} }
CBotString& CBotStringArray::ElementAt(int 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 // reprend la liste des mots clefs dans les ressources
/// \todo Fixme Figure out how this should work.
void CBotToken::LoadKeyWords() void CBotToken::LoadKeyWords()
{ {
CBotString s; CBotString s;

View File

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