Merge and a few cleanup / bug fixes

This commit is contained in:
KimLS
2013-05-23 12:35:00 -07:00
26 changed files with 107 additions and 112 deletions
-1
View File
@@ -315,7 +315,6 @@ INCLUDE_DIRECTORIES(Patches SocketLib StackWalker TinyXML)
ADD_LIBRARY(Common ${common_sources} ${common_headers})
IF(UNIX)
ADD_DEFINITIONS(-fPIC)
SET_SOURCE_FILES_PROPERTIES("patches/SoD.cpp" "patches/SoF.cpp" "patches/RoF.cpp" "patches/Underfoot.cpp" PROPERTIES COMPILE_FLAGS -O0)
-1
View File
@@ -20,7 +20,6 @@
#include <iomanip>
#include <iostream>
#include <vector>
#include <time.h>
#include <sys/types.h>
#ifdef _WINDOWS
#include <time.h>
+7 -7
View File
@@ -39,16 +39,16 @@ void MakeUpperString(const char *source, char *target);
void MakeLowerString(const char *source, char *target);
int MakeAnyLenString(char** ret, const char* format, ...);
uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...);
int MakeAnyLenString(char** ret, const char* format, ...);
uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...);
uint32 hextoi(char* num);
uint64 hextoi64(char* num);
bool atobool(char* iBool);
uint32 hextoi(char* num);
uint64 hextoi64(char* num);
bool atobool(char* iBool);
char* strn0cpy(char* dest, const char* source, uint32 size);
char* strn0cpy(char* dest, const char* source, uint32 size);
// return value =true if entire string(source) fit, false if it was truncated
bool strn0cpyt(char* dest, const char* source, uint32 size);
bool strn0cpyt(char* dest, const char* source, uint32 size);
char *CleanMobName(const char *in, char *out);
+34 -48
View File
@@ -1,5 +1,3 @@
#include "debug.h"
#include <iostream>
#include <string>
#include <cstdarg>
@@ -12,16 +10,18 @@
#define vsnprintf _vsnprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <sys/types.h>
#include <unistd.h>
#endif
#include "../common/StringUtil.h"
#include "../common/MiscFunctions.h"
#include "../common/platform.h"
#include "debug.h"
#include "StringUtil.h"
#include "MiscFunctions.h"
#include "platform.h"
#ifndef va_copy
#define va_copy(d,s) ((d) = (s))
@@ -75,7 +75,6 @@ EQEMuLog::~EQEMuLog() {
}
bool EQEMuLog::open(LogIDs id) {
if (!logFileValid) {
return false;
}
@@ -91,40 +90,36 @@ bool EQEMuLog::open(LogIDs id) {
return true;
}
std::string filename = FileNames[id];
char exename[200] = "";
const EQEmuExePlatform &platform = GetExecutablePlatform();
if(platform == ExePlatformWorld) {
filename.append("_world");
snprintf(exename, sizeof(exename), "_world");
} else if(platform == ExePlatformZone) {
filename.append("_zone");
snprintf(exename, sizeof(exename), "_zone");
} else if(platform == ExePlatformLaunch) {
filename.append("_launch");
snprintf(exename, sizeof(exename), "_launch");
} else if(platform == ExePlatformUCS) {
filename.append("_ucs");
snprintf(exename, sizeof(exename), "_ucs");
} else if(platform == ExePlatformQueryServ) {
filename.append("_queryserv");
snprintf(exename, sizeof(exename), "_queryserv");
} else if(platform == ExePlatformSharedMemory) {
filename.append("_shared_memory");
snprintf(exename, sizeof(exename), "_shared_memory");
}
char filename[200];
#ifndef NO_PIDLOG
// According to http://msdn.microsoft.com/en-us/library/vstudio/ee404875(v=vs.100).aspx
// Visual Studio 2010 doesn't have std::to_string(int) but it does have one for
// long long. Oh well, it works fine and formats perfectly acceptably.
filename.append(std::to_string((long long)getpid()));
snprintf(filename, sizeof(filename), "%s%s_%04i.log", FileNames[id], exename, getpid());
#else
snprintf(filename, sizeof(filename), "%s%s.log", FileNames[id], exename);
#endif
filename.append(".log");
fp[id] = fopen(filename.c_str(), "a");
fp[id] = fopen(filename, "a");
if (!fp[id]) {
std::cerr << "Failed to open log file: " << filename << std::endl;
pLogStatus[id] |= 4; // set file state to error
return false;
}
fputs("---------------------------------------------\n",fp[id]);
write(id, "Starting Log: %s", filename.c_str());
write(id, "Starting Log: %s", filename);
return true;
}
@@ -151,54 +146,44 @@ bool EQEMuLog::write(LogIDs id, const char *fmt, ...) {
time( &aclock ); /* Get time in seconds */
newtime = localtime( &aclock ); /* Convert time to struct */
if (dofile) {
if (dofile)
#ifndef NO_PIDLOG
fprintf(fp[id], "[%02d.%02d. - %02d:%02d:%02d] ", newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#else
fprintf(fp[id], "%04i [%02d.%02d. - %02d:%02d:%02d] ", getpid(), newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#endif
}
va_list argptr,tmpargptr;
va_list argptr, tmpargptr;
va_start(argptr, fmt);
if (dofile) {
va_start(argptr, fmt);
va_copy(tmpargptr,argptr);
va_copy(tmpargptr, argptr);
vfprintf( fp[id], fmt, tmpargptr );
va_end(tmpargptr);
}
if(logCallbackFmt[id]) {
msgCallbackFmt p = logCallbackFmt[id];
va_start(argptr, fmt);
va_copy(tmpargptr,argptr);
va_copy(tmpargptr, argptr);
p(id, fmt, tmpargptr );
va_end(tmpargptr);
}
std::string outputMessage;
va_start(argptr, fmt);
va_copy(tmpargptr,argptr);
vStringFormat(outputMessage, fmt, tmpargptr);
va_end(tmpargptr);
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8) {
std::cerr << "[" << LogNames[id] << "] ";
std::cerr << outputMessage;
fprintf(stderr, "[%s] ", LogNames[id]);
vfprintf( stderr, fmt, argptr );
}
else {
std::cout << "[" << LogNames[id] << "] ";
std::cout << outputMessage;
fprintf(stdout, "[%s] ", LogNames[id]);
vfprintf( stdout, fmt, argptr );
}
}
va_end(argptr);
if (dofile)
fprintf(fp[id], "\n");
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8) {
std::cerr << std::endl;
fprintf(stderr, "\n");
fflush(stderr);
} else {
std::cout << std::endl;
fprintf(stdout, "\n");
fflush(stdout);
}
}
if(dofile)
@@ -462,3 +447,4 @@ void EQEMuLog::SetAllCallbacks(msgCallbackPva proc) {
SetCallback((LogIDs)r, proc);
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ RDTSC_Timer::RDTSC_Timer(bool start_it) {
}
int64 RDTSC_Timer::rdtsc() {
int64 res;
int64 res = 0;
#ifdef USE_RDTSC
#ifndef WIN64
#ifdef WIN32