* fixed line-end problems in different platforms

* one more toNumber() -> toUint64() fix
* fixed logging from DefScript not only to console, but also to logfile (errors and such) - coloring included
* fixed: display correct image of currently used video driver on startup ;)
- thx shlainn for 1 & 4
This commit is contained in:
false_genesis 2008-03-28 14:03:46 +00:00
parent fce0efcfc2
commit de92dd9fc4
12 changed files with 94 additions and 66 deletions

View File

@ -12,6 +12,7 @@ using namespace DefScriptTools;
#define SN_ONLOAD "?onload?"
enum DefScriptBlockType
{
BLOCK_IF,
@ -21,9 +22,6 @@ enum DefScriptBlockType
// --- SECTION FOR SCRIPT PACKAGES ---
DefScriptPackage::DefScriptPackage()
{
SetLog(printf);
SetDebugLog(printf);
SetErrorLog(printf);
_DEFSC_DEBUG
(
hLogfile.open("DefScriptLog.txt",std::ios_base::out);
@ -44,30 +42,6 @@ DefScriptPackage::~DefScriptPackage()
_DEFSC_DEBUG(hLogfile.close());
}
void DefScriptPackage::Log(const char* fmt,...)
{
va_list ap;
va_start(ap, fmt);
(*_slog)(fmt,ap);
va_end(ap);
}
void DefScriptPackage::DebugLog(const char* fmt,...)
{
va_list ap;
va_start(ap, fmt);
(*_sdebuglog)(fmt,ap);
va_end(ap);
}
void DefScriptPackage::ErrorLog(const char* fmt,...)
{
va_list ap;
va_start(ap, fmt);
(*_serrorlog)(fmt,ap);
va_end(ap);
}
void DefScriptPackage::SetParentMethod(void *p)
{
parentMethod = p;
@ -293,7 +267,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
while (true)
{
f.get(z);
if(z=='\n' || f.eof())
if(z=='\n' || z==10 || z==13 || f.eof()) // checking for all just to be sure
break;
line+=z;
}
@ -303,6 +277,8 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
while( !line.empty() && (line.at(0)==' ' || line.at(0)=='\t') )
line.erase(0,1);
//while( !line.empty() && (line.at(line.length()-1)==13 || line.at(line.length()-1)==10) )
// line.erase(line.length()-1);
if(line.empty())
continue;
if(line.at(0)=='/' && line.at(1)=='/')
@ -360,7 +336,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
DeleteScript(curScript->GetName());
sn = stringToLower(value);
_UpdateOrCreateScriptByName(sn);
_DEFSC_DEBUG(printf("DefScript: now loading '%s'\n",sn.c_str()));
_DEFSC_DEBUG(PRINT_DEBUG("DefScript: now loading '%s'",sn.c_str()));
curScript=Script[sn];
}
else if(label=="linestrip")
@ -476,7 +452,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
}
if(mismatch || bopen) // no bracket must be left open now
{
printf("DefScript [%s:%u]: Bracket mismatch at line '%s'\n",sn.c_str(),absline,line.c_str());
PRINT_ERROR("DefScript [%s:%u]: Bracket mismatch at line '%s'",sn.c_str(),absline,line.c_str());
continue; // continue with next line without adding the current line to script
}
@ -485,7 +461,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
f.close();
if(cantload || Blocks.size())
{
printf("DefScript: Error loading file '%s'. block mismatch?\n",fn.c_str());
PRINT_ERROR("DefScript: Error loading file '%s'. block mismatch?",fn.c_str());
DeleteScript(sn);
return false;
}
@ -615,7 +591,7 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
{
if(!Blocks.size())
{
printf("DEBUG: else-block without any block?! [%s:%u]\n",name.c_str(),i);
PRINT_ERROR("DEBUG: else-block without any block?! [%s:%u]",name.c_str(),i);
r.ok=false;
break;
}
@ -642,13 +618,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
{
if(!Blocks.size())
{
printf("DEBUG: endif without any block [%s:%u]\n",name.c_str(),i);
PRINT_ERROR("DEBUG: endif without any block [%s:%u]",name.c_str(),i);
r.ok=false;
break;
}
if(Blocks.back().type!=BLOCK_IF)
{
printf("DEBUG: endif: closed block is not an if block! [%s:%u]\n",name.c_str(),i);
PRINT_ERROR("DEBUG: endif: closed block is not an if block! [%s:%u]",name.c_str(),i);
r.ok=false;
break;
}
@ -668,13 +644,13 @@ DefReturnResult DefScriptPackage::RunScript(std::string name, CmdSet *pSet,std::
{
if(!Blocks.size())
{
printf("DEBUG: endloop without any block [%s:%u]\n",name.c_str(),i);
PRINT_ERROR("DEBUG: endloop without any block [%s:%u]",name.c_str(),i);
r.ok=false;
break;
}
if(Blocks.back().type!=BLOCK_LOOP)
{
printf("DEBUG: endloop: closed block is not a loop block! [%s:%u]\n",name.c_str(),i);
PRINT_ERROR("DEBUG: endloop: closed block is not a loop block! [%s:%u]",name.c_str(),i);
r.ok=false;
break;
}
@ -1263,3 +1239,14 @@ bool DefScriptPackage::RunScriptIfExists(std::string name,CmdSet *pSet)
}
return false;
}
void DefScriptPackage::def_print(const char *fmt, ...)
{
if(!fmt)
return;
va_list ap;
va_start(ap, fmt);
vprintf( fmt, ap );
va_end(ap);
printf("\n");
}

View File

@ -15,8 +15,6 @@
class DefScriptPackage;
class DefScript;
typedef void (*_slog_func)(const char*,...);
// general struct for if..else..endif / loop..endloop blocks
struct Def_Block
{
@ -143,18 +141,6 @@ public:
std::string EscapeString(std::string);
std::string UnescapeString(std::string);
std::string GetUnescapedVar(std::string);
// own logging functions. default is printf.
// DO NOT USE THEM YET! THEY DO NOT WORK CORRECTLY!
// need some help with this [FG]
inline void SetLog(void *ptr) { _slog=(_slog_func)ptr; }
inline void SetDebugLog(void *ptr) { _sdebuglog=(_slog_func)ptr; }
inline void SetErrorLog(void *ptr) { _serrorlog=(_slog_func)ptr; }
void Log(const char*,...);
void DebugLog(const char*,...);
void ErrorLog(const char*,...);
std::string scPath;
@ -171,12 +157,12 @@ private:
void RemoveBrackets(CmdSet&);
void UnescapeSet(CmdSet&);
std::string RemoveBracketsFromString(std::string);
void def_print(const char *fmt, ...);
void *parentMethod;
DefScript_DynamicEventMgr *_eventmgr;
std::map<std::string,DefScript*> Script;
std::map<std::string,unsigned char> scriptPermissionMap;
DefScriptFunctionTable _functable;
_slog_func _slog,_serrorlog,_sdebuglog;
_DEFSC_DEBUG(std::fstream hLogfile);
// Usable internal basic functions:

View File

@ -37,4 +37,8 @@ typedef long double ldbl;
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
#define PRINT def_print
#define PRINT_DEBUG def_print
#define PRINT_ERROR def_print
#endif

View File

@ -473,8 +473,8 @@ DefReturnResult DefScriptPackage::func_substr(CmdSet& Set)
else
{
unsigned int start,len;
len=(unsigned int)toNumber(Set.arg[0]);
start=(unsigned int)toNumber(Set.arg[1]);
len=(unsigned int)toUint64(Set.arg[0]);
start=(unsigned int)toUint64(Set.arg[1]);
if(start+len>Set.defaultarg.length())
len=Set.defaultarg.length()-start;
r.ret=Set.defaultarg.substr(start,len);
@ -502,7 +502,7 @@ DefReturnResult DefScriptPackage::func_random(CmdSet& Set)
int min,max;
min=(int)toUint64(Set.arg[0]);
max=(int)toUint64(Set.defaultarg);
r.ret=toString(ldbl( min + ( rand() % (max - min + 1)) ));
r.ret=toString(min + ( rand() % (max - min + 1)) );
return r;
}

View File

@ -92,7 +92,7 @@ bool VarSet::ReadVarsFromFile(std::string fn)
while(!fh.eof())
{
c=fh.get();
if(c=='\n' || fh.eof())
if(c=='\n' || c==13 || c==10 || fh.eof())
{
if(line.empty())
continue;

View File

@ -1235,7 +1235,41 @@ void DefScriptPackage::My_Run(std::string line, std::string username)
}
void DefScriptPackage::my_print(const char *fmt, ...)
{
if(!fmt)
return;
char buf[1000];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf,1000, fmt, ap);
va_end(ap);
log(buf);
}
void DefScriptPackage::my_print_error(const char *fmt, ...)
{
if(!fmt)
return;
char buf[1000];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf,1000, fmt, ap);
va_end(ap);
logerror(buf);
}
void DefScriptPackage::my_print_debug(const char *fmt, ...)
{
if(!fmt)
return;
char buf[1000];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf,1000, fmt, ap);
va_end(ap);
logdebug(buf);
}

View File

@ -53,4 +53,24 @@ DefReturnResult SCSwitchOpcodeHandler(CmdSet&);
DefReturnResult SCOpcodeDisabled(CmdSet&);
DefReturnResult SCSpoofWorldPacket(CmdSet&);
void my_print(const char *fmt, ...);
void my_print_error(const char *fmt, ...);
void my_print_debug(const char *fmt, ...);
#ifdef PRINT
#undef PRINT
#define PRINT my_print
#endif
#ifdef PRINT_ERROR
#undef PRINT_ERROR
#define PRINT_ERROR my_print_error
#endif
#ifdef PRINT_DEBUG
#undef PRINT_DEBUG
#define PRINT_DEBUG my_print_debug
#endif
#endif

View File

@ -11,12 +11,12 @@ SceneGuiStart::SceneGuiStart(PseuGUI *gui) : Scene(gui)
char *fn;
switch(gui->_driverType)
{
case DIRECTX8:
case DIRECTX9:
case video::EDT_DIRECT3D8:
case video::EDT_DIRECT3D9:
fn = "data/misc/directxlogo.png";
break;
case OPENGL:
case video::EDT_OPENGL:
fn = "data/misc/opengllogo.png";
break;

View File

@ -110,9 +110,6 @@ bool PseuInstance::Init(void)
_conf=new PseuInstanceConf();
_scp->SetPath(_scpdir);
_scp->SetLog(logdetail); // does anyone have an idea why log() is not accepted here?
_scp->SetDebugLog(logdebug);
_scp->SetErrorLog(logerror);
_scp->variables.Set("@version_short",_ver_short);
_scp->variables.Set("@version",_ver);

View File

@ -185,7 +185,7 @@ void ItemProtoCache_InsertDataToSession(WorldSession *session)
{
buf.clear();
fh.read((char*)&datasize,sizeof(uint32));
DEBUG(logdebug("ItemProtoCache: (%u/%u) - datasize=%u",i,total,datasize));
//DEBUG(logdebug("ItemProtoCache: (%u/%u) - datasize=%u",i,total,datasize));
buf.resize(datasize);
fh.read((char*)buf.contents(),datasize);
ItemProto *proto = new ItemProto();

View File

@ -839,7 +839,7 @@ void WorldSession::_HandleNameQueryResponseOpcode(WorldPacket& recvPacket)
uint64 pguid;
std::string pname;
recvPacket >> pguid >> pname;
if(pname.length()>12 || pname.length()<2)
if(pname.length()>MAX_PLAYERNAME_LENGTH || pname.length()<MIN_PLAYERNAME_LENGTH)
return; // playernames maxlen=12, minlen=2
// rest of the packet is not interesting for now
if(plrNameCache.AddInfo(pguid,pname))

View File

@ -54,7 +54,7 @@ void _OnSignal(int s)
void quitproc(void)
{
printf("Waiting for all instances to finish... [%u]\n",instanceList.size());
log("Waiting for all instances to finish... [%u]\n",instanceList.size());
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
{
(*i)->GetInstance()->Stop();
@ -63,7 +63,7 @@ void quitproc(void)
void abortproc(void)
{
printf("Terminating all instances... [%u]\n",instanceList.size());
log("Terminating all instances... [%u]\n",instanceList.size());
for(std::list<PseuInstanceRunnable*>::iterator i=instanceList.begin();i!=instanceList.end();i++)
{
(*i)->GetInstance()->SetFastQuit(true);