Moving global files function from CBotProgram.cpp to CBotFileUtils.cpp.
parent
889c0fbe8e
commit
751999064b
|
@ -50,21 +50,6 @@ class CBotWhile; // while (...) {...};
|
||||||
class CBotIf; // if (...) {...} else {...}
|
class CBotIf; // if (...) {...} else {...}
|
||||||
class CBotDefParam; // paramerer list of a function
|
class CBotDefParam; // paramerer list of a function
|
||||||
|
|
||||||
|
|
||||||
extern bool SaveVar(FILE* pf, CBotVar* pVar);
|
|
||||||
|
|
||||||
extern bool WriteWord(FILE* pf, unsigned short w);
|
|
||||||
extern bool ReadWord(FILE* pf, unsigned short& w);
|
|
||||||
extern bool ReadLong(FILE* pf, long& w);
|
|
||||||
extern bool WriteFloat(FILE* pf, float w);
|
|
||||||
extern bool WriteLong(FILE* pf, long w);
|
|
||||||
extern bool ReadFloat(FILE* pf, float& w);
|
|
||||||
extern bool ReadString(FILE* pf, CBotString& s);
|
|
||||||
extern bool WriteType(FILE* pf, CBotTypResult type);
|
|
||||||
extern bool ReadType(FILE* pf, CBotTypResult& type);
|
|
||||||
|
|
||||||
extern float GetNumFloat( const char* p );
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
extern void DEBUG( const char* text, int val, CBotStack* pile );
|
extern void DEBUG( const char* text, int val, CBotStack* pile );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
#include "CBotCStack.h"
|
#include "CBotCStack.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
#include "CBotCallMethode.h"
|
#include "CBotCallMethode.h"
|
||||||
|
|
||||||
#include "CBotVar/CBotVar.h"
|
#include "CBotVar/CBotVar.h"
|
||||||
|
|
|
@ -20,6 +20,11 @@
|
||||||
// Modules inlcude
|
// Modules inlcude
|
||||||
#include "CBotFileUtils.h"
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
|
#include "CBotString.h"
|
||||||
|
#include "CBotClass.h"
|
||||||
|
|
||||||
|
#include "CBotEnums.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
@ -60,3 +65,111 @@ std::size_t fRead(void *buffer,
|
||||||
{
|
{
|
||||||
return fread(buffer, elemsize, length, filehandle);
|
return fread(buffer, elemsize, length, filehandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ReadWord(FILE* pf, unsigned short& w)
|
||||||
|
{
|
||||||
|
size_t lg;
|
||||||
|
|
||||||
|
lg = fread(&w, sizeof( unsigned short ), 1, pf );
|
||||||
|
|
||||||
|
return (lg == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ReadFloat(FILE* pf, float& w)
|
||||||
|
{
|
||||||
|
size_t lg;
|
||||||
|
|
||||||
|
lg = fread(&w, sizeof( float ), 1, pf );
|
||||||
|
|
||||||
|
return (lg == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool WriteLong(FILE* pf, long w)
|
||||||
|
{
|
||||||
|
size_t lg;
|
||||||
|
|
||||||
|
lg = fwrite(&w, sizeof( long ), 1, pf );
|
||||||
|
|
||||||
|
return (lg == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ReadLong(FILE* pf, long& w)
|
||||||
|
{
|
||||||
|
size_t lg;
|
||||||
|
|
||||||
|
lg = fread(&w, sizeof( long ), 1, pf );
|
||||||
|
|
||||||
|
return (lg == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ReadString(FILE* pf, CBotString& s)
|
||||||
|
{
|
||||||
|
unsigned short w;
|
||||||
|
char buf[1000];
|
||||||
|
size_t lg1, lg2;
|
||||||
|
|
||||||
|
if (!ReadWord(pf, w)) return false;
|
||||||
|
lg1 = w;
|
||||||
|
lg2 = fread(buf, 1, lg1, pf );
|
||||||
|
buf[lg2] = 0;
|
||||||
|
|
||||||
|
s = buf;
|
||||||
|
return (lg1 == lg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool WriteType(FILE* pf, CBotTypResult type)
|
||||||
|
{
|
||||||
|
int typ = type.GetType();
|
||||||
|
if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
|
||||||
|
if ( !WriteWord(pf, typ) ) return false;
|
||||||
|
if ( typ == CBotTypClass )
|
||||||
|
{
|
||||||
|
CBotClass* p = type.GetClass();
|
||||||
|
if ( !WriteString(pf, p->GetName()) ) return false;
|
||||||
|
}
|
||||||
|
if ( type.Eq( CBotTypArrayBody ) ||
|
||||||
|
type.Eq( CBotTypArrayPointer ) )
|
||||||
|
{
|
||||||
|
if ( !WriteWord(pf, type.GetLimite()) ) return false;
|
||||||
|
if ( !WriteType(pf, type.GetTypElem()) ) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ReadType(FILE* pf, CBotTypResult& type)
|
||||||
|
{
|
||||||
|
unsigned short w, ww;
|
||||||
|
if ( !ReadWord(pf, w) ) return false;
|
||||||
|
type.SetType(w);
|
||||||
|
|
||||||
|
if ( type.Eq( CBotTypIntrinsic ) )
|
||||||
|
{
|
||||||
|
type = CBotTypResult( w, "point" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.Eq( CBotTypClass ) )
|
||||||
|
{
|
||||||
|
CBotString s;
|
||||||
|
if ( !ReadString(pf, s) ) return false;
|
||||||
|
type = CBotTypResult( w, s );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.Eq( CBotTypArrayPointer ) ||
|
||||||
|
type.Eq( CBotTypArrayBody ) )
|
||||||
|
{
|
||||||
|
CBotTypResult r;
|
||||||
|
if ( !ReadWord(pf, ww) ) return false;
|
||||||
|
if ( !ReadType(pf, r) ) return false;
|
||||||
|
type = CBotTypResult( w, r );
|
||||||
|
type.SetLimite(static_cast<short>(ww));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -20,12 +20,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Modules inlcude
|
// Modules inlcude
|
||||||
|
#include "CBotTypResult.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
|
class CBotVar;
|
||||||
|
class CBotString;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// routines for file management (* FILE)
|
// routines for file management (* FILE)
|
||||||
|
|
||||||
|
@ -69,3 +74,83 @@ std::size_t fRead(void *buffer,
|
||||||
std::size_t elemsize,
|
std::size_t elemsize,
|
||||||
std::size_t length,
|
std::size_t length,
|
||||||
FILE* filehandle);
|
FILE* filehandle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief SaveVar
|
||||||
|
* \param pf
|
||||||
|
* \param pVar
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool SaveVar(FILE* pf, CBotVar* pVar);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief WriteWord
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool WriteWord(FILE* pf, unsigned short w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ReadWord
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool ReadWord(FILE* pf, unsigned short& w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ReadLong
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool ReadLong(FILE* pf, long& w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief WriteFloat
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool WriteFloat(FILE* pf, float w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief WriteLong
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool WriteLong(FILE* pf, long w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ReadFloat
|
||||||
|
* \param pf
|
||||||
|
* \param w
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool ReadFloat(FILE* pf, float& w);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ReadString
|
||||||
|
* \param pf
|
||||||
|
* \param s
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool ReadString(FILE* pf, CBotString& s);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief WriteType
|
||||||
|
* \param pf
|
||||||
|
* \param type
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool WriteType(FILE* pf, CBotTypResult type);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ReadType
|
||||||
|
* \param pf
|
||||||
|
* \param type
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool ReadType(FILE* pf, CBotTypResult& type);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "CBotCStack.h"
|
#include "CBotCStack.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
#include "CBotUtils.h"
|
#include "CBotUtils.h"
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
#include "CBotInstr/CBotFunction.h"
|
#include "CBotInstr/CBotFunction.h"
|
||||||
|
|
||||||
|
@ -385,113 +386,6 @@ bool CBotProgram::AddFunction(const char* name,
|
||||||
return CBotCall::AddFunction(name, rExec, rCompile);
|
return CBotCall::AddFunction(name, rExec, rCompile);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool ReadWord(FILE* pf, unsigned short& w)
|
|
||||||
{
|
|
||||||
size_t lg;
|
|
||||||
|
|
||||||
lg = fread(&w, sizeof( unsigned short ), 1, pf );
|
|
||||||
|
|
||||||
return (lg == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool ReadFloat(FILE* pf, float& w)
|
|
||||||
{
|
|
||||||
size_t lg;
|
|
||||||
|
|
||||||
lg = fread(&w, sizeof( float ), 1, pf );
|
|
||||||
|
|
||||||
return (lg == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool WriteLong(FILE* pf, long w)
|
|
||||||
{
|
|
||||||
size_t lg;
|
|
||||||
|
|
||||||
lg = fwrite(&w, sizeof( long ), 1, pf );
|
|
||||||
|
|
||||||
return (lg == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool ReadLong(FILE* pf, long& w)
|
|
||||||
{
|
|
||||||
size_t lg;
|
|
||||||
|
|
||||||
lg = fread(&w, sizeof( long ), 1, pf );
|
|
||||||
|
|
||||||
return (lg == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool ReadString(FILE* pf, CBotString& s)
|
|
||||||
{
|
|
||||||
unsigned short w;
|
|
||||||
char buf[1000];
|
|
||||||
size_t lg1, lg2;
|
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false;
|
|
||||||
lg1 = w;
|
|
||||||
lg2 = fread(buf, 1, lg1, pf );
|
|
||||||
buf[lg2] = 0;
|
|
||||||
|
|
||||||
s = buf;
|
|
||||||
return (lg1 == lg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool WriteType(FILE* pf, CBotTypResult type)
|
|
||||||
{
|
|
||||||
int typ = type.GetType();
|
|
||||||
if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
|
|
||||||
if ( !WriteWord(pf, typ) ) return false;
|
|
||||||
if ( typ == CBotTypClass )
|
|
||||||
{
|
|
||||||
CBotClass* p = type.GetClass();
|
|
||||||
if ( !WriteString(pf, p->GetName()) ) return false;
|
|
||||||
}
|
|
||||||
if ( type.Eq( CBotTypArrayBody ) ||
|
|
||||||
type.Eq( CBotTypArrayPointer ) )
|
|
||||||
{
|
|
||||||
if ( !WriteWord(pf, type.GetLimite()) ) return false;
|
|
||||||
if ( !WriteType(pf, type.GetTypElem()) ) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool ReadType(FILE* pf, CBotTypResult& type)
|
|
||||||
{
|
|
||||||
unsigned short w, ww;
|
|
||||||
if ( !ReadWord(pf, w) ) return false;
|
|
||||||
type.SetType(w);
|
|
||||||
|
|
||||||
if ( type.Eq( CBotTypIntrinsic ) )
|
|
||||||
{
|
|
||||||
type = CBotTypResult( w, "point" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( type.Eq( CBotTypClass ) )
|
|
||||||
{
|
|
||||||
CBotString s;
|
|
||||||
if ( !ReadString(pf, s) ) return false;
|
|
||||||
type = CBotTypResult( w, s );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( type.Eq( CBotTypArrayPointer ) ||
|
|
||||||
type.Eq( CBotTypArrayBody ) )
|
|
||||||
{
|
|
||||||
CBotTypResult r;
|
|
||||||
if ( !ReadWord(pf, ww) ) return false;
|
|
||||||
if ( !ReadType(pf, r) ) return false;
|
|
||||||
type = CBotTypResult( w, r );
|
|
||||||
type.SetLimite(static_cast<short>(ww));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "CBotVar/CBotVarPointer.h"
|
#include "CBotVar/CBotVarPointer.h"
|
||||||
#include "CBotVar/CBotVarClass.h"
|
#include "CBotVar/CBotVarClass.h"
|
||||||
|
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "CBotVarArray.h"
|
#include "CBotVarArray.h"
|
||||||
#include "CBotVarClass.h"
|
#include "CBotVarClass.h"
|
||||||
|
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "CBotStack.h"
|
#include "CBotStack.h"
|
||||||
#include "CBotDefines.h"
|
#include "CBotDefines.h"
|
||||||
|
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
#include "CBotInstr/CBotInstr.h"
|
#include "CBotInstr/CBotInstr.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
#include "CBotClass.h"
|
#include "CBotClass.h"
|
||||||
#include "CBotVarClass.h"
|
#include "CBotVarClass.h"
|
||||||
|
|
||||||
|
#include "CBotFileUtils.h"
|
||||||
|
|
||||||
// Local include
|
// Local include
|
||||||
|
|
||||||
// Global include
|
// Global include
|
||||||
|
|
Loading…
Reference in New Issue