* more fixes for gcc. thx shlainn!

This commit is contained in:
false_genesis 2008-03-24 15:18:26 +00:00
parent 12045179e4
commit a8ad601dca
43 changed files with 506 additions and 498 deletions

View File

@ -173,7 +173,7 @@ DefReturnResult DefScriptPackage::func_setscriptpermission(CmdSet& Set)
if(Set.defaultarg.empty() || Set.arg[0].empty()) if(Set.defaultarg.empty() || Set.arg[0].empty())
return r; return r;
scriptPermissionMap[Set.arg[0]] = (unsigned char)toUint64(Set.defaultarg.c_str()); scriptPermissionMap[Set.arg[0]] = (unsigned char)toUint64(Set.defaultarg);
return r; return r;
} }

View File

@ -13,13 +13,27 @@
std::string DefScriptTools::stringToLower(std::string s) std::string DefScriptTools::stringToLower(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::tolower); std::transform(s.begin(), s.end(), s.begin(), tolower);
return s; return s;
} }
std::string DefScriptTools::stringToUpper(std::string s) std::string DefScriptTools::stringToUpper(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::toupper); std::transform(s.begin(), s.end(), s.begin(), toupper);
return s;
}
std::string DefScriptTools::toString(ldbl num)
{
std::stringstream ss;
ss.setf(std::ios_base::fixed);
ss.precision(15);
ss << Round(num,15);
std::string s(ss.str());
while(s[s.length()-1]=='0')
s.erase(s.length()-1,1);
if(s[s.length()-1]=='.')
s.erase(s.length()-1,1);
return s; return s;
} }
@ -29,7 +43,7 @@ std::string DefScriptTools::stringToUpper(std::string s)
// hex numbers: 0xa56ff, 0XFF, 0xDEADBABE, etc (must begin with 0x) // hex numbers: 0xa56ff, 0XFF, 0xDEADBABE, etc (must begin with 0x)
// float numbers: 99.65, 0.025 // float numbers: 99.65, 0.025
// negative numbers: -100, -0x3d, -55.123 // negative numbers: -100, -0x3d, -55.123
ldbl DefScriptTools::toNumber(std::string str) ldbl DefScriptTools::toNumber(std::string& str)
{ {
ldbl num=0; ldbl num=0;
uint64 u=0; uint64 u=0;
@ -61,32 +75,32 @@ ldbl DefScriptTools::toNumber(std::string str)
u|=lobits; u|=lobits;
} }
else else
u = atoi64(str.c_str()); u = atoi64(str);
if(ppos!=std::string::npos) if(ppos!=std::string::npos)
{ {
std::string mantissa("0"); std::string mantissa("0");
mantissa+=str.c_str()+ppos; mantissa+=str.c_str()+ppos;
num=(ldbl)atof(mantissa.c_str()); num=(ldbl)atof(mantissa.c_str());
} }
num=(unsigned long double)num + u; num=(long double)num + u;
num=Round(num,10); num=Round(num,10);
if(negative) if(negative)
num = -num; num = -num;
return num; return num;
} }
bool DefScriptTools::isTrue(std::string s) bool DefScriptTools::isTrue(std::string& s)
{ {
if(s.empty() || s=="false" || s=="0") if(s.empty() || s=="false" || s=="0")
return false; return false;
return true; return true;
} }
uint64 DefScriptTools::toUint64(std::string str) uint64 DefScriptTools::toUint64(std::string& str)
{ {
bool negative=false; bool negative=false;
uint64 num = 0; uint64 num = 0;
@ -115,21 +129,20 @@ uint64 DefScriptTools::toUint64(std::string str)
num|=lobits; num|=lobits;
} }
else else
num = atoi64(str.c_str()); num = atoi64(str);
if(negative) if(negative)
num = (uint64)(-1) - num; // is this correct? num = (uint64)(-1) - num; // is this correct?
return num; return num;
} }
uint64 DefScriptTools::atoi64(const char *str) uint64 DefScriptTools::atoi64(std::string& str)
{ {
#if COMPILER == COMPILER_MICROSOFT uint64 l = 0;
__int64 tmp = _atoi64(str); for (size_t i = 0; i < str.size(); i++)
return tmp; {
#else l = l * 10 + str[i] - 48;
#error "Fix Me!" }
//return _atoi64(str); return l;
#endif
} }
inline long double DefScriptTools::Round(long double z,unsigned int n) inline long double DefScriptTools::Round(long double z,unsigned int n)

View File

@ -7,35 +7,22 @@ namespace DefScriptTools
{ {
std::string stringToUpper(std::string); std::string stringToUpper(std::string);
std::string stringToLower(std::string); std::string stringToLower(std::string);
ldbl toNumber(std::string); std::string toString(ldbl);
bool isTrue(std::string); inline std::string toString(double num) { return toString(ldbl(num)); }
uint64 toUint64(std::string); inline std::string toString(float num) { return toString(ldbl(num)); }
uint64 atoi64(const char*);
inline long double Round(long double z,unsigned int n);
template <class T> inline std::string toString(T num) template <class T> inline std::string toString(T num)
{ {
std::stringstream ss; std::stringstream ss;
ss << num; ss << num;
return ss.str(); return ss.str();
} }
template <ldbl> inline std::string toString(ldbl num)
{
std::stringstream ss;
ss.setf(std::ios_base::fixed);
ss.precision(15);
ss << Round(num,15);
std::string s(ss.str());
while(s[s.length()-1]=='0')
s.erase(s.length()-1,1);
if(s[s.length()-1]=='.')
s.erase(s.length()-1,1);
return s;
}
template <float> inline std::string toString(float num)
{
return toString<ldbl>(num);
}
ldbl toNumber(std::string&);
bool isTrue(std::string&);
uint64 toUint64(std::string&);
uint64 atoi64(std::string&);
inline long double Round(long double z,unsigned int n);
} }

View File

@ -99,5 +99,4 @@ void DefScript_DynamicEventMgr::Update(void)
i++; i++;
} }
} }
} }

View File

@ -173,16 +173,12 @@ bool VarSet::ReadVarsFromFile(std::string fn)
std::string VarSet::toLower(std::string s) std::string VarSet::toLower(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::tolower); std::transform(s.begin(), s.end(), s.begin(), tolower);
return s; return s;
} }
std::string VarSet::toUpper(std::string s) std::string VarSet::toUpper(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::toupper); std::transform(s.begin(), s.end(), s.begin(), toupper);
return s; return s;
} }

View File

@ -33,4 +33,4 @@ private:
}; };
#endif #endif

View File

@ -974,7 +974,7 @@ DefReturnResult DefScriptPackage::SCBBGetPackedGuid(CmdSet &Set)
DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set) DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set)
{ {
ByteBuffer *bb = bytebuffers.Get(_NormalizeVarName(Set.arg[0],Set.myname)); ByteBuffer *bb = bytebuffers.Get(_NormalizeVarName(Set.arg[0],Set.myname));
uint64 guid = DefScriptTools::toUint64(Set.defaultarg); uint64 guid = DefScriptTools::toUint64(Set.defaultarg);
if (!guid) // fast check if guid is empty (in this case mask must be 0 with no extra data) if (!guid) // fast check if guid is empty (in this case mask must be 0 with no extra data)
{ {
@ -1012,7 +1012,7 @@ DefReturnResult DefScriptPackage::SCGui(CmdSet &Set)
return false; return false;
} }
while(!ins->GetGUI() && !ins->GetGUI()->IsInitialized()) while(!ins->GetGUI() && !ins->GetGUI()->IsInitialized())
Sleep(1); ins->GetRunnable()->sleep(1);
// TODO: not sure if this piece of code will work as intended, needs some testing // TODO: not sure if this piece of code will work as intended, needs some testing
if(ins->GetWSession() && ins->GetWSession()->InWorld()) if(ins->GetWSession() && ins->GetWSession()->InWorld())

View File

@ -12,4 +12,4 @@ DefScriptFunctionTable *_GetSCTable(void);
#endif #endif

View File

@ -1,5 +1,5 @@
#include "common.h" #include "common.h"
#include "PseuGui.h" #include "PseuGUI.h"
#include "DrawObject.h" #include "DrawObject.h"
#include "PseuWoW.h" #include "PseuWoW.h"

View File

@ -22,7 +22,7 @@ struct IKeys
{ {
return code[keycode]; return code[keycode];
} }
bool pressed_once(EKEY_CODE keycode) bool pressed_once(EKEY_CODE keycode)
{ {
if(code[keycode]) if(code[keycode])
@ -32,14 +32,14 @@ struct IKeys
} }
return false; return false;
} }
void reset() void reset()
{ {
for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++) code[i] = false; for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++) code[i] = false;
} }
bool code[KEY_KEY_CODES_COUNT]; bool code[KEY_KEY_CODES_COUNT];
}; };
struct IMouse struct IMouse
@ -48,17 +48,17 @@ struct IMouse
{ {
return left; return left;
} }
bool middle_pressed() bool middle_pressed()
{ {
return middle; return middle;
} }
bool right_pressed() bool right_pressed()
{ {
return right; return right;
} }
bool left_pressed_once() bool left_pressed_once()
{ {
if(left) if(left)
@ -68,7 +68,7 @@ struct IMouse
} }
return false; return false;
} }
bool middle_pressed_once() bool middle_pressed_once()
{ {
if(middle) if(middle)
@ -78,7 +78,7 @@ struct IMouse
} }
return false; return false;
} }
bool right_pressed_once() bool right_pressed_once()
{ {
if(right) if(right)
@ -88,7 +88,7 @@ struct IMouse
} }
return false; return false;
} }
void reset() void reset()
{ {
X = 0; X = 0;
@ -98,14 +98,14 @@ struct IMouse
middle = false; middle = false;
right = false; right = false;
} }
s32 X; s32 X;
s32 Y; s32 Y;
f32 wheel; f32 wheel;
bool left; bool left;
bool middle; bool middle;
bool right; bool right;
}; };
class MyEventReceiver : public IEventReceiver class MyEventReceiver : public IEventReceiver
@ -115,7 +115,7 @@ public:
{ {
for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++) for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++)
key.code[i] = false; key.code[i] = false;
mouse.X = 0; mouse.X = 0;
mouse.Y = 0; mouse.Y = 0;
mouse.wheel = 0.0f; mouse.wheel = 0.0f;
@ -123,17 +123,17 @@ public:
mouse.middle = false; mouse.middle = false;
mouse.right = false; mouse.right = false;
} }
virtual bool OnEvent(SEvent event) virtual bool OnEvent(SEvent event)
{ {
bool value = false; bool value = false;
if (event.EventType == irr::EET_KEY_INPUT_EVENT) if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{ {
key.code[event.KeyInput.Key] = event.KeyInput.PressedDown; key.code[event.KeyInput.Key] = event.KeyInput.PressedDown;
value = true; value = true;
} }
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{ {
switch(event.MouseInput.Event) switch(event.MouseInput.Event)
@ -149,7 +149,7 @@ public:
} }
value = true; value = true;
} }
return value; return value;
} }

View File

@ -9,6 +9,7 @@ using namespace scene;
using namespace video; using namespace video;
using namespace io; using namespace io;
using namespace gui; using namespace gui;
class PseuGUI; class PseuGUI;
@ -82,4 +83,4 @@ private:
#endif #endif

View File

@ -208,7 +208,7 @@ void SceneWorld::InitTerrain(void)
mapsize = 8 * 16 * 3; // 9-1 height floats in 16 chunks per tile per axis in 3 MapTiles mapsize = 8 * 16 * 3; // 9-1 height floats in 16 chunks per tile per axis in 3 MapTiles
tilesize = UNITSIZE; tilesize = UNITSIZE;
meshsize = CHUNKSIZE*3; meshsize = (s32)CHUNKSIZE*3;
vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here? vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here?
camera->setPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos); camera->setPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos);
@ -300,16 +300,16 @@ void SceneWorld::UpdateTerrain(void)
highest = max(highest,curheight); highest = max(highest,curheight);
lowest = min(lowest,curheight); lowest = min(lowest,curheight);
} }
f32 heightdiff = highest - lowest; // f32 heightdiff = highest - lowest;
// randomize terrain color depending on height // randomize terrain color depending on height
for(s32 j=0; j<terrain->getSize().Height+1; j++) for(s32 j=0; j<terrain->getSize().Height+1; j++)
for(s32 i=0; i<terrain->getSize().Width+1; i++) for(s32 i=0; i<terrain->getSize().Width+1; i++)
{ {
curheight = terrain->getHeight(i,j); curheight = terrain->getHeight(i,j);
u32 g = (curheight / highest * 120) + 125; u32 g = (u32)(curheight / highest * 120) + 125;
u32 r = (curheight / highest * 120) + 60; u32 r = (u32)(curheight / highest * 120) + 60;
u32 b = (curheight / highest * 120) + 60; u32 b = (u32)(curheight / highest * 120) + 60;
terrain->setColor(i,j, video::SColor(255,r,g,b)); terrain->setColor(i,j, video::SColor(255,r,g,b));
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
#ifndef _HELPERDEFS_H #ifndef _HELPERDEFS_H
#define _HELPERDEFS_H #define _HELPERDEFS_H
#define GUID_HIPART(x) (*(((uint32*)&(x))+1)) #define GUID_HIPART(x) (*(((uint32*)&(x))+1))
#define GUID_LOPART(x) (*((uint32*)&(x))) #define GUID_LOPART(x) (*((uint32*)&(x)))
#define MAKE_GUID(l, h) uint64( uint32(l) | ( uint64(h) << 32 ) ) #define MAKE_GUID(l, h) uint64( uint32(l) | ( uint64(h) << 32 ) )
#define CHAT_ITEM_BEGIN_STRING "|Hitem:" #define CHAT_ITEM_BEGIN_STRING "|Hitem:"
#endif #endif

View File

@ -50,4 +50,4 @@ private:
}; };
#endif #endif

View File

@ -43,4 +43,4 @@ private:
#endif #endif

View File

@ -34,4 +34,4 @@ private:
uint8 _perm; uint8 _perm;
}; };
#endif #endif

View File

@ -11,4 +11,4 @@ Bag::Bag() : Item()
void Bag::Create(uint64 guid) void Bag::Create(uint64 guid)
{ {
Item::Create(guid); Item::Create(guid);
} }

View File

@ -234,7 +234,7 @@ void ItemProtoCache_InsertDataToSession(WorldSession *session)
buf >> proto->Delay; buf >> proto->Delay;
buf >> proto->Ammo_type; buf >> proto->Ammo_type;
buf >> (float)proto->RangedModRange; buf >> proto->RangedModRange;
for(int s = 0; s < 5; s++) for(int s = 0; s < 5; s++)
{ {
buf >> proto->Spells[s].SpellId; buf >> proto->Spells[s].SpellId;
@ -309,7 +309,7 @@ void ItemProtoCache_WriteDataToCache(WorldSession *session)
} }
uint32 total = session->objmgr.GetItemProtoCount(); uint32 total = session->objmgr.GetItemProtoCount();
fh.write((char*)&(uint32)ITEMPROTOTYPES_CACHE_VERSION,4); fh.write((char*)&ITEMPROTOTYPES_CACHE_VERSION,4);
fh.write((char*)&total,4); fh.write((char*)&total,4);
uint32 counter=0; uint32 counter=0;
@ -497,7 +497,7 @@ void CreatureTemplateCache_WriteDataToCache(WorldSession *session)
return; return;
} }
uint32 total = session->objmgr.GetCreatureTemplateCount(); uint32 total = session->objmgr.GetCreatureTemplateCount();
fh.write((char*)&(uint32)CREATURETEMPLATES_CACHE_VERSION,4); fh.write((char*)&CREATURETEMPLATES_CACHE_VERSION,4);
fh.write((char*)&total,4); fh.write((char*)&total,4);
uint32 counter=0; uint32 counter=0;
ByteBuffer buf; ByteBuffer buf;

View File

@ -29,4 +29,4 @@ private:
WorldSession *_worldSession; WorldSession *_worldSession;
}; };
#endif #endif

View File

@ -10,4 +10,4 @@ Corpse::Corpse()
void Corpse::Create(uint64 guid) void Corpse::Create(uint64 guid)
{ {
Object::Create(guid); Object::Create(guid);
} }

View File

@ -11,4 +11,4 @@ DynamicObject::DynamicObject()
void DynamicObject::Create(uint64 guid) void DynamicObject::Create(uint64 guid)
{ {
Object::Create(guid); Object::Create(guid);
} }

View File

@ -11,4 +11,4 @@ GameObject::GameObject()
void GameObject::Create(uint64 guid) void GameObject::Create(uint64 guid)
{ {
Object::Create(guid); Object::Create(guid);
} }

View File

@ -60,7 +60,7 @@ void WorldSession::_HandleItemQuerySingleResponseOpcode(WorldPacket& recvPacket)
recvPacket >> proto->Delay; recvPacket >> proto->Delay;
recvPacket >> proto->Ammo_type; recvPacket >> proto->Ammo_type;
recvPacket >> (float)proto->RangedModRange; recvPacket >> proto->RangedModRange;
for(int s = 0; s < 5; s++) for(int s = 0; s < 5; s++)
{ {
recvPacket >> proto->Spells[s].SpellId; recvPacket >> proto->Spells[s].SpellId;

View File

@ -40,4 +40,4 @@ private:
bool _mapsLoaded; bool _mapsLoaded;
}; };
#endif #endif

View File

@ -65,4 +65,4 @@ private:
}; };
#endif #endif

View File

@ -71,6 +71,4 @@ uint16 MyCharacter::GetSpellSlot(uint32 spellid)
if(i->id == spellid) if(i->id == spellid)
return i->slot; return i->slot;
return 0; return 0;
} }

View File

@ -202,4 +202,4 @@ private:
}; };
#endif #endif

View File

@ -81,4 +81,4 @@ protected:
}; };
#endif #endif

View File

@ -71,3 +71,4 @@ float World::GetPosZ(float x, float y)
logdebug("WORLD: GetPosZ() called, but no MapMgr exists (do you really use maps?)"); logdebug("WORLD: GetPosZ() called, but no MapMgr exists (do you really use maps?)");
return 0; return 0;
} }

View File

@ -21,4 +21,4 @@ private:
}; };
#endif #endif

View File

@ -45,4 +45,4 @@ private:
}; };
#endif #endif

View File

@ -19,15 +19,15 @@ void _HookSignals(void)
#endif #endif
} }
void _UnhookSignals(void) void _UnhookSignals(void)
{ {
signal(SIGINT, 0); signal(SIGINT, 0);
signal(SIGQUIT, 0); signal(SIGQUIT, 0);
signal(SIGTERM, 0); signal(SIGTERM, 0);
signal(SIGABRT, 0); signal(SIGABRT, 0);
#ifdef _WIN32 #ifdef _WIN32
signal(SIGBREAK, 0); signal(SIGBREAK, 0);
#endif #endif
} }
void _OnSignal(int s) void _OnSignal(int s)
@ -112,4 +112,4 @@ int main(int argc, char* argv[]) {
raise(SIGABRT); raise(SIGABRT);
return 1; return 1;
} }
} }

View File

@ -9,4 +9,4 @@ void abortproc(void);
void _new_handler(void); void _new_handler(void);
int main(int,char**); int main(int,char**);
#endif #endif

View File

@ -209,4 +209,4 @@ struct ADTMapChunk
}; };
#endif #endif

View File

@ -28,12 +28,12 @@ class ByteBufferException
{ {
public: public:
ByteBufferException(const char *act, uint32 rp, uint32 wp, uint32 rs, uint32 cs) ByteBufferException(const char *act, uint32 rp, uint32 wp, uint32 rs, uint32 cs)
{ {
action = act; action = act;
rpos = rp; rpos = rp;
wpos = wp; wpos = wp;
readsize = rs; readsize = rs;
cursize = cs; cursize = cs;
} }
uint32 rpos, wpos, readsize, cursize; uint32 rpos, wpos, readsize, cursize;
const char *action; const char *action;
@ -239,7 +239,7 @@ class ByteBuffer
void append(const std::string& str) void append(const std::string& str)
{ {
append((uint8 *)str.c_str(),str.size() + 1); append((const uint8 *)str.c_str(),str.size() + 1);
} }
void append(const char *src, size_t cnt) void append(const char *src, size_t cnt)
{ {

View File

@ -16,4 +16,4 @@
#endif #endif

View File

@ -49,14 +49,14 @@
// Compiler defines // Compiler defines
//////////////////////////////////// ////////////////////////////////////
#if COMPILER == COMPILER_MICROSOFT #if COMPILER == COMPILER_MICROSOFT
#define I64FMT "%016I64X" #define I64FMT "%016I64X"
#define I64FMTD "%I64u" #define I64FMTD "%I64u"
#define SI64FMTD "%I64d" #define SI64FMTD "%I64d"
#define snprintf _snprintf #define snprintf _snprintf
#define atoll __atoi64 #define atoll __atoi64
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#define strdup _strdup #define strdup _strdup
typedef __int64 int64; typedef __int64 int64;
typedef long int32; typedef long int32;
typedef short int16; typedef short int16;
@ -64,14 +64,14 @@
typedef unsigned __int64 uint64; typedef unsigned __int64 uint64;
typedef unsigned long uint32; typedef unsigned long uint32;
typedef unsigned short uint16; typedef unsigned short uint16;
typedef unsigned char uint8; typedef unsigned char uint8;
#else #else
#define stricmp strcasecmp #define stricmp strcasecmp
#define strnicmp strncasecmp #define strnicmp strncasecmp
#define I64FMT "%016llX" #define I64FMT "%016llX"
#define I64FMTD "%llu" #define I64FMTD "%llu"
#define SI64FMTD "%lld" #define SI64FMTD "%lld"
# if PLATFORM == PLATFORM_UNIX # if PLATFORM == PLATFORM_UNIX
typedef __int64_t int64; typedef __int64_t int64;
typedef __int32_t int32; typedef __int32_t int32;
typedef __int16_t int16; typedef __int16_t int16;
@ -81,8 +81,8 @@
typedef __uint16_t uint16; typedef __uint16_t uint16;
typedef __uint8_t uint8; typedef __uint8_t uint8;
typedef uint16 WORD; typedef uint16 WORD;
typedef uint32 DWORD; typedef uint32 DWORD;
# else # else
typedef long long int64; typedef long long int64;
typedef long int32; typedef long int32;
typedef short int16; typedef short int16;
@ -92,14 +92,22 @@
typedef unsigned short uint16; typedef unsigned short uint16;
typedef unsigned char uint8; typedef unsigned char uint8;
typedef unsigned short WORD; typedef unsigned short WORD;
typedef uint32 DWORD; typedef uint32 DWORD;
# endif # endif
#endif #endif
#ifndef SIGQUIT #ifndef SIGQUIT
#define SIGQUIT 3 #define SIGQUIT 3
#endif #endif
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#if COMPILER == COMPILER_MICROSOFT #if COMPILER == COMPILER_MICROSOFT
# if _MSC_VER >= 1500 # if _MSC_VER >= 1500
# define COMPILER_NAME "VC90" # define COMPILER_NAME "VC90"

View File

@ -9,8 +9,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <iostream> #include <iostream>
#include <string>
#include <string.h> #include <string.h>
#include <string>
#include <sstream> #include <sstream>
#include <list> #include <list>
#include <deque> #include <deque>

View File

@ -33,8 +33,8 @@ void log(const char *str, ...)
return; return;
va_list ap; va_list ap;
_log_setcolor(true,GREY); _log_setcolor(true,GREY);
va_start(ap, str); va_start(ap, str);
vprintf( str, ap ); vprintf( str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(true); _log_resetcolor(true);
@ -43,12 +43,12 @@ void log(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -58,8 +58,8 @@ void logdetail(const char *str, ...)
return; return;
va_list ap; va_list ap;
_log_setcolor(true,LCYAN); _log_setcolor(true,LCYAN);
va_start(ap, str); va_start(ap, str);
vprintf( str, ap ); vprintf( str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(true); _log_resetcolor(true);
@ -68,12 +68,12 @@ void logdetail(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -83,8 +83,8 @@ void logdebug(const char *str, ...)
return; return;
va_list ap; va_list ap;
_log_setcolor(true,LBLUE); _log_setcolor(true,LBLUE);
va_start(ap, str); va_start(ap, str);
vprintf( str, ap ); vprintf( str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(true); _log_resetcolor(true);
@ -94,12 +94,12 @@ void logdebug(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -109,8 +109,8 @@ void logdev(const char *str, ...)
return; return;
va_list ap; va_list ap;
_log_setcolor(true,LMAGENTA); _log_setcolor(true,LMAGENTA);
va_start(ap, str); va_start(ap, str);
vprintf( str, ap ); vprintf( str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(true); _log_resetcolor(true);
@ -120,12 +120,12 @@ void logdev(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -133,8 +133,8 @@ void logerror(const char *str, ...)
{ {
va_list ap; va_list ap;
_log_setcolor(false,LRED); _log_setcolor(false,LRED);
va_start(ap, str); va_start(ap, str);
vfprintf( stderr, str, ap ); vfprintf( stderr, str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(false); _log_resetcolor(false);
@ -143,12 +143,12 @@ void logerror(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -156,8 +156,8 @@ void logcritical(const char *str, ...)
{ {
va_list ap; va_list ap;
_log_setcolor(false,RED); _log_setcolor(false,RED);
va_start(ap, str); va_start(ap, str);
vfprintf( stderr, str, ap ); vfprintf( stderr, str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(false); _log_resetcolor(false);
@ -166,12 +166,12 @@ void logcritical(const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -181,8 +181,8 @@ void logcustom(uint8 lvl, Color color, const char *str, ...)
return; return;
va_list ap; va_list ap;
_log_setcolor(true,color); _log_setcolor(true,color);
va_start(ap, str); va_start(ap, str);
vprintf( str, ap ); vprintf( str, ap );
va_end(ap); va_end(ap);
_log_resetcolor(true); _log_resetcolor(true);
@ -191,12 +191,12 @@ void logcustom(uint8 lvl, Color color, const char *str, ...)
if(logfile) if(logfile)
{ {
fprintf(logfile, getDateString().c_str()); fprintf(logfile, getDateString().c_str());
va_start(ap, str); va_start(ap, str);
vfprintf(logfile, str, ap); vfprintf(logfile, str, ap);
fprintf(logfile, "\n" ); fprintf(logfile, "\n" );
va_end(ap); va_end(ap);
fflush(logfile); fflush(logfile);
} }
fflush(stdout); fflush(stdout);
} }
@ -205,89 +205,88 @@ void log_close()
fclose(logfile); fclose(logfile);
} }
void _log_setcolor(bool stdout_stream, Color color) void _log_setcolor(bool stdout_stream, Color color)
{ {
#if PLATFORM == PLATFORM_WIN32 #if PLATFORM == PLATFORM_WIN32
static WORD WinColorFG[Color_count] = static WORD WinColorFG[Color_count] =
{ {
0, // BLACK 0, // BLACK
FOREGROUND_RED, // RED FOREGROUND_RED, // RED
FOREGROUND_GREEN, // GREEN FOREGROUND_GREEN, // GREEN
FOREGROUND_RED | FOREGROUND_GREEN, // BROWN FOREGROUND_RED | FOREGROUND_GREEN, // BROWN
FOREGROUND_BLUE, // BLUE FOREGROUND_BLUE, // BLUE
FOREGROUND_RED | FOREGROUND_BLUE,// MAGENTA FOREGROUND_RED | FOREGROUND_BLUE,// MAGENTA
FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE
// YELLOW // YELLOW
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
// RED_BOLD // RED_BOLD
FOREGROUND_RED | FOREGROUND_INTENSITY, FOREGROUND_RED | FOREGROUND_INTENSITY,
// GREEN_BOLD // GREEN_BOLD
FOREGROUND_GREEN | FOREGROUND_INTENSITY, FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD
// MAGENTA_BOLD // MAGENTA_BOLD
FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
// CYAN_BOLD // CYAN_BOLD
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
// WHITE_BOLD // WHITE_BOLD
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
}; };
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, WinColorFG[color]); SetConsoleTextAttribute(hConsole, WinColorFG[color]);
#else #else
enum ANSITextAttr enum ANSITextAttr
{ {
TA_NORMAL=0, TA_NORMAL=0,
TA_BOLD=1, TA_BOLD=1,
TA_BLINK=5, TA_BLINK=5,
TA_REVERSE=7 TA_REVERSE=7
}; };
enum ANSIFgTextAttr enum ANSIFgTextAttr
{ {
FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE, FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW
}; };
enum ANSIBgTextAttr enum ANSIBgTextAttr
{ {
BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
BG_MAGENTA, BG_CYAN, BG_WHITE BG_MAGENTA, BG_CYAN, BG_WHITE
}; };
static uint8 UnixColorFG[Color_count] = static uint8 UnixColorFG[Color_count] =
{ {
FG_BLACK, // BLACK FG_BLACK, // BLACK
FG_RED, // RED FG_RED, // RED
FG_GREEN, // GREEN FG_GREEN, // GREEN
FG_BROWN, // BROWN FG_BROWN, // BROWN
FG_BLUE, // BLUE FG_BLUE, // BLUE
FG_MAGENTA, // MAGENTA FG_MAGENTA, // MAGENTA
FG_CYAN, // CYAN FG_CYAN, // CYAN
FG_WHITE, // WHITE FG_WHITE, // WHITE
FG_YELLOW, // YELLOW FG_YELLOW, // YELLOW
FG_RED, // LRED FG_RED, // LRED
FG_GREEN, // LGREEN FG_GREEN, // LGREEN
FG_BLUE, // LBLUE FG_BLUE, // LBLUE
FG_MAGENTA, // LMAGENTA FG_MAGENTA, // LMAGENTA
FG_CYAN, // LCYAN FG_CYAN, // LCYAN
FG_WHITE // LWHITE FG_WHITE // LWHITE
}; };
fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm",UnixColorFG[color],(color>=YELLOW&&color<Color_count ?";1":"")); fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm",UnixColorFG[color],(color>=YELLOW&&color<Color_count ?";1":""));
#endif #endif
} }
void _log_resetcolor(bool stdout_stream) void _log_resetcolor(bool stdout_stream)
{ {
#if PLATFORM == PLATFORM_WIN32 #if PLATFORM == PLATFORM_WIN32
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED ); SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED );
#else #else
fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m"); fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m");
#endif #endif
} }

View File

@ -1,23 +1,23 @@
#ifndef _LOG_H #ifndef _LOG_H
#define _LOG_H #define _LOG_H
enum Color enum Color
{ {
BLACK, BLACK,
RED, RED,
GREEN, GREEN,
BROWN, BROWN,
BLUE, BLUE,
MAGENTA, MAGENTA,
CYAN, CYAN,
GREY, GREY,
YELLOW, YELLOW,
LRED, LRED,
LGREEN, LGREEN,
LBLUE, LBLUE,
LMAGENTA, LMAGENTA,
LCYAN, LCYAN,
WHITE WHITE
}; };
void log_prepare(char *fn, char *mode); void log_prepare(char *fn, char *mode);
@ -37,4 +37,3 @@ void _log_resetcolor(bool);
const int Color_count = int(WHITE)+1; const int Color_count = int(WHITE)+1;
#endif #endif

View File

@ -11,7 +11,8 @@
# include <mmsystem.h> # include <mmsystem.h>
# include <time.h> # include <time.h>
#else #else
# include <sys/dir.h> # include <sys/dir.h>
# include <sys/stat.h>
# if defined(__FreeBSD__) || defined(__APPLE_CC__) # if defined(__FreeBSD__) || defined(__APPLE_CC__)
# include <time.h> # include <time.h>
# endif # endif
@ -25,9 +26,9 @@ void printchex(std::string in, bool spaces=true)
len=in.length(); len=in.length();
printf("["); printf("[");
if(spaces) if(spaces)
for(i=0;i<len;i++)printf("%x ",(unsigned char)in[i]); for(i=0;i<len;i++)printf("%x ",(unsigned char)in[i]);
else else
for(i=0;i<len;i++)printf("%x",(unsigned char)in[i]); for(i=0;i<len;i++)printf("%x",(unsigned char)in[i]);
printf("]\n"); printf("]\n");
} }
@ -36,21 +37,21 @@ void printchex(char *in, uint32 len, bool spaces=true)
unsigned int i; unsigned int i;
printf("["); printf("[");
if(spaces) if(spaces)
for(i=0;i<len;i++)printf("%x ",(unsigned char)in[i]); for(i=0;i<len;i++)printf("%x ",(unsigned char)in[i]);
else else
for(i=0;i<len;i++)printf("%x",(unsigned char)in[i]); for(i=0;i<len;i++)printf("%x",(unsigned char)in[i]);
printf("]\n"); printf("]\n");
} }
std::string stringToLower(std::string s) std::string stringToLower(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::tolower); std::transform(s.begin(), s.end(), s.begin(), tolower);
return s; return s;
} }
std::string stringToUpper(std::string s) std::string stringToUpper(std::string s)
{ {
std::transform(s.begin(), s.end(), s.begin(), std::toupper); std::transform(s.begin(), s.end(), s.begin(), toupper);
return s; return s;
} }
@ -171,7 +172,7 @@ bool CreateDir(const char *dir)
# else # else
// NOT tested for Linux!! whats the return value on success? // NOT tested for Linux!! whats the return value on success?
// TODO: fix me! // TODO: fix me!
result = mkdir(dir); result = mkdir(dir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif #endif
return result; return result;
} }

View File

@ -23,4 +23,4 @@ uint32 GetFileSize(const char*);
void _FixFileName(std::string&); void _FixFileName(std::string&);
std::string _PathToFileName(std::string); std::string _PathToFileName(std::string);
#endif #endif